forked from bnb-chain/node-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bsc_fullnode.sh
executable file
·116 lines (100 loc) · 2.8 KB
/
bsc_fullnode.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
# Exit script on error
set -e
basedir=$(cd `dirname $0`; pwd)
workspace=${basedir}
source ${workspace}/.env
stateScheme="hash"
syncmode="full"
gcmode="full"
index=0
extraflags=""
src=${workspace}/.local/bsc/node0
if [ ! -d "$src" ] ;then
echo "you must startup validator firstly..."
exit 1
fi
if [ ! -z "$2" ] ;then
index=$2
fi
if [ ! -z "$3" ] ;then
syncmode=$3
fi
if [ ! -z "$4" ] ;then
extraflags=$4
fi
node=node$index
dst=${workspace}/.local/bsc/fullnode/${node}
hardforkfile=${workspace}/.local/bsc/hardforkTime.txt
rialtoHash=`cat $src/init.log|grep "database=chaindata"|awk -F"=" '{print $NF}'|awk -F'"' '{print $1}'`
PassedForkTime=`cat ${workspace}/.local/bsc/hardforkTime.txt|grep passedHardforkTime|awk -F" " '{print $NF}'`
LastHardforkTime=$(expr ${PassedForkTime} + ${LAST_FORK_MORE_DELAY})
mkdir -pv $dst/
function init() {
cp $src/config.toml $dst/ && cp $src/genesis.json $dst/
${workspace}/bin/geth init --state.scheme ${stateScheme} --datadir ${dst}/ ${dst}/genesis.json
}
function start() {
nohup ${workspace}/bin/geth --config $dst/config.toml --port $(( 31000 + $index )) \
--datadir $dst --rpc.allow-unprotected-txs --allow-insecure-unlock \
--ws.addr 0.0.0.0 --ws.port $(( 8600 + $index )) --http.addr 0.0.0.0 --http.port $(( 8600 + $index )) --http.corsdomain "*" \
--metrics --metrics.addr 0.0.0.0 --metrics.port $(( 6100 + $index )) --metrics.expensive \
--gcmode $gcmode --syncmode $syncmode --state.scheme ${stateScheme} $extraflags \
--rialtohash ${rialtoHash} --override.passedforktime ${PassedForkTime} \
--override.immutabilitythreshold ${FullImmutabilityThreshold} --override.breatheblockinterval ${BreatheBlockInterval} \
--override.minforblobrequest ${MinBlocksForBlobRequests} --override.defaultextrareserve ${DefaultExtraReserveForBlobRequests} \
> $dst/bsc-node.log 2>&1 &
echo $! > $dst/pid
}
function pruneblock() {
${workspace}/bin/geth snapshot prune-block --datadir $dst --datadir.ancient $dst/geth/chaindata/ancient/chain
}
function stop() {
if [ ! -f "$dst/pid" ];then
echo "$dst/pid not exist"
else
kill `cat $dst/pid`
rm -f $dst/pid
sleep 5
fi
}
function clean() {
stop
rm -rf $dst/*
}
CMD=$1
case ${CMD} in
start)
echo "===== start ===="
clean
init
start
echo "===== end ===="
;;
stop)
echo "===== stop ===="
stop
echo "===== end ===="
;;
restart)
echo "===== restart ===="
stop
start
echo "===== end ===="
;;
clean)
echo "===== clean ===="
clean
echo "===== end ===="
;;
pruneblock)
echo "===== pruneblock ===="
stop
pruneblock
echo "===== end ===="
;;
*)
echo "Usage: bsc_fullnode.sh start|stop|restart|clean nodeIndex syncmode"
echo "like: bsc_fullnode.sh start 1 snap, it will startup a snapsync node1"
;;
esac