forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
273 lines (257 loc) · 7.8 KB
/
entrypoint.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/bin/sh
set -exu
GETH_BIN_PATH=${GETH_BIN_PATH:-geth}
GENESIS_L1_PATH=${GENESIS_L1_PATH:-/genesis_pos.json}
GETH_VERBOSITY=${GETH_VERBOSITY:-3}
GETH_LOG_FORMAT=${GETH_LOG_FORMAT:-terminal}
GETH_SYNC_MODE=${GETH_SYNC_MODE:-snap}
GETH_STATE_SCHEME=${GETH_STATE_SCHEME:-path}
GETH_DATA_DIR=${GETH_DATA_DIR:-/data}
GETH_CHAINDATA_DIR="$GETH_DATA_DIR/geth/chaindata"
GETH_KEYSTORE_DIR="$GETH_DATA_DIR/keystore"
GETH_KEYSTORE_PASSWORD=${GETH_KEYSTORE_PASSWORD:-"primev"}
GETH_ZERO_FEE_ADDRESSES=${GETH_ZERO_FEE_ADDRESSES:-}
CHAIN_ID=$(cat "$GENESIS_L1_PATH" | jq -r .config.chainId)
RPC_PORT="${RPC_PORT:-8545}"
WS_PORT="${WS_PORT:-8546}"
RPC_ENGINE_PORT="${RPC_ENGINE_PORT:-8551}"
BLOCK_SIGNER_PRIVATE_KEY=${BLOCK_SIGNER_PRIVATE_KEY:-""}
JWT_SECRET=${JWT_SECRET:-"13373d9a0257983ad150392d7ddb2f9172c9396b4c450e26af469d123c7aaa5c"}
ZERO_FEE_ADDRESSES=""
# Generate signer key if needed
if [ "$GETH_NODE_TYPE" = "signer" ]; then
if [ ! -f "$GETH_DATA_DIR/password" ]; then
echo -n "$GETH_KEYSTORE_PASSWORD" > "$GETH_DATA_DIR"/password
fi
if [ ! -d "$GETH_KEYSTORE_DIR" ]; then
if [ -n "$BLOCK_SIGNER_PRIVATE_KEY" ]; then
echo "$GETH_KEYSTORE_DIR missing, running account import"
echo -n "$BLOCK_SIGNER_PRIVATE_KEY" | sed 's/0x//' > "$GETH_DATA_DIR"/block-signer-key
"$GETH_BIN_PATH" \
--verbosity="$GETH_VERBOSITY" \
--log.format="$GETH_LOG_FORMAT" \
--nousb \
account import \
--datadir="$GETH_DATA_DIR" \
--password="$GETH_DATA_DIR"/password \
"$GETH_DATA_DIR"/block-signer-key
fi
else
echo "$GETH_KEYSTORE_DIR exists."
if [ -z "$BLOCK_SIGNER_PRIVATE_KEY" ]; then
GETH_ACCOUNT_LIST=$("$GETH_BIN_PATH" --verbosity="$GETH_VERBOSITY" account list --datadir "$GETH_DATA_DIR")
BLOCK_SIGNER_ADDRESS_WITHOUT_PREFIX=$(echo "$GETH_ACCOUNT_LIST" | grep -oE '[0-9a-fA-F]{40}$')
BLOCK_SIGNER_ADDRESS="0x$BLOCK_SIGNER_ADDRESS_WITHOUT_PREFIX"
echo "Block signer address with 0x prefix: $BLOCK_SIGNER_ADDRESS"
fi
fi
fi
# Init geth if needed
if [ ! -d "$GETH_CHAINDATA_DIR" ]; then
echo "$GETH_CHAINDATA_DIR missing, running init"
echo "Initializing genesis."
"$GETH_BIN_PATH" \
--verbosity="$GETH_VERBOSITY" \
--log.format="$GETH_LOG_FORMAT" \
--nousb \
--state.scheme="$GETH_STATE_SCHEME" \
--datadir="$GETH_DATA_DIR" init \
"$GENESIS_L1_PATH"
else
echo "$GETH_CHAINDATA_DIR exists."
fi
# Obtain assigned container IP for p2p
NODE_IP=${NODE_IP:-$(hostname -i)}
echo "NODE_IP is set to: $NODE_IP"
PUBLIC_NODE_IP=${PUBLIC_NODE_IP:-""}
echo "EXTERNAL_NODE_IP is set to: $PUBLIC_NODE_IP"
# Set NAT_FLAG based on whether PUBLIC_NODE_IP is empty or not
if [ -n "$PUBLIC_NODE_IP" ]; then
NAT_FLAG="--nat=extip:$PUBLIC_NODE_IP"
else
NAT_FLAG="--nat=none"
fi
# (Optional) Echo the values for verification
if [ "$GETH_NODE_TYPE" = "bootnode" ]; then
echo "Starting bootnode"
echo "$NODE_KEY" > $GETH_DATA_DIR/nodekey
exec "$GETH_BIN_PATH" \
--verbosity="$GETH_VERBOSITY" \
--log.format="$GETH_LOG_FORMAT" \
$ZERO_FEE_ADDRESSES \
--datadir="$GETH_DATA_DIR" \
--port 30301 \
--http \
--http.corsdomain="*" \
--http.vhosts="*" \
--http.addr="$NODE_IP" \
--http.port="$RPC_PORT" \
--http.api=web3,debug,eth,txpool,net,engine \
--ws \
--ws.addr="$NODE_IP" \
--ws.port="$WS_PORT" \
--ws.origins="*" \
--ws.api=debug,eth,txpool,net,engine \
--syncmode="${GETH_SYNC_MODE}" \
--gcmode=full \
--state.scheme="$GETH_STATE_SCHEME" \
--networkid=$CHAIN_ID \
--nousb \
--metrics \
--metrics.addr="$NODE_IP" \
--metrics.port=6060 \
--pprof \
--pprof.addr="$NODE_IP" \
--pprof.port=60601 \
--nodekey $GETH_DATA_DIR/nodekey \
--netrestrict $NET_RESTRICT \
"$NAT_FLAG" \
--txpool.accountqueue=512 \
--rpc.allow-unprotected-txs \
--miner.gasprice=1000000000 \
--miner.recommit=300ms \
--gpo.maxprice=500000000000 \
--authrpc.addr="$NODE_IP" \
--authrpc.jwtsecret $GETH_DATA_DIR/jwt.hex
elif [ "$GETH_NODE_TYPE" = "signer" ]; then
echo "Starting signer node"
echo "$NODE_KEY" > $GETH_DATA_DIR/nodekey
echo "$JWT_SECRET" > $GETH_DATA_DIR/jwt.hex
GETH_PORT="${GETH_PORT:-30311}"
exec "$GETH_BIN_PATH" \
--verbosity="$GETH_VERBOSITY" \
--log.format="$GETH_LOG_FORMAT" \
$ZERO_FEE_ADDRESSES \
--datadir="$GETH_DATA_DIR" \
--port="$GETH_PORT" \
--syncmode="${GETH_SYNC_MODE}" \
--gcmode=full \
--state.scheme="$GETH_STATE_SCHEME" \
--http \
--http.corsdomain="*" \
--http.vhosts="*" \
--http.addr="$NODE_IP" \
--http.port="$RPC_PORT" \
--http.api=web3,debug,eth,txpool,net,engine \
--networkid=$CHAIN_ID \
--unlock=$BLOCK_SIGNER_ADDRESS \
--password="$GETH_DATA_DIR"/password \
--mine \
--miner.etherbase=$BLOCK_SIGNER_ADDRESS \
--allow-insecure-unlock \
--nousb \
--nodekey $GETH_DATA_DIR/nodekey \
--netrestrict $NET_RESTRICT \
--metrics \
--metrics.addr="$NODE_IP" \
--metrics.port=6060 \
--pprof \
--pprof.addr="$NODE_IP" \
--pprof.port=60601 \
--ws \
--ws.addr="$NODE_IP" \
--ws.port="$WS_PORT" \
--ws.origins="*" \
--ws.api=debug,eth,txpool,net,engine \
--rpc.allow-unprotected-txs \
--authrpc.addr="$NODE_IP" \
--authrpc.port="$RPC_ENGINE_PORT" \
--authrpc.vhosts="*" \
--txpool.accountqueue=512 \
--miner.gasprice=1000000000 \
--miner.recommit=300ms \
--gpo.maxprice=500000000000 \
--authrpc.jwtsecret $GETH_DATA_DIR/jwt.hex \
"$NAT_FLAG"
elif [ "$GETH_NODE_TYPE" = "member" ]; then
echo "Starting member node"
echo "$NODE_KEY" > $GETH_DATA_DIR/nodekey
echo "BOOTNODE_ENDPOINT is set to: $BOOTNODE_ENDPOINT"
GETH_PORT="${GETH_PORT:-30311}"
exec "$GETH_BIN_PATH" \
--verbosity="$GETH_VERBOSITY" \
--log.format="$GETH_LOG_FORMAT" \
$ZERO_FEE_ADDRESSES \
--datadir="$GETH_DATA_DIR" \
--port="$GETH_PORT" \
--syncmode="${GETH_SYNC_MODE}" \
--gcmode=full \
--state.scheme="$GETH_STATE_SCHEME" \
--db.engine=pebble \
--http \
--http.corsdomain="*" \
--http.vhosts="*" \
--http.addr="$NODE_IP" \
--http.port="$RPC_PORT" \
--http.api=web3,debug,eth,txpool,net,engine \
--bootnodes $BOOTNODE_ENDPOINT \
--networkid=$CHAIN_ID \
--password="$GETH_DATA_DIR"/password \
--nodekey $GETH_DATA_DIR/nodekey \
--metrics \
--metrics.addr="$NODE_IP" \
--metrics.port=6060 \
--pprof \
--pprof.addr="$NODE_IP" \
--pprof.port=60601 \
--ws \
--ws.addr="$NODE_IP" \
--ws.port="$WS_PORT" \
--ws.origins="*" \
--ws.api=debug,eth,txpool,net,engine \
--rpc.allow-unprotected-txs \
--authrpc.addr="$NODE_IP" \
--authrpc.port="$RPC_ENGINE_PORT" \
--authrpc.vhosts="*" \
--txpool.accountqueue=512 \
--miner.gasprice=1000000000 \
--miner.recommit=300ms \
--gpo.maxprice=500000000000 \
"$NAT_FLAG"
elif [ "$GETH_NODE_TYPE" = "archive" ]; then
echo "Starting archive node"
echo "BOOTNODE_ENDPOINT is set to: $BOOTNODE_ENDPOINT"
GETH_PORT="${GETH_PORT:-30311}"
exec "$GETH_BIN_PATH" \
--verbosity="$GETH_VERBOSITY" \
--log.format="$GETH_LOG_FORMAT" \
--datadir="$GETH_DATA_DIR" \
--port="$GETH_PORT" \
--syncmode="${GETH_SYNC_MODE}" \
--gcmode=archive \
--history.state=0 \
--history.transactions=0 \
--state.scheme="$GETH_STATE_SCHEME" \
--db.engine=pebble \
--http \
--http.corsdomain="*" \
--http.vhosts="*" \
--http.addr="$NODE_IP" \
--http.port="$RPC_PORT" \
--http.api=web3,debug,eth,txpool,net,engine \
--bootnodes $BOOTNODE_ENDPOINT \
--networkid=$CHAIN_ID \
--password="$GETH_DATA_DIR"/password \
--metrics \
--metrics.addr="$NODE_IP" \
--metrics.port=6060 \
--pprof \
--pprof.addr="$NODE_IP" \
--pprof.port=60601 \
--ws \
--ws.addr="$NODE_IP" \
--ws.port="$WS_PORT" \
--ws.origins="*" \
--ws.api=debug,eth,txpool,net,engine \
--rpc.allow-unprotected-txs \
--authrpc.addr="$NODE_IP" \
--authrpc.port="$RPC_ENGINE_PORT" \
--authrpc.vhosts="*" \
--txpool.accountqueue=512 \
--miner.gasprice=1000000000 \
--miner.recommit=300ms \
--gpo.maxprice=500000000000 \
"$NAT_FLAG"
else
echo "Invalid GETH_NODE_TYPE specified"
fi