Last active
August 29, 2015 14:18
-
-
Save zelig/adcbb8cd4e9c8259327c to your computer and use it in GitHub Desktop.
local ethereum cluster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/bin/bash | |
# bash cluster <cluster_root> <number_of_clusters> <network_id> <runid> <local_IP> [[params]...] | |
# sets up a local ethereum network cluster of nodes | |
# - <n> is the number of clusters | |
# - <root> is the root directory for the cluster, the nodes are set up | |
# with datadir `<root>/00`, `<root>/01`, ... | |
# - new accounts are created for each node | |
# - they launch on port 30300, 30301, ... | |
# - they star rpc on port 8100, 8101, ... | |
# - 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 nodes log into `<root>/00.<runid>.log`, `<root>/01.<runid>.log`, ... | |
# - `<runid>` is just an arbitrary tag or index you can use to log multiple | |
# subsequent launches of the same cluster | |
# - The nodes launch in mining mode | |
# - the cluster can be killed with `killall geth` (FIXME: should record PIDs) | |
# and restarted from the same state | |
# - if you want to interact with the nodes, use rpc | |
# - you can supply additional params on the command line which will be passed | |
# to each node | |
root=$1 | |
mkdir -p $1 | |
shift | |
N=$1 | |
shift | |
network_id=$1 | |
shift | |
run_id=$1 | |
shift | |
local_ip=$1 | |
shift | |
if [ ! -f "$root/nodes" ]; then | |
for ((i=0;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.$run_id.log -loglevel 5 -mine -port 303$id --bootnodes=\"$bootnodes\"" | |
cmd="$eth" | |
echo "launching miner $i/$N ---> tail -f $root/$id.$run_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