@@ -11,6 +11,9 @@ DISCOVERY_PORT="${DISCOVERY_PORT:-30303}"
1111P2P_PORT=" ${P2P_PORT:- 30303} "
1212ADDITIONAL_ARGS=" "
1313BINARY=" ./base-reth-node"
14+ RETH_HISTORICAL_PROOFS=" ${RETH_HISTORICAL_PROOFS:- false} "
15+ RETH_HISTORICAL_PROOFS_STORAGE_PATH=" ${RETH_HISTORICAL_PROOFS_STORAGE_PATH:- } "
16+ LOG_LEVEL=" ${LOG_LEVEL:- info} "
1417
1518if [[ -z " ${RETH_CHAIN:- } " ]]; then
1619 echo " expected RETH_CHAIN to be set" 1>&2
2528 echo " Running in vanilla node mode (no Flashblocks URL provided)"
2629fi
2730
31+ case " $LOG_LEVEL " in
32+ " error" )
33+ LOG_LEVEL=" v"
34+ ;;
35+ " warn" )
36+ LOG_LEVEL=" vv"
37+ ;;
38+ " info" |* )
39+ LOG_LEVEL=" vvv"
40+ ;;
41+ " debug" )
42+ LOG_LEVEL=" vvvv"
43+ ;;
44+ " trace" )
45+ LOG_LEVEL=" vvvvv"
46+ ;;
47+ esac
48+
2849# Add pruning for base
2950if [[ " ${RETH_PRUNING_ARGS+x} " = x ]]; then
3051 echo " Adding pruning arguments: $RETH_PRUNING_ARGS "
3152 ADDITIONAL_ARGS=" $ADDITIONAL_ARGS $RETH_PRUNING_ARGS "
3253fi
3354
55+ if [[ " $RETH_HISTORICAL_PROOFS " == " true" && -n " $RETH_HISTORICAL_PROOFS_STORAGE_PATH " ]]; then
56+ # 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
57+ " $BINARY " node \
58+ -$LOG_LEVEL \
59+ --datadir=" $RETH_DATA_DIR " \
60+ --log.stdout.format json \
61+ --http \
62+ --http.addr=127.0.0.1 \
63+ --http.port=" $RPC_PORT " \
64+ --http.api=eth \
65+ --chain " $RETH_CHAIN " &
66+
67+ PID=$!
68+
69+ MAX_WAIT=$(( 60 * 60 * 6 )) # 6 hours (static file manager init is slow)
70+
71+ # wait for json-rpc to return a block number greater than 0 (synced beyond genesis)
72+ while true ; do
73+ 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)
74+
75+ if echo " $RESPONSE " | grep -q ' "number":"0x0"' ; then
76+ echo " waiting for reth node to sync beyond genesis block"
77+ elif echo " $RESPONSE " | grep -q ' "result"' ; then
78+ # curl succeeded and returned a valid result with block number != 0x0
79+ break
80+ else
81+ echo " waiting for reth node to start up"
82+ fi
83+
84+ sleep 1
85+ MAX_WAIT=$(( MAX_WAIT - 1 ))
86+ if [ " $MAX_WAIT " -eq 0 ]; then
87+ echo " timed out waiting for reth node to start up"
88+ kill " $PID "
89+ exit 1
90+ fi
91+ done
92+
93+ # shut down gracefully
94+ kill " $PID "
95+
96+ (wait " $PID " && echo " reth node initialized" ) || echo " warning: reth node exited with code $? "
97+
98+ ADDITIONAL_ARGS=" $ADDITIONAL_ARGS --proofs-history --proofs-history.storage-path=$RETH_HISTORICAL_PROOFS_STORAGE_PATH "
99+
100+ # in this case, we need to run the init script first (idempotent)
101+ " $BINARY " proofs init \
102+ -$LOG_LEVEL \
103+ --log.stdout.format json \
104+ --chain " $RETH_CHAIN " \
105+ --datadir=" $RETH_DATA_DIR " \
106+ --proofs-history.storage-path=$RETH_HISTORICAL_PROOFS_STORAGE_PATH
107+ fi
108+
34109mkdir -p " $RETH_DATA_DIR "
35110echo " Starting reth with additional args: $ADDITIONAL_ARGS "
36111echo " $OP_NODE_L2_ENGINE_AUTH_RAW " > " $OP_NODE_L2_ENGINE_AUTH "
37112
38113exec " $BINARY " node \
39- -vvv \
114+ -$LOG_LEVEL \
40115 --datadir=" $RETH_DATA_DIR " \
41116 --log.stdout.format json \
42117 --ws \
0 commit comments