-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnode-start.sh
executable file
·215 lines (170 loc) · 5.55 KB
/
node-start.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
#set -x
set -e
GREEN='\033[0;32m'
RED='\033[0;31m'
ORANGE='\033[0;33m'
NC='\033[0m' # No Color
#########################################################################
totalRpc=0
totalValidator=0
totalNodes=$(($totalRpc + $totalValidator))
isRPC=false
isValidator=false
#########################################################################
source ./.env
#########################################################################
#+-----------------------------------------------------------------------------------------------+
#| |
#| |
#| FUNCTIONS |
#| |
#| |
#+-----------------------------------------------------------------------------------------------+
welcome(){
# display welcome message
echo -e "\n\n\t${ORANGE}Total RPC installed: $totalRpc"
echo -e "\t${ORANGE}Total Validators installed: $totalValidator"
echo -e "\t${ORANGE}Total nodes installed: $totalNodes"
echo -e "${GREEN}
\t+------------------------------------------------+
\t+ DPos node Execution Utility
\t+ Target OS: Ubuntu 20.04 LTS (Focal Fossa)
\t+ Your OS: $(. /etc/os-release && printf '%s\n' "${PRETTY_NAME}")
\t+ example usage: ./node-start.sh --help
\t+------------------------------------------------+
${NC}\n"
echo -e "${ORANGE}
\t+------------------------------------------------+
\t+------------------------------------------------+
${NC}"
}
countNodes(){
local i=1
totalNodes=$(ls -l ./chaindata/ | grep -c ^d)
while [[ $i -le $totalNodes ]]; do
if [ -f "./chaindata/node$i/.rpc" ]; then
((totalRpc += 1))
else
if [ -f "./chaindata/node$i/.validator" ]; then
((totalValidator += 1))
fi
fi
((i += 1))
done
}
startRpc(){
i=$((totalValidator + 1))
while [[ $i -le $totalNodes ]]; do
if tmux has-session -t node$i > /dev/null 2>&1; then
:
else
tmux new-session -d -s node$i
tmux send-keys -t node$i " ./node_src/build/bin/geth --datadir ./chaindata/node$i --networkid $CHAINID --ws --ws.addr $IP --ws.origins '*' --ws.port 8545 --http --http.port 80 --rpc.txfeecap 0 --http.corsdomain '*' --nat 'any' --http.api db,eth,net,web3,personal,txpool,miner,debug --http.addr $IP --http.vhosts=$VHOST --vmdebug --pprof --pprof.port 6060 --pprof.addr $IP --gcmode=archive --syncmode=full --ipcpath './chaindata/node$i/geth.ipc' console" Enter
fi
((i += 1))
done
}
startValidator(){
i=1
j=69
while [[ $i -le $totalValidator ]]; do
if tmux has-session -t node$i > /dev/null 2>&1; then
:
else
tmux new-session -d -s node$i
tmux send-keys -t 0 "./node_src/build/bin/geth --datadir ./chaindata/node$i --networkid $CHAINID --bootnodes $BOOTNODE --mine --port 326$j --nat extip:$IP --gpo.percentile 0 --gpo.maxprice 100 --gpo.ignoreprice 0 --unlock 0 --password ./chaindata/node$i/pass.txt --syncmode=full console" Enter
fi
((i += 1))
((j += 1))
done
}
finalize(){
countNodes
welcome
if [ "$isRPC" = true ]; then
echo -e "\n${GREEN}+------------------- Starting RPC -------------------+"
startRpc
fi
if [ "$isValidator" = true ]; then
echo -e "\n${GREEN}+------------------- Starting Validator -------------------+"
startValidator
fi
echo -e "\n${GREEN}+------------------ Active Nodes -------------------+"
tmux ls
echo -e "\n${GREEN}+------------------ Active Nodes -------------------+${NC}"
}
# Default variable values
verbose_mode=false
output_file=""
# Function to display script usage
usage() {
echo -e "\nUsage: $0 [OPTIONS]"
echo "Options:"
echo -e "\t\t -h, --help Display this help message"
echo -e " \t\t -v, --verbose Enable verbose mode"
echo -e "\t\t --rpc Start all the RPC nodes installed"
echo -e "\t\t --validator Start all the Validator nodes installed"
}
has_argument() {
[[ ("$1" == *=* && -n ${1#*=}) || (! -z "$2" && "$2" != -*) ]]
}
extract_argument() {
echo "${2:-${1#*=}}"
}
# Function to handle options and arguments
handle_options() {
while [ $# -gt 0 ]; do
case $1 in
# display help
-h | --help)
usage
exit 0
;;
# toggle verbose
-v | --verbose)
verbose_mode=true
;;
# take file input
-f | --file*)
if ! has_argument $@; then
echo "File not specified." >&2
usage
exit 1
fi
output_file=$(extract_argument $@)
shift
;;
# take ROC count
--rpc)
isRPC=true
;;
# take validator count
--validator)
isValidator=true
;;
*)
echo "Invalid option: $1" >&2
usage
exit 1
;;
esac
shift
done
}
# Main script execution
handle_options "$@"
# Perform the desired actions based on the provided flags and arguments
if [ "$verbose_mode" = true ]; then
echo "Verbose mode enabled."
fi
if [ -n "$output_file" ]; then
echo "Output file specified: $output_file"
fi
if [ $# -eq 0 ]
then
echo "No arguments supplied"
usage
exit 1
fi
finalize