Skip to content

Commit

Permalink
Merge pull request #88 from hypersign-protocol/3-node-network
Browse files Browse the repository at this point in the history
Running Node locally and using Docker
  • Loading branch information
arnabghose997 authored Mar 9, 2022
2 parents d489bd4 + 0854382 commit c599b10
Show file tree
Hide file tree
Showing 634 changed files with 274,914 additions and 271 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Dependency directories (remove the comment below to include it)
vue/node_modules
vue/dist
vue/src/store/generated
# vue/src/store/generated
release/
.idea/
.vscode/
Expand Down
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM golang:1.16-alpine

# Set up dependencies
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 jq

# Set working directory for the build
WORKDIR /usr/local/app

# Add source files
COPY . .

# Install minimum necessary dependencies, build persistenceCore, remove packages
RUN apk add --no-cache $PACKAGES && make build

# Install ca-certificates
RUN apk add --update ca-certificates

# Run hid-noded by default, omit entrypoint to ease using container with cli
RUN bash ./scripts/docker-node/setup.sh

# Entry for containers
ENTRYPOINT [ "bash", "./scripts/docker-node/start.sh" ]

# Expose Ports
EXPOSE 26657 1317 9090 9091 26656
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git rev-parse --short HEAD)

GOBIN = $(shell go env GOPATH)/bin

ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=hid-node \
-X github.com/cosmos/cosmos-sdk/version.AppName=hid-node \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT)

BUILD_FLAGS := -ldflags '$(ldflags)'

export GO111MODULE=on

###############################################################################
### Build ###
###############################################################################

build: go.sum
go build -mod=readonly $(BUILD_FLAGS) -o ${GOBIN}/hid-noded ./cmd/hid-noded

go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
@go mod verify

###############################################################################
### Proto ###
###############################################################################

proto-build:
./scripts/protocgen.sh
53 changes: 36 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,42 @@ Following are the prerequisites that needs to be installed:

## Get started

Clone the hid-node repository:
### Local:

```
$ git clone https://github.com/hypersign-protocol/hid-node.git
$ cd hid-node
```
Clone the hid-node repository and build the binary:

Run the following command to build the binary file and start the blockchain:
```
starport chain serve
```sh
git clone https://github.com/hypersign-protocol/hid-node.git
cd hid-node
make build
```

You now have a blockchain up and running!

The binary `hid-noded` will be generated in `$GO_PATH/bin` directory. To explore its functionalities, type `hid-noded --help` im a seperate terminal window.

To stop the blockchain, navigate to the terminal window where the blockchain is running, and hit `Ctrl+C`.
#### Running the Blockchain

To start a single-node blockchain, refer to the README.md file present in [`/scripts/localnet-single-node/README.md`](/scripts/localnet-single-node/README.md)`

### Docker:

To run a single node `hid-node` docker container, run the following:

1. Clone the repository:

```sh
git clone https://github.com/hypersign-protocol/hid-node.git
cd hid-node
```

2. Build the image:
```sh
sudo docker build -t hidnode .
```

3. Run the container:
```sh
sudo docker run -d hidnode
```

## Operations

Expand All @@ -53,7 +72,7 @@ hid-noded tx ssi create-did '{
"authentication": [
"did:hs:0f49341a-20ef-43d1-bc93-de30993e6c51#zEYJrMxWigf9boyeJMTRN4Ern8DJMoCXaLK77pzQmxVjf"
]
}' did:hs:0f49341a-20ef-43d1-bc93-de30993e6c51#zEYJrMxWigf9boyeJMTRN4Ern8DJMoCXaLK77pzQmxVjf --ver-key oVtY1xceDZQjkfwlbCEC2vgeADcxpgd27vtYasBhcM/JLR6PnPoD9jvjSJrMsMJwS7faPy5OlFCdj/kgLVZMEg== --from alice --chain-id hidnode
}' did:hs:0f49341a-20ef-43d1-bc93-de30993e6c51#zEYJrMxWigf9boyeJMTRN4Ern8DJMoCXaLK77pzQmxVjf --ver-key oVtY1xceDZQjkfwlbCEC2vgeADcxpgd27vtYasBhcM/JLR6PnPoD9jvjSJrMsMJwS7faPy5OlFCdj/kgLVZMEg== --from alice --keyring-backend test --chain-id hidnode
```
Note: While performing a CLI transaction, it is required to pass chain-id as `--chain-id hidnode` , as the default chain id set is `hid-node` which will cause the transaction to fail.

Expand Down Expand Up @@ -82,7 +101,7 @@ hid-noded tx ssi update-did '{
"authentication": [
"did:hs:0f49341a-20ef-43d1-bc93-de30993e6c51#zEYJrMxWigf9boyeJMTRN4Ern8DJMoCXaLK77pzQmxVjf"
]
}' <version-id> did:hs:0f49341a-20ef-43d1-bc93-de30993e6c51#zEYJrMxWigf9boyeJMTRN4Ern8DJMoCXaLK77pzQmxVjf --ver-key oVtY1xceDZQjkfwlbCEC2vgeADcxpgd27vtYasBhcM/JLR6PnPoD9jvjSJrMsMJwS7faPy5OlFCdj/kgLVZMEg== --from alice --chain-id hidnode
}' <version-id> did:hs:0f49341a-20ef-43d1-bc93-de30993e6c51#zEYJrMxWigf9boyeJMTRN4Ern8DJMoCXaLK77pzQmxVjf --ver-key oVtY1xceDZQjkfwlbCEC2vgeADcxpgd27vtYasBhcM/JLR6PnPoD9jvjSJrMsMJwS7faPy5OlFCdj/kgLVZMEg== --from alice --keyring-backend test --chain-id hidnode
```

The second param `<version-id>` should be the version-id of the latest DID Doc.
Expand Down Expand Up @@ -114,7 +133,7 @@ hid-noded tx ssi deactivate-did '{
"authentication": [
"did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52#z8BXg2zjwBRTrjPs7uCnkFBKrL9bPD14HxEJMENxm3CJ4"
]
}' <version-id> did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52#z8BXg2zjwBRTrjPs7uCnkFBKrL9bPD14HxEJMENxm3CJ4 --ver-key bZBUkLGChnJujYHUZ4L8PECoN2Odv6adWGXc1qVWCRVqtEx0o/FmtFZnd5pT3laR518P58TRUGY5q5KSrToSmQ== --from alice --chain-id hidnode --yes
}' <version-id> did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52#z8BXg2zjwBRTrjPs7uCnkFBKrL9bPD14HxEJMENxm3CJ4 --ver-key bZBUkLGChnJujYHUZ4L8PECoN2Odv6adWGXc1qVWCRVqtEx0o/FmtFZnd5pT3laR518P58TRUGY5q5KSrToSmQ== --from alice --keyring-backend test --chain-id hidnode --yes
```

### Resolve DID
Expand All @@ -129,17 +148,17 @@ There are two ways to resolve DID:

1. Retrieve a did Document by providing a Did ID:
```sh
curl -X GET "http://localhost:1318/hypersign-protocol/hidnode/ssi/did/did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52:" -H "accept: application/json"
curl -X GET "http://localhost:<API-PORT>/hypersign-protocol/hidnode/ssi/did/did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52:" -H "accept: application/json"
```

2. Retrieve the count and list of did Documents:
```sh
curl -X GET "http://localhost:1318/hypersign-protocol/hidnode/ssi/did" -H "accept: application/json"
curl -X GET "http://localhost:<API-PORT>/hypersign-protocol/hidnode/ssi/did" -H "accept: application/json"
```

Note: The above curl command was taken from the Swagger UI of Blockchain API, where the `did` input parameter was entered along with an extra semicolon appended, because gRPC server has issues parsing the regular DID string.

**CLI**:
```sh
hid-noded query ssi did did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52
hid-noded query ssi did did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52 --chain-id hidnode
```
6 changes: 3 additions & 3 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
accounts:
- name: alice
coins: ["20000uatom", "200000000stake"]
coins: ["20000uhid", "200000000stake"]
- name: bob
coins: ["10000uatom", "100000000stake"]
coins: ["10000uhid", "100000000stake"]
validator:
name: alice
staked: "100000000stake"
Expand All @@ -22,4 +22,4 @@ client:
path: "vue/src/store"
faucet:
name: bob
coins: ["5uatom", "100000stake"]
coins: ["5000uhid", "100000stake"]
6 changes: 3 additions & 3 deletions docs/ssi/walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ hid-noded tx ssi create-did '{
"authentication": [
"did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52#z8BXg2zjwBRTrjPs7uCnkFBKrL9bPD14HxEJMENxm3CJ4"
]
}' did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52#z8BXg2zjwBRTrjPs7uCnkFBKrL9bPD14HxEJMENxm3CJ4 --ver-key <private-key> --from alice --chain-id hidnode --yes
}' did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52#z8BXg2zjwBRTrjPs7uCnkFBKrL9bPD14HxEJMENxm3CJ4 --ver-key <private-key> --from alice --keyring-backend test --chain-id hidnode --yes
```

