#!/command/with-contenv bash

set -eu

GETH_DATA_DIR=/db
CHAIN_ID=$(cat "/etc/op-geth/genesis.json" | jq -r .config.chainId)

# Warning: Archive mode is required, otherwise old trie nodes will be
# pruned within minutes of starting the devnet.

exec geth \
	--datadir="$GETH_DATA_DIR" \
	--verbosity="$OP_GETH_VERBOSITY" \
	--http \
	--http.addr="$OP_GETH_HTTP_ADDR" \
	--http.corsdomain="$OP_GETH_HTTP_CORSDOMAIN" \
	--http.vhosts="$OP_GETH_HTTP_VHOSTS" \
	--http.port="$OP_GETH_HTTP_PORT" \
	--http.api=web3,debug,eth,txpool,net,engine \
	--ws \
	--ws.addr="$OP_GETH_WS_ADDR" \
	--ws.port="$OP_GETH_WS_PORT" \
	--ws.origins="$OP_GETH_WS_ORIGINS" \
	--ws.api=debug,eth,txpool,net,engine \
	--syncmode=full \
	--nodiscover \
	--maxpeers="$OP_GETH_MAX_PEERS" \
	--networkid=$CHAIN_ID \
	--gcmode=archive \
	--rollup.sequencerhttp="$OP_GETH_SEQUENCER_HTTP" \
	--authrpc.jwtsecret=/etc/secrets/jwt-secret.txt
	"$@"