Skip to content
Snippets Groups Projects
Commit b6df3357 authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

Moving things around and making scripts simpler (more logic in libbfa.sh)

parent 36eac7a1
No related branches found
No related tags found
No related merge requests found
export BFAHOME=${HOME}/bfa
BFAHOME=${HOME}/bfa
BFANETWORKDIR/${BFAHOME}/network5445
......@@ -52,43 +52,84 @@ function geth_exec_js
echo $out
}
function getnetworkid
{
local dir="${BFANETWORKDIR}" for dir in $( ls -1d "${BFAHOME}"/* | sort --version-sort )
do
if [ -d "${dir}" ]
then
local base=$( basename "${dir}" )
base=$( echo "${base}" | grep -E '^network[0-9]+$' )
if [ -n "$base" ]
then
BFANETWORKID=${network:7}
return
fi
fi
done
}
function networkdir
{
test -z "${BFAHOME}" -o ! -d "${BFAHOME}" ||
fatal "\$BFAHOME in your environment must point to a directory."
local creating=0
# If no BFANETWORKDIR variable has been set, we will try to guess
# the network directory based on the directory we are in.
if [ -n "${BFANETWORKDIR}" ]
if [ -z "${BFANETWORKDIR}" ]
then
test -d "${BFANETWORKDIR}" ||
fatal "\$BFANETWORKDIR (\"${BFANETWORKDIR}\") not found."
else
local basedir=$( basename $PWD )
if $( echo "${basedir}" | grep -qE '^network[0-9]+$' )
then
BFANETWORKDIR="$basedir"
fi
if [ -z "${BFANETWORKDIR}" ]
then
local num=0
while [ $num -lt 9876 ]
do
num=$(( $RANDOM * $RANDOM ))
done
stderr "I can't find your BFANETWORKDIR."
fatal "Consider running: mkdir ${BFAHOME}/network${num}"
fi
BFANETWORKDIR=$(
ls -1d "${BFAHOME}"/* |
grep -qE '/network[0-9]+$' |
sort --version-sort |
head -1
)
fi
if [ -n "${BFANETWORKDIR}" -a ! -d "${BFANETWORKDIR}" ]
fatal "\$BFANETWORKDIR (\"${BFANETWORKDIR}\") not found."
fi
if [ -z "${BFANETWORKDIR}" -o ! -d "${BFANETWORKDIR}" ]
then
local num=0
while [ $num -lt 9876 ]
do
num=$(( $RANDOM * $RANDOM ))
done
stderr "I can not find your BFANETWORKDIR."
stderr "Consider running: mkdir ${BFAHOME}/network${num} or set BFANETWORKDIR in ${BFAHOME}/bin/env"
exit 1
fi
# Get network id
BFANETWORKID=${BFANETWORKDIR:7}
}
function nodedir
{
networkdir
# set defaults
true ${BFANODEDIR:=${BFAHOME}/node1}
test -n "${BFANODEDIR}"
test -d "${BFANODEDIR}"
if [ -z "$BFANODEDIR" ]
then
# If there is no nodedir found, use the first node we
# find in the networkdir
BFANODEDIR=$(
ls -1d "${BFANETWORKDIR}"/*/keystore |
sort --version-sort |
head -1
)
# Get rid of the keystore label
BFANODEDIR=$( dirname $BFANODEDIR )
fi
test -n "${BFANODEDIR}" ||
fatal "Unable to guess \$BFANODEDIR . Consider setting it explicitly in ${BFAHOME}/bin/env"
test -d "${BFANODEDIR}" ||
fatal "$BFANODEDIR is not a directory."
test -d "${BFANODEDIR}/geth/chaindata" ||
fatal "Node is not initialised. Consider running: geth --datadir $BFANODEDIR init ${BFANETWORKDIR}/genesis.json"
test -r "${BFANODEDIR}/port" ||
echo $(( $RANDOM / 2 + 12345 )) > ${BFANODEDIR}/tcpport
httpport=$( cat ${BFANODEDIR}/tcpport )
test -r "${BFANODEDIR}/rpcport" ||
echo $(( $RANDOM / 2 + 12345 )) > ${BFANODEDIR}/rpcport
rpcport=$( cat ${BFANODEDIR}/rpcport )
}
function account
......@@ -99,7 +140,10 @@ function account
test -d "${BFANODEDIR}/keystore"
account=$( ls -1dl "${BFANODEDIR}"/keystore/*--* | head -1 | sed 's/.*--//' )
fi
test -n "$account"
if [ -n "$account" ]
then
fatal "No accounts found. Consider running: geth --datadir ${BFANETWORKDIR}/node1 --password /dev/null account new"
fi
}
function bfaconfig
......
#!/bin/bash
true ${MAXSIZE:=$((10*1024*1024))}
log=$1
test -n "$log" ||
log=log
exec >> "$log"
while read
do
echo "$REPLY"
size=$( stat -c '%s' "${log}" )
if [ $size -ge $MAXSIZE ]
then
for gen in 8 7 6 5 4 3 2 1
do
test -e "${log}.${gen}" &&
mv -f "${log}.${gen}" "${log}.$(( ${gen} + 1 ))"
done
mv -f "${log}" "${log}.1"
exec >> "$log"
fi
done
#!/bin/bash trap "exit 1" ERR
if [ -n "$1" ]
then
dir="$1"
else
dir=node1
fi
SECONDS=$( date +%s )
cd `dirname $0`
function repeat
{
printf -- "$2%0.s" $( seq 1 $1 )
}
function gen_genesis
{
local genesis="${BFANETWORKDIR}/genesis.json"
test -e "${genesis}" &&
return
bfaconfig account
nodes=$account
echo "** If you want extra nodes added, add them to nodes.remote.txt and run $0 again."
test -r "nodes.remote.txt" &&
nodes="${nodes} $( cat nodes.remote.txt )"
allocs=
sealers=
for node in ${nodes}
do
test "${node:0:2}" = "0x" &&
node=${node:2}
allocs="${allocs}"$(
printf ', "%s": { "balance": "%s" }' \
$node \
0x200000000000000000000000000000000000000000000000000000000000000
)
sealers="${sealers}${node}"
done
# Get rid of leading comma-space
allocs="${allocs:2}"
cat <<-EOCONF > ${genesis}
{
"config": {
"chainId": ${BFANETWORKID},
"homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 4,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"clique": { "period": 15, "epoch": 30000 }
},
"nonce": "0x0000000000000000",
"timestamp": "$( printf '0x%08x' $SECONDS )",
"extraData": "0x426c6f636b636861696e204665646572616c20417267656e74696e61204e4943${sealers}$( repeat 130 0 )",
"gasLimit": "0xffeeddcc", "difficulty": "0x1", "number": "0x0", "gasUsed": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"alloc": { $allocs }
}
EOCONF
}
# Create a genesis.json if one does not already exist
gen_genesis
# Fix on a random port number.
# Do I have IPv6?
bootnodeid=6c81b38551fec2f1142b58ed65137cc1b7dfdc7b35bc556ef26604c41e30fcdeb12212b3c19913584f71dc7bf87d76cd67fa523e96996c0f148390fb76fdc5f7
bootnodev6=2800:40:1:6::135
bootnodev4=200.68.65.135
bootnodeport=5445
bootnodes="enode://${bootnodeid}@[$bootnodev6]:${bootnodeport},enode://${bootnodeid}@[$bootnodev4]:${bootnodeport}"
set -x
# Start the miner.
exec flock --nonblock --exclusive ${dir}/rpcport \
geth \
--datadir ${BFANODEDIR} \
--unlock "$account" \
--password /dev/null \
--mine \
--networkid $BFANETWORKID \
--rpc \
--rpcport $rpcport \
--port $tcpport \
--syncmode full \
--nousb \
--bootnodes "${bootnodes}" \
--verbosity 3
#!/bin/bash
trap "exit 1" ERR
if [ -n "$1" ]
then
dir="$1"
else
dir=node1
fi
SECONDS=$( date +%s )
cd `dirname $0`
function repeat
{
printf -- "$2%0.s" $( seq 1 $1 )
}
function gen_genesis
{
nodes=$( ls -1d node*/keystore/* | sed 's/.*--//' )
test -n "$nodes" &&
echo "Found local nodes:" $nodes
echo "** If you want extra nodes added, add them to nodes.remote.txt and run $0 again."
test -r "nodes.remote.txt" &&
nodes="${nodes} $( cat nodes.remote.txt )"
allocs=
sealers=
for node in ${nodes}
do
allocs="${allocs}"$(
printf ', "%s": { "balance": "%s" }' \
$node \
0x200000000000000000000000000000000000000000000000000000000000000
)
sealers="${sealers}${node}"
done
allocs="${allocs:2}"
cat << EOCONF > genesis.json
{
"config": {
"chainId": ${network},
"homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 4,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"clique": { "period": 15, "epoch": 30000 }
},
"nonce": "0x0000000000000000",
"timestamp": "$( printf '0x%08x' $SECONDS )",
"extraData": "0x426c6f636b636861696e204665646572616c20417267656e74696e61204e4943${sealers}$( repeat 130 0 )",
"gasLimit": "0xffeeddcc", "difficulty": "0x1", "number": "0x0", "gasUsed": "0x0",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"alloc": { $allocs }
}
EOCONF
}
# Get network id
for part in `pwd | sed 's,/, ,g'`
do
if [ "${part:0:7}" = "network" ]
then
network=${part:7}
fi
done
# Create an account if none was found.
test ` ls -1 ${dir}/keystore 2>/dev/null | wc -l ` -ge 1 ||
geth --datadir ${dir} --password /dev/null account new
# Create a genesis.json if one does not already exist
test -r genesis.json ||
gen_genesis
# Initialise if needed
test -d ${dir}/geth/chaindata ||
geth --datadir ${dir} init genesis.json
# Fix on a random port number.
test -r ${dir}/port ||
echo $(( $RANDOM / 2 + 12345 )) > ${dir}/port
test -r ${dir}/rpcport ||
echo $(( $RANDOM / 2 + 12345 )) > ${dir}/rpcport
port=$( cat ${dir}/port )
rpcport=$( cat ${dir}/rpcport )
account=$( ls -1ld ${dir}/keystore/* | head -1 | sed 's/.*--//' )
verbosity=0
if [ -t 1 ]
then
verbosity=3
set -x
fi
# Start the miner.
exec flock --nonblock --exclusive ${dir}/rpcport \
geth \
--datadir ${dir} \
--unlock "$account" \
--password /dev/null \
--mine \
--networkid $network \
--rpc \
--rpcport $rpcport \
--port $port \
--syncmode full \
--nousb \
--bootnodes 'enode://6c81b38551fec2f1142b58ed65137cc1b7dfdc7b35bc556ef26604c41e30fcdeb12212b3c19913584f71dc7bf87d76cd67fa523e96996c0f148390fb76fdc5f7@[2800:40:1:6::135]:5445,enode://6c81b38551fec2f1142b58ed65137cc1b7dfdc7b35bc556ef26604c41e30fcdeb12212b3c19913584f71dc7bf87d76cd67fa523e96996c0f148390fb76fdc5f7@[200.68.65.135]:5445' \
--verbosity ${verbosity}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment