Skip to content

Commit 8bf3a68

Browse files
NathanBSCbuddh0
authored andcommitted
support QA deploy
1 parent bdf7104 commit 8bf3a68

File tree

9 files changed

+248
-14
lines changed

9 files changed

+248
-14
lines changed

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ KEYPASS="0123456789"
55
INIT_HOLDER="0x04d63aBCd2b9b1baa327f2Dda0f873F197ccd186"
66
INIT_HOLDER_PRV="59ba8068eb256d520179e903f43dacf6d8d57d72bd306e1bd603fdb8c8da10e8"
77
RPC_URL="http://127.0.0.1:8545"
8-
PASSED_FORK_DELAY=40
9-
LAST_FORK_MORE_DELAY=10
8+
PASSED_FORK_DELAY=100
9+
LAST_FORK_MORE_DELAY=300
1010
FullImmutabilityThreshold=512
1111
MinBlocksForBlobRequests=576
1212
DefaultExtraReserveForBlobRequests=32

bsc_cluster.sh

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ basedir=$(
99
)
1010
workspace=${basedir}
1111
source ${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+
size=${#ips2ids[@]}
1314
stateScheme="hash"
1415
dbEngine="leveldb"
1516
gcmode="full"
1617
epoch=200
1718
blockInterval=3
18-
needRegister=false
19+
needRegister=true
1920
sleepBeforeStart=10
21+
copyDir="bsc-qa"
2022

2123
# stop geth client
2224
function exit_previous() {
@@ -47,14 +49,13 @@ function reset_genesis() {
4749
mv genesis-template.json.bk genesis-template.json
4850
fi
4951

50-
poetry install --no-root
52+
# poetry install --no-root
5153
npm install
5254
rm -rf lib/forge-std
5355
forge install --no-git --no-commit foundry-rs/forge-std@v1.7.3
5456
cd lib/forge-std/lib
5557
rm -rf ds-test
5658
git clone https://github.com/dapphub/ds-test
57-
5859
}
5960

6061
function prepare_config() {
@@ -73,6 +74,8 @@ function prepare_config() {
7374
mkdir -p ${workspace}/.local/bsc/node${i}
7475
cp ${workspace}/keys/password.txt ${workspace}/.local/bsc/node${i}/
7576
cp ${workspace}/.local/bsc/hardforkTime.txt ${workspace}/.local/bsc/node${i}/
77+
cp ${workspace}/qa-env-resource/* ${workspace}/.local/bsc/node${i}/
78+
sed -i -e "s/{{validatorAddr}}/${cons_addr}/g" ${workspace}/.local/bsc/node${i}/chaind.sh
7679
bbcfee_addrs=${fee_addr}
7780
powers="0x000001d1a94a2000" #2000000000000
7881
mv ${workspace}/.local/bsc/bls${i}/bls ${workspace}/.local/bsc/node${i}/ && rm -rf ${workspace}/.local/bsc/bls${i}
@@ -89,9 +92,9 @@ function prepare_config() {
8992
sed -i -e '/registeredContractChannelMap\[VALIDATOR_CONTRACT_ADDR\]\[STAKING_CHANNELID\]/d' ${workspace}/genesis/contracts/deprecated/CrossChain.sol
9093
sed -i -e 's/public onlyCoinbase onlyZeroGasPrice {/public onlyCoinbase onlyZeroGasPrice {if (block.number < 30) return;/' ${workspace}/genesis/contracts/BSCValidatorSet.sol
9194
fi
92-
poetry run python -m scripts.generate generate-validators
93-
poetry run python -m scripts.generate generate-init-holders "${initHolders}"
94-
poetry run python -m scripts.generate dev --dev-chain-id ${BSC_CHAIN_ID} --whitelist-1 "${INIT_HOLDER}" \
95+
python3 -m scripts.generate generate-validators
96+
python3 -m scripts.generate generate-init-holders "${initHolders}"
97+
python3 -m scripts.generate dev --dev-chain-id ${BSC_CHAIN_ID} --whitelist-1 "${INIT_HOLDER}" \
9598
--epoch ${epoch} \
9699
--init-felony-slash-scope "60" \
97100
--breathe-block-interval "10 minutes" \
@@ -115,13 +118,14 @@ function initNetwork() {
115118
mkdir ${workspace}/.local/bsc/node${i}/geth
116119
cp ${workspace}/keys/nodekey${i} ${workspace}/.local/bsc/node${i}/geth/nodekey
117120
done
118-
${workspace}/bin/geth init-network --init.dir ${workspace}/.local/bsc --init.size=${size} --config ${workspace}/config.toml ${workspace}/genesis/genesis.json
121+
${workspace}/bin/geth init-network --init.dir ${workspace}/.local/bsc --init.size=${size} --init.ips "${validator_ips_comma}" --config ${workspace}/qa-env-resource/config.toml ${workspace}/genesis/genesis.json
119122
rm -rf ${workspace}/*bsc.log*
120123
for ((i = 0; i < size; i++)); do
121124
sed -i -e '/"<nil>"/d' ${workspace}/.local/bsc/node${i}/config.toml
122125
mv ${workspace}/.local/bsc/validator${i}/keystore ${workspace}/.local/bsc/node${i}/ && rm -rf ${workspace}/.local/bsc/validator${i}
123126

124-
cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/geth${i}
127+
#cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/geth${i}
128+
cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/bsc
125129
# init genesis
126130
initLog=${workspace}/.local/bsc/node${i}/init.log
127131
if [ $i -eq 0 ] ; then
@@ -179,15 +183,34 @@ function native_start() {
179183

180184
function register_stakehub(){
181185
if ${needRegister};then
182-
echo "sleep 45s to wait feynman enable"
183-
sleep 45
186+
echo "sleep 100s to wait feynman enable"
187+
sleep 100
184188
for ((i = 0; i < size; i++));do
185189
${workspace}/create-validator/create-validator --consensus-key-dir ${workspace}/keys/validator${i} --vote-key-dir ${workspace}/keys/bls${i} \
186190
--password-path ${workspace}/keys/password.txt --amount 20001 --validator-desc Val${i} --rpc-url ${RPC_URL}
187191
done
188192
fi
189193
}
190194

195+
function remote_start() {
196+
rm -rf /mnt/efs/${copyDir}/clusterNetwork
197+
cp -r ${workspace}/.local/bsc /mnt/efs/${copyDir}/clusterNetwork
198+
ips=(${validator_ips_comma//,/ })
199+
for ((i=0;i<${#ips[@]};i++));do
200+
dst_id=${ips2ids[${ips[i]}]}
201+
aws ssm send-command --instance-ids "${dst_id}" --document-name "AWS-RunShellScript" --parameters commands="sudo bash -x /mnt/efs/${copyDir}/clusterNetwork/node${i}/init.sh"
202+
done
203+
}
204+
205+
function remote_upgrade() {
206+
cp ${workspace}/bin/geth /mnt/efs/${copyDir}/clusterNetwork/
207+
cp ${workspace}/qa-env-resource/upgrade-single.sh /mnt/efs/${copyDir}/clusterNetwork/
208+
for dst_id in ${ips2ids[@]}; do
209+
aws ssm send-command --instance-ids "${dst_id}" --document-name "AWS-RunShellScript" \
210+
--parameters commands="sudo cp /mnt/efs/${copyDir}/clusterNetwork/geth /tmp/bsc && sudo cp /mnt/efs/${copyDir}/clusterNetwork/upgrade-single.sh /tmp/ && sudo bash -x /tmp/upgrade-single.sh"
211+
done
212+
}
213+
191214
CMD=$1
192215
ValidatorIdx=$2
193216
case ${CMD} in
@@ -210,7 +233,18 @@ restart)
210233
exit_previous $ValidatorIdx
211234
native_start $ValidatorIdx
212235
;;
236+
remote_reset)
237+
create_validator
238+
reset_genesis
239+
prepare_config
240+
initNetwork
241+
remote_start
242+
register_stakehub
243+
;;
244+
remote_upgrade)
245+
remote_upgrade
246+
;;
213247
*)
214-
echo "Usage: bsc_cluster.sh | reset | stop [vidx]| start [vidx]| restart [vidx]"
248+
echo "Usage: bsc_cluster.sh | reset | stop [vidx]| start [vidx]| restart [vidx]| remote_reset | remote_upgrade"
215249
;;
216250
esac

qa-env-resource/bsc.service

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[Unit]
2+
Description=bsc
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
User=root
8+
Group=root
9+
ExecStart=/server/validator/chaind.sh -start
10+
ExecReload=/server/validator/chaind.sh -restart
11+
ExecStop=/server/validator/chaind.sh -stop
12+
PrivateTmp=true
13+
Restart=always
14+
LimitNOFILE=10000
15+
RestartSec=5
16+
StartLimitInterval=0
17+
18+
[Install]
19+
WantedBy=multi-user.target

qa-env-resource/chaind.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
export GOGC=200
4+
# default values
5+
FullImmutabilityThreshold=90000
6+
MinBlocksForBlobRequests=524288
7+
DefaultExtraReserveForBlobRequests=28800
8+
BreatheBlockInterval=600
9+
FixedTurnLength=1
10+
LAST_FORK_MORE_DELAY=1800
11+
12+
function startChaind() {
13+
workspace=/server/validator
14+
15+
PassedForkTime=`cat ${workspace}/hardforkTime.txt|grep passedHardforkTime|awk -F" " '{print $NF}'`
16+
LastHardforkTime=$(expr ${PassedForkTime} + ${LAST_FORK_MORE_DELAY})
17+
initLog=${workspace}/init.log
18+
rialtoHash=`cat ${initLog}|grep "database=lightchaindata"|awk -F"=" '{print $NF}'|awk -F'"' '{print $1}'`
19+
20+
ip=`ifconfig eth0|grep inet|grep -v inet6 |awk '{ print $2 }'`
21+
sed -i -e "s?FileRoot = \"\"?FileRoot = \"/mnt/efs/validator/${ip}/\"?g" /server/validator/config.toml
22+
mkdir -p /mnt/efs/validator/${ip}
23+
${workspace}/bsc --config ${workspace}/config.toml \
24+
--datadir ${workspace} \
25+
--password ${workspace}/password.txt \
26+
--blspassword ${workspace}/password.txt \
27+
--unlock {{validatorAddr}} --miner.etherbase {{validatorAddr}} --rpc.allow-unprotected-txs --allow-insecure-unlock \
28+
--ws --ws.port 8545 --ws.addr ${ip} --http.addr 0.0.0.0 --http.corsdomain "*" \
29+
--metrics --metrics.addr 0.0.0.0 \
30+
--pprof --pprof.port 6061 \
31+
--syncmode snap --mine --vote --monitor.maliciousvote \
32+
--cache 10480 --light.serve 50 \
33+
--rialtohash ${rialtoHash} --override.passedforktime ${PassedForkTime} --override.bohr ${LastHardforkTime} \
34+
--override.immutabilitythreshold ${FullImmutabilityThreshold} --override.breatheblockinterval ${BreatheBlockInterval} \
35+
--override.minforblobrequest ${MinBlocksForBlobRequests} --override.defaultextrareserve ${DefaultExtraReserveForBlobRequests} \
36+
`# --override.fixedturnlength ${FixedTurnLength}` \
37+
>> /mnt/efs/validator/${ip}/bscnode.log 2>&1
38+
}
39+
40+
function stopChaind() {
41+
pid=`ps -ef | grep /server/validator/bsc | grep -v grep | awk '{print $2}'`
42+
if [ -n "$pid" ]; then
43+
for((i=1;i<=4;i++));
44+
do
45+
kill $pid
46+
sleep 5
47+
pid=`ps -ef | grep /server/validator/bsc | grep -v grep | awk '{print $2}'`
48+
if [ -z "$pid" ]; then
49+
break
50+
elif [ $i -eq 4 ]; then
51+
kill -9 $kid
52+
fi
53+
done
54+
fi
55+
}
56+
57+
CMD=$1
58+
59+
case $CMD in
60+
-start)
61+
echo "start"
62+
startChaind
63+
;;
64+
-stop)
65+
echo "stop"
66+
stopChaind
67+
;;
68+
-restart)
69+
stopChaind
70+
sleep 3
71+
startChaind
72+
;;
73+
*)
74+
echo "Usage: chaind.sh -start | -stop | -restart .Or use systemctl start | stop | restart bsc.service "
75+
;;
76+
esac

qa-env-resource/config.toml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
[Eth]
2+
NetworkId = 714
3+
SyncMode = "full"
4+
NoPruning = false
5+
NoPrefetch = false
6+
LightPeers = 100
7+
TrieTimeout = 100000000000
8+
DatabaseCache = 512
9+
DatabaseFreezer = ""
10+
TriesInMemory = 128
11+
TrieCleanCache = 256
12+
TrieDirtyCache = 256
13+
EnablePreimageRecording = false
14+
15+
[Eth.Miner]
16+
GasFloor = 500000000
17+
GasCeil = 500000000
18+
GasPrice = 1000000000
19+
Recommit = 10000000000
20+
21+
[Eth.TxPool]
22+
Locals = []
23+
NoLocals = true
24+
Journal = "transactions.rlp"
25+
Rejournal = 3600000000000
26+
PriceLimit = 1000000000
27+
PriceBump = 10
28+
AccountSlots = 512
29+
GlobalSlots = 10000
30+
AccountQueue = 256
31+
GlobalQueue = 5000
32+
Lifetime = 10800000000000
33+
34+
[Eth.GPO]
35+
Blocks = 20
36+
Percentile = 60
37+
OracleThreshold = 1000
38+
39+
[Node]
40+
IPCPath = "geth.ipc"
41+
HTTPHost = "localhost"
42+
NoUSB = true
43+
InsecureUnlockAllowed = false
44+
HTTPPort = 8545
45+
HTTPVirtualHosts = ["localhost"]
46+
HTTPModules = ["eth", "net", "web3", "txpool", "parlia", "miner"]
47+
WSPort = 8546
48+
WSModules = ["net", "web3", "eth"]
49+
50+
[Node.P2P]
51+
MaxPeers = 30
52+
NoDiscovery = false
53+
ListenAddr = ":30311"
54+
EnableMsgEvents = false
55+
56+
[Node.HTTPTimeouts]
57+
ReadTimeout = 30000000000
58+
WriteTimeout = 30000000000
59+
IdleTimeout = 120000000000
60+
61+
[Node.LogConfig]
62+
FilePath = "bsc.log"
63+
TimeFormat = "01-02|15:04:05.000"
64+
MaxBytesSize = 10485760
65+
Level = "debug"
66+
FileRoot = ""

qa-env-resource/init.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
workspace=$(cd `dirname $0`; pwd)
4+
5+
cp ${workspace}/bsc.service /usr/lib/systemd/system/
6+
chmod +x ${workspace}/start.sh ${workspace}/chaind.sh ${workspace}/bsc
7+
8+
service bsc stop
9+
rm -rf /server/validator
10+
mv ${workspace} /server/validator
11+
12+
/server/validator/start.sh

qa-env-resource/machines_meta.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
validator_ips_comma=""
4+
declare -A ips2ids

qa-env-resource/start.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
systemctl daemon-reload
3+
chkconfig bsc on
4+
service bsc restart

qa-env-resource/upgrade-single.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
service bsc stop
4+
cp /tmp/bsc /server/validator/bsc
5+
6+
#cd /server/validator/geth/
7+
#rm -rf chaindata les.server nodes triecache
8+
9+
#sed -i -e 's/sleep 5/sleep 40/' /server/validator/chaind.sh
10+
#sed -i -e 's/FixedTurnLength=1/FixedTurnLength=4/' /server/validator/chaind.sh
11+
12+
#/server/validator/bsc init --datadir /server/validator/ /server/validator/genesis.json
13+
14+
#sed -i -e 's/HTTPModules = \[/HTTPModules = \["debug",/g' /server/validator/config.toml
15+
#sed -i -e 's/GlobalSlots = 10000/GlobalSlots = 10000/g' /server/validator/config.toml
16+
#sed -i -e 's/GlobalQueue = 5000/GlobalQueue = 5000/g' /server/validator/config.toml
17+
#sed -i -e 's/Level = "info"/Level = "debug"/g' /server/validator/config.toml
18+
19+
service bsc start

0 commit comments

Comments
 (0)