blockchain: discard_pending_subtree recurses once per pending descendant

Open
#810 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 6 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust

Research direction

Read crates/blockchain/src/lib.rs, especially BlockChainServer::discard_pending_subtree near line 3196 and invalidate_subtree for the existing worklist pattern. Replace recursive child processing with an explicit worklist while preserving per-root cleanup, then add a deep pending-chain test that discards its root on a thread with a 2 MiB stack. Done means the discard completes without stack overflow and the test passes.

Written by the indexing model from the issue text.

Description

BlockChainServer::discard_pending_subtree (crates/blockchain/src/lib.rs:3196) calls itself for every child in pending_blocks (lib.rs:3223), on the chain actor's thread. That thread runs with the default 2 MiB stack.

I found no cap on pending_blocks (lib.rs:464). No use of it in crates/blockchain/src checks its length or evicts by size; the inserts are at lib.rs:2810 and 2863. A chain of pending blocks N deep would make the discard recurse N times. A deep enough chain would abort the process with a stack overflow, the failure lambdaclass/ethlambda#758 removed from filter_block_tree.

Not traced or measured:

  • whether such a chain forms in practice (a range catch-up whose first block's parent is missing is one unverified candidate);
  • the function's frame size;
  • the depth at which it would overflow.

The import cascade that releases pending children (lib.rs:3078) already uses a queue, so only the discard path recurses.

This is out of scope for lambdaclass/ethlambda#758, which changes only the fork-choice filter.

A fix would use an explicit worklist, the way invalidate_subtree already does: let mut stack = vec![block_root]; while let Some(root) = stack.pop() { ...; stack.extend(children) }, with the same per-root cleanup. A test like #758's deep-chain test would cover it: build a deep pending chain, then discard its root on a thread with an explicit 2 MiB stack.

Dominant language
Rust
Stars
86
Forks
34
Avg merge
9d 20h
Merged PRs (30d)
77

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lambdaclass/ethlambda

All issues in lambdaclass/ethlambda

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.