-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathexecution-entrypoint
More file actions
executable file
·160 lines (140 loc) · 4.75 KB
/
execution-entrypoint
File metadata and controls
executable file
·160 lines (140 loc) · 4.75 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
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
#!/bin/bash
set -eu
IPC_PATH="/data/reth.ipc"
RETH_DATA_DIR=/data
RPC_PORT="${RPC_PORT:-8545}"
WS_PORT="${WS_PORT:-8546}"
AUTHRPC_PORT="${AUTHRPC_PORT:-8551}"
METRICS_PORT="${METRICS_PORT:-6060}"
DISCOVERY_PORT="${DISCOVERY_PORT:-30303}"
V5_DISCOVERY_PORT="${V5_DISCOVERY_PORT:-9200}"
P2P_PORT="${P2P_PORT:-30303}"
ADDITIONAL_ARGS=""
BINARY="./base-reth-node"
RETH_HISTORICAL_PROOFS="${RETH_HISTORICAL_PROOFS:-false}"
RETH_HISTORICAL_PROOFS_STORAGE_PATH="${RETH_HISTORICAL_PROOFS_STORAGE_PATH:-}"
LOG_LEVEL="${LOG_LEVEL:-info}"
if [[ -z "${RETH_CHAIN:-}" ]]; then
echo "expected RETH_CHAIN to be set" 1>&2
exit 1
fi
# Enable Flashblocks support if websocket URL is provided
if [[ -n "${RETH_FB_WEBSOCKET_URL:-}" ]]; then
ADDITIONAL_ARGS="$ADDITIONAL_ARGS --websocket-url=$RETH_FB_WEBSOCKET_URL"
echo "Enabling Flashblocks support with endpoint: $RETH_FB_WEBSOCKET_URL"
else
echo "Running in vanilla node mode (no Flashblocks URL provided)"
fi
case "$LOG_LEVEL" in
"error")
LOG_LEVEL="v"
;;
"warn")
LOG_LEVEL="vv"
;;
"info")
LOG_LEVEL="vvv"
;;
"debug")
LOG_LEVEL="vvvv"
;;
"trace")
LOG_LEVEL="vvvvv"
;;
*)
echo "Unknown log level: $LOG_LEVEL"
LOG_LEVEL="vvv"
;;
esac
wait_for_pid() {
local pid="$1"
# Check if the process exists at all before waiting
if [[ ! -e "/proc/$pid" ]]; then
echo "Process $pid does not exist." >&2
return 1
fi
echo "Waiting for process $pid to exit..."
while [[ -e "/proc/$pid" ]]; do
sleep 1
done
echo "Process $pid has exited."
}
# Add pruning for base
if [[ "${RETH_PRUNING_ARGS+x}" = x ]]; then
echo "Adding pruning arguments: $RETH_PRUNING_ARGS"
ADDITIONAL_ARGS="$ADDITIONAL_ARGS $RETH_PRUNING_ARGS"
fi
if [[ "$RETH_HISTORICAL_PROOFS" == "true" && -n "$RETH_HISTORICAL_PROOFS_STORAGE_PATH" ]]; then
# reth doesn't like starting an old database in RO mode, so we have to start the reth node, wait for it to start up, then shut it down first
"$BINARY" node \
-$LOG_LEVEL \
--datadir="$RETH_DATA_DIR" \
--log.stdout.format json \
--http \
--http.addr=127.0.0.1 \
--http.port="$RPC_PORT" \
--http.api=eth \
--chain "$RETH_CHAIN" &
PID=$!
MAX_WAIT=$((60 * 60 * 6)) # 6 hours (static file manager init is slow)
# wait for json-rpc to return a block number greater than 0 (synced beyond genesis)
while true; do
RESPONSE=$(curl -s -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' http://127.0.0.1:"$RPC_PORT" 2>/dev/null || true)
if echo "$RESPONSE" | grep -q '"number":"0x0"'; then
echo "waiting for reth node to sync beyond genesis block"
elif echo "$RESPONSE" | grep -q '"result"'; then
# curl succeeded and returned a valid result with block number != 0x0
break
else
echo "waiting for reth node to start up"
fi
sleep 1
MAX_WAIT=$((MAX_WAIT - 1))
if [ "$MAX_WAIT" -eq 0 ]; then
echo "timed out waiting for reth node to start up"
kill "$PID"
exit 1
fi
done
# shut down gracefully
kill "$PID"
(wait_for_pid "$PID" && echo "reth node initialized") || echo "warning: reth node exited with code $?"
ADDITIONAL_ARGS="$ADDITIONAL_ARGS --proofs-history --proofs-history.storage-path=$RETH_HISTORICAL_PROOFS_STORAGE_PATH"
# in this case, we need to run the init script first (idempotent)
"$BINARY" proofs init \
-$LOG_LEVEL \
--log.stdout.format json \
--chain "$RETH_CHAIN" \
--datadir="$RETH_DATA_DIR" \
--proofs-history.storage-path=$RETH_HISTORICAL_PROOFS_STORAGE_PATH
fi
mkdir -p "$RETH_DATA_DIR"
echo "Starting reth with additional args: $ADDITIONAL_ARGS"
echo "$BASE_NODE_L2_ENGINE_AUTH_RAW" > "$BASE_NODE_L2_ENGINE_AUTH"
exec "$BINARY" node \
-$LOG_LEVEL \
--datadir="$RETH_DATA_DIR" \
--log.stdout.format json \
--ws \
--ws.origins="*" \
--ws.addr=0.0.0.0 \
--ws.port="$WS_PORT" \
--ws.api=web3,debug,eth,net,txpool \
--http \
--http.corsdomain="*" \
--http.addr=0.0.0.0 \
--http.port="$RPC_PORT" \
--http.api=web3,debug,eth,net,txpool,miner \
--ipcpath="$IPC_PATH" \
--authrpc.addr=0.0.0.0 \
--authrpc.port="$AUTHRPC_PORT" \
--authrpc.jwtsecret="$BASE_NODE_L2_ENGINE_AUTH" \
--metrics=0.0.0.0:"$METRICS_PORT" \
--max-outbound-peers=100 \
--chain "$RETH_CHAIN" \
--rollup.sequencer-http="$RETH_SEQUENCER_HTTP" \
--rollup.disable-tx-pool-gossip \
--discovery.port="$DISCOVERY_PORT" \
--discovery.v5.port="$V5_DISCOVERY_PORT" \
--port="$P2P_PORT" \
$ADDITIONAL_ARGS