Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions demo-apps/auth-chain/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:alpine

RUN apk update
RUN apk add --no-cache ca-certificates curl make git libc-dev bash gcc linux-headers eudev-dev python3

WORKDIR /auth-chain

COPY . .

RUN go get github.com/go-delve/delve/cmd/dlv
RUN make install-debug

RUN cp ./auth-chaind /usr/bin
RUN cp ./auth-chaincli /usr/bin


EXPOSE 26656 26657 1317 9090 40000
21 changes: 21 additions & 0 deletions demo-apps/auth-chain/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,28 @@ init-validator:
go run cmd/auth-chaind/main.go cmd/auth-chaind/genaccounts.go gentx --name auth-chain1 --home ./build/.auth-chaind --moniker authchain --website test.com --identity test --security-contact test@test.com --details atest
go run cmd/auth-chaind/main.go cmd/auth-chaind/genaccounts.go collect-gentxs --home ./build/.auth-chaind

install-debug: go.sum
go build -mod=readonly -gcflags="all=-N -l" ./cmd/auth-chaind
go build -mod=readonly -gcflags="all=-N -l" ./cmd/auth-chaincli

build:
@mkdir -p build/
@go build -mod=mod -o build/clayd ./cmd/clayd
@go build -mod=mod -o build/claycli ./cmd/claycli

###############################################################################
### Tests & Simulation ###
###############################################################################

localnet-consensus:
./scripts/add-validators-to-validator-set.sh

localnet-start: init-dev export-key
NODE0ADDRESS=$(shell go run cmd/auth-chaind/main.go cmd/auth-chaind/genaccounts.go tendermint show-node-id --home ./build/.auth-chaind)@192.16.10.2:26656 docker-compose up

export-key:
echo "password1234\npassword1234" | go run cmd/auth-chaincli/main.go keys export auth-chain1 2> ./build/validator

clean:
sudo rm -r ./build
docker-compose down
82 changes: 82 additions & 0 deletions demo-apps/auth-chain/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
version: "3"

services:
auth-chaindnode0:
container_name: auth-chaindnode0
image: "poa"
ports:
- "26656-26657:26656-26657"
- "1317:1317"
- "9090:9090"
- "40000:40000"
environment:
- ID=0
- LOG=${LOG:-auth-chaind.log}
volumes:
- ./build/.auth-chaind:/root/.auth-chaind
- ./build/validator:/root/validator
command: ["sh", "-c", "dlv --listen=:40000 --headless --accept-multiclient exec --continue ./auth-chaind -- start --home /root/.auth-chaind"]
networks:
localnet:
ipv4_address: 192.16.10.2

auth-chaindnode1:
container_name: auth-chaindnode1
image: "poa"
ports:
- "26666-26667:26656-26657"
- "1318:1317"
- "9091:9090"
environment:
- NODE0ADDRESS=${NODE0ADDRESS}
- ID=1
- LOG=${LOG:-auth-chaind.log}
command: ["sh", "-c", "auth-chaind init ac1 && cp genesis.json /root/.authchaind/config && sed -i 's/peers = \"\"/peers = \"$NODE0ADDRESS\"/g' /root/.authchaind/config/config.toml && auth-chaind start"]
volumes:
- ./build/.auth-chaind/config/genesis.json:/auth-chain/genesis.json
networks:
localnet:
ipv4_address: 192.16.10.3

auth-chaindnode2:
container_name: auth-chaindnode2
image: "poa"
ports:
- "26676-26677:26656-26657"
- "1319:1317"
- "9092:9090"
environment:
- NODE0ADDRESS=${NODE0ADDRESS}
- ID=1
- LOG=${LOG:-auth-chaind.log}
command: ["sh", "-c", "auth-chaind init ac2 && cp genesis.json /root/.authchaind/config && sed -i 's/peers = \"\"/peers = \"$NODE0ADDRESS\"/g' /root/.authchaind/config/config.toml && auth-chaind start"]
volumes:
- ./build/.auth-chaind/config/genesis.json:/auth-chain/genesis.json
networks:
localnet:
ipv4_address: 192.16.10.4

auth-chaindnode3:
container_name: auth-chaindnode3
image: "poa"
ports:
- "26686-26687:26656-26657"
- "1320:1317"
- "9093:9090"
environment:
- NODE0ADDRESS=${NODE0ADDRESS}
- ID=1
- LOG=${LOG:-auth-chaind.log}
command: ["sh", "-c", "auth-chaind init ac3 && cp genesis.json /root/.authchaind/config && sed -i 's/peers = \"\"/peers = \"$NODE0ADDRESS\"/g' /root/.authchaind/config/config.toml && auth-chaind start"]
volumes:
- ./build/.auth-chaind/config/genesis.json:/auth-chain/genesis.json
networks:
localnet:
ipv4_address: 192.16.10.5

networks:
localnet:
ipam:
driver: default
config:
- subnet: 192.16.10.0/16
1 change: 0 additions & 1 deletion demo-apps/auth-chain/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/allinbits/modules/demo-apps/auth-chain
go 1.15

require (
github.com/allinbits/modules/poa v0.0.0-20201006081502-d144cbfb0613
github.com/allinbits/modules/x/poa v0.0.0-20201009193500-337b33a517b1
github.com/cosmos/cosmos-sdk v0.39.1
github.com/golang/mock v1.4.3 // indirect
Expand Down
115 changes: 115 additions & 0 deletions demo-apps/auth-chain/scripts/add-validators-to-validator-set.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/sh

###############################################################################
### FUNCTIONS ###
###############################################################################

# Creates a validator for a given node
# Take 1 arg the name of the node e.g auth-chaindnode0
createValidator() {
echo "Creating validator for node $1\n"

# Create the validator
docker exec -e MONIKER=$1 $1 /bin/sh -c 'auth-chaincli tx poa create-validator $(auth-chaincli keys show validator --bech val -a --keyring-backend test) $(auth-chaind tendermint show-validator) $(echo $MONIKER) identity website security@contact details -y --trust-node --from validator --chain-id auth --keyring-backend test'

sleep 5
}

# Votes for a perspecitve canidate
# Take 2 args the name of the node voting and the candidate node e.g auth-chaindnode0 auth-chaindnode1
voteForValidator() {
eval CANDIDATE=$(docker exec $2 /bin/sh -c "auth-chaincli keys show validator --bech val -a --keyring-backend test")
echo "Voter $1 is voting for candidate $2"
docker exec -e CANDIDATE=$CANDIDATE $1 /bin/sh -c 'auth-chaincli tx poa vote-validator $(echo $CANDIDATE) -y --trust-node --from validator --chain-id auth --keyring-backend test'

sleep 5
}

# Kicks for a perspecitve canidate
# Take 2 args the name of the node voting and the candidate node e.g auth-chaindnode0 auth-chaindnode1
kickValidator() {
eval CANDIDATE=$(docker exec $2 /bin/sh -c "auth-chaincli keys show validator --bech val -a --keyring-backend test")
echo "Votee $1 is voting to kick candidate $2"
docker exec -e CANDIDATE=$CANDIDATE $1 /bin/sh -c 'auth-chaincli tx poa kick-validator $(echo $CANDIDATE) -y --trust-node --from validator --chain-id auth --keyring-backend test'

sleep 5
}
###############################################################################
### STEP 1 ###
###############################################################################

# Import the exported key for the first node
docker exec auth-chaindnode0 /bin/sh -c "echo -e 'password1234\n' | auth-chaincli keys import validator /root/validator --keyring-backend test"

## Create the validator
voteForValidator auth-chaindnode0 auth-chaindnode0

###############################################################################
### STEP 2 ###
###############################################################################

# Create the keys for each node
for var in auth-chaindnode1 auth-chaindnode2 auth-chaindnode3
do
echo "Creating key for node $var\n"
docker exec $var /bin/sh -c "auth-chaincli keys add validator --keyring-backend test"
done


## Send tokens to each validator
for node in auth-chaindnode1 auth-chaindnode2 auth-chaindnode3
do
eval ADDRESS=$(docker exec $node /bin/sh -c "auth-chaincli keys show validator -a --keyring-backend test")
echo "Sending tokens to $ADDRESS\n"
docker exec -e ADDRESS=$ADDRESS auth-chaindnode0 /bin/sh -c 'auth-chaincli tx send $(auth-chaincli keys show validator -a --keyring-backend test) $(echo $ADDRESS) 100000stake -y --trust-node --from validator --chain-id auth --keyring-backend test'
sleep 5
done

###############################################################################
### STEP 3 ###
###############################################################################

# Create validator for validator set
for var in auth-chaindnode1 auth-chaindnode2 auth-chaindnode3
do
createValidator $var
done

###############################################################################
### STEP 4 ###
###############################################################################

# Adding new validators to the set

# Vote for validator1 to join the set
voteForValidator auth-chaindnode0 auth-chaindnode1

# auth-chaindnode1 votes for auth-chaindnode0 to prove the node is in the consensus
voteForValidator auth-chaindnode1 auth-chaindnode0

# auth-chaindnode1 votes for auth-chaindnode1 to stay relevant in the consensus
voteForValidator auth-chaindnode1 auth-chaindnode1

# auth-chaindnode1 and poanode0 votes for auth-chaindnode2 to join the consensus
voteForValidator auth-chaindnode0 auth-chaindnode2
voteForValidator auth-chaindnode1 auth-chaindnode2

# auth-chaindnode2 votes for auth-chaindnode2 to stay relevant in the consensus
voteForValidator auth-chaindnode2 auth-chaindnode2

# auth-chaindnode2 votes for auth-chaindnode1 to prove the node is in the consensus
voteForValidator auth-chaindnode2 auth-chaindnode1

# auth-chaindnode2 votes for auth-chaindnode0 to prove the node is in the consensus
voteForValidator auth-chaindnode2 auth-chaindnode0

# kick auth-chaindnode2 out of the consensus
kickValidator auth-chaindnode0 auth-chaindnode2
kickValidator auth-chaindnode1 auth-chaindnode2

echo "POA Consensus started with 2 nodes :thumbs_up:\n"

sleep 5

## Verify valdiators are in the set by checking the validator set
docker exec auth-chaindnode0 /bin/sh -c "curl -X GET 'localhost:26657/validators'"