feat: new engine API handler (#8559)

Co-authored-by: Roman Krasiuk <rokrassyuk@gmail.com>
Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com>
Co-authored-by: Federico Gimenez <fgimenez@users.noreply.github.com>
This commit is contained in:
Matthias Seitz
2024-07-01 14:03:44 +02:00
committed by GitHub
parent 068bf57c06
commit 01979c4bde
17 changed files with 2208 additions and 11 deletions

View File

@ -3,7 +3,7 @@ use reth_rpc_types::engine::{ForkchoiceState, PayloadStatusEnum};
/// The struct that keeps track of the received forkchoice state and their status.
#[derive(Debug, Clone, Default)]
pub(crate) struct ForkchoiceStateTracker {
pub struct ForkchoiceStateTracker {
/// The latest forkchoice state that we received.
///
/// Caution: this can be invalid.
@ -76,7 +76,7 @@ impl ForkchoiceStateTracker {
}
/// Returns the last received `ForkchoiceState` to which we need to sync.
pub(crate) const fn sync_target_state(&self) -> Option<ForkchoiceState> {
pub const fn sync_target_state(&self) -> Option<ForkchoiceState> {
self.last_syncing
}
@ -139,9 +139,12 @@ impl From<PayloadStatusEnum> for ForkchoiceStatus {
/// A helper type to check represent hashes of a [`ForkchoiceState`]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum ForkchoiceStateHash {
pub enum ForkchoiceStateHash {
/// Head hash of the [`ForkchoiceState`].
Head(B256),
/// Safe hash of the [`ForkchoiceState`].
Safe(B256),
/// Finalized hash of the [`ForkchoiceState`].
Finalized(B256),
}

View File

@ -14,7 +14,8 @@ use tracing::warn;
const INVALID_HEADER_HIT_EVICTION_THRESHOLD: u8 = 128;
/// Keeps track of invalid headers.
pub(crate) struct InvalidHeaderCache {
#[derive(Debug)]
pub struct InvalidHeaderCache {
/// This maps a header hash to a reference to its invalid ancestor.
headers: LruMap<B256, HeaderEntry>,
/// Metrics for the cache.
@ -34,7 +35,7 @@ impl InvalidHeaderCache {
///
/// If this is called, the hit count for the entry is incremented.
/// If the hit count exceeds the threshold, the entry is evicted and `None` is returned.
pub(crate) fn get(&mut self, hash: &B256) -> Option<Arc<Header>> {
pub fn get(&mut self, hash: &B256) -> Option<Arc<Header>> {
{
let entry = self.headers.get(hash)?;
entry.hit_count += 1;
@ -49,7 +50,7 @@ impl InvalidHeaderCache {
}
/// Inserts an invalid block into the cache, with a given invalid ancestor.
pub(crate) fn insert_with_invalid_ancestor(
pub fn insert_with_invalid_ancestor(
&mut self,
header_hash: B256,
invalid_ancestor: Arc<Header>,

View File

@ -53,7 +53,7 @@ pub use error::{
};
mod invalid_headers;
use invalid_headers::InvalidHeaderCache;
pub use invalid_headers::InvalidHeaderCache;
mod event;
pub use event::{BeaconConsensusEngineEvent, ConsensusEngineLiveSyncProgress};
@ -62,13 +62,12 @@ mod handle;
pub use handle::BeaconConsensusEngineHandle;
mod forkchoice;
pub use forkchoice::ForkchoiceStatus;
use forkchoice::{ForkchoiceStateHash, ForkchoiceStateTracker};
pub use forkchoice::{ForkchoiceStateHash, ForkchoiceStateTracker, ForkchoiceStatus};
mod metrics;
use metrics::EngineMetrics;
pub(crate) mod sync;
pub mod sync;
use sync::{EngineSyncController, EngineSyncEvent};
/// Hooks for running during the main loop of