Skip to content

Commit

Permalink
Working arbitrary node dockerized cosmos chain
Browse files Browse the repository at this point in the history
This commit generates a working arbitrary node cosmos chain after
building the required binaries from scratch. Very nice for testing.
It still needs a lot of convience features but it's working well enough
to be good for now.

Next up is the addition of the Etherum chain and deployment of the
peggy contracts.
  • Loading branch information
jkilpatr committed Jul 20, 2020
1 parent 3244646 commit 9010bbb
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 11 deletions.
8 changes: 5 additions & 3 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
FROM fedora
ENV GOPATH=/go
ENV PATH=$PATH:/go/bin
RUN dnf install -y git golang make gcc gcc-c++ which
RUN dnf install -y git golang make gcc gcc-c++ which iproute iputils procps-ng vim tmux net-tools htop
ARG REPOFOLDER
ARG NODES
ENV NODES=$NODES
ADD $REPOFOLDER /peggy
RUN pushd /peggy/module/ && make && make install
RUN pushd /peggy/ && bash tests/setup-validators.sh
CMD peggyd start
RUN pushd /peggy/ && tests/setup-validators.sh 20
CMD pushd /peggy/ && tests/run-validators.sh 20
3 changes: 2 additions & 1 deletion tests/integration-test.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ set -eux
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DOCKERFOLDER=$DIR
REPOFOLDER=$DIR/..
NODES=50
# clean up docker images system wide, this does bust caching but it also
# keeps storage requirements reasonable. Without it you won't be able to
# run the test again and again without running out of root disk space
#docker system prune -a -f

pushd $REPOFOLDER
time docker build -f $DOCKERFOLDER/Dockerfile -t peggy-test .
time docker run -it peggy-test
time docker run --cap-add=NET_ADMIN -it peggy-test
popd
31 changes: 31 additions & 0 deletions tests/run-validators.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -eux
# your gaiad binary name
BIN=peggyd
CLI=peggycli

NODES=$1

for i in $(seq 1 $NODES);
do
# add this ip for loopback dialing
ip addr add 7.7.7.$i/32 dev eth0

GAIA_HOME="--home /validator$i"
# this implicitly caps us at ~6000 nodes for this sim
# note that we start on 26656 the idea here is that the first
# node (node 1) is at the expected contact address from the gentx
# faciliating automated peer exchange
# not sure what this one does but we need to set it or we'll
# see port conflicts
LISTEN_ADDRESS="--address tcp://7.7.7.$i:26655"
RPC_ADDRESS="--rpc.laddr tcp://7.7.7.$i:26657"
P2P_ADDRESS="--p2p.laddr tcp://7.7.7.$i:26656"
ARGS="$GAIA_HOME $LISTEN_ADDRESS $RPC_ADDRESS $P2P_ADDRESS"
if [ $i -le $NODES ]; then
$BIN $ARGS start &
fi
if [ $i -gt $(($NODES - 1)) ]; then
$BIN $ARGS start
fi
done
63 changes: 56 additions & 7 deletions tests/setup-validators.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,61 @@ set -eux
# your gaiad binary name
BIN=peggyd
CLI=peggycli

NODES=$1

ALLOCATION="1000000000stake,1000000000footoken"

# first we start a genesis.json with validator 1
# validator 1 will also collect the gentx's once gnerated
STARTING_VALIDATOR=1
STARTING_VALIDATOR_HOME="--home /validator$STARTING_VALIDATOR"
# todo add git hash to chain name
$BIN init $STARTING_VALIDATOR_HOME --chain-id=peggy-test validator1
mv /validator$STARTING_VALIDATOR/config/genesis.json /genesis.json

# Sets up an arbitrary number of validators on a single machine by manipulating
# the --home parameter on gaiad
# todo add git hash to chain name
$BIN init --chain-id=peggy-test validator1
$CLI keys add --keyring-backend test validator1
KEY=$($CLI keys show validator1 -a --keyring-backend test)
$BIN add-genesis-account --keyring-backend test $KEY 1000000000stake,1000000000footoken
$BIN gentx --keyring-backend test --name validator1
$BIN collect-gentxs test
for i in $(seq 1 $NODES);
do
GAIA_HOME="--home /validator$i"
GENTX_HOME="--home-client /validator$i"
ARGS="$GAIA_HOME --keyring-backend test"
$CLI keys add $ARGS validator$i
KEY=$($CLI keys show validator$i -a $ARGS)
# move the genesis in
mkdir -p /validator$i/config/
mv /genesis.json /validator$i/config/genesis.json
$BIN add-genesis-account $ARGS $KEY $ALLOCATION
# move the genesis back out
mv /validator$i/config/genesis.json /genesis.json
done


for i in $(seq 1 $NODES);
do
cp /genesis.json /validator$i/config/genesis.json
GAIA_HOME="--home /validator$i"
GENTX_HOME="--home-client /validator$i"
ARGS="$GAIA_HOME --keyring-backend test"
# the /8 containing 7.7.7.7 is assigned to the DOD and never routable on the public internet
# we're using it in private to prevent gaia from blacklisting it as unroutable
# and allow local pex
$BIN gentx $ARGS $GENTX_HOME --name validator$i --ip 7.7.7.$i
# obviously we don't need to copy validator1's gentx to itself
if [ $i -gt 1 ]; then
cp /validator$i/config/gentx/* /validator1/config/gentx/
fi
done


$BIN collect-gentxs $STARTING_VALIDATOR_HOME test
GENTXS=$(ls /validator1/config/gentx | wc -l)
cp /validator1/config/genesis.json /genesis.json
echo "Collected $GENTXS gentx"

# put the now final genesis.json into the correct folders
for i in $(seq 1 $NODES);
do
cp /genesis.json /validator$i/config/genesis.json
done

0 comments on commit 9010bbb

Please sign in to comment.