mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-10 07:48:19 -05:00
feat: API scaffolding
This commit is contained in:
@@ -384,7 +384,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Launches the node and returns a handle to it.
|
||||
/// Launches the node with the [`DefaultNodeLauncher`] that sets up engine API consensus and rpc
|
||||
pub async fn launch(
|
||||
self,
|
||||
) -> eyre::Result<NodeHandle<NodeAdapter<RethFullAdapter<DB, T>, CB::Components>>> {
|
||||
|
||||
@@ -150,6 +150,7 @@ pub struct NodeBuilderWithComponents<T: FullNodeTypes, CB: NodeComponentsBuilder
|
||||
/// container for type specific components
|
||||
pub(crate) components_builder: CB,
|
||||
/// Additional node extensions.
|
||||
// TODO make Addons generic over NodeAdapter + context
|
||||
pub(crate) add_ons: NodeAddOns<NodeAdapter<T, CB::Components>>,
|
||||
}
|
||||
|
||||
@@ -237,11 +238,40 @@ impl<T: FullNodeTypes, CB: NodeComponentsBuilder<T>> NodeBuilderWithComponents<T
|
||||
}
|
||||
|
||||
/// Additional node extensions.
|
||||
pub(crate) struct NodeAddOns<Node: FullNodeComponents> {
|
||||
///
|
||||
/// At this point we consider all necessary components defined.
|
||||
pub(crate) struct NodeAddOns<Node: FullNodeComponents, Ctx = ()> {
|
||||
/// Additional `NodeHooks` that are called at specific points in the node's launch lifecycle.
|
||||
pub hooks: NodeHooks<Node>,
|
||||
/// Additional RPC hooks.
|
||||
pub rpc: RpcHooks<Node>,
|
||||
/// The `ExExs` (execution extensions) of the node.
|
||||
pub exexs: Vec<(String, Box<dyn BoxedLaunchExEx<Node>>)>,
|
||||
/// Additional user-defined context, such as:
|
||||
/// - RPC
|
||||
/// - Additional hooks that can be invoked when the node is launched.
|
||||
// TODO: perhaps rename to addon
|
||||
pub ctx: Ctx,
|
||||
}
|
||||
|
||||
/// Additional context addon that captures settings required for a regular, ethereum or optimism
|
||||
/// node that make use of engine API and RPC.
|
||||
pub struct EngineApiAddon<Node: FullNodeComponents, EthApi> {
|
||||
rpc: RpcAddon<Node, EthApi>,
|
||||
// TODO anything rpc specific we need here? if not, maybe this type is redundant and engine can
|
||||
// be enforced via the launcher type entirely
|
||||
}
|
||||
|
||||
/// Captures node specific addons that can be installed on top of the type configured node and are
|
||||
/// required for launching the node, such as RPC.
|
||||
pub struct RpcAddon<Node: FullNodeComponents, EthApi> {
|
||||
// TODO enforce the the ethAPI builder trait
|
||||
eth_api_builder: EthApi,
|
||||
/// Additional `NodeHooks` that are called at specific points in the node's launch lifecycle.
|
||||
// TODO make hooks generic over ethapi config
|
||||
pub(crate) hooks: NodeHooks<Node>,
|
||||
/// Additional RPC hooks.
|
||||
pub(crate) rpc: RpcHooks<Node>,
|
||||
/// The `ExExs` (execution extensions) of the node.
|
||||
pub(crate) exexs: Vec<(String, Box<dyn BoxedLaunchExEx<Node>>)>,
|
||||
}
|
||||
|
||||
// TODO impl install hook functions.
|
||||
|
||||
@@ -41,7 +41,8 @@ pub use exex::ExExLauncher;
|
||||
|
||||
/// A general purpose trait that launches a new node of any kind.
|
||||
///
|
||||
/// Acts as a node factory.
|
||||
/// Acts as a node factory that targets a certain node configuration and returns a handle to the
|
||||
/// node.
|
||||
///
|
||||
/// This is essentially the launch logic for a node.
|
||||
///
|
||||
@@ -80,6 +81,7 @@ impl DefaultNodeLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO enforce the nodeaddons type in `NodeBuilderWithComponents`
|
||||
impl<T, CB> LaunchNode<NodeBuilderWithComponents<T, CB>> for DefaultNodeLauncher
|
||||
where
|
||||
T: FullNodeTypes<Provider = BlockchainProvider<<T as FullNodeTypes>::DB>>,
|
||||
@@ -95,7 +97,7 @@ where
|
||||
let NodeBuilderWithComponents {
|
||||
adapter: NodeTypesAdapter { database },
|
||||
components_builder,
|
||||
add_ons: NodeAddOns { hooks, rpc, exexs: installed_exex },
|
||||
add_ons: NodeAddOns { hooks, rpc, exexs: installed_exex, ctx },
|
||||
config,
|
||||
} = target;
|
||||
let NodeHooks { on_component_initialized, on_node_started, .. } = hooks;
|
||||
|
||||
@@ -24,6 +24,9 @@ pub trait Node<N: FullNodeTypes>: NodeTypes + Clone {
|
||||
/// The type that builds the node's components.
|
||||
type ComponentsBuilder: NodeComponentsBuilder<N>;
|
||||
|
||||
// TODO define nodeAddons types, that will create the rpc setup for example ethAPI
|
||||
type NodeAddon;
|
||||
|
||||
/// Returns a [`NodeComponentsBuilder`] for the node.
|
||||
fn components_builder(self) -> Self::ComponentsBuilder;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user