mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: ExExContext's dynamic config (#11983)
This commit is contained in:
@ -7,7 +7,7 @@ use reth_primitives::Head;
|
||||
use reth_tasks::TaskExecutor;
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
use crate::{ExExEvent, ExExNotifications, ExExNotificationsStream};
|
||||
use crate::{ExExContextDyn, ExExEvent, ExExNotifications, ExExNotificationsStream};
|
||||
|
||||
/// Captures the context that an `ExEx` has access to.
|
||||
pub struct ExExContext<Node: FullNodeComponents> {
|
||||
@ -55,7 +55,24 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents> ExExContext<Node> {
|
||||
impl<Node> ExExContext<Node>
|
||||
where
|
||||
Node: FullNodeComponents,
|
||||
Node::Provider: Debug,
|
||||
Node::Executor: Debug,
|
||||
{
|
||||
/// Returns dynamic version of the context
|
||||
pub fn into_dyn(self) -> ExExContextDyn {
|
||||
ExExContextDyn::from(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node> ExExContext<Node>
|
||||
where
|
||||
Node: FullNodeComponents,
|
||||
Node::Provider: Debug,
|
||||
Node::Executor: Debug,
|
||||
{
|
||||
/// Returns the transaction pool of the node.
|
||||
pub fn pool(&self) -> &Node::Pool {
|
||||
self.components.pool()
|
||||
|
||||
86
crates/exex/exex/src/dyn_context.rs
Normal file
86
crates/exex/exex/src/dyn_context.rs
Normal file
@ -0,0 +1,86 @@
|
||||
//! Mirrored version of [`ExExContext`](`crate::ExExContext`)
|
||||
//! without generic abstraction over [Node](`reth_node_api::FullNodeComponents`)
|
||||
|
||||
use std::{fmt::Debug, sync::Arc};
|
||||
|
||||
use reth_chainspec::{EthChainSpec, Head};
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_node_core::node_config::NodeConfig;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::{ExExContext, ExExEvent, ExExNotificationsStream};
|
||||
|
||||
// TODO(0xurb) - add `node` after abstractions
|
||||
/// Captures the context that an `ExEx` has access to.
|
||||
pub struct ExExContextDyn {
|
||||
/// The current head of the blockchain at launch.
|
||||
pub head: Head,
|
||||
/// The config of the node
|
||||
pub config: NodeConfig<Box<dyn EthChainSpec + 'static>>,
|
||||
/// The loaded node config
|
||||
pub reth_config: reth_config::Config,
|
||||
/// Channel used to send [`ExExEvent`]s to the rest of the node.
|
||||
///
|
||||
/// # Important
|
||||
///
|
||||
/// The exex should emit a `FinishedHeight` whenever a processed block is safe to prune.
|
||||
/// Additionally, the exex can pre-emptively emit a `FinishedHeight` event to specify what
|
||||
/// blocks to receive notifications for.
|
||||
pub events: mpsc::UnboundedSender<ExExEvent>,
|
||||
/// Channel to receive [`ExExNotification`](crate::ExExNotification)s.
|
||||
///
|
||||
/// # Important
|
||||
///
|
||||
/// Once an [`ExExNotification`](crate::ExExNotification) is sent over the channel, it is
|
||||
/// considered delivered by the node.
|
||||
pub notifications: Box<dyn ExExNotificationsStream>,
|
||||
}
|
||||
|
||||
impl Debug for ExExContextDyn {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("ExExContext")
|
||||
.field("head", &self.head)
|
||||
.field("config", &self.config)
|
||||
.field("reth_config", &self.reth_config)
|
||||
.field("events", &self.events)
|
||||
.field("notifications", &self.notifications)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node> From<ExExContext<Node>> for ExExContextDyn
|
||||
where
|
||||
Node: FullNodeComponents,
|
||||
Node::Provider: Debug,
|
||||
Node::Executor: Debug,
|
||||
{
|
||||
fn from(ctx: ExExContext<Node>) -> Self {
|
||||
// convert `NodeConfig` with generic over chainspec into `NodeConfig<Box<dyn EthChainSpec>`
|
||||
let chain: Arc<Box<dyn EthChainSpec + 'static>> =
|
||||
Arc::new(Box::new(ctx.config.chain) as Box<dyn EthChainSpec>);
|
||||
let config = NodeConfig {
|
||||
chain,
|
||||
datadir: ctx.config.datadir,
|
||||
config: ctx.config.config,
|
||||
metrics: ctx.config.metrics,
|
||||
instance: ctx.config.instance,
|
||||
network: ctx.config.network,
|
||||
rpc: ctx.config.rpc,
|
||||
txpool: ctx.config.txpool,
|
||||
builder: ctx.config.builder,
|
||||
debug: ctx.config.debug,
|
||||
db: ctx.config.db,
|
||||
dev: ctx.config.dev,
|
||||
pruning: ctx.config.pruning,
|
||||
};
|
||||
let notifications = Box::new(ctx.notifications) as Box<dyn ExExNotificationsStream>;
|
||||
|
||||
Self {
|
||||
head: ctx.head,
|
||||
config,
|
||||
reth_config: ctx.reth_config,
|
||||
events: ctx.events,
|
||||
notifications,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -40,6 +40,9 @@ pub use backfill::*;
|
||||
mod context;
|
||||
pub use context::*;
|
||||
|
||||
mod dyn_context;
|
||||
pub use dyn_context::*;
|
||||
|
||||
mod event;
|
||||
pub use event::*;
|
||||
|
||||
|
||||
@ -24,7 +24,9 @@ pub struct ExExNotifications<P, E> {
|
||||
/// A trait, that represents a stream of [`ExExNotification`]s. The stream will emit notifications
|
||||
/// for all blocks. If the stream is configured with a head via [`ExExNotifications::set_with_head`]
|
||||
/// or [`ExExNotifications::with_head`], it will run backfill jobs to catch up to the node head.
|
||||
pub trait ExExNotificationsStream: Stream<Item = eyre::Result<ExExNotification>> + Unpin {
|
||||
pub trait ExExNotificationsStream:
|
||||
Debug + Stream<Item = eyre::Result<ExExNotification>> + Unpin
|
||||
{
|
||||
/// Sets [`ExExNotificationsStream`] to a stream of [`ExExNotification`]s without a head.
|
||||
///
|
||||
/// It's a no-op if the stream has already been configured without a head.
|
||||
@ -90,8 +92,8 @@ impl<P, E> ExExNotifications<P, E> {
|
||||
|
||||
impl<P, E> ExExNotificationsStream for ExExNotifications<P, E>
|
||||
where
|
||||
P: BlockReader + HeaderProvider + StateProviderFactory + Clone + Unpin + 'static,
|
||||
E: BlockExecutorProvider + Clone + Unpin + 'static,
|
||||
P: BlockReader + HeaderProvider + StateProviderFactory + Clone + Debug + Unpin + 'static,
|
||||
E: BlockExecutorProvider + Clone + Debug + Unpin + 'static,
|
||||
{
|
||||
fn set_without_head(&mut self) {
|
||||
let current = std::mem::replace(&mut self.inner, ExExNotificationsInner::Invalid);
|
||||
|
||||
Reference in New Issue
Block a user