Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set finalized & safe block information on startup #9105

Closed
wants to merge 2 commits into from

Conversation

danyalprout
Copy link
Contributor

Description

Currently when you restart Reth, fetching blocks by finalized or safe block returns "block not found". This causes an issue when running op-reth via consensus layer sync, as it'll cause op-node to walk the chain back to genesis.

This PR loads the finalized block number from the database and initializes it on startup. It'll also set the safe block equal to the finalized value -- as the finalized block is also safe.

You can repro this bug on main with the following steps:

# set safe/finalized head via forkchoice update

# Fetch the finalized block
curl localhost:8545 \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"eth_getBlockByNumber","params":["finalized",false],"id":1,"jsonrpc":"2.0"}' | jq
{... block info}

# restart reth

# Fetch the finalized block
curl localhost:8545 \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"eth_getBlockByNumber","params":["finalized",false],"id":1,"jsonrpc":"2.0"}' | jq

{
  "jsonrpc": "2.0",
  "error": {
    "code": -39001,
    "message": "unknown block"
  },
  "id": 1
}

@danyalprout danyalprout marked this pull request as ready for review June 25, 2024 20:41
@joshieDo
Copy link
Collaborator

joshieDo commented Jun 25, 2024

We only recently started storing the last finalized block, so this makes sense overall, even beyond op-reth.

But given how op-node switches between el-sync and cl-sync on boot-up, this will have the effect that a node won't use our staged sync beyond the first time syncing. (eg. stopping the node for a week, and starting it again).

@mattsse
Copy link
Collaborator

mattsse commented Jul 16, 2024

@joshieDo confirming we still want this?

@danyalprout
Copy link
Contributor Author

danyalprout commented Jul 17, 2024

@joshieDo FYI I'm going to test this now with engine kind reth param from ethereum-optimism/optimism#10767 and see if it works as expected.

@danyalprout danyalprout force-pushed the fix-finalized-block branch from e77d0c5 to e9c561c Compare July 17, 2024 07:09
@danyalprout
Copy link
Contributor Author

@joshieDo was able to restore from a snapshot and it would EL sync from the snapshot to tip -- without having to walk back to genesis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants