feat(rpc): implement debug_traceBadBlock (#22719)

This commit is contained in:
John Chase
2026-03-03 12:17:55 +08:00
committed by GitHub
parent 6366201f16
commit 91182f6535
2 changed files with 26 additions and 5 deletions

View File

@@ -404,7 +404,7 @@ pub trait DebugApi<TxReq: RpcObject> {
&self,
block_hash: B256,
opts: Option<GethDebugTracingCallOptions>,
) -> RpcResult<()>;
) -> RpcResult<Vec<TraceResult>>;
/// Sets the logging verbosity ceiling. Log messages with level up to and including the given
/// level will be printed.

View File

@@ -1070,10 +1070,25 @@ where
async fn debug_trace_bad_block(
&self,
_block_hash: B256,
_opts: Option<GethDebugTracingCallOptions>,
) -> RpcResult<()> {
Ok(())
block_hash: B256,
opts: Option<GethDebugTracingCallOptions>,
) -> RpcResult<Vec<TraceResult>> {
let _permit = self.acquire_trace_permit().await;
let block = self
.inner
.bad_block_store
.get(block_hash)
.ok_or_else(|| internal_rpc_err("bad block not found in cache"))?;
let evm_env = self
.eth_api()
.evm_config()
.evm_env(block.header())
.map_err(RethError::other)
.to_rpc_result()?;
let opts = opts.map(|o| o.tracing_options).unwrap_or_default();
self.trace_block(block, evm_env, opts).await.map_err(Into::into)
}
async fn debug_verbosity(&self, _level: usize) -> RpcResult<()> {
@@ -1153,6 +1168,12 @@ impl<B: BlockTrait> BadBlockStore<B> {
let guard = self.inner.read();
guard.iter().rev().cloned().collect()
}
/// Returns the bad block with the given hash, if cached.
fn get(&self, hash: B256) -> Option<Arc<RecoveredBlock<B>>> {
let guard = self.inner.read();
guard.iter().find(|b| b.hash() == hash).cloned()
}
}
impl<B: BlockTrait> Default for BadBlockStore<B> {