Skip to content

fix: If the PoX anchor block is a shadow block, then none of its grandchildren tenures' block-commits will be valid#6985

Open
jcnelson wants to merge 11 commits intostacks-network:developfrom
jcnelson:fix/shadow-block-pox-descendant
Open

fix: If the PoX anchor block is a shadow block, then none of its grandchildren tenures' block-commits will be valid#6985
jcnelson wants to merge 11 commits intostacks-network:developfrom
jcnelson:fix/shadow-block-pox-descendant

Conversation

@jcnelson
Copy link
Copy Markdown
Member

@jcnelson jcnelson commented Mar 13, 2026

This fixes the flaky integration test test_shadow_recovery by means of fixing a legitimate bug: if a PoX anchor block happens to be a shadow block, it's immediate child commit can be accepted, but not its grandchild commit nor its descendants. This is because we have a special case check to treat a block-commit as having descended from the anchor block if it happens to be a child of the anchor block (as determined by its parent_block_ptr and parent_vtxindex fields), but the SortitionHandle::descends_from() check will fail for any block that descends from a shadow PoX anchor block on the count of the fact that shadow blocks have no sortition (it instead has a "phony" block-commit at vtxindex = 0, which is impossible).

The fix here is to add a field descends_from_anchor_block to LeaderBlockCommitOp, which is set to true on a call to check_pox() if the block does indeed descend from the anchor block, and false otherwise. Then, to determine if a given block-commit descends from a parent block-commit in the same reward cycle, we perform the same checks today as well as consider the parent commit's descends_from_anchor_block value. So, if a block-commit is a grandchild of a shadow PoX anchor block phony block-commit, it will be treated as having descended from the anchor block because its parent did as long as the parent is in the same reward cycle (which it must be; otherwise block processing will have halted before this commit could have been processed).

This PR adds a descends_from_anchor_block column to block_commits in SortitionDB to track this field. It is NULL by default, since it will never be needed until we actually to produce a shadow block. This does not affect correctness since subsequent block-commits stored with this new schema will automatically have descends_from_anchor_block set to the correct value on insertion.

…heir anchor block. This is necessary in the special case where the PoX anchor block is a shadow block, and the block-commit being considered is the grandchild of the block-commit. Before, this and subsequent commits would be incorrectly rejected since the descend_from() check would fail for them (since the shadow block has no sortition). With this change, such block-commits would be accepted because their parent (a block-commit in the same reward cycle whose parent is a shadow block and the PoX anchor block) would have been accepted (on the count that it is the immediate child of the anchor block).
@jcnelson jcnelson changed the title fix: Update block-commits to track whether or not they descend from t… fix: If the PoX anchor block is a shadow block, then none of its grandchildren tenures' block-commits will be valid Mar 13, 2026
Comment thread stacks-node/src/tests/nakamoto_integrations.rs Outdated
Comment thread stacks-node/src/tests/nakamoto_integrations.rs Outdated
Copy link
Copy Markdown
Contributor

@jacinta-stacks jacinta-stacks left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for looking into this. I just have the nits, but I think you may need to pull develop and add a changelog entry now given the merging of Brice's changelog PR.

Comment thread stackslib/src/chainstate/burn/db/sortdb.rs Outdated
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 79.24528% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.92%. Comparing base (f01f194) to head (a440c40).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
.../chainstate/burn/operations/leader_block_commit.rs 72.15% 22 Missing ⚠️
stackslib/src/chainstate/burn/db/sortdb.rs 83.63% 9 Missing ⚠️
...-node/src/burnchains/bitcoin_regtest_controller.rs 50.00% 1 Missing ⚠️
stackslib/src/config/chain_data.rs 91.66% 1 Missing ⚠️

❌ Your project check has failed because the head coverage (84.12%) is below the adjusted base coverage (84.17%). You can increase the head coverage or adjust the Removed Code Behavior.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6985      +/-   ##
===========================================
- Coverage    84.96%   84.92%   -0.05%     
===========================================
  Files          412      412              
  Lines       219113   219264     +151     
  Branches       338      338              
===========================================
+ Hits        186172   186202      +30     
- Misses       32941    33062     +121     
Files with missing lines Coverage Δ
stacks-node/src/burnchains/mocknet_controller.rs 69.12% <ø> (ø)
stacks-node/src/nakamoto_node/relayer.rs 86.25% <100.00%> (+<0.01%) ⬆️
stacks-node/src/neon_node.rs 82.71% <100.00%> (-0.37%) ⬇️
stacks-node/src/node.rs 87.32% <100.00%> (+0.01%) ⬆️
stackslib/src/chainstate/burn/db/processing.rs 86.30% <100.00%> (+0.04%) ⬆️
stackslib/src/chainstate/burn/distribution.rs 98.47% <100.00%> (+<0.01%) ⬆️
stackslib/src/chainstate/burn/operations/mod.rs 74.42% <ø> (ø)
...ackslib/src/chainstate/burn/operations/test/mod.rs 71.92% <100.00%> (+0.13%) ⬆️
stackslib/src/chainstate/burn/sortition.rs 94.20% <100.00%> (+<0.01%) ⬆️
stackslib/src/chainstate/stacks/block.rs 94.97% <100.00%> (+<0.01%) ⬆️
... and 4 more

... and 43 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f01f194...a440c40. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@cylewitruk-stacks cylewitruk-stacks left a comment

Choose a reason for hiding this comment

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

Code-wise this LGTM, but I don't feel familiar enough with the actual underlying issue/domain to give an approve - so maybe @aaronb-stacks or @brice-stacks could make a quick pass and give their ✅ ?

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 26, 2026

Coverage Report for CI Build 24680395267

Coverage decreased (-0.02%) to 85.695%

Details

  • Coverage decreased (-0.02%) from the base build.
  • Patch coverage: 32 uncovered changes across 3 files (127 of 159 lines covered, 79.87%).
  • 3239 coverage regressions across 83 files.

Uncovered Changes

File Changed Covered %
stackslib/src/chainstate/burn/operations/leader_block_commit.rs 79 57 72.15%
stackslib/src/chainstate/burn/db/sortdb.rs 55 46 83.64%
stackslib/src/config/chain_data.rs 12 11 91.67%

Coverage Regressions

3239 previously-covered lines in 83 files lost coverage.

Top 10 Files by Coverage Loss Lines Losing Coverage Coverage
stackslib/src/net/inv/epoch2x.rs 219 79.55%
stackslib/src/chainstate/stacks/db/transactions.rs 208 97.07%
stackslib/src/net/chat.rs 201 93.01%
stackslib/src/chainstate/stacks/miner.rs 190 83.5%
stacks-node/src/nakamoto_node/miner.rs 139 88.09%
stackslib/src/chainstate/stacks/db/mod.rs 135 86.21%
stackslib/src/net/api/postblock_proposal.rs 126 80.0%
clarity/src/vm/costs/mod.rs 125 83.57%
stackslib/src/config/mod.rs 101 68.84%
stacks-node/src/nakamoto_node/relayer.rs 100 87.12%

Coverage Stats

Coverage Status
Relevant Lines: 218461
Covered Lines: 187211
Line Coverage: 85.7%
Coverage Strength: 17254008.0 hits per line

💛 - Coveralls

Copy link
Copy Markdown
Contributor

@brice-stacks brice-stacks left a comment

Choose a reason for hiding this comment

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

This looks good, I just have a question about the default for the new column.

Comment thread stackslib/src/chainstate/burn/db/sortdb.rs
@dhaney-stacks
Copy link
Copy Markdown
Contributor

@jcnelson please wrap up this PR.

Copy link
Copy Markdown
Contributor

@brice-stacks brice-stacks left a comment

Choose a reason for hiding this comment

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

lgtm

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants