Skip to content

Commit c9854fd

Browse files
committed
support QA deploy
1 parent ad37269 commit c9854fd

File tree

9 files changed

+243
-15
lines changed

9 files changed

+243
-15
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BSC_CHAIN_ID=714
44
KEYPASS="0123456789"
55
INIT_HOLDER="0x04d63aBCd2b9b1baa327f2Dda0f873F197ccd186"
66
INIT_HOLDER_PRV="59ba8068eb256d520179e903f43dacf6d8d57d72bd306e1bd603fdb8c8da10e8"
7-
HARD_FORK_DELAY=40
7+
HARD_FORK_DELAY=200
88
FullImmutabilityThreshold=512
99
MinBlocksForBlobRequests=576
1010
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

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} \
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: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ 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
@@ -45,14 +46,13 @@ function reset_genesis() {
4546
mv genesis-template.json.bk genesis-template.json
4647
fi
4748

48-
poetry install --no-root
49+
# poetry install --no-root
4950
npm install
5051
rm -rf lib/forge-std
5152
forge install --no-git --no-commit foundry-rs/forge-std@v1.7.3
5253
cd lib/forge-std/lib
5354
rm -rf ds-test
5455
git clone https://github.com/dapphub/ds-test
55-
5656
}
5757

5858
function prepare_config() {
@@ -67,6 +67,10 @@ function prepare_config() {
6767
done
6868

6969
mkdir -p ${workspace}/.local/bsc/node${i}
70+
cp ${workspace}/.local/bsc/password.txt ${workspace}/.local/bsc/node${i}/
71+
cp ${workspace}/qa-env-resource/* ${workspace}/.local/bsc/node${i}/
72+
sed -i -e "s/{{validatorAddr}}/${cons_addr}/g" ${workspace}/.local/bsc/node${i}/chaind.sh
73+
cp ${workspace}/.local/bsc/hardforkTime.txt ${workspace}/.local/bsc/node${i}/hardforkTime.txt
7074
bbcfee_addrs=${fee_addr}
7175
powers="0x000001d1a94a2000"
7276
mv ${workspace}/.local/bsc/bls${i}/bls ${workspace}/.local/bsc/node${i}/ && rm -rf ${workspace}/.local/bsc/bls${i}
@@ -80,10 +84,10 @@ function prepare_config() {
8084
cd ${workspace}/genesis/
8185
git checkout HEAD contracts
8286
sed -i -e s/^}/"function shutdownBCStaking() external { registeredContractChannelMap[VALIDATOR_CONTRACT_ADDR][STAKING_CHANNELID] = false; }}/" ${workspace}/genesis/contracts/CrossChain.sol
83-
poetry run python -m scripts.generate generate-validators
84-
poetry run python -m scripts.generate generate-init-holders "${INIT_HOLDER}"
85-
poetry run python -m scripts.generate dev --dev-chain-id ${BSC_CHAIN_ID} --whitelist-1 "${INIT_HOLDER}" \
86-
--epoch ${epoch} --misdemeanor-threshold "5" --felony-threshold "10" \
87+
python3 -m scripts.generate generate-validators
88+
python3 -m scripts.generate generate-init-holders "${INIT_HOLDER}"
89+
python3 -m scripts.generate dev --dev-chain-id ${BSC_CHAIN_ID} --whitelist-1 "${INIT_HOLDER}" \
90+
--epoch ${epoch} \
8791
--init-felony-slash-scope "60" \
8892
--breathe-block-interval "1 minutes" \
8993
--block-interval ${blockInterval} \
@@ -102,16 +106,21 @@ function prepare_config() {
102106

103107
function initNetwork() {
104108
cd ${workspace}
105-
${workspace}/bin/geth init-network --init.dir ${workspace}/.local/bsc --init.size=${size} --config ${workspace}/config.toml ${workspace}/genesis/genesis.json
109+
${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
106110
rm -rf ${workspace}/*bsc.log*
107111
for ((i = 0; i < size; i++)); do
108112
sed -i -e '/"<nil>"/d' ${workspace}/.local/bsc/node${i}/config.toml
109113
cp -R ${workspace}/.local/bsc/validator${i}/keystore ${workspace}/.local/bsc/node${i}
110114

111-
cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/geth${i}
115+
#cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/geth${i}
116+
cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/bsc
112117
# init genesis
113118
initLog=${workspace}/.local/bsc/node${i}/init.log
114-
${workspace}/bin/geth --datadir ${workspace}/.local/bsc/node${i} init --state.scheme ${stateScheme} --db.engine ${dbEngine} ${workspace}/genesis/genesis.json > "${initLog}" 2>&1
119+
if [ `expr $i \* 2` -ge ${size} ] ; then
120+
${workspace}/bin/geth --datadir ${workspace}/.local/bsc/node${i} init --state.scheme path --db.engine pebble ${workspace}/genesis/genesis.json > "${initLog}" 2>&1
121+
else
122+
${workspace}/bin/geth --datadir ${workspace}/.local/bsc/node${i} init --state.scheme ${stateScheme} --db.engine ${dbEngine} ${workspace}/genesis/genesis.json > "${initLog}" 2>&1
123+
fi
115124
done
116125
}
117126

@@ -151,6 +160,25 @@ function native_start() {
151160
done
152161
}
153162

163+
function remote_start() {
164+
rm -rf /mnt/efs/bsc-qa/clusterNetwork
165+
cp -r ${workspace}/.local/bsc /mnt/efs/bsc-qa/clusterNetwork
166+
ips=(${validator_ips_comma//,/ })
167+
for ((i=0;i<${#ips[@]};i++));do
168+
dst_id=${ips2ids[${ips[i]}]}
169+
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"
170+
done
171+
}
172+
173+
function remote_upgrade() {
174+
cp ${workspace}/bin/geth /mnt/efs/bsc-qa/clusterNetwork/
175+
cp ${workspace}/qa-env-resource/upgrade-single.sh /mnt/efs/bsc-qa/clusterNetwork/
176+
for dst_id in ${ips2ids[@]}; do
177+
aws ssm send-command --instance-ids "${dst_id}" --document-name "AWS-RunShellScript" \
178+
--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"
179+
done
180+
}
181+
154182
## docker relate begin
155183
function generate_static_peers() {
156184
tool=${workspace}/bin/bootnode
@@ -257,6 +285,16 @@ restart)
257285
exit_previous
258286
native_start
259287
;;
288+
remote_reset)
289+
create_validator
290+
reset_genesis
291+
prepare_config
292+
initNetwork
293+
remote_start
294+
;;
295+
remote_upgrade)
296+
remote_upgrade
297+
;;
260298
install_k8s)
261299
create_validator
262300
reset_genesis
@@ -269,6 +307,6 @@ uninstall_k8s)
269307
uninstall_k8s
270308
;;
271309
*)
272-
echo "Usage: start_cluster.sh | reset | stop | start | restart"
310+
echo "Usage: start_cluster.sh | reset | stop | start | restart | remote_reset | remote_upgrade"
273311
;;
274312
esac

0 commit comments

Comments
 (0)