Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/consensus/beacon/src/engine/invalid_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use tracing::warn;
const INVALID_HEADER_HIT_EVICTION_THRESHOLD: u8 = 128;

/// Keeps track of invalid headers.
#[derive(Debug)]
pub struct InvalidHeaderCache {
/// This maps a header hash to a reference to its invalid ancestor.
headers: LruMap<B256, HeaderEntry>,
Expand Down
10 changes: 6 additions & 4 deletions crates/engine/tree/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use std::{
/// emitted events. Requests and events are passed to the [`ChainHandler`] via
/// [`ChainHandler::on_event`].
#[must_use = "Stream does nothing unless polled"]
#[derive(Debug)]
pub struct ChainOrchestrator<T>
where
T: ChainHandler,
Expand Down Expand Up @@ -74,6 +75,7 @@ where
/// Event emitted by the [`ChainOrchestrator`]
///
/// These are meant to be used for observability and debugging purposes.
#[derive(Debug)]
pub enum ChainEvent {
/// Pipeline sync started
PipelineStarted,
Expand All @@ -91,7 +93,7 @@ pub trait ChainHandler: Send + Sync {
}

/// Events/Requests that the [`ChainHandler`] can emit to the [`ChainOrchestrator`].
#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
pub enum HandlerEvent {
Pipeline(PipelineAction),
/// Ack paused write access to the database
Expand All @@ -100,7 +102,7 @@ pub enum HandlerEvent {
WriteAccess,
}

#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
pub enum PipelineAction {
/// Start pipeline sync
SyncPipeline,
Expand All @@ -109,7 +111,7 @@ pub enum PipelineAction {
}

/// Internal events issued by the [`ChainOrchestrator`].
#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
pub enum FromOrchestrator {
/// Request to temporarily freeze write access to the database.
PausedWriteHookAccess,
Expand All @@ -120,7 +122,7 @@ pub enum FromOrchestrator {
}

/// Represents the state of the chain.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
pub enum OrchestratorState {
/// Orchestrator has exclusive write access to the database.
WriteAccess,
Expand Down
2 changes: 2 additions & 0 deletions crates/engine/tree/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::{
///
/// The core logic is part of the [EngineRequestHandler], which is responsible for processing the
/// incoming requests.
#[derive(Debug)]
pub struct EngineHandler<T>
where
T: EngineRequestHandler,
Expand Down Expand Up @@ -87,6 +88,7 @@ pub trait EngineRequestHandler: Send + Sync {
///
/// In case required blocks are missing, the handler will request them from the network, by emitting
/// a download request upstream.
#[derive(Debug)]
pub struct EngineApiRequestHandler<T>
where
T: EngineApiTreeHandler,
Expand Down
29 changes: 16 additions & 13 deletions crates/engine/tree/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ use crate::{chain::PipelineAction, engine::DownloadRequest};
use parking_lot::Mutex;
use reth_beacon_consensus::{ForkchoiceStateTracker, InvalidHeaderCache, OnForkChoiceUpdated};
use reth_engine_primitives::EngineTypes;
use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::SealedBlockWithSenders;
use reth_rpc_types::{
engine::{CancunPayloadFields, ForkchoiceState, PayloadStatus},
ExecutionPayload,
};
use std::sync::Arc;
use std::{marker::PhantomData, sync::Arc};

/// Keeps track of the state of the tree.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct TreeState {
// TODO: this is shared state for the blocks etc.
}
Expand All @@ -24,7 +25,7 @@ impl TreeState {
/// Tracks the state of the engine api internals.
///
/// This type is shareable.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct EngineApiTreeState {
/// Tracks the received forkchoice state updates received by the CL.
forkchoice_state_tracker: ForkchoiceStateTracker,
Expand All @@ -45,9 +46,7 @@ pub trait EngineApiTreeHandler: Send + Sync + Clone {
type Engine: EngineTypes;

/// Invoked when previously requested blocks were downloaded.
fn on_downloaded(&self, blocks: Vec<SealedBlockWithSenders>) -> Option<TreeEvent> {
todo!()
}
fn on_downloaded(&self, blocks: Vec<SealedBlockWithSenders>) -> Option<TreeEvent>;

/// When the Consensus layer receives a new block via the consensus gossip protocol,
/// the transactions in the block are sent to the execution layer in the form of a
Expand All @@ -65,9 +64,7 @@ pub trait EngineApiTreeHandler: Send + Sync + Clone {
&self,
payload: ExecutionPayload,
cancun_fields: Option<CancunPayloadFields>,
) -> TreeOutcome<PayloadStatus> {
todo!()
}
) -> TreeOutcome<PayloadStatus>;

/// Invoked when we receive a new forkchoice update message. Calls into the blockchain tree
/// to resolve chain forks and ensure that the Execution Layer is working with the latest valid
Expand All @@ -81,12 +78,11 @@ pub trait EngineApiTreeHandler: Send + Sync + Clone {
&self,
state: ForkchoiceState,
attrs: Option<<Self::Engine as EngineTypes>::PayloadAttributes>,
) -> TreeOutcome<Result<OnForkChoiceUpdated, String>> {
todo!()
}
) -> TreeOutcome<Result<OnForkChoiceUpdated, String>>;
}

/// The outcome of a tree operation.
#[derive(Debug)]
pub struct TreeOutcome<T> {
/// The outcome of the operation.
pub outcome: T,
Expand All @@ -95,19 +91,26 @@ pub struct TreeOutcome<T> {
}

/// Events that can be emitted by the [EngineApiTreeHandler].
#[derive(Debug)]
pub enum TreeEvent {
PipelineAction(PipelineAction),
Download(DownloadRequest),
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct EngineApiTreeHandlerImpl<T: EngineTypes> {
state: EngineApiTreeState,
payload_validator: ExecutionPayloadValidator,
_marker: PhantomData<T>,
}

impl<T: EngineTypes> EngineApiTreeHandler for EngineApiTreeHandlerImpl<T> {
type Engine = T;

fn on_downloaded(&self, blocks: Vec<SealedBlockWithSenders>) -> Option<TreeEvent> {
todo!()
}

fn on_new_payload(
&self,
payload: ExecutionPayload,
Expand Down