Skip to content

Conversation

@0xKarl98
Copy link
Contributor

@0xKarl98 0xKarl98 commented Dec 5, 2025

This targets on issue #20123 , as below :

  • Add a shared BadBlockStore (bounded, deduped, newest-first) and wire it into DebugApi
  • Implement debug_getBadBlocks to expose recent invalid blocks with full transactions, hash, and RLP
  • Listen for ConsensusEngineEvent::InvalidBlock, recover the sealed block with senders, and cache it for the debug API

cc @mattsse @klkvr @Rjected

@0xKarl98 0xKarl98 requested a review from gakonst as a code owner December 5, 2025 16:37
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, a few suggestions

paging @klkvr re type generics

/// 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>>;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

#[method(name = "getBlockByHash")]
async fn block_by_hash(&self, hash: B256, full: bool) -> RpcResult<Option<B>>;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah think we need to unify the block def in rpc here

eth_api: Eth,
// restrict the number of concurrent calls to blocking calls
blocking_task_guard: BlockingTaskGuard,
bad_block_store: BadBlockStore<ProviderBlock<Eth::Provider>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we need the types for this

I guess an alternative here would be to just use EthApiTypes here

Comment on lines +71 to +73
// drop existing entry with same hash to keep most recent order
guard.retain(|b| b.hash() != hash);
guard.push_back(Arc::new(block));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of removing, I think we should just check if we already have it

because it's common that we see bad blocks a few times, and this would then mess up the ordering

Copy link
Contributor Author

@0xKarl98 0xKarl98 Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah def should do that , skip the duplicated bad block hash

Comment on lines +52 to +54
/// A bounded, deduplicating store of recently observed bad blocks.
#[derive(Clone, Debug)]
pub struct BadBlockStore<B: BlockTrait> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this type def is out of order, we should move this to after all the impl blocks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah will look more ordered

Comment on lines +1023 to +1026
// 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(
Copy link
Collaborator

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

Copy link
Contributor Author

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

Comment on lines +1023 to +1026
// 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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can spawn this as regular task imo

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Dec 6, 2025
@mattsse mattsse added M-changelog This change should be included in the changelog A-rpc Related to the RPC implementation labels Dec 6, 2025
@0xKarl98
Copy link
Contributor Author

0xKarl98 commented Dec 7, 2025

Just closes this and open another with more proper name debug_getBadBlocks

@0xKarl98 0xKarl98 closed this Dec 7, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rpc Related to the RPC implementation M-changelog This change should be included in the changelog

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants