|
3 | 3 | use reth_chainspec::ChainSpec; |
4 | 4 | use reth_consensus::{Consensus, ConsensusError, FullConsensus, HeaderValidator}; |
5 | 5 | use reth_consensus_common::validation::validate_body_against_header; |
| 6 | +use reth_ethereum::node::builder::{components::ConsensusBuilder, BuilderContext}; |
6 | 7 | use reth_ethereum_consensus::EthBeaconConsensus; |
7 | 8 | use reth_ethereum_primitives::{Block, BlockBody, EthPrimitives, Receipt}; |
8 | 9 | use reth_execution_types::BlockExecutionResult; |
| 10 | +use reth_node_api::{FullNodeTypes, NodeTypes}; |
9 | 11 | use reth_primitives::{GotExpected, GotExpectedBoxed, RecoveredBlock, SealedBlock, SealedHeader}; |
10 | 12 | use std::sync::Arc; |
11 | 13 |
|
| 14 | +/// Builder for `RollkitConsensus` |
| 15 | +#[derive(Debug, Default, Clone)] |
| 16 | +#[non_exhaustive] |
| 17 | +pub struct RollkitConsensusBuilder; |
| 18 | + |
| 19 | +impl RollkitConsensusBuilder { |
| 20 | + /// Create a new `RollkitConsensusBuilder` |
| 21 | + pub const fn new() -> Self { |
| 22 | + Self |
| 23 | + } |
| 24 | + |
| 25 | + /// Build the consensus implementation |
| 26 | + pub fn build(chain_spec: Arc<ChainSpec>) -> Arc<RollkitConsensus> { |
| 27 | + Arc::new(RollkitConsensus::new(chain_spec)) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +impl<Node> ConsensusBuilder<Node> for RollkitConsensusBuilder |
| 32 | +where |
| 33 | + Node: FullNodeTypes, |
| 34 | + Node::Types: NodeTypes<ChainSpec = ChainSpec, Primitives = EthPrimitives>, |
| 35 | +{ |
| 36 | + type Consensus = Arc<dyn FullConsensus<EthPrimitives, Error = ConsensusError>>; |
| 37 | + |
| 38 | + async fn build_consensus(self, ctx: &BuilderContext<Node>) -> eyre::Result<Self::Consensus> { |
| 39 | + Ok(Arc::new(RollkitConsensus::new(ctx.chain_spec())) as Self::Consensus) |
| 40 | + } |
| 41 | +} |
| 42 | + |
12 | 43 | /// Rollkit consensus implementation that allows blocks with the same timestamp. |
13 | 44 | /// |
14 | 45 | /// This consensus implementation wraps the standard Ethereum beacon consensus |
@@ -111,24 +142,3 @@ impl FullConsensus<EthPrimitives> for RollkitConsensus { |
111 | 142 | <EthBeaconConsensus<ChainSpec> as FullConsensus<EthPrimitives>>::validate_block_post_execution(&self.inner, block, result) |
112 | 143 | } |
113 | 144 | } |
114 | | - |
115 | | -/// Builder for `RollkitConsensus` |
116 | | -#[derive(Debug, Default, Clone)] |
117 | | -#[non_exhaustive] |
118 | | -pub struct RollkitConsensusBuilder; |
119 | | - |
120 | | -impl RollkitConsensusBuilder { |
121 | | - /// Create a new `RollkitConsensusBuilder` |
122 | | - pub const fn new() -> Self { |
123 | | - Self |
124 | | - } |
125 | | -} |
126 | | - |
127 | | -// Instead of implementing the generic ConsensusBuilder trait, |
128 | | -// we'll use a direct approach that works with the node builder |
129 | | -impl RollkitConsensusBuilder { |
130 | | - /// Build the consensus implementation |
131 | | - pub fn build(chain_spec: Arc<ChainSpec>) -> Arc<RollkitConsensus> { |
132 | | - Arc::new(RollkitConsensus::new(chain_spec)) |
133 | | - } |
134 | | -} |
|
0 commit comments