Skip to content

Commit 69f9506

Browse files
committed
support QA deploy
1 parent fca65ad commit 69f9506

File tree

10 files changed

+246
-17
lines changed

10 files changed

+246
-17
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ KEYPASS="0123456789"
55
INIT_HOLDER="0x04d63aBCd2b9b1baa327f2Dda0f873F197ccd186"
66
INIT_HOLDER_PRV="59ba8068eb256d520179e903f43dacf6d8d57d72bd306e1bd603fdb8c8da10e8"
77
RPC_URL="http://127.0.0.1:8545"
8-
HARD_FORK_DELAY=40
8+
HARD_FORK_DELAY=200
99
FullImmutabilityThreshold=512
1010
MinBlocksForBlobRequests=576
1111
DefaultExtraReserveForBlobRequests=32

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66

77
.local/
88

9-
.idea/
9+
.idea/
10+
11+
/qa-env-resource/machines_meta.sh

config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ GasPrice = 10000000000
1919
Recommit = 10000000000
2020

2121
[Eth.Miner.Mev]
22-
Enabled = false
22+
Enabled = true
2323
GreedyMergeTx = true
2424
BuilderFeeCeil= "0"
2525
ValidatorCommission = 1000

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

qa-env-resource/config.toml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
MaxBytesSize = 10485760
64+
Level = "info"
65+
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/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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
11+
#/server/validator/bsc init --datadir /server/validator/ /server/validator/genesis.json
12+
13+
#sed -i -e 's/HTTPModules = \[/HTTPModules = \["debug",/g' /server/validator/config.toml
14+
15+
service bsc start

start_cluster.sh

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ basedir=$(
99
)
1010
workspace=${basedir}
1111
source ${workspace}/.env
12-
size=$((BSC_CLUSTER_SIZE))
13-
stateScheme="path"
14-
dbEngine="pebble"
12+
source ${workspace}/qa-env-resource/machines_meta.sh # including machine ips and ids, don't upload!!!
13+
size=${#ips2ids[@]}
14+
stateScheme="hash"
15+
dbEngine="leveldb"
1516
gcmode="full"
1617
epoch=200
1718
blockInterval=3
18-
needRegister=false
19+
needRegister=true
1920
sleepBeforeStart=10
2021

2122
# stop geth client
@@ -48,14 +49,13 @@ function reset_genesis() {
4849
mv genesis-template.json.bk genesis-template.json
4950
fi
5051

51-
poetry install --no-root
52+
# poetry install --no-root
5253
npm install
5354
rm -rf lib/forge-std
5455
forge install --no-git --no-commit foundry-rs/forge-std@v1.7.3
5556
cd lib/forge-std/lib
5657
rm -rf ds-test
5758
git clone https://github.com/dapphub/ds-test
58-
5959
}
6060

6161
function prepare_config() {
@@ -72,6 +72,10 @@ function prepare_config() {
7272
done
7373

7474
mkdir -p ${workspace}/.local/bsc/node${i}
75+
cp ${workspace}/.local/bsc/password.txt ${workspace}/.local/bsc/node${i}/
76+
cp ${workspace}/qa-env-resource/* ${workspace}/.local/bsc/node${i}/
77+
sed -i -e "s/{{validatorAddr}}/${cons_addr}/g" ${workspace}/.local/bsc/node${i}/chaind.sh
78+
cp ${workspace}/.local/bsc/hardforkTime.txt ${workspace}/.local/bsc/node${i}/hardforkTime.txt
7579
bbcfee_addrs=${fee_addr}
7680
powers="0x000001d1a94a2000" #2000000000000
7781
mv ${workspace}/.local/bsc/bls${i}/bls ${workspace}/.local/bsc/node${i}/ && rm -rf ${workspace}/.local/bsc/bls${i}
@@ -88,10 +92,10 @@ function prepare_config() {
8892
sed -i -e '/registeredContractChannelMap\[VALIDATOR_CONTRACT_ADDR\]\[STAKING_CHANNELID\]/d' ${workspace}/genesis/contracts/CrossChain.sol
8993
sed -i -e 's/public onlyCoinbase onlyZeroGasPrice {/public onlyCoinbase onlyZeroGasPrice {if (block.number < 30) return;/' ${workspace}/genesis/contracts/BSCValidatorSet.sol
9094
fi
91-
poetry run python -m scripts.generate generate-validators
92-
poetry run python -m scripts.generate generate-init-holders "${initHolders}"
93-
poetry run python -m scripts.generate dev --dev-chain-id ${BSC_CHAIN_ID} --whitelist-1 "${INIT_HOLDER}" \
94-
--epoch ${epoch} --misdemeanor-threshold "5" --felony-threshold "10" \
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}" \
98+
--epoch ${epoch} \
9599
--init-felony-slash-scope "60" \
96100
--breathe-block-interval "1 minutes" \
97101
--block-interval ${blockInterval} \
@@ -110,16 +114,21 @@ function prepare_config() {
110114

111115
function initNetwork() {
112116
cd ${workspace}
113-
${workspace}/bin/geth init-network --init.dir ${workspace}/.local/bsc --init.size=${size} --config ${workspace}/config.toml ${workspace}/genesis/genesis.json
117+
${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
114118
rm -rf ${workspace}/*bsc.log*
115119
for ((i = 0; i < size; i++)); do
116120
sed -i -e '/"<nil>"/d' ${workspace}/.local/bsc/node${i}/config.toml
117121
cp -R ${workspace}/.local/bsc/validator${i}/keystore ${workspace}/.local/bsc/node${i}
118122

119-
cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/geth${i}
123+
#cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/geth${i}
124+
cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/bsc
120125
# init genesis
121126
initLog=${workspace}/.local/bsc/node${i}/init.log
122-
${workspace}/bin/geth --datadir ${workspace}/.local/bsc/node${i} init --state.scheme ${stateScheme} --db.engine ${dbEngine} ${workspace}/genesis/genesis.json > "${initLog}" 2>&1
127+
if [ `expr $i \* 2` -ge ${size} ] ; then
128+
${workspace}/bin/geth --datadir ${workspace}/.local/bsc/node${i} init --state.scheme path --db.engine pebble ${workspace}/genesis/genesis.json > "${initLog}" 2>&1
129+
else
130+
${workspace}/bin/geth --datadir ${workspace}/.local/bsc/node${i} init --state.scheme ${stateScheme} --db.engine ${dbEngine} ${workspace}/genesis/genesis.json > "${initLog}" 2>&1
131+
fi
123132
done
124133
}
125134

@@ -175,6 +184,25 @@ function register_stakehub(){
175184
fi
176185
}
177186

187+
function remote_start() {
188+
rm -rf /mnt/efs/bsc-qa/clusterNetwork
189+
cp -r ${workspace}/.local/bsc /mnt/efs/bsc-qa/clusterNetwork
190+
ips=(${validator_ips_comma//,/ })
191+
for ((i=0;i<${#ips[@]};i++));do
192+
dst_id=${ips2ids[${ips[i]}]}
193+
aws ssm send-command --instance-ids "${dst_id}" --document-name "AWS-RunShellScript" --parameters commands="sudo bash -x /mnt/efs/bsc-qa/clusterNetwork/node${i}/init.sh"
194+
done
195+
}
196+
197+
function remote_upgrade() {
198+
cp ${workspace}/bin/geth /mnt/efs/bsc-qa/clusterNetwork/
199+
cp ${workspace}/qa-env-resource/upgrade-single.sh /mnt/efs/bsc-qa/clusterNetwork/
200+
for dst_id in ${ips2ids[@]}; do
201+
aws ssm send-command --instance-ids "${dst_id}" --document-name "AWS-RunShellScript" \
202+
--parameters commands="sudo cp /mnt/efs/bsc-qa/clusterNetwork/geth /tmp/bsc && sudo cp /mnt/efs/bsc-qa/clusterNetwork/upgrade-single.sh /tmp/ && sudo bash -x /tmp/upgrade-single.sh"
203+
done
204+
}
205+
178206
## docker relate begin
179207
function generate_static_peers() {
180208
tool=${workspace}/bin/bootnode
@@ -283,6 +311,17 @@ restart)
283311
exit_previous $ValidatorIdx
284312
native_start $ValidatorIdx
285313
;;
314+
remote_reset)
315+
create_validator
316+
reset_genesis
317+
prepare_config
318+
initNetwork
319+
remote_start
320+
register_stakehub
321+
;;
322+
remote_upgrade)
323+
remote_upgrade
324+
;;
286325
install_k8s)
287326
create_validator
288327
reset_genesis
@@ -295,6 +334,6 @@ uninstall_k8s)
295334
uninstall_k8s
296335
;;
297336
*)
298-
echo "Usage: start_cluster.sh | reset | stop | start | restart"
337+
echo "Usage: start_cluster.sh | reset | stop | start | restart | remote_reset | remote_upgrade"
299338
;;
300339
esac

0 commit comments

Comments
 (0)