Repository navigation
Expand file tree
/
Copy pathnode.sh
More file actions
executable file
·111 lines (97 loc) · 3.7 KB
/
Copy pathnode.sh
File metadata and controls
executable file
·111 lines (97 loc) · 3.7 KB
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
#!/usr/bin/env bash
# Starts one node of the private network: ./node.sh <number>
# Settings are read from config.yml and .env. See the README.
set -euo pipefail
die() {
echo "node.sh: $*" >&2
exit 1
}
node="${1:-}"
[[ "$node" =~ ^[1-9][0-9]*$ ]] || die "usage: ./node.sh <number>, starting from 1"
cd "$(dirname "$0")"
if [[ -f .env ]]; then
# .env is run as shell code and holds keys, so it must be yours alone
if [[ -n "$(find -L .env \( -perm -040 -o -perm -004 -o -perm -020 -o -perm -002 \))" ]]; then
die ".env can be read or changed by other accounts. Run: chmod 600 .env"
fi
# shellcheck disable=SC1091
. ./.env
fi
# The node process must not inherit secrets, because its environment can be read back
key_name="PRIVATE_KEY_$node"
key="${!key_name:-}"
ethstats="${ETHSTATS:-}"
for name in "${!PRIVATE_KEY_@}"; do
unset "$name"
done
unset ETHSTATS
project_dir="${PROJECT_DIR:-$HOME/XDPoSChain}"
xdc="$project_dir/build/bin/XDC"
genesis="${GENESIS_FILE:-./genesis/genesis.json}"
[[ -x "$xdc" ]] || die "$xdc not found. Run setup.sh first, or set PROJECT_DIR"
python3 config.py check >/dev/null
network_id="$(python3 config.py get networkID)"
total_nodes="$(python3 config.py get Total_Nodes)"
((node <= total_nodes)) || die "node $node is outside Total_Nodes ($total_nodes)"
[[ -n "${BOOTNODES:-}" ]] || die "set BOOTNODES in .env to your bootnode's enode URL"
rpc_addr="${RPC_ADDR:-127.0.0.1}"
rpc_api="${RPC_API:-eth,net,web3,XDPoS}"
rpc_api="${rpc_api//[[:space:]]/}"
[[ -n "$rpc_api" ]] || die "RPC_API is blank. Leave it out for the default, or list the APIs to offer"
case "$rpc_addr" in
127.0.0.1 | localhost | ::1) ;;
*)
# The wallet is unlocked, so eth_sendTransaction would let anyone who reaches the port spend from it
IFS=, read -r -a apis <<<"$rpc_api"
for api in "${apis[@]}"; do
case "$api" in
net | web3 | XDPoS) ;;
*) die "refusing to offer the $api API on $rpc_addr: this node holds an unlocked wallet. Set RPC_API=net,web3,XDPoS, and see the README for remote access" ;;
esac
done
;;
esac
umask 077
if [[ ! -s .pwd ]]; then
openssl rand -hex 32 >.pwd
fi
chmod 600 .pwd
datadir="./nodes/$node"
pid_file="$datadir/XDC.pid"
log_file="$datadir/XDC.log"
if [[ -f "$pid_file" ]] && kill -0 "$(cat "$pid_file")" 2>/dev/null; then
die "node $node is already running with process $(cat "$pid_file")"
fi
if [[ ! -d "$datadir/XDC/chaindata" ]]; then
[[ -f "$genesis" ]] || die "$genesis not found. Create it with Puppeth, or set GENESIS_FILE"
[[ -n "$key" ]] || die "set $key_name in .env"
mkdir -p "$datadir"
wallet="$("$xdc" account import --password .pwd --datadir "$datadir" <(printf '%s\n' "${key#0x}") | awk -F '[{}]' '{print $2}')"
[[ -n "$wallet" ]] || die "could not import $key_name"
"$xdc" --datadir "$datadir" init "$genesis"
else
wallet="$("$xdc" account list --datadir "$datadir" | head -n 1 | awk -F '[{}]' '{print $2}')"
[[ -n "$wallet" ]] || die "no account found in $datadir"
fi
unset key
args=(
--datadir "$datadir"
--networkid "$network_id"
--bootnodes "$BOOTNODES"
--syncmode full
--gcmode archive
--port "$((30302 + node))"
--http --http-addr "$rpc_addr" --http-port "$((8544 + node))" --http-api "$rpc_api"
--ws --ws-addr "$rpc_addr" --ws-port "$((8554 + node))" --ws-api "$rpc_api"
--unlock "$wallet" --password ./.pwd
--mine
--verbosity 3
)
if [[ -n "$ethstats" ]]; then
args+=(--ethstats "$ethstats")
fi
nohup "$xdc" "${args[@]}" >>"$log_file" 2>&1 &
echo $! >"$pid_file"
sleep "${START_WAIT:-2}"
kill -0 "$(cat "$pid_file")" 2>/dev/null || die "node $node stopped straight away. See $log_file"
echo "Node $node started as process $(cat "$pid_file"), wallet $wallet. Check $log_file to see that it stays up and syncs"