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

Add merge indicator to fork choice struct #2627

Conversation

realbigsean
Copy link
Member

Issue Addressed

  • The merge P2P spec requires checking whether a block's parent state has a non-empty ExecutionPayload. In order to avoid loading a parent state for every block we see in gossip, this PR adds an is_merge_complete bool to the ProtoNode struct
    so we can call fork_choice.get_block(block.parent_root).is_merge_complete

Proposed Changes

  • Adds the field described above
  • Adds a database migration from schema 4 to schema 5, so we can add the new field to the PersistedForkChoice

Additional Info

To facilitate the database migration I added the new field to ProtoNode and created a LegacyProtoNode struct (which doesn't include the new field) and LegacySszContainser struct. I initially tried to use superstruct to create variants with and without the field but it didn't seem worth the complexity because the old struct is only going to be used during the database migration.

realbigsean and others added 5 commits September 24, 2021 17:29
* Remove unchecked arith from ssz_derive

* Address clippy lints in block_verfication

* Use safe math for is_valid_gas_limit
@@ -73,6 +75,28 @@ pub fn migrate_schema<T: BeaconChainTypes>(

Ok(())
}
// Migration for adding `is_merge_complete` field to the fork choice store.
(SchemaVersion(4), SchemaVersion(5)) => {
Copy link
Member

Choose a reason for hiding this comment

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

There's a schema 5 in unstable already for checkpoint sync, so this should be 5->6 once merge-f2f gets updated for the latest unstable

@paulhauner paulhauner added the work-in-progress PR is a work-in-progress label Sep 27, 2021
@paulhauner
Copy link
Member

paulhauner commented Sep 27, 2021

Rebasing onto merge-f2f should (hopefully) solve these merge conflicts pretty cleanly.

I suggest doing a rebase -i merge-f2f and then just deleting all the commits that aren't your own (i.e., anything before cbedda1)

@paulhauner paulhauner added the merge-f2f Relates to the Oct 2021 Merge F2F label Sep 27, 2021
@paulhauner
Copy link
Member

Whilst working on #2635, I noticed that we need access to the execution block hash for finalized block when we're setting the head. We don't have this on hand, so there's two options:

  1. Load the finalized block from the DB, then read the execution payload block hash from that (I'm doing this for the time being).
  2. Store the payload block hash on each block in the fork choice.

Going with (2) seems appealing. Whilst (1) only involves block read (not a state read) from the database, it's still IO that I think would be nice to avoid.

Instead of storing the is_merge_complete bool, we could store the execution_payload.block_hash and then say that is_merge_complete = execution_payload.block_hash != Hash256::zero().

What are your thoughts @realbigsean? Sorry for the last minute info.

@realbigsean
Copy link
Member Author

realbigsean commented Sep 27, 2021

@paulhauner I rebased as you suggested, but I'm a little confused because I'm seeing a7e866f show up in this PR's diff but it already should be in the merge-f2f branch?

I implemented (2) here, it wasn't much to change on my end and it seems reasonable to me 👍

@realbigsean realbigsean added ready-for-review The code is ready for review and removed work-in-progress PR is a work-in-progress labels Sep 27, 2021
@realbigsean
Copy link
Member Author

Moving to #2643

@realbigsean realbigsean deleted the add-merge-indicator-to-fork-choice-struct branch November 21, 2023 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-f2f Relates to the Oct 2021 Merge F2F ready-for-review The code is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants