Skip to content

Commit 1c26ba4

Browse files
committed
support QA deploy
1 parent 3d9fe7b commit 1c26ba4

File tree

10 files changed

+249
-16
lines changed

10 files changed

+249
-16
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

.gitignore

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

77
.local/
88

9-
.idea/
9+
.idea/

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

start_cluster.sh

Lines changed: 46 additions & 13 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))
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
2021

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

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

6060
function prepare_config() {
@@ -73,6 +73,8 @@ function prepare_config() {
7373
mkdir -p ${workspace}/.local/bsc/node${i}
7474
cp ${workspace}/keys/password.txt ${workspace}/.local/bsc/node${i}/
7575
cp ${workspace}/.local/bsc/hardforkTime.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
7678
bbcfee_addrs=${fee_addr}
7779
powers="0x000001d1a94a2000" #2000000000000
7880
mv ${workspace}/.local/bsc/bls${i}/bls ${workspace}/.local/bsc/node${i}/ && rm -rf ${workspace}/.local/bsc/bls${i}
@@ -89,10 +91,10 @@ function prepare_config() {
8991
sed -i -e '/registeredContractChannelMap\[VALIDATOR_CONTRACT_ADDR\]\[STAKING_CHANNELID\]/d' ${workspace}/genesis/contracts/deprecated/CrossChain.sol
9092
sed -i -e 's/public onlyCoinbase onlyZeroGasPrice {/public onlyCoinbase onlyZeroGasPrice {if (block.number < 30) return;/' ${workspace}/genesis/contracts/BSCValidatorSet.sol
9193
fi
92-
poetry run python -m scripts.generate generate-validators
93-
poetry run python -m scripts.generate generate-init-holders "${initHolders}"
94-
quorum=$(($BSC_CLUSTER_SIZE*2/3+1))
95-
poetry run python -m scripts.generate dev --dev-chain-id ${BSC_CHAIN_ID} --whitelist-1 "${INIT_HOLDER}" \
94+
python3 -m scripts.generate generate-validators
95+
python3 -m scripts.generate generate-init-holders "${initHolders}"
96+
quorum=$(($size*2/3+1))
97+
python3 -m scripts.generate dev --dev-chain-id ${BSC_CHAIN_ID} --whitelist-1 "${INIT_HOLDER}" \
9698
--epoch ${epoch} \
9799
--init-felony-slash-scope "60" \
98100
--breathe-block-interval "10 minutes" \
@@ -117,13 +119,14 @@ function initNetwork() {
117119
mkdir ${workspace}/.local/bsc/node${i}/geth
118120
cp ${workspace}/keys/nodekey${i} ${workspace}/.local/bsc/node${i}/geth/nodekey
119121
done
120-
${workspace}/bin/geth init-network --init.dir ${workspace}/.local/bsc --init.size=${size} --config ${workspace}/config.toml ${workspace}/genesis/genesis.json
122+
${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
121123
rm -rf ${workspace}/*bsc.log*
122124
for ((i = 0; i < size; i++)); do
123125
sed -i -e '/"<nil>"/d' ${workspace}/.local/bsc/node${i}/config.toml
124126
mv ${workspace}/.local/bsc/validator${i}/keystore ${workspace}/.local/bsc/node${i}/ && rm -rf ${workspace}/.local/bsc/validator${i}
125127

126-
cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/geth${i}
128+
#cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/geth${i}
129+
cp ${workspace}/bin/geth ${workspace}/.local/bsc/node${i}/bsc
127130
# init genesis
128131
initLog=${workspace}/.local/bsc/node${i}/init.log
129132
if [ $i -eq 0 ] ; then
@@ -181,15 +184,34 @@ function native_start() {
181184

182185
function register_stakehub(){
183186
if ${needRegister};then
184-
echo "sleep 45s to wait feynman enable"
185-
sleep 45
187+
echo "sleep 100s to wait feynman enable"
188+
sleep 100
186189
for ((i = 0; i < size; i++));do
187190
${workspace}/create-validator/create-validator --consensus-key-dir ${workspace}/keys/validator${i} --vote-key-dir ${workspace}/keys/bls${i} \
188191
--password-path ${workspace}/keys/password.txt --amount 20001 --validator-desc Val${i} --rpc-url ${RPC_URL}
189192
done
190193
fi
191194
}
192195

196+
function remote_start() {
197+
rm -rf /mnt/efs/bsc-qa/clusterNetwork
198+
cp -r ${workspace}/.local/bsc /mnt/efs/bsc-qa/clusterNetwork
199+
ips=(${validator_ips_comma//,/ })
200+
for ((i=0;i<${#ips[@]};i++));do
201+
dst_id=${ips2ids[${ips[i]}]}
202+
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"
203+
done
204+
}
205+
206+
function remote_upgrade() {
207+
cp ${workspace}/bin/geth /mnt/efs/bsc-qa/clusterNetwork/
208+
cp ${workspace}/qa-env-resource/upgrade-single.sh /mnt/efs/bsc-qa/clusterNetwork/
209+
for dst_id in ${ips2ids[@]}; do
210+
aws ssm send-command --instance-ids "${dst_id}" --document-name "AWS-RunShellScript" \
211+
--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"
212+
done
213+
}
214+
193215
## docker relate begin
194216
function generate_static_peers() {
195217
tool=${workspace}/bin/bootnode
@@ -298,6 +320,17 @@ restart)
298320
exit_previous $ValidatorIdx
299321
native_start $ValidatorIdx
300322
;;
323+
remote_reset)
324+
create_validator
325+
reset_genesis
326+
prepare_config
327+
initNetwork
328+
remote_start
329+
register_stakehub
330+
;;
331+
remote_upgrade)
332+
remote_upgrade
333+
;;
301334
install_k8s)
302335
create_validator
303336
reset_genesis
@@ -310,6 +343,6 @@ uninstall_k8s)
310343
uninstall_k8s
311344
;;
312345
*)
313-
echo "Usage: start_cluster.sh | reset | stop | start | restart"
346+
echo "Usage: start_cluster.sh | reset | stop | start | restart | remote_reset | remote_upgrade"
314347
;;
315348
esac

0 commit comments

Comments
 (0)