### Update DID
Expand Down Expand Up @@ -124,7 +124,7 @@ hid-noded tx ssi update-did '{
"authentication": [
"did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52#z8BXg2zjwBRTrjPs7uCnkFBKrL9bPD14HxEJMENxm3CJ4"
]
}' "${VERSION_ID}" did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52#z8BXg2zjwBRTrjPs7uCnkFBKrL9bPD14HxEJMENxm3CJ4 --ver-key <private-key> --from alice --chain-id hidnode --yes
}' "${VERSION_ID}" did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52#z8BXg2zjwBRTrjPs7uCnkFBKrL9bPD14HxEJMENxm3CJ4 --ver-key <private-key> --keyring-backend test --from alice --chain-id hidnode --yes
```

Here, the `${VERSION_ID}` should have the version id of the latest DID of User 2 (`did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52`)
Expand Down Expand Up @@ -154,7 +154,7 @@ hid-noded tx ssi deactivate-did '{
"authentication": [
"did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52#z8BXg2zjwBRTrjPs7uCnkFBKrL9bPD14HxEJMENxm3CJ4"
]
}' "${VERSION_ID}" did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52#z8BXg2zjwBRTrjPs7uCnkFBKrL9bPD14HxEJMENxm3CJ4 --ver-key <private-key> --from alice --chain-id hidnode --yes
}' "${VERSION_ID}" did:hs:0f49341a-20ef-43d1-bc93-de30993e6c52#z8BXg2zjwBRTrjPs7uCnkFBKrL9bPD14HxEJMENxm3CJ4 --ver-key <private-key> --keyring-backend test --from alice --chain-id hidnode --yes
```

### Resolving DID
Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions scripts/docker-node/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

echo "Setting up Chain."

# Setting up config files
rm -rf /usr/local/app/node1


# Make directories for hid-node config
mkdir /usr/local/app/node1

# Init node
hid-noded init --chain-id=hidnode node1 --home=/usr/local/app/node1 &> /dev/null

# Create key for the node
hid-noded keys add node1 --keyring-backend=test --home=/usr/local/app/node1 &> /dev/null

# change staking denom to uhid
cat /usr/local/app/node1/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="uhid"' > /usr/local/app/node1/config/tmp_genesis.json && mv /usr/local/app/node1/config/tmp_genesis.json /usr/local/app/node1/config/genesis.json

# create validator node with tokens
hid-noded add-genesis-account $(hid-noded keys show node1 -a --keyring-backend=test --home=/usr/local/app/node1) 100000000000uhid,100000000000stake --home=/usr/local/app/node1
hid-noded gentx node1 500000000uhid --keyring-backend=test --home=/usr/local/app/node1 --chain-id=hidnode
hid-noded collect-gentxs --home=/usr/local/app/node1

# update crisis variable to uhid
cat /usr/local/app/node1/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="uhid"' > /usr/local/app/node1/config/tmp_genesis.json && mv /usr/local/app/node1/config/tmp_genesis.json /usr/local/app/node1/config/genesis.json

# udpate gov genesis
cat /usr/local/app/node1/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="uhid"' > /usr/local/app/node1/config/tmp_genesis.json && mv /usr/local/app/node1/config/tmp_genesis.json /usr/local/app/node1/config/genesis.json

# update mint genesis
cat /usr/local/app/node1/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="uhid"' > /usr/local/app/node1/config/tmp_genesis.json && mv /usr/local/app/node1/config/tmp_genesis.json /usr/local/app/node1/config/genesis.json

# change app.toml values
sed -i -E '104s/enable = false/enable = true/' /usr/local/app/node1/config/app.toml
sed -i -E '107s/swagger = false/swagger = true/' /usr/local/app/node1/config/app.toml


# change config.toml values
sed -i -E 's|tcp://127.0.0.1:26658|tcp://0.0.0.0:26658|g' /usr/local/app/node1/config/config.toml
sed -i -E 's|tcp://127.0.0.1:26657|tcp://0.0.0.0:26657|g' /usr/local/app/node1/config/config.toml
sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' /usr/local/app/node1/config/config.toml
sed -i -E 's|addr_book_strict = true|addr_book_strict = false|g' /usr/local/app/node1/config/config.toml
sed -i -E 's|cors_allowed_origins = \[\]|cors_allowed_origins = \[\"\*\"\]|g' /usr/local/app/node1/config/config.toml

