Skip to content

validation: don't report unstored blocks as new - #37028

Open
l0rinc wants to merge 2 commits into
bitcoin:masterfrom
l0rinc:l0rinc/new-block-flag-after-storage
Open

l0rinc wants to merge 2 commits into
bitcoin:masterfrom
l0rinc:l0rinc/new-block-flag-after-storage

Conversation

@l0rinc

@l0rinc l0rinc commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Problem: When a block write fails, AcceptBlock has already set the new-block flag, so the peer manager still updates the peer's last-block time and clears any in-flight request for the block.

Fix: Set the flag only after recording the stored block's position in the block index.

Submit another block in the flush-failure test while its block file still fails to open.
Check that `ProcessNewBlock` returns false and reports the block as new.
`AcceptBlock` sets the new-block flag before writing the block, so after a failed write `PeerManagerImpl::ProcessBlock` still updates the peer's last-block time and clears any in-flight request for the block.
Set the flag only after updating the block index with the stored block's position.
@DrahtBot

DrahtBot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK Conradgabe, nervana21

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36858 (refactor: break the blockstorage/validation circular dependency by pzafonte)
  • #36856 (kernel: add manual pruning by pzafonte)
  • #36738 (refactor: move block writes and pruning into BlockManager by pzafonte)
  • #36735 (validation: delete pruned files after a failed flush by pzafonte)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@Conradgabe

Copy link
Copy Markdown
Contributor

tACK 074945e

Verified that the test catches the block write failure and that the flag is only set after the block has been successfully written.

nit: You might want to mention in the PR description that it also adds test coverage for failed block writes.

@nervana21

Copy link
Copy Markdown
Contributor

tACK 074945e

After this PR, we no longer set fNewBlock before a successful disk write. This assures that PeerManager no longer treats a failed store like a new block.

For a follow-up, could consider a test of this behavior from the PeerManager side.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants