testinprod-io / op-erigon

Optimism implementation on the efficiency frontier
https://op-erigon.testinprod.io
GNU Lesser General Public License v3.0
85 stars 14 forks source link

Support Execution Layer syncing #164

Open mininny opened 2 months ago

mininny commented 2 months ago

This PR adds support for execution layer syncing through the op-node. Instead of deriving every block through the op-node, EL sync allows the execution client to retrieve blocks from other P2P peers to speed up the process of syncing. This leverages the existing staged sync infrastructure and require very minimal diff on op-erigon compared to the upstream erigon.

Changes

Add bootnodes

Add OP bootnodes. See op-geth for existing set of bootnodes for reference.

Fixed an issue where NewPayload will return VALID without validating

When the op-erigon and op-node is performing execution-layer syncing, op-erigon performs existing p2p sync logic while op-node sends l2 payloads to drive EL sync. This NewPayload and ForkchoiceUpdated informs op-erigon where to begin syncing, and the response for these engine apis are used to determine whether the EL sync is complete.

When op-erigon is first initialized from genesis, it downloads the block headers from gensis to the latest chain head in order to retrieve ancestor data when it's not known. After downloading the block headers, because the amount of headers downloaded is too large, erigon skips validation of the downloaded blocks (see this commit). Instead, it just returns VALID as a response for the NewPayload, even though erigon client hasn't completely synced or validated the blocks.

However, this VALID signal incorrectly informs op-node that the EL sync is complete. op-node then retrieves the current head of the op-erigon, which pretended to be the chain head, while there actually isn't any validated blocks.

Diagram Apr 23 2024

an illustration of the problematic flow

In order to fix this, the engine server now attempts to validate the chain at the head block, and returns SYNCING if the block validation was skipped. The engine will return VALID only after initial sync is complete and actually validated the chain.

Update TTD calculation for bedrock

For OP-stack chains, we use bedrock activation number for op-stack for determining when TTD has been reached.


Tested on op-sepolia(about 3 hours for complete sync) and will be tested on mainnet as well.