docs: fix incorrect API example in node-components.mdx (#20297)

This commit is contained in:
bigbear
2025-12-16 17:09:29 +02:00
committed by GitHub
parent 0b607113dc
commit 4231f4b688

View File

@@ -53,44 +53,56 @@ Provides external API access to the node:
## Component Customization ## Component Customization
Each component can be customized through Reth's builder pattern: Each component can be customized through Reth's builder pattern. You can replace individual components
while keeping the defaults for others using `EthereumNode::components()`:
```rust ```rust
use reth_ethereum::node::{EthereumNode, NodeBuilder}; use reth_ethereum::{
cli::interface::Cli,
node::{
node::EthereumAddOns,
EthereumNode,
},
};
let node = NodeBuilder::new(config) fn main() {
.with_types::<EthereumNode>() Cli::parse_args()
.with_components(|ctx| { .run(|builder, _| async move {
// Use the ComponentBuilder to customize components let handle = builder
ctx.components_builder() // Use the default ethereum node types
// Custom network configuration .with_types::<EthereumNode>()
.network(|network_builder| { // Configure the components of the node
network_builder // Use default ethereum components but replace specific ones
.peer_manager(custom_peer_manager) .with_components(
.build() EthereumNode::components()
}) // Custom transaction pool
// Custom transaction pool .pool(CustomPoolBuilder::default())
.pool(|pool_builder| { // Other customizable components:
pool_builder // .network(CustomNetworkBuilder::default())
.validator(custom_validator) // .executor(CustomExecutorBuilder::default())
.ordering(custom_ordering) // .consensus(CustomConsensusBuilder::default())
.build() // .payload(CustomPayloadBuilder::default())
}) )
// Custom consensus .with_add_ons(EthereumAddOns::default())
.consensus(custom_consensus) .launch()
// Custom EVM configuration .await?;
.evm(|evm_builder| {
evm_builder handle.wait_for_node_exit().await
.with_precompiles(custom_precompiles) })
.build() .unwrap();
}) }
// Build all components
.build()
})
.build()
.await?;
``` ```
Custom component builders must implement their respective traits (`PoolBuilder`, `NetworkBuilder`,
`ExecutorBuilder`, `ConsensusBuilder`, `PayloadServiceBuilder`). Each trait requires implementing
an async `build_*` method that receives a `BuilderContext` with access to node configuration,
providers, and task executors.
For complete working examples with full trait implementations, see:
- [custom-node-components](https://github.com/paradigmxyz/reth/tree/main/examples/custom-node-components) - Custom transaction pool
- [custom-payload-builder](https://github.com/paradigmxyz/reth/tree/main/examples/custom-payload-builder) - Custom payload builder
- [custom-evm](https://github.com/paradigmxyz/reth/tree/main/examples/custom-evm) - Custom EVM configuration
## Component Lifecycle ## Component Lifecycle
Components follow a specific lifecycle starting from node builder initialization to shutdown: Components follow a specific lifecycle starting from node builder initialization to shutdown: