Repository navigation
fix(blockchain): discard a pending subtree with a worklist, not a call per descendant - #955
Open
pablodeymo wants to merge 1 commit into
Open
pablodeymo wants to merge 1 commit into
pablodeymo wants to merge 1 commit into
Conversation
…l per descendant `discard_pending_subtree` called itself for every pending child, on the chain actor's thread (2 MiB stack), and nothing caps how deep a chain of pending blocks gets. A block by a proposer the head state lacks waits for its parent unsigned, and a parked block's slot is not compared with its child's, so the depth is not bounded by the unfinalized window either. A block at or below the finalized slot then discards everything parked on it. Measured with the new test on the old code: the stack overflows, aborting the process, about 2,200 parked blocks down under `release-fast` and about 12,700 under `release`. The walk now keeps the roots still to discard in a `Vec`. The per-root cleanup is unchanged. Closes #810
Collaborator
Author
|
/review |
AI security review: 0 finding(s) to checkReviewed by Opus, GPT, Kimi, GLM, DeepSeek. No findings to check. Cost of this review: ~$0.94 of a $30 budget (estimated from token counts). |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🗒️ Description / Motivation
BlockChainServer::discard_pending_subtreecalled itself once for every pending child. It runs on the chain actor's thread (Backend::Thread, astd::threadwith the default 2 MiB stack), and nothing caps how deep a chain of pending blocks gets, so a deep enough chain overflows the stack and aborts the process (#810).The issue left three things unmeasured. This PR answers them:
precheck_before_waiting,UnknownProposerunderWait::Parent), and a parked block's slot is never compared with its child's, so the depth is not bounded by the unfinalized window. The new test parks 50,000 blocks at one slot this way, throughprocess_or_pend_blockrelease-fast(roughly 940 bytes a level) and about 12,700 underrelease(roughly 164 bytes), bisected with the new test on the old code. Measured on macOS aarch64 in the crate's test binary; the shipped binary may differIntended for
release/v2.0.0by cherry-pick once merged here.What Changed
crates/blockchain/src/lib.rsonly.discard_pending_subtreekeeps the roots still to discard in aVecand loops, in place of the self-call. The per-root cleanup is the same code, re-indented: the diff is small with whitespace hidden (?w=1).Correctness / Behavior Guarantees
blocks_awaiting_columns, the parent-payload hold, envelopes awaiting import,held_timings,pending_blocks,pending_block_parents). Only the order changes, and no step reads what another root's step wrote.pending_blocksis still uncapped, so a peer can still make the node hold many parked blocks. That is a memory bound, a separate matter from this crash.Tests Added / Run
a_parked_chain_is_discarded_whole_without_overflowing_a_default_stack: parks a 50,000-block chain throughprocess_or_pend_block(unsigned blocks, tip first, all at one slot) on a thread with an explicit 2 MiB stack, delivers the block at the finalized slot, and checkspending_blocks,pending_block_parentsandheld_timingsare empty. On the old code it aborts withhas overflowed its stackunder both profiles. It runs in about 0.3 s.a_discard_takes_every_branch_and_leaves_other_parked_chains: a branching subtree goes whole and a chain parked elsewhere stays. Checked to fail when the walk stops at the first childless block.cargo test -p ethlambda-blockchain --profile release-fast --lib: 427 passed, 46 ignored (the fixture-gated ones).cargo clippy -p ethlambda-blockchain --all-targets -- -D warningsandcargo fmt --all -- --check: clean.make lintandmake test.process_or_pend_block, not at the p2p layer. Each parked block costs the peer one answered by-root request, and a retry picks a peer at random, so how fast a single peer can build the chain is not measured.Related Issues / PRs
held_timingsis checked too; and the old code's overflow depth is measured. fix(blockchain): discard pending subtrees with an explicit stack #945's tests are also inserted between an existing test and its doc comment.filter_block_tree.✅ Verification Checklist
make fmt— cleanmake lint(clippy with-D warnings) — clean (onlyethlambda-blockchain)make test(test-consensus,test-nodeandtest-ethrex, atrelease-fast) — all passing (onlyethlambda-blockchain --lib)