Skip to content

Instantly share code, notes, and snippets.

@zelig
Last active August 29, 2015 14:17
Show Gist options
  • Save zelig/a923ab2dda2f8a8db3b8 to your computer and use it in GitHub Desktop.
Save zelig/a923ab2dda2f8a8db3b8 to your computer and use it in GitHub Desktop.
local ethereum cluster
:) bash cluster.sh /tmp/59/01 4 1 blah
:) grep ChainHeadEvent /tmp/59/01/04.log |cut -d':' -f5,7|tr -d ',' |awk '{print $1, $3}'> /tmp/59/01/04.blox
:) grep ChainHeadEvent /tmp/59/01/03.log |cut -d':' -f5,7|tr -d ',' |awk '{print $1, $3}'> /tmp/59/01/03.blox
:) grep ChainHeadEvent /tmp/59/01/02.log |cut -d':' -f5,7|tr -d ',' |awk '{print $1, $3}'> /tmp/59/01/02.blox
:) grep ChainHeadEvent /tmp/59/01/01.log |cut -d':' -f5,7|tr -d ',' |awk '{print $1, $3}'> /tmp/59/01/01.blox
:) paste /tmp/59/01/*.blox | tail
151 5dc86dcc 151 5dc86dcc 151 5dc86dcc 151 5dc86dcc
152 3ad33047 152 3ad33047 152 3ad33047 152 3ad33047
152 92cf6e23 152 92cf6e23 152 92cf6e23 152 92cf6e23
153 b4faa0eb 153 b4faa0eb 153 b4faa0eb 153 b4faa0eb
153 2edc7f6c 153 2edc7f6c 153 2edc7f6c 153 2edc7f6c
154 4df72cf0 154 4df72cf0 154 4df72cf0 154 4df72cf0
154 2014ffd5 154 2014ffd5 154 2014ffd5 154 2014ffd5
155 ce53b892 155 ce53b892 155 ce53b892 155 ce53b892
155 dc2c19e6 155 dc2c19e6 155 dc2c19e6 155 dc2c19e6
156 27784fd5 156 27784fd5
:) killall ethereum
#!/bin/bash
# bash cluster <cluster_root> <number_of_clusters> <network_id> <local_IP> [[params]...]
#
# sets up a local ethereum network cluster of nodes
# - the nodes are set up with datadir root/00, root/01, ...
# - the nodes log into root/00.log root/01.log, ...
# - new accounts are created for each
# - the new account is unlocked when they launch
# - they launch on port 30300, 30301, ...
# - by collecting the nodes nodeUrl, they get connected to each other
# - if enode has no IP, local_IP is substituted
# - if network_id is not 0, they will not connect to a default client,
# resulting in a private isolated network
#
# the cluster can be killed with `killall ethereum` (FIXME: should record PIDs)
# and restarted from the same state
root=$1
mkdir -p $1
shift
N=$1
shift
network_id=$1
shift
local_ip=$1
shift
if [ ! -f "$root/nodes" ]; then
# typeset -i i N # let's be explicit
for ((i=1;i<=N;++i)); do
id=`printf "%02d" $i`
echo "getting enode for instance $id ($i/$N)"
eth="./geth -datadir $root/$id -logfile /dev/null -port 303$id -networkid $network_id"
cmd="$eth js <(echo 'console.log(admin.nodeInfo().NodeUrl)') "
echo $cmd
bash -c "$cmd" >> $root/nodes
echo "setting coinbase for instance $i:"
cmd="$eth -password <(echo $id) account new"
echo $cmd
bash -c "$cmd"
done
fi
bootnodes=`cat $root/nodes|tr '\n' ' '|perl -pe "s/\[\:\:\]/$local_ip/g"`
echo $bootnodes | tr ' ' '\n' | nl
for ((i=1;i<=N;++i)); do
id=`printf "%02d" $i`
eth="./geth -unlock primary -password <(echo $id) -networkid $network_id -datadir $root/$id -logfile $root/$id.log -loglevel 5 -mine -port 303$id --bootnodes=\"$bootnodes\""
cmd="$eth"
echo "launching miner $i/$N \t tail -f $root/$id.log"
echo $cmd $*
bash -c "$cmd $* &"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment