-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: add support for debug_getBadblock #20144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ use crate::{ | |
| }; | ||
| use alloy_rpc_types::engine::ClientVersionV1; | ||
| use alloy_rpc_types_engine::ExecutionData; | ||
| use futures::StreamExt; | ||
| use jsonrpsee::{core::middleware::layer::Either, RpcModule}; | ||
| use reth_chain_state::CanonStateSubscriptions; | ||
| use reth_chainspec::{ChainSpecProvider, EthChainSpec, EthereumHardforks, Hardforks}; | ||
|
|
@@ -23,6 +24,7 @@ use reth_node_core::{ | |
| version::{version_metadata, CLIENT_CODE}, | ||
| }; | ||
| use reth_payload_builder::{PayloadBuilderHandle, PayloadStore}; | ||
| use reth_primitives_traits::RecoveredBlock; | ||
| use reth_rpc::{ | ||
| eth::{core::EthRpcConverterFor, DevSigner, EthApiTypes, FullEthApiServer}, | ||
| AdminApi, | ||
|
|
@@ -1018,6 +1020,23 @@ where | |
| registry.eth_api().signers().write().extend(signers); | ||
| } | ||
|
|
||
| // keep track of invalid blocks for `debug_getBadBlocks` | ||
| let bad_block_store = registry.bad_block_store().clone(); | ||
| let mut engine_events_stream = engine_events.new_listener(); | ||
| node.task_executor().spawn_critical( | ||
|
Comment on lines
+1023
to
+1026
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can spawn this as regular task imo |
||
| "collect bad blocks", | ||
| Box::pin(async move { | ||
| while let Some(event) = engine_events_stream.next().await { | ||
| if let ConsensusEngineEvent::InvalidBlock(block) = event && | ||
| let Ok(recovered) = | ||
| RecoveredBlock::try_recover_sealed(block.as_ref().clone()) | ||
| { | ||
| bad_block_store.insert(recovered); | ||
| } | ||
| } | ||
| }), | ||
| ); | ||
|
|
||
| let mut registry = RpcRegistry { registry }; | ||
| let ctx = RpcContext { | ||
| node: node.clone(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ use alloy_genesis::ChainConfig; | |||||
| use alloy_json_rpc::RpcObject; | ||||||
| use alloy_primitives::{Address, Bytes, B256}; | ||||||
| use alloy_rpc_types_debug::ExecutionWitness; | ||||||
| use alloy_rpc_types_eth::{Block, Bundle, StateContext}; | ||||||
| use alloy_rpc_types_eth::{BadBlock, Bundle, StateContext}; | ||||||
| use alloy_rpc_types_trace::geth::{ | ||||||
| BlockTraceResult, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace, TraceResult, | ||||||
| }; | ||||||
|
|
@@ -38,7 +38,7 @@ pub trait DebugApi<TxReq: RpcObject> { | |||||
|
|
||||||
| /// Returns an array of recent bad blocks that the client has seen on the network. | ||||||
| #[method(name = "getBadBlocks")] | ||||||
| async fn bad_blocks(&self) -> RpcResult<Vec<Block>>; | ||||||
| async fn bad_blocks(&self) -> RpcResult<Vec<BadBlock>>; | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can actually make this just serde_json::Value, seems easier or we use the actual rpc type see also reth/crates/rpc/rpc-eth-api/src/core.rs Lines 90 to 91 in 1902970
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah think we need to unify the block def in rpc here |
||||||
|
|
||||||
| /// Returns the structured logs created during the execution of EVM between two blocks | ||||||
| /// (excluding start) as a JSON object. | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is kinda redundant if we dont have the debug_ endpoint installed because then the blockstore wont be useable, but this doesnt really hurt anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have set a flag to enable blockstore only when debug_ endpoint installed