diff --git a/CODEOWNERS b/CODEOWNERS index 76c9b881688..e015d47ae86 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -8,7 +8,7 @@ crates/config/ @onbjerg crates/consensus/ @rkrasiuk @mattsse @Rjected crates/engine @rkrasiuk @mattsse @Rjected crates/e2e-test-utils/ @mattsse @Rjected -crates/engine-primitives/ @rkrasiuk @mattsse @Rjected +crates/engine/ @rkrasiuk @mattsse @Rjected @fgimenez crates/errors/ @mattsse crates/ethereum/ @mattsse @Rjected crates/ethereum-forks/ @mattsse @Rjected diff --git a/crates/consensus/beacon/src/engine/forkchoice.rs b/crates/consensus/beacon/src/engine/forkchoice.rs index c305cee7d21..491d0ff8aad 100644 --- a/crates/consensus/beacon/src/engine/forkchoice.rs +++ b/crates/consensus/beacon/src/engine/forkchoice.rs @@ -140,8 +140,11 @@ impl From for ForkchoiceStatus { /// A helper type to check represent hashes of a [`ForkchoiceState`] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum ForkchoiceStateHash { + /// Head hash of the [`ForkchoiceState`]. Head(B256), + /// Safe hash of the [`ForkchoiceState`]. Safe(B256), + /// Finalized hash of the [`ForkchoiceState`]. Finalized(B256), } diff --git a/crates/engine/tree/src/backfill.rs b/crates/engine/tree/src/backfill.rs index 6fce16c3490..ec0b4ef06cc 100644 --- a/crates/engine/tree/src/backfill.rs +++ b/crates/engine/tree/src/backfill.rs @@ -245,7 +245,7 @@ mod tests { checkpoint: StageCheckpoint::new(BlockNumber::from(pipeline_done_after)), done: true, })])) - .build(chain_spec.clone()); + .build(chain_spec); let pipeline_sync = PipelineSync::new(pipeline, Box::::default()); let client = TestFullBlockClient::default(); diff --git a/crates/engine/tree/src/chain.rs b/crates/engine/tree/src/chain.rs index badff5a0925..97c6d615c11 100644 --- a/crates/engine/tree/src/chain.rs +++ b/crates/engine/tree/src/chain.rs @@ -102,27 +102,24 @@ where Poll::Pending => {} } - // drain the handler - loop { - // poll the handler for the next event - match this.handler.poll(cx) { - Poll::Ready(handler_event) => { - match handler_event { - HandlerEvent::Pipeline(target) => { - // trigger pipeline and start polling it - this.pipeline.on_action(BackfillAction::Start(target)); - continue 'outer - } - HandlerEvent::Event(ev) => { - // bubble up the event - return Poll::Ready(ChainEvent::Handler(ev)); - } + // poll the handler for the next event + match this.handler.poll(cx) { + Poll::Ready(handler_event) => { + match handler_event { + HandlerEvent::Pipeline(target) => { + // trigger pipeline and start polling it + this.pipeline.on_action(BackfillAction::Start(target)); + continue 'outer + } + HandlerEvent::Event(ev) => { + // bubble up the event + return Poll::Ready(ChainEvent::Handler(ev)); } } - Poll::Pending => { - // no more events to process - break 'outer - } + } + Poll::Pending => { + // no more events to process + break 'outer } } } diff --git a/crates/engine/tree/src/download.rs b/crates/engine/tree/src/download.rs index f264b54535d..12b2bd18928 100644 --- a/crates/engine/tree/src/download.rs +++ b/crates/engine/tree/src/download.rs @@ -42,7 +42,7 @@ pub enum DownloadOutcome { Blocks(Vec), } -/// Basic [BlockDownloader]. +/// Basic [`BlockDownloader`]. pub struct BasicBlockDownloader where Client: HeadersClient + BodiesClient + Clone + Unpin + 'static, @@ -253,7 +253,7 @@ impl From for SealedBlockWithSenders { } } -/// A [BlockDownloader] that does nothing. +/// A [`BlockDownloader`] that does nothing. #[derive(Debug, Clone, Default)] #[non_exhaustive] pub struct NoopBlockDownloader; diff --git a/crates/engine/tree/src/engine.rs b/crates/engine/tree/src/engine.rs index c375afa0ea5..d77162e4cd0 100644 --- a/crates/engine/tree/src/engine.rs +++ b/crates/engine/tree/src/engine.rs @@ -1,21 +1,18 @@ //! An engine API handler for the chain. use crate::{ - chain::{ChainHandler, FromOrchestrator, HandlerEvent, OrchestratorState}, + chain::{ChainHandler, FromOrchestrator, HandlerEvent}, download::{BlockDownloader, DownloadAction, DownloadOutcome}, - tree::{EngineApiTreeHandler, TreeEvent}, }; use futures::{Stream, StreamExt}; -use reth_beacon_consensus::{BeaconEngineMessage, OnForkChoiceUpdated}; +use reth_beacon_consensus::BeaconEngineMessage; use reth_engine_primitives::EngineTypes; use reth_primitives::{SealedBlockWithSenders, B256}; -use reth_rpc_types::engine::{PayloadStatus, PayloadStatusEnum}; use std::{ - collections::{HashSet, VecDeque}, + collections::HashSet, task::{Context, Poll}, }; use tokio::sync::mpsc; -use tracing::trace; /// Advances the chain based on incoming requests. /// @@ -46,7 +43,7 @@ pub struct EngineHandler { impl EngineHandler { /// Creates a new [`EngineHandler`] with the given handler and downloader. - pub fn new(handler: T, downloader: D, incoming_requests: S) -> Self + pub const fn new(handler: T, downloader: D, incoming_requests: S) -> Self where T: EngineRequestHandler, { @@ -70,31 +67,26 @@ where fn poll(&mut self, cx: &mut Context<'_>) -> Poll> { loop { // drain the handler first - loop { - match self.handler.poll(cx) { - Poll::Ready(ev) => { - match ev { - RequestHandlerEvent::Idle => break, - RequestHandlerEvent::HandlerEvent(ev) => { - return match ev { - HandlerEvent::Pipeline(target) => { - // bubble up pipeline request - self.downloader.on_action(DownloadAction::Clear); - Poll::Ready(HandlerEvent::Pipeline(target)) - } - HandlerEvent::Event(ev) => { - // bubble up the event - Poll::Ready(HandlerEvent::Event(ev)) - } - } + while let Poll::Ready(ev) = self.handler.poll(cx) { + match ev { + RequestHandlerEvent::Idle => break, + RequestHandlerEvent::HandlerEvent(ev) => { + return match ev { + HandlerEvent::Pipeline(target) => { + // bubble up pipeline request + self.downloader.on_action(DownloadAction::Clear); + Poll::Ready(HandlerEvent::Pipeline(target)) } - RequestHandlerEvent::Download(req) => { - // delegate download request to the downloader - self.downloader.on_action(DownloadAction::Download(req)); + HandlerEvent::Event(ev) => { + // bubble up the event + Poll::Ready(HandlerEvent::Event(ev)) } } } - Poll::Pending => break, + RequestHandlerEvent::Download(req) => { + // delegate download request to the downloader + self.downloader.on_action(DownloadAction::Download(req)); + } } } @@ -185,8 +177,11 @@ pub enum EngineApiEvent {} #[derive(Debug)] pub enum FromEngine { + /// Event from the top level orchestrator. Event(FromOrchestrator), + /// Request from the engine Request(Req), + /// Downloaded blocks from the network. DownloadedBlocks(Vec), } @@ -199,8 +194,11 @@ impl From for FromEngine { /// Requests produced by a [`EngineRequestHandler`]. #[derive(Debug)] pub enum RequestHandlerEvent { + /// The handler is idle. Idle, + /// An event emitted by the handler. HandlerEvent(HandlerEvent), + /// Request to download blocks. Download(DownloadRequest), } diff --git a/crates/engine/tree/src/lib.rs b/crates/engine/tree/src/lib.rs index 7aa7fcf75b9..062dd583a9e 100644 --- a/crates/engine/tree/src/lib.rs +++ b/crates/engine/tree/src/lib.rs @@ -8,6 +8,7 @@ )] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] // #![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![allow(missing_docs, dead_code, missing_debug_implementations, unused_variables)] // TODO rm /// Re-export of the blockchain tree API. pub use reth_blockchain_tree_api::*; diff --git a/crates/engine/tree/src/tree/memory_overlay.rs b/crates/engine/tree/src/tree/memory_overlay.rs index 3f232b55c20..7e0e1d52e5b 100644 --- a/crates/engine/tree/src/tree/memory_overlay.rs +++ b/crates/engine/tree/src/tree/memory_overlay.rs @@ -17,7 +17,7 @@ pub struct MemoryOverlayStateProvider { impl MemoryOverlayStateProvider { /// Create new memory overlay state provider. - pub fn new(in_memory: Vec, historical: H) -> Self { + pub const fn new(in_memory: Vec, historical: H) -> Self { Self { in_memory, historical } } } diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index 371834b53f9..888183ec6a0 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -162,7 +162,7 @@ pub struct TreeOutcome { impl TreeOutcome { /// Create new tree outcome. - pub fn new(outcome: T) -> Self { + pub const fn new(outcome: T) -> Self { Self { outcome, event: None } } @@ -518,7 +518,7 @@ where PayloadStatus::from_status(PayloadStatusEnum::Syncing) } else { let mut latest_valid_hash = None; - let status = match self.insert_block_without_senders(block.clone()).unwrap() { + let status = match self.insert_block_without_senders(block).unwrap() { InsertPayloadOk::Inserted(BlockStatus::Valid(_)) | InsertPayloadOk::AlreadySeen(BlockStatus::Valid(_)) => { latest_valid_hash = Some(block_hash);