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: Use OptimismBeaconConsensus in the OptimismNode #8487

Merged
merged 5 commits into from
Jun 11, 2024

Conversation

BrianBland
Copy link
Contributor

@BrianBland BrianBland commented May 29, 2024

  • Adds Consensus as a new Node Component, with default implementations for the EthereumNode and OptimismNode.
  • EthereumConsensusBuilder builds either EthBeaconConsensus or AutoSealConsensus depending on whether or not dev mode is enabled

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.

thanks, I wanted to do this for a while now,
need to check if we can make this work without features

@mattsse mattsse self-assigned this May 29, 2024
@mattsse mattsse added the A-op-reth Related to Optimism and op-reth label May 29, 2024
@BrianBland BrianBland marked this pull request as ready for review May 29, 2024 20:25
Comment on lines 124 to 129
#[cfg(feature = "optimism")]
if ctx.chain_spec().is_optimism() {
Arc::new(OptimismBeaconConsensus::new(ctx.chain_spec()))
} else {
Arc::new(EthBeaconConsensus::new(ctx.chain_spec()))
}
Copy link
Member

@gakonst gakonst May 29, 2024

Choose a reason for hiding this comment

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

could this be part of node components so that each node builder implementer defines its own consensus interface implementation?

Copy link
Collaborator

Choose a reason for hiding this comment

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

good point, I believe it should be, yes, because it's stateful

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I'll push up another change soon with Consensus added as a new Component

Copy link
Contributor Author

@BrianBland BrianBland Jun 1, 2024

Choose a reason for hiding this comment

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

This ended up becoming a much larger change, but hopefully this is directionally aligned with your intent

crates/node/builder/src/launch/mod.rs Show resolved Hide resolved
Comment on lines 124 to 129
#[cfg(feature = "optimism")]
if ctx.chain_spec().is_optimism() {
Arc::new(OptimismBeaconConsensus::new(ctx.chain_spec()))
} else {
Arc::new(EthBeaconConsensus::new(ctx.chain_spec()))
}
Copy link
Contributor Author

@BrianBland BrianBland Jun 1, 2024

Choose a reason for hiding this comment

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

This ended up becoming a much larger change, but hopefully this is directionally aligned with your intent

@BrianBland BrianBland marked this pull request as draft June 1, 2024 01:22
@BrianBland BrianBland force-pushed the node-optimism-consensus branch 9 times, most recently from 447a370 to 7ddfc8c Compare June 5, 2024 00:24
@BrianBland BrianBland marked this pull request as ready for review June 5, 2024 02:24
@BrianBland BrianBland changed the title fix: Node uses optimism beacon consensus for op chains fix: Use OptimismBeaconConsensus for the OptimismNode Jun 6, 2024
@BrianBland BrianBland changed the title fix: Use OptimismBeaconConsensus for the OptimismNode fix: Use OptimismBeaconConsensus in the OptimismNode Jun 6, 2024
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.

ah now I get this,

this basically promotes the Consensus impl to a component.

imo this is reasonable and we should do this.

but we should keep using Arc<dyn>

separately, if you have any feedback re builder api/complexity, please let me know

/// The state of the tree
///
/// Tracks all the chains, the block indices, and the block buffer.
state: TreeState,
/// External components (the database, consensus engine etc.)
externals: TreeExternals<DB, E>,
externals: TreeExternals<DB, C, E>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

the Consensus type is super invasive and would introduce generics everywhere, I'd like to keep using Arc<dyn Consensus>

Copy link
Contributor Author

@BrianBland BrianBland Jun 10, 2024

Choose a reason for hiding this comment

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

Fair enough - I wasn't sure whether the use of dyn was actually preferred or only used as a placeholder for a future generic. Agreed that this additional type parameter increases the developer overhead anywhere that this struct is utilized.

Copy link
Collaborator

Choose a reason for hiding this comment

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

developer overhead anywhere that this struct is utilized.

yeah we initial had this as a generic but pivoted to dyn because trait is object safe and the functions aren't called frequently.

we could likely use dyn for a few more generics but some aren't object safe, although we could likely make them, like Database

@BrianBland BrianBland force-pushed the node-optimism-consensus branch 2 times, most recently from 5609b54 to c1125f6 Compare June 10, 2024 23:39
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.

this is great, tysm.

one nit re features

eventually, we will push the engine impls there as well.

Comment on lines 78 to 86
[features]
optimism = [
"reth-primitives/optimism",
"reth-rpc/optimism",
"reth-provider/optimism",
"reth-beacon-consensus/optimism",
"reth-blockchain-tree/optimism",
"reth-node-core/optimism",
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is required?

we want to keep this crate feature free and instead push all things down to the node crates like you did with consensus

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch - this was left over from my original implementation

Comment on lines +304 to +305
Ok(OptimismBeaconConsensus::new(ctx.chain_spec()))
}
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 great,

we can now remove all the optimism features from eth beacon consensus in a followup: #8739

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.

lgtm, tysm!

@mattsse mattsse added this pull request to the merge queue Jun 11, 2024
Merged via the queue into paradigmxyz:main with commit 5eecc4f Jun 11, 2024
49 of 60 checks passed
@BrianBland BrianBland deleted the node-optimism-consensus branch June 11, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-op-reth Related to Optimism and op-reth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants