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

chore(chainspec): Use SealedHeader in ChainSpec #14441

Closed
wants to merge 20 commits into from

Conversation

emhane
Copy link
Member

@emhane emhane commented Feb 12, 2025

Closes #14355

Fixes bug: devnet genesis hash must be hard coded like op mainnet to match alloy_consensus::constants::DEV_GENESIS_HASH

@emhane emhane added the C-debt A clean up/refactor of existing code label Feb 12, 2025
@emhane emhane force-pushed the emhane/chainspec-header branch from 27844ea to 615ca4b Compare February 12, 2025 14:06
Copy link
Member Author

Choose a reason for hiding this comment

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

will make issue to move to op alloy once merged so I can permalink this code

Comment on lines 357 to 359
if self.is_dev() {
SealedHeader::new(header, DEV_GENESIS_HASH)
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can't do this, this shouldn't be necessary

Copy link
Member Author

@emhane emhane Feb 12, 2025

Choose a reason for hiding this comment

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

right, so before I impl this change, this test broke 615ca4b
then when I implemented it, this test broke 4228106 but the first one was fixed by this

Copy link
Member Author

Choose a reason for hiding this comment

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

reverted this change, and now I get the fork id error again, as expected

thread 'spec::tests::dev_fork_ids' panicked at crates/chainspec/src/spec.rs:1008:9:
assertion `left == right` failed: Expected fork ID ForkId { hash: ForkHash("45b83612"), next: 0 }, computed fork ID ForkId { hash: ForkHash("d5bca3a4"), next: 0 } at block 0
  left: ForkId { hash: ForkHash("45b83612"), next: 0 }
 right: ForkId { hash: ForkHash("d5bca3a4"), next: 0 }

@emhane emhane requested a review from mattsse February 12, 2025 20:56
@emhane
Copy link
Member Author

emhane commented Feb 12, 2025

re-request review re: #14441 (comment)

@emhane emhane requested a review from klkvr February 13, 2025 10:18
@emhane emhane enabled auto-merge February 13, 2025 10:35
@emhane emhane mentioned this pull request Feb 13, 2025
pub genesis_header: OnceLock<Header>,
/// This is either stored at construction time if it is known, or computed once on the first
/// access.
pub genesis_header: OnceLock<SealedHeader>,
Copy link
Member

Choose a reason for hiding this comment

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

we still have OnceLock here requiring to define the lazy initializer per chainspec

can we just always initialize the header when creating a chainspec?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah sure, but would like to do that as sep pr

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

I don't think it's useful to introduce a change that we want to change again right away so I'd prefer if we can to the sealedheader init here

Comment on lines +206 to +209
if self.is_optimism_mainnet() {
// for OP mainnet we have to do this because the genesis header can't be
// properly computed from the genesis.json file due to OVM history
return SealedHeader::new(header, OP_MAINNET_GENESIS_HASH)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is problematic because this can also be a modified genesis file

Copy link
Member Author

Choose a reason for hiding this comment

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

p sure that would make it a devnet

Copy link
Collaborator

Choose a reason for hiding this comment

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

what if you run a custom genesis with mainnet chainid?

we can't do that here this must be set on the static MAINNET

Copy link
Member Author

Choose a reason for hiding this comment

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

ok. if that's not running on LAN then it's useful for dos:ing op mainnet 😅

@emhane
Copy link
Member Author

emhane commented Feb 13, 2025

I don't think it's useful to introduce a change that we want to change again right away so I'd prefer if we can to the sealedheader init here

sealed header is already init here, see calls to new methods OpChainSpec::get_or_init_sealed_header and ChainSpec::get_or_init_sealed_header

if you're referring to the OnceLock, @Ayushdubey86 is keen to pick that up

@emhane emhane requested review from mattsse and klkvr February 13, 2025 15:47
@mattsse
Copy link
Collaborator

mattsse commented Feb 13, 2025

I'd prefer if we could only change it once and not merge something that is supposed to be temporary

@emhane emhane mentioned this pull request Feb 14, 2025
@emhane
Copy link
Member Author

emhane commented Feb 14, 2025

@klkvr @mattsse to remove OnceLock requires alloy Sealable::hash_slow to be const, which isn't possible on trait methods. it's also not possible on impl of Sealable for Header anyway because it handles Vec<u8> so we get

destructor of `std::vec::Vec<u8>` cannot be evaluated at compile-time

@emhane
Copy link
Member Author

emhane commented Feb 15, 2025

would have been better open source etiquette if this pr was committed as incremental progress before #14514 . put in several hours into this, is rather discouraging :/ @klkvr

@emhane emhane closed this Feb 15, 2025
auto-merge was automatically disabled February 15, 2025 15:02

Pull request was closed

@emhane emhane deleted the emhane/chainspec-header branch February 15, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-debt A clean up/refactor of existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ChainSpec genesis header as SealedHeader
3 participants