Skip to content

blockchain: discard_pending_subtree recurses once per pending descendant #810

Open

Description

@MegaRedHand

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 #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 #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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions