Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 74 additions & 1 deletion reth/reth-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ DISCOVERY_PORT="${DISCOVERY_PORT:-30303}"
P2P_PORT="${P2P_PORT:-30303}"
ADDITIONAL_ARGS=""
BINARY="./base-reth-node"
NODE_TYPE="${NODE_TYPE:-base}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used, maybe delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Expand All @@ -25,18 +29,87 @@ else
echo "Running in vanilla node mode (no Flashblocks URL provided)"
fi

case "$LOG_LEVEL" in
"debug")
LOG_LEVEL="vvvv"
;;
"warn")
LOG_LEVEL="vv"
;;
"info"|*)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please be exhaustive here, otherwise, error / trace level maps to info

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG_LEVEL="vvv"
;;
esac

# 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 "$PID"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this been tested?

From Devin:
wait "$PID" exits script due to set -e after killing the reth process
After kill "$PID" sends SIGTERM to the background reth process on line 89, wait "$PID" on line 91 returns exit code 143 (128 + 15 for SIGTERM). Because the script runs with set -eu (reth/reth-entrypoint:2), this non-zero exit code causes the script to abort immediately. Lines 92-104 (including the proofs init command and the final exec) are never reached.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been tested. I think Devin is wrong. I don't think it gets aborted because it's forked to a different process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, I guess wait returns the exit code of the child process. SIGTERM should return exit code 0 for reth though because it gracefully shuts down.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the exit handler does catch SIGTERM gracefully

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interestingly, it seems like Reth might be technically wrong to do this... https://stackoverflow.com/a/57944209

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignored exit code here just in case: dc52b6c

echo "reth node initialized"

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

sleep 60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the sleep here? is proofs init async?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we do. Not sure why this was added.

fi

mkdir -p "$RETH_DATA_DIR"
echo "Starting reth with additional args: $ADDITIONAL_ARGS"
echo "$OP_NODE_L2_ENGINE_AUTH_RAW" > "$OP_NODE_L2_ENGINE_AUTH"

exec "$BINARY" node \
-vvv \
-$LOG_LEVEL \
--datadir="$RETH_DATA_DIR" \
--log.stdout.format json \
--ws \
Expand Down