Skip to content

Commit 49c2a3e

Browse files
NathanBSCbuddh0
authored andcommitted
support QA deploy
1 parent 2eac55d commit 49c2a3e

11 files changed

Lines changed: 269 additions & 20 deletions

File tree

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ INIT_HOLDER="0x04d63aBCd2b9b1baa327f2Dda0f873F197ccd186"
55
INIT_HOLDER_PRV="59ba8068eb256d520179e903f43dacf6d8d57d72bd306e1bd603fdb8c8da10e8"
66
RPC_URL="http://127.0.0.1:8545"
77
GENESIS_COMMIT="020c0459e37d1f9d635c1cff86dd1099ab1383fa" # pascal commit
8-
PASSED_FORK_DELAY=40
8+
PASSED_FORK_DELAY=150
99
LAST_FORK_MORE_DELAY=10
1010
FullImmutabilityThreshold=512
1111
MinBlocksForBlobRequests=576

bsc_cluster.sh

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ 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
1819
sleepBeforeStart=10
20+
copyDir="bsc-qa"
1921

2022
# stop geth client
2123
function exit_previous() {
@@ -48,14 +50,13 @@ function reset_genesis() {
4850
mv genesis-template.json.bk genesis-template.json
4951
fi
5052

51-
poetry install --no-root
53+
# poetry install --no-root
5254
npm install
5355
rm -rf lib/forge-std
5456
forge install --no-git --no-commit foundry-rs/forge-std@v1.7.3
5557
cd lib/forge-std/lib
5658
rm -rf ds-test
5759
git clone https://github.com/dapphub/ds-test
58-
5960
}
6061

6162
function prepare_config() {
@@ -74,6 +75,9 @@ function prepare_config() {
7475
mkdir -p ${workspace}/.local/bsc/node${i}
7576
cp ${workspace}/keys/password.txt ${workspace}/.local/bsc/node${i}/
7677
cp ${workspace}/.local/bsc/hardforkTime.txt ${workspace}/.local/bsc/node${i}/
78+
cp ${workspace}/qa-env-resource/* ${workspace}/.local/bsc/node${i}/
79+
sed -i -e "s/{{validatorAddr}}/${cons_addr}/g" ${workspace}/.local/bsc/node${i}/chaind.sh
80+
rm -f ${workspace}/.local/bsc/node${i}/chaind.sh.bak
7781
bbcfee_addrs=${fee_addr}
7882
powers="0x000001d1a94a2000" #2000000000000
7983
mv ${workspace}/.local/bsc/bls${i}/bls ${workspace}/.local/bsc/node${i}/ && rm -rf ${workspace}/.local/bsc/bls${i}
@@ -88,13 +92,14 @@ function prepare_config() {
8892
cd ${workspace}/genesis/
8993
git checkout HEAD contracts
9094

91-
sed -i -e '/registeredContractChannelMap\[VALIDATOR_CONTRACT_ADDR\]\[STAKING_CHANNELID\]/d' ${workspace}/genesis/contracts/deprecated/CrossChain.sol
92-
sed -i -e 's/alreadyInit = true;/turnLength = 4;alreadyInit = true;/' ${workspace}/genesis/contracts/BSCValidatorSet.sol
95+
# to test unregister relayer
96+
# sed -i -e 's/currentRelayers\[addr\] = true;/currentRelayers\[addr\] = true; relayersExistMap\[addr\] = true;/' ${workspace}/genesis/contracts/deprecated/RelayerHub.sol
97+
sed -i -e 's/alreadyInit = true;/turnLength = 8;alreadyInit = true;/' ${workspace}/genesis/contracts/BSCValidatorSet.sol
9398
sed -i -e 's/public onlyCoinbase onlyZeroGasPrice {/public onlyCoinbase onlyZeroGasPrice {if (block.number < 30) return;/' ${workspace}/genesis/contracts/BSCValidatorSet.sol
94-
95-
poetry run python -m scripts.generate generate-validators
96-
poetry run python -m scripts.generate generate-init-holders "${initHolders}"
97-
poetry run python -m scripts.generate dev \
99+
100+
python3 -m scripts.generate generate-validators
101+
python3 -m scripts.generate generate-init-holders "${initHolders}"
102+
python3 -m scripts.generate dev \
98103
--epoch ${epoch} \
99104
--init-felony-slash-scope "60" \
100105
--breathe-block-interval "10 minutes" \
@@ -116,13 +121,14 @@ function initNetwork() {
116121
mkdir ${workspace}/.local/bsc/node${i}/geth
117122
cp ${workspace}/keys/nodekey${i} ${workspace}/.local/bsc/node${i}/geth/nodekey
118123
done
119-
${workspace}/bin/geth init-network --init.dir ${workspace}/.local/bsc --init.size=${size} --config ${workspace}/config.toml ${workspace}/genesis/genesis.json
124+
${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
120125
rm -f ${workspace}/*bsc.log*
121126
for ((i = 0; i < size; i++)); do
122127
sed -i -e '/"<nil>"/d' ${workspace}/.local/bsc/node${i}/config.toml
123128
mv ${workspace}/.local/bsc/validator${i}/keystore ${workspace}/.local/bsc/node${i}/ && rm -rf ${workspace}/.local/bsc/validator${i}
124129

125-
cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/geth${i}
130+
#cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/geth${i}
131+
cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/bsc
126132
# init genesis
127133
initLog=${workspace}/.local/bsc/node${i}/init.log
128134
if [ $i -eq 0 ] ; then
@@ -174,7 +180,7 @@ function native_start() {
174180
--ws.addr 0.0.0.0 --ws.port ${WSPort} --http.addr 0.0.0.0 --http.port ${HTTPPort} --http.corsdomain "*" \
175181
--metrics --metrics.addr localhost --metrics.port ${MetricsPort} --metrics.expensive \
176182
--gcmode ${gcmode} --syncmode full --mine --vote --monitor.maliciousvote \
177-
--rialtohash ${rialtoHash} --override.passedforktime ${PassedForkTime} --override.lorentz ${LastHardforkTime} \
183+
--rialtohash ${rialtoHash} --override.passedforktime ${PassedForkTime} --override.lorentz ${PassedForkTime} --override.maxwell ${LastHardforkTime} \
178184
--override.immutabilitythreshold ${FullImmutabilityThreshold} --override.breatheblockinterval ${BreatheBlockInterval} \
179185
--override.minforblobrequest ${MinBlocksForBlobRequests} --override.defaultextrareserve ${DefaultExtraReserveForBlobRequests} \
180186
> ${workspace}/.local/bsc/node${i}/bsc-node.log 2>&1 &
@@ -183,15 +189,34 @@ function native_start() {
183189

184190
function register_stakehub(){
185191
if ${needRegister};then
186-
echo "sleep 45s to wait feynman enable"
187-
sleep 45
192+
echo "sleep 100s to wait feynman enable"
193+
sleep 100
188194
for ((i = 0; i < size; i++));do
189195
${workspace}/create-validator/create-validator --consensus-key-dir ${workspace}/keys/validator${i} --vote-key-dir ${workspace}/keys/bls${i} \
190196
--password-path ${workspace}/keys/password.txt --amount 20001 --validator-desc Val${i} --rpc-url ${RPC_URL}
191197
done
192198
fi
193199
}
194200

201+
function remote_start() {
202+
rm -rf /mnt/efs/${copyDir}/clusterNetwork
203+
cp -r ${workspace}/.local/bsc /mnt/efs/${copyDir}/clusterNetwork
204+
ips=(${validator_ips_comma//,/ })
205+
for ((i=0;i<${#ips[@]};i++));do
206+
dst_id=${ips2ids[${ips[i]}]}
207+
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"
208+
done
209+
}
210+
211+
function remote_upgrade() {
212+
cp ${workspace}/bin/geth /mnt/efs/${copyDir}/clusterNetwork/
213+
cp ${workspace}/qa-env-resource/upgrade-single.sh /mnt/efs/${copyDir}/clusterNetwork/
214+
for dst_id in ${ips2ids[@]}; do
215+
aws ssm send-command --instance-ids "${dst_id}" --document-name "AWS-RunShellScript" \
216+
--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"
217+
done
218+
}
219+
195220
CMD=$1
196221
ValidatorIdx=$2
197222
case ${CMD} in
@@ -214,7 +239,18 @@ restart)
214239
exit_previous $ValidatorIdx
215240
native_start $ValidatorIdx
216241
;;
242+
remote_reset)
243+
create_validator
244+
reset_genesis
245+
prepare_config
246+
initNetwork
247+
remote_start
248+
register_stakehub
249+
;;
250+
remote_upgrade)
251+
remote_upgrade
252+
;;
217253
*)
218-
echo "Usage: bsc_cluster.sh | reset | stop [vidx]| start [vidx]| restart [vidx]"
254+
echo "Usage: bsc_cluster.sh | reset | stop [vidx]| start [vidx]| restart [vidx]| remote_reset | remote_upgrade"
219255
;;
220256
esac

bsc_fullnode.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function start() {
5252
--ws.addr 0.0.0.0 --ws.port $(( 8600 + $index )) --http.addr 0.0.0.0 --http.port $(( 8600 + $index )) --http.corsdomain "*" \
5353
--metrics --metrics.addr 0.0.0.0 --metrics.port $(( 6100 + $index )) --metrics.expensive \
5454
--gcmode $gcmode --syncmode $syncmode --state.scheme ${stateScheme} $extraflags \
55-
--rialtohash ${rialtoHash} --override.passedforktime ${PassedForkTime} --override.lorentz ${LastHardforkTime} \
55+
--rialtohash ${rialtoHash} --override.passedforktime ${PassedForkTime} --override.lorentz ${PassedForkTime} --override.maxwell ${LastHardforkTime} \
5656
--override.immutabilitythreshold ${FullImmutabilityThreshold} --override.breatheblockinterval ${BreatheBlockInterval} \
5757
--override.minforblobrequest ${MinBlocksForBlobRequests} --override.defaultextrareserve ${DefaultExtraReserveForBlobRequests} \
5858
> $dst/bsc-node.log 2>&1 &

config.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ TrieTimeout = 3600000000000
1212
EnablePreimageRecording = false
1313

1414
[Eth.Miner]
15-
GasCeil = 40000000
15+
GasCeil = 35000000
1616
GasPrice = 10000000000
1717
Recommit = 10000000000
18-
DelayLeftOver = 50000000
18+
DelayLeftOver = 25000000
1919

2020
[Eth.Miner.Mev]
2121
Enabled = true
2222
GreedyMergeTx = true
2323
BuilderFeeCeil= "0"
2424
ValidatorCommission = 1000
25-
BidSimulationLeftOver = 50000000
25+
BidSimulationLeftOver = 25000000
26+
NoInterruptLeftOver = 150000000
27+
MaxBidsPerBuilder = 1
2628

2729
[[Eth.Miner.Mev.Builders]]
2830
Address = "0x04d63aBCd2b9b1baa327f2Dda0f873F197ccd186"

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

qa-env-resource/config.toml

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

0 commit comments

Comments
 (0)