echo "Chain Setup is done."
4 changes: 4 additions & 0 deletions scripts/docker-node/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# Start all three nodes
hid-noded start --home=/usr/local/app/node1
33 changes: 33 additions & 0 deletions scripts/localnet-single-node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# LocalNet

## Port Configuration

- RPC: `:26657`
- P2P: `:26656`
- REST Server:`:1317`

## Prerequisite

Install the following:

- golang (ver 1.17+): https://go.dev/doc/install
- jq (`sudo apt-get install jq`)
- tmux (`sudo apt-get install tmux`)

## Running the locanet

- Setup the config files and install `hid-node` binary if it doesn't exists:
- `sh setup.sh`

- Run the localnet
- `sh start.sh`

- To display the logs of each node, run the following in a seperate terminal:

Node1: `tmux a -t node1`<br>

## Stop the localnet

```sh
sh stop.sh
```
58 changes: 58 additions & 0 deletions scripts/localnet-single-node/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

# Download the binary if it doesn't exist
hid-noded &> /dev/null

RET_VAL=$?
if [ ${RET_VAL} -ne 0 ]; then
URL_PATH="https://github.com/hypersign-protocol/hid-node/releases/download/latest/"
FILE_NAME="hid-node_latest_linux_amd64.tar.gz"
DOWNLOAD_URL="${URL_PATH}${FILE_NAME}"
echo "hid-noded binary doesn't exist, installing......"
sleep 2
wget ${DOWNLOAD_URL}
tar -xvzf hid-node_latest_linux_amd64.tar.gz
mv hid-noded $(go env GOPATH)/bin/
rm -rf ${FILE_NAME}
fi

# Setting up config files
rm -rf $HOME/.hid-node/


# Make directories for hid-node config
mkdir $HOME/.hid-node
mkdir $HOME/.hid-node/node1

# Init node
hid-noded init --chain-id=hidnode node1 --home=$HOME/.hid-node/node1

# Create key for the node
hid-noded keys add node1 --keyring-backend=test --home=$HOME/.hid-node/node1

# change staking denom to uhid
cat $HOME/.hid-node/node1/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="uhid"' > $HOME/.hid-node/node1/config/tmp_genesis.json && mv $HOME/.hid-node/node1/config/tmp_genesis.json $HOME/.hid-node/node1/config/genesis.json

# create validator node with tokens
hid-noded add-genesis-account $(hid-noded keys show node1 -a --keyring-backend=test --home=$HOME/.hid-node/node1) 100000000000uhid,100000000000stake --home=$HOME/.hid-node/node1
hid-noded gentx node1 500000000uhid --keyring-backend=test --home=$HOME/.hid-node/node1 --chain-id=hidnode
hid-noded collect-gentxs --home=$HOME/.hid-node/node1

# update crisis variable to uhid
cat $HOME/.hid-node/node1/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="uhid"' > $HOME/.hid-node/node1/config/tmp_genesis.json && mv $HOME/.hid-node/node1/config/tmp_genesis.json $HOME/.hid-node/node1/config/genesis.json

# udpate gov genesis
cat $HOME/.hid-node/node1/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="uhid"' > $HOME/.hid-node/node1/config/tmp_genesis.json && mv $HOME/.hid-node/node1/config/tmp_genesis.json $HOME/.hid-node/node1/config/genesis.json

# update mint genesis
cat $HOME/.hid-node/node1/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="uhid"' > $HOME/.hid-node/node1/config/tmp_genesis.json && mv $HOME/.hid-node/node1/config/tmp_genesis.json $HOME/.hid-node/node1/config/genesis.json

# change app.toml values
sed -i -E '104s/enable = false/enable = true/' $HOME/.hid-node/node1/config/app.toml
sed -i -E '107s/swagger = false/swagger = true/' $HOME/.hid-node/node1/config/app.toml


# change config.toml values
sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $HOME/.hid-node/node1/config/config.toml
sed -i -E 's|addr_book_strict = true|addr_book_strict = false|g' $HOME/.hid-node/node1/config/config.toml
sed -i -E 's|cors_allowed_origins = \[\]|cors_allowed_origins = \[\"\*\"\]|g' $HOME/.hid-node/node1/config/config.toml
4 changes: 4 additions & 0 deletions scripts/localnet-single-node/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# Start all three nodes
tmux new -s node1 -d hid-noded start --home=$HOME/.hid-node/node1
3 changes: 3 additions & 0 deletions scripts/localnet-single-node/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

tmux kill-session -t node1
Loading

0 comments on commit c599b10

Please sign in to comment.