11#! /usr/bin/env bash
22
33workspace=$(
4- cd $( dirname $0 )
5- pwd
4+ cd $( dirname $0 )
5+ pwd
66) /..
77
88function prepare() {
9- if ! [[ -f /usr/local/bin/geth ]]; then
10- echo " geth do not exist!"
11- exit 1
12- fi
13- # run `make clean` to remove files
14- cd ${workspace} /genesis
15- rm -rf validators.conf
9+ if ! [[ -f /usr/local/bin/geth ]]; then
10+ echo " geth do not exist!"
11+ exit 1
12+ fi
13+ # run `make clean` to remove files
14+ cd ${workspace} /genesis
15+ rm -rf validators.conf
1616}
1717
1818function init_validator() {
19- node_id=$1
19+ node_id=$1
2020
2121 # set validator address
22- mkdir -p ${workspace} /storage/${node_id} /keystore
23- cp ${workspace} /validators/keystore/${node_id} ${workspace} /storage/${node_id} /keystore/${node_id}
22+ mkdir -p ${workspace} /storage/${node_id} /keystore
23+ cp ${workspace} /validators/keystore/${node_id} ${workspace} /storage/${node_id} /keystore/${node_id}
2424 validatorAddr=0x$( cat ${workspace} /storage/${node_id} /keystore/${node_id} | jq .address | sed ' s/"//g' )
25- echo ${validatorAddr} > ${workspace} /storage/${node_id} /address
25+ echo ${validatorAddr} > ${workspace} /storage/${node_id} /address
2626
27- # import BLS vote address
28- echo password01 > ${workspace} /storage/${node_id} /blspassword.txt
29- geth --datadir ${workspace} /storage/${node_id} bls account import ${workspace} /validators/bls/${node_id} --blspassword ${workspace} /storage/${node_id} /blspassword.txt --blsaccountpassword ${workspace} /storage/${node_id} /blspassword.txt
30- geth --datadir ${workspace} /storage/${node_id} bls account list --blspassword ${workspace} /storage/${node_id} /blspassword.txt
31- voteAddr=0x$( cat ${workspace} /validators/bls/${node_id} | jq .pubkey | sed ' s/"//g' )
27+ # create new BLS vote address
28+ expect ${workspace} /scripts/create_bls_key.sh ${workspace} /storage/${node_id}
29+ voteAddr=0x$( cat ${workspace} /storage/${node_id} /bls/keystore/* json| jq .pubkey | sed ' s/"//g' )
30+ echo $voteAddr
3231
33- echo " ${validatorAddr} ,${validatorAddr} ,${validatorAddr} ,0x0000000010000000,${voteAddr} " >> ${workspace} /genesis/validators.conf
32+ echo " ${validatorAddr} ,${validatorAddr} ,${validatorAddr} ,0x0000000010000000,${voteAddr} " >> ${workspace} /genesis/validators.conf
3433}
3534
3635function generate_genesis() {
37- INIT_HOLDER_ADDRESSES=$( ls ${workspace} /init-holders | tr ' \n' ' ,' )
38- INIT_HOLDER_ADDRESSES=${INIT_HOLDER_ADDRESSES/% ,/ }
39- echo " blocks per epoch = ${BLOCKS_PER_EPOCH} "
40- sed " s/{{BLOCKS_PER_EPOCH}}/${BLOCKS_PER_EPOCH} /g" ${workspace} /genesis/genesis-template.template > ${workspace} /genesis/genesis-template.json
41- sed " s/{{INIT_HOLDER_ADDRESSES}}/${INIT_HOLDER_ADDRESSES} /g" ${workspace} /genesis/init_holders.template | sed " s/{{INIT_HOLDER_BALANCE}}/${INIT_HOLDER_BALANCE} /g" > ${workspace} /genesis/init_holders.js
42- node generate-validator.js
43- chainIDHex=$( printf ' %04x\n' ${BSC_CHAIN_ID} )
44- node generate-genesis.js --chainid ${BSC_CHAIN_ID} --bscChainId ${chainIDHex}
36+ INIT_HOLDER_ADDRESSES=$( ls ${workspace} /init-holders | tr ' \n' ' ,' )
37+ INIT_HOLDER_ADDRESSES=${INIT_HOLDER_ADDRESSES/% ,/ }
38+ echo " blocks per epoch = ${BLOCKS_PER_EPOCH} "
39+ sed " s/{{BLOCKS_PER_EPOCH}}/${BLOCKS_PER_EPOCH} /g" ${workspace} /genesis/genesis-template.template > ${workspace} /genesis/genesis-template.json
40+ sed " s/{{INIT_HOLDER_ADDRESSES}}/${INIT_HOLDER_ADDRESSES} /g" ${workspace} /genesis/init_holders.template | sed " s/{{INIT_HOLDER_BALANCE}}/${INIT_HOLDER_BALANCE} /g" > ${workspace} /genesis/init_holders.js
41+ node generate-validator.js
42+ chainIDHex=$( printf ' %04x\n' ${BSC_CHAIN_ID} )
43+ node generate-genesis.js --chainid ${BSC_CHAIN_ID} --bscChainId ${chainIDHex}
4544}
4645
4746function init_genesis_data() {
48- node_type=$1
49- node_id=$2
50- geth --datadir ${workspace} /storage/${node_id} init ${workspace} /genesis/genesis.json
51- cp ${workspace} /config/config-${node_type} .toml ${workspace} /storage/${node_id} /config.toml
52- sed -i -e " s/{{NetworkId}}/${BSC_CHAIN_ID} /g" ${workspace} /storage/${node_id} /config.toml
53- if [ " ${node_id} " == " bsc-rpc" ]; then
54- cp ${workspace} /init-holders/* ${workspace} /storage/${node_id} /keystore
55- cp ${workspace} /genesis/genesis.json ${workspace} /storage/${node_id}
56- cp ${workspace} /config/bootstrap.key ${workspace} /storage/${node_id} /geth/nodekey
57- fi
47+ node_type=$1
48+ node_id=$2
49+ geth --datadir ${workspace} /storage/${node_id} init --state.scheme hash --db.engine=leveldb ${workspace} /genesis/genesis.json
50+ cp ${workspace} /config/config-${node_type} .toml ${workspace} /storage/${node_id} /config.toml
51+ sed -i -e " s/{{NetworkId}}/${BSC_CHAIN_ID} /g" ${workspace} /storage/${node_id} /config.toml
52+ if [ " ${node_id} " == " bsc-rpc" ]; then
53+ cp ${workspace} /init-holders/* ${workspace} /storage/${node_id} /keystore
54+ cp ${workspace} /genesis/genesis.json ${workspace} /storage/${node_id}
55+ cp ${workspace} /config/bootstrap.key ${workspace} /storage/${node_id} /geth/nodekey
56+ fi
5857}
5958
6059prepare
6160
6261# First, generate config for each validator
6362for (( i = 1 ; i <= ${NUMS_OF_VALIDATOR} ; i++ )) ; do
64- init_validator " bsc-validator${i} "
65- generate_validator_conf " bsc-validator${i} "
63+ init_validator " bsc-validator${i} "
6664done
6765
6866# Then, use validator configs to generate genesis file
@@ -72,5 +70,5 @@ generate_genesis
7270init_genesis_data bsc-rpc bsc-rpc
7371
7472for (( i = 1 ; i <= ${NUMS_OF_VALIDATOR} ; i++ )) ; do
75- init_genesis_data validator " bsc-validator${i} "
73+ init_genesis_data validator " bsc-validator${i} "
7674done
0 commit comments