@@ -9,12 +9,15 @@ basedir=$(
99)
1010workspace=${basedir}
1111source ${workspace} /.env
12- size=$(( BSC_CLUSTER_SIZE))
12+ source ${workspace} /qa-env-resource/machines_meta.sh # including machine ips and ids, don't upload!!!
13+ validator_ips=(${validator_ips_comma// ,/ } )
14+ size=${# validator_ips[@]}
1315stateScheme=" hash"
1416dbEngine=" leveldb"
1517gcmode=" full"
1618sleepBeforeStart=15
1719sleepAfterStart=10
20+ copyDir=" bsc-qa"
1821
1922# stop geth client
2023function exit_previous() {
@@ -57,7 +60,7 @@ function reset_genesis() {
5760 mv genesis-template.json.bk genesis-template.json
5861 mv scripts/init_holders.template.bk scripts/init_holders.template
5962
60- poetry install --no-root
63+ # poetry install --no-root
6164 npm install
6265 rm -rf lib/forge-std
6366 forge install --no-git --no-commit foundry-rs/forge-std@v1.7.3
@@ -83,28 +86,49 @@ function prepare_config() {
8386 mkdir -p ${targetDir} && cd ${targetDir}
8487 cp ${workspace} /keys/password.txt ./
8588 cp ${workspace} /.local/hardforkTime.txt ./
89+ cp ${workspace} /qa-env-resource/* ./ && rm -f upgrade-single*
90+ sed -i -e " s/{{validatorAddr}}/${cons_addr} /g" chaind.sh && rm -f chaind.sh.bak
8691 bbcfee_addrs=${fee_addr}
8792 powers=" 0x000001d1a94a2000" # 2000000000000
8893 mv ${workspace} /.local/bls${i} /bls ./ && rm -rf ${workspace} /.local/bls${i}
8994 vote_addr=0x$( cat ./bls/keystore/* json | jq .pubkey | sed ' s/"//g' )
9095 echo " ${cons_addr} ,${bbcfee_addrs} ,${fee_addr} ,${powers} ,${vote_addr} " >> ${workspace} /genesis/validators.conf
9196 if [ ${EnableSentryNode} = true ]; then
92- mkdir -p ${workspace} /.local/sentry${i}
97+ targetDir=${workspace} /.local/sentry${i}
98+ mkdir -p ${targetDir} && cd ${targetDir}
99+ cp ${workspace} /.local/hardforkTime.txt ./
100+ cp ${workspace} /qa-env-resource/* ./ && rm -f upgrade-single*
101+ sed -i -e ' /--mine/d' chaind.sh
102+ sed -i -e ' s/workdir="validator"/workdir="sentry"/g' chaind.sh
103+ sed -i -e ' s/bin="bsc"/bin="sentry"/g' chaind.sh
104+ sed -i -e " s/portInc=0/portInc=2/g" chaind.sh
105+ rm -f chaind.sh.bak
106+ sed -i -e ' s/workdir="validator"/workdir="sentry"/g' init.sh
107+ sed -i -e ' s/bin="bsc"/bin="sentry"/g' init.sh
108+ rm -f init.sh.bak
109+ mv bsc.service sentry.service
110+ sed -i -e ' s/validator/sentry/g' sentry.service
111+ sed -i -e ' s/bsc/sentry/g' sentry.service
112+ rm -f sentry.service.bak
93113 fi
94114 done
95115 if [ ${EnableFullNode} = true ]; then
96- mkdir -p ${workspace} /.local/fullnode0
116+ targetDir=${workspace} /.local/fullnode0
117+ mkdir -p ${targetDir} && cd ${targetDir}
118+ cp ${workspace} /.local/hardforkTime.txt ./
119+ cp ${workspace} /qa-env-resource/* ./ && rm -f upgrade-single*
120+ sed -i -e ' /--mine/d' chaind.sh && rm -f chaind.sh.bak
97121 fi
98122 rm -f ${workspace} /.local/hardforkTime.txt
99123
100124 cd ${workspace} /genesis/
101125 git checkout HEAD contracts
102126 sed -i -e ' s/alreadyInit = true;/turnLength = 16;alreadyInit = true;/' ${workspace} /genesis/contracts/BSCValidatorSet.sol
103127 sed -i -e ' s/public onlyCoinbase onlyZeroGasPrice {/public onlyCoinbase onlyZeroGasPrice {if (block.number < 300) return;/' ${workspace} /genesis/contracts/BSCValidatorSet.sol
104-
105- poetry run python -m scripts.generate generate-validators
106- poetry run python -m scripts.generate generate-init-holders " ${initHolders} "
107- poetry run python -m scripts.generate dev \
128+
129+ python3 -m scripts.generate generate-validators
130+ python3 -m scripts.generate generate-init-holders " ${initHolders} "
131+ python3 -m scripts.generate dev \
108132 --dev-chain-id " ${CHAIN_ID} " \
109133 --init-burn-ratio " 1000" \
110134 --init-felony-slash-scope " 60" \
@@ -121,6 +145,7 @@ function prepare_config() {
121145 --governor-protector " ${INIT_HOLDER} " \
122146 --init-minimal-delay " 1 minutes" \
123147 --token-recover-portal-protector " ${INIT_HOLDER} "
148+ # cp genesis-dev.json genesis.json
124149}
125150
126151function initNetwork() {
@@ -141,10 +166,10 @@ function initNetwork() {
141166
142167 init_extra_args=" "
143168 if [ ${EnableSentryNode} = true ]; then
144- init_extra_args=" --init.sentrynode-size ${size} --init.sentrynode-ports 30411 "
169+ init_extra_args=" --init.sentrynode-size ${size} --init.sentrynode-ips ${sentry_ips_comma} "
145170 fi
146171 if [ ${EnableFullNode} = true ]; then
147- init_extra_args=" ${init_extra_args} --init.fullnode-size 1 --init.fullnode-ports 30511 "
172+ init_extra_args=" ${init_extra_args} --init.fullnode-size 1 --init.fullnode-ips ${fullnode_ips_comma} "
148173 fi
149174 if [ " ${RegisterNodeID} " = true ]; then
150175 if [ " ${EnableSentryNode} " = true ]; then
@@ -160,7 +185,7 @@ function initNetwork() {
160185 init_extra_args=" ${init_extra_args} --init.evn-validator-whitelist"
161186 fi
162187 fi
163- ${workspace} /bin/geth init-network --init.dir ${workspace} /.local --init.size=${size} --config ${workspace} /config.toml ${init_extra_args} ${workspace} /genesis/genesis.json
188+ ${workspace} /bin/geth init-network --init.dir ${workspace} /.local --init.size=${size} --init.ips " ${validator_ips_comma} " -- config ${workspace} /qa-env-resource /config.toml ${init_extra_args} ${workspace} /genesis/genesis.json
164189 rm -f ${workspace} /* bsc.log*
165190 for (( i = 0 ; i < size; i++ )) ; do
166191 sed -i -e ' /"<nil>"/d' ${workspace} /.local/node${i} /config.toml
@@ -176,14 +201,21 @@ function initNetwork() {
176201 rm -f ${workspace} /.local/node${i} /* bsc.log*
177202
178203 if [ ${EnableSentryNode} = true ]; then
204+ sed -i -e ' s/:30311/:30611/g' ${workspace} /.local/node${i} /config.toml
205+ sed -i -e ' s/:30411/:30311/g' ${workspace} /.local/node${i} /config.toml
206+
179207 sed -i -e ' /"<nil>"/d' ${workspace} /.local/sentry${i} /config.toml
208+ sed -i -e ' s/:30311/:30611/g' ${workspace} /.local/sentry${i} /config.toml
209+ sed -i -e ' s/:30411/:30311/g' ${workspace} /.local/sentry${i} /config.toml
180210 initLog=${workspace} /.local/sentry${i} /init.log
181211 ${workspace} /bin/geth --datadir ${workspace} /.local/sentry${i} init --state.scheme path --db.engine pebble ${workspace} /genesis/genesis.json > " ${initLog} " 2>&1
182212 rm -f ${workspace} /.local/sentry${i} /* bsc.log*
183213 fi
184214 done
185215 if [ ${EnableFullNode} = true ]; then
186216 sed -i -e ' /"<nil>"/d' ${workspace} /.local/fullnode0/config.toml
217+ sed -i -e ' s/:30311/:30611/g' ${workspace} /.local/fullnode0/config.toml
218+ sed -i -e ' s/:30411/:30311/g' ${workspace} /.local/fullnode0/config.toml
187219 sed -i -e ' s/EnableEVNFeatures = true/EnableEVNFeatures = false/g' ${workspace} /.local/fullnode0/config.toml
188220 initLog=${workspace} /.local/fullnode0/init.log
189221 ${workspace} /bin/geth --datadir ${workspace} /.local/fullnode0 init --state.scheme path --db.engine pebble ${workspace} /genesis/genesis.json > " ${initLog} " 2>&1
@@ -267,13 +299,76 @@ function native_start() {
267299
268300function register_stakehub(){
269301 # wait feynman enable
270- sleep 45
302+ sleep 100
271303 for (( i = 0 ; i < size; i++ )) ; do
272304 ${workspace} /create-validator/create-validator --consensus-key-dir ${workspace} /keys/validator${i} --vote-key-dir ${workspace} /keys/bls${i} \
273305 --password-path ${workspace} /keys/password.txt --amount 20001 --validator-desc Val${i} --rpc-url ${RPC_URL}
274306 done
275307}
276308
309+ function remote_reset_config() {
310+ rm -rf /mnt/efs/${copyDir} /clusterNetwork
311+ cp -r ${workspace} /.local /mnt/efs/${copyDir} /clusterNetwork
312+ ips=(${validator_ips_comma// ,/ } )
313+ for (( i= 0 ;i< ${# ips[@]} ;i++ )) ; do
314+ dst_id=${ips2ids[${ips[i]} ]}
315+ if [ ${EnableSentryNode} = true ]; then
316+ aws ssm send-command --instance-ids " ${dst_id} " --document-name " AWS-RunShellScript" --parameters commands=" sudo \cp -f /mnt/efs/${copyDir} /clusterNetwork/sentry${i} /config.toml /server/sentry/"
317+ aws ssm send-command --instance-ids " ${dst_id} " --document-name " AWS-RunShellScript" --parameters commands=" sudo \cp -f /mnt/efs/${copyDir} /clusterNetwork/sentry${i} /chaind.sh /server/sentry/"
318+ fi
319+ aws ssm send-command --instance-ids " ${dst_id} " --document-name " AWS-RunShellScript" --parameters commands=" sudo \cp -f /mnt/efs/${copyDir} /clusterNetwork/node${i} /config.toml /server/validator/"
320+ aws ssm send-command --instance-ids " ${dst_id} " --document-name " AWS-RunShellScript" --parameters commands=" sudo \cp -f /mnt/efs/${copyDir} /clusterNetwork/node${i} /chaind.sh /server/validator/"
321+ done
322+ if [ ${EnableFullNode} = true ]; then
323+ fullnode_ips=(${fullnode_ips_comma// ,/ } )
324+ dst_id=${ips2ids[${fullnode_ips[0]} ]}
325+ aws ssm send-command --instance-ids " ${dst_id} " --document-name " AWS-RunShellScript" --parameters commands=" sudo \cp -f /mnt/efs/${copyDir} /clusterNetwork/fullnode0/config.toml /server/validator/"
326+ aws ssm send-command --instance-ids " ${dst_id} " --document-name " AWS-RunShellScript" --parameters commands=" sudo \cp -f /mnt/efs/${copyDir} /clusterNetwork/fullnode0/chaind.sh /server/validator/"
327+ fi
328+ }
329+
330+ function remote_start() {
331+ rm -rf /mnt/efs/${copyDir} /clusterNetwork
332+ cp -r ${workspace} /.local /mnt/efs/${copyDir} /clusterNetwork
333+ for dst_id in ${ips2ids[@]} ; do
334+ if [ ${EnableSentryNode} = true ]; then
335+ aws ssm send-command --instance-ids " ${dst_id} " --document-name " AWS-RunShellScript" --parameters commands=" sudo service sentry stop"
336+ fi
337+ aws ssm send-command --instance-ids " ${dst_id} " --document-name " AWS-RunShellScript" --parameters commands=" sudo service bsc stop"
338+ done
339+ sleep 100
340+ cp ${workspace} /bin/geth /mnt/efs/${copyDir} /clusterNetwork/
341+ ips=(${validator_ips_comma// ,/ } )
342+ for (( i= 0 ;i< ${# ips[@]} ;i++ )) ; do
343+ dst_id=${ips2ids[${ips[i]} ]}
344+ if [ ${EnableSentryNode} = true ]; then
345+ aws ssm send-command --instance-ids " ${dst_id} " --document-name " AWS-RunShellScript" --parameters commands=" sudo cp /mnt/efs/${copyDir} /clusterNetwork/geth /tmp/geth && sudo bash -x /mnt/efs/${copyDir} /clusterNetwork/sentry${i} /init.sh"
346+ fi
347+ aws ssm send-command --instance-ids " ${dst_id} " --document-name " AWS-RunShellScript" --parameters commands=" sudo cp /mnt/efs/${copyDir} /clusterNetwork/geth /tmp/geth && sudo bash -x /mnt/efs/${copyDir} /clusterNetwork/node${i} /init.sh"
348+ done
349+ if [ ${EnableFullNode} = true ]; then
350+ fullnode_ips=(${fullnode_ips_comma// ,/ } )
351+ dst_id=${ips2ids[${fullnode_ips[0]} ]}
352+ aws ssm send-command --instance-ids " ${dst_id} " --document-name " AWS-RunShellScript" --parameters commands=" sudo cp /mnt/efs/${copyDir} /clusterNetwork/geth /tmp/geth && sudo bash -x /mnt/efs/${copyDir} /clusterNetwork/fullnode0/init.sh"
353+ fi
354+ }
355+
356+ function remote_upgrade() {
357+ cp ${workspace} /bin/geth /mnt/efs/${copyDir} /clusterNetwork/
358+ if [ ${EnableSentryNode} = true ]; then
359+ cp ${workspace} /qa-env-resource/upgrade-single-sentry.sh /mnt/efs/${copyDir} /clusterNetwork/
360+ fi
361+ cp ${workspace} /qa-env-resource/upgrade-single-validator.sh /mnt/efs/${copyDir} /clusterNetwork/
362+ for dst_id in ${ips2ids[@]} ; do
363+ if [ ${EnableSentryNode} = true ]; then
364+ aws ssm send-command --instance-ids " ${dst_id} " --document-name " AWS-RunShellScript" \
365+ --parameters commands=" sudo cp /mnt/efs/${copyDir} /clusterNetwork/geth /tmp/geth && sudo cp /mnt/efs/${copyDir} /clusterNetwork/upgrade-single-sentry.sh /tmp/ && sudo bash -x /tmp/upgrade-single-sentry.sh"
366+ fi
367+ aws ssm send-command --instance-ids " ${dst_id} " --document-name " AWS-RunShellScript" \
368+ --parameters commands=" sudo cp /mnt/efs/${copyDir} /clusterNetwork/geth /tmp/geth && sudo cp /mnt/efs/${copyDir} /clusterNetwork/upgrade-single-validator.sh /tmp/ && sudo bash -x /tmp/upgrade-single-validator.sh"
369+ done
370+ }
371+
277372CMD=$1
278373ValidatorIdx=$2
279374case ${CMD} in
@@ -284,7 +379,7 @@ reset)
284379 reset_genesis
285380 prepare_config
286381 initNetwork
287- native_start
382+ native_start
288383 register_stakehub
289384 ;;
290385stop)
@@ -297,7 +392,31 @@ restart)
297392 exit_previous $ValidatorIdx
298393 native_start $ValidatorIdx
299394 ;;
395+ remote_reset)
396+ create_validator
397+ reset_genesis
398+ prepare_config
399+ initNetwork
400+ remote_start
401+ # to prevent stuck
402+ sleep 10
403+ remote_upgrade
404+ register_stakehub
405+ ;;
406+ remote_reset_config)
407+ create_validator
408+ reset_genesis
409+ prepare_config
410+ initNetwork
411+ remote_reset_config
412+ ;;
413+ remote_upgrade)
414+ remote_upgrade
415+ ;;
416+ register_stakehub)
417+ register_stakehub
418+ ;;
300419* )
301- echo " Usage: bsc_cluster.sh | reset | stop [vidx]| start [vidx]| restart [vidx]"
420+ echo " Usage: bsc_cluster.sh | reset | stop [vidx]| start [vidx]| restart [vidx]| remote_reset | remote_upgrade | register_stakehub "
302421 ;;
303422esac
0 commit comments