Skip to content

Commit b95c1df

Browse files
committed
support QA deploy
1 parent 27e7ca6 commit b95c1df

File tree

9 files changed

+241
-15
lines changed

9 files changed

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

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

5959
function prepare_config() {
@@ -71,6 +71,10 @@ function prepare_config() {
7171
done
7272

7373
mkdir -p ${workspace}/.local/bsc/node${i}
74+
cp ${workspace}/.local/bsc/password.txt ${workspace}/.local/bsc/node${i}/
75+
cp ${workspace}/qa-env-resource/* ${workspace}/.local/bsc/node${i}/
76+
sed -i -e "s/{{validatorAddr}}/${cons_addr}/g" ${workspace}/.local/bsc/node${i}/chaind.sh
77+
cp ${workspace}/.local/bsc/hardforkTime.txt ${workspace}/.local/bsc/node${i}/hardforkTime.txt
7478
bbcfee_addrs=${fee_addr}
7579
powers="0x000001d1a94a2000"
7680
mv ${workspace}/.local/bsc/bls${i}/bls ${workspace}/.local/bsc/node${i}/ && rm -rf ${workspace}/.local/bsc/bls${i}
@@ -83,10 +87,10 @@ function prepare_config() {
8387

8488
cd ${workspace}/genesis/
8589
git checkout HEAD contracts
86-
poetry run python -m scripts.generate generate-validators
87-
poetry run python -m scripts.generate generate-init-holders "${INIT_HOLDER}"
88-
poetry run python -m scripts.generate dev --dev-chain-id ${BSC_CHAIN_ID} --whitelist-1 "${INIT_HOLDER}" \
89-
--epoch ${epoch} --misdemeanor-threshold "5" --felony-threshold "10" \
90+
python3 -m scripts.generate generate-validators
91+
python3 -m scripts.generate generate-init-holders "${INIT_HOLDER}"
92+
python3 -m scripts.generate dev --dev-chain-id ${BSC_CHAIN_ID} --whitelist-1 "${INIT_HOLDER}" \
93+
--epoch ${epoch} \
9094
--init-felony-slash-scope "60" \
9195
--breathe-block-interval "1 minutes" \
9296
--block-interval ${blockInterval} \
@@ -105,16 +109,21 @@ function prepare_config() {
105109

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

114-
cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/geth${i}
118+
#cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/geth${i}
119+
cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/bsc
115120
# init genesis
116121
initLog=${workspace}/.local/bsc/node${i}/init.log
117-
${workspace}/bin/geth --datadir ${workspace}/.local/bsc/node${i} init --state.scheme ${stateScheme} --db.engine ${dbEngine} ${workspace}/genesis/genesis.json > "${initLog}" 2>&1
122+
if [ `expr $i \* 2` -ge ${size} ] ; then
123+
${workspace}/bin/geth --datadir ${workspace}/.local/bsc/node${i} init --state.scheme path --db.engine pebble ${workspace}/genesis/genesis.json > "${initLog}" 2>&1
124+
else
125+
${workspace}/bin/geth --datadir ${workspace}/.local/bsc/node${i} init --state.scheme ${stateScheme} --db.engine ${dbEngine} ${workspace}/genesis/genesis.json > "${initLog}" 2>&1
126+
fi
118127
done
119128
}
120129

@@ -154,6 +163,25 @@ function native_start() {
154163
done
155164
}
156165

166+
function remote_start() {
167+
rm -rf /mnt/efs/bsc-qa/clusterNetwork
168+
cp -r ${workspace}/.local/bsc /mnt/efs/bsc-qa/clusterNetwork
169+
ips=(${validator_ips_comma//,/ })
170+
for ((i=0;i<${#ips[@]};i++));do
171+
dst_id=${ips2ids[${ips[i]}]}
172+
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"
173+
done
174+
}
175+
176+
function remote_upgrade() {
177+
cp ${workspace}/bin/geth /mnt/efs/bsc-qa/clusterNetwork/
178+
cp ${workspace}/qa-env-resource/upgrade-single.sh /mnt/efs/bsc-qa/clusterNetwork/
179+
for dst_id in ${ips2ids[@]}; do
180+
aws ssm send-command --instance-ids "${dst_id}" --document-name "AWS-RunShellScript" \
181+
--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"
182+
done
183+
}
184+
157185
## docker relate begin
158186
function generate_static_peers() {
159187
tool=${workspace}/bin/bootnode
@@ -260,6 +288,16 @@ restart)
260288
exit_previous
261289
native_start
262290
;;
291+
remote_reset)
292+
create_validator
293+
reset_genesis
294+
prepare_config
295+
initNetwork
296+
remote_start
297+
;;
298+
remote_upgrade)
299+
remote_upgrade
300+
;;
263301
install_k8s)
264302
create_validator
265303
reset_genesis
@@ -272,6 +310,6 @@ uninstall_k8s)
272310
uninstall_k8s
273311
;;
274312
*)
275-
echo "Usage: start_cluster.sh | reset | stop | start | restart"
313+
echo "Usage: start_cluster.sh | reset | stop | start | restart | remote_reset | remote_upgrade"
276314
;;
277315
esac

0 commit comments

Comments
 (0)