Skip to content

feat(l1): reorgs for blocks that are connected to the canonical chain#577

Merged
Arkenan merged 44 commits into
mainfrom
long-reorgs
Oct 15, 2024
Merged

feat(l1): reorgs for blocks that are connected to the canonical chain#577
Arkenan merged 44 commits into
mainfrom
long-reorgs

Conversation

@Arkenan

@Arkenan Arkenan commented Sep 27, 2024

Copy link
Copy Markdown
Collaborator

Motivation

Up until now we can perform reorgs as long as the parent of the newly added block is canonical. This PR aims to enable blocks that have canonical ancestors, even if they may not be direct parents.

Changes

  • blockchain.add_block:
    • We now stopped checking if the parent is canonical, we rely on the state transition to check that the parent's state exists in the db, which is all we need to execute the block.
    • The latest canonical block is not updated here now, as it now symbolizes the head of the chain instead of the latest block that has arrived.
  • ForkChoiceUpdatedV3:
    • All ancestors of head are made canonical after the reorg.
    • New checks: it is checked that finalized, safe and head blocks are part of the new canonical chain and in the correct order.
    • We now allow for finalized and safe hashes to be zero in the request (needed for near-merge times when no blocks can be yet dimmed safe or finalized).
    • Most of the fork choice functionality is moved to the blockchain.rs file and errors are returned when the request should fail and payload attributes should not be executed.
    • Fork choice has now been moved to before payload building, as it needs to be applied regardless of wether the payload succeeds or not. This is to be completed by Fork choice should still be applied when payload attributes are invalid #853 as the parsing needs to be fixed too.
    • Logs are added for easier debugging.
  • A basic integration test is added for the payload + fork choice updated functionality.
  • We no longer make imported blocks canonical, even if they come from the genesis file.

Closes #444

@Arkenan Arkenan requested a review from a team as a code owner September 27, 2024 18:15
@Arkenan Arkenan marked this pull request as draft September 27, 2024 18:15
Comment thread crates/blockchain/blockchain.rs
Comment thread crates/blockchain/blockchain.rs Outdated
Comment thread crates/blockchain/blockchain.rs Outdated
@Arkenan Arkenan requested a review from mpaulucci October 4, 2024 16:28
@Arkenan Arkenan marked this pull request as ready for review October 4, 2024 16:28
Comment thread crates/blockchain/blockchain.rs Outdated
Comment thread crates/blockchain/blockchain.rs Outdated
Comment thread crates/blockchain/blockchain.rs Outdated
Comment thread cmd/ethereum_rust/ethereum_rust.rs
Comment thread crates/blockchain/blockchain.rs
Comment thread crates/blockchain/blockchain.rs Outdated
Comment thread crates/blockchain/error.rs Outdated
Comment thread crates/blockchain/fork_choice.rs
Comment thread crates/networking/rpc/engine/fork_choice.rs
Comment thread crates/storage/store/engines/in_memory.rs

@mpaulucci mpaulucci left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

great work! 🚀

@Arkenan Arkenan enabled auto-merge October 15, 2024 16:15
@Arkenan Arkenan added this pull request to the merge queue Oct 15, 2024
Merged via the queue into main with commit 5c86af8 Oct 15, 2024
@Arkenan Arkenan deleted the long-reorgs branch October 15, 2024 16:36
mpaulucci pushed a commit that referenced this pull request Oct 16, 2024
…#577)

**Motivation**

Up until now we can perform reorgs as long as the parent of the newly
added block is canonical. This PR aims to enable blocks that have
canonical ancestors, even if they may not be direct parents.

**Changes**

- `blockchain.add_block`:
- We now stopped checking if the parent is canonical, we rely on the
state transition to check that the parent's state exists in the db,
which is all we need to execute the block.
- The latest canonical block is not updated here now, as it now
symbolizes the head of the chain instead of the latest block that has
arrived.
- `ForkChoiceUpdatedV3`:
  - All ancestors of head are made canonical after the reorg.
- New checks: it is checked that finalized, safe and head blocks are
part of the new canonical chain and in the correct order.
- We now allow for finalized and safe hashes to be zero in the request
(needed for near-merge times when no blocks can be yet dimmed safe or
finalized).
- Most of the fork choice functionality is moved to the blockchain.rs
file and errors are returned when the request should fail and payload
attributes should not be executed.
- Fork choice has now been moved to before payload building, as it needs
to be applied regardless of wether the payload succeeds or not. This is
to be completed by #853 as the parsing needs to be fixed too.
  - Logs are added for easier debugging.
- A basic integration test is added for the payload + fork choice
updated functionality.
- We no longer make imported blocks canonical, even if they come from
the genesis file.

Closes #444
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.

Implement indirectly linked reorgs

3 participants