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

Open
l0rinc wants to merge 2 commits from l0rinc/new-block-flag-after-storage into master AGit
l0rinc commented 2026-12-01 14:06:11 +00:00 (Migrated from github.com)

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.

**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.
DrahtBot commented 2026-12-01 14:06:23 +00:00 (Migrated from github.com)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/37028 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/37028.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/37028#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [Conradgabe](https://github.com/bitcoin/bitcoin/pull/37028#issuecomment-7325131202), [nervana21](https://github.com/bitcoin/bitcoin/pull/37028#issuecomment-7350502859) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36858](https://github.com/bitcoin/bitcoin/pull/36858) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36858.svg"></sub> (refactor: break the blockstorage/validation circular dependency by pzafonte) * [#36856](https://github.com/bitcoin/bitcoin/pull/36856) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36856.svg"></sub> (kernel: add manual pruning by pzafonte) * [#36738](https://github.com/bitcoin/bitcoin/pull/36738) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36738.svg"></sub> (refactor: move block writes and pruning into BlockManager by pzafonte) * [#36735](https://github.com/bitcoin/bitcoin/pull/36735) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36735.svg"></sub> (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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

🟠 Minor · bitcoin-chainstate mislabels a failed block write as a duplicate

The experimental bitcoin-chainstate demo now prints “Block is a duplicate” for a first-time block whose write fails, extending its pre-existing misclassification of validation failures.

Location: src/validation.cpp:4471 (head).

🔵 Suggestion · The new_block API docs still describe receipt rather than storage

The ProcessNewBlock and kernel API docs still describe first receipt or processing, although a first-time block whose write fails now leaves new_block false.

Location: src/validation.cpp:4471 (head).


Reviewed: 074945e50672 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:312ddb2095238aa2ca395a9cc39b05ab5a38a7177afbdb0d69098df9c3e0bef9:9a7f127b15c6116c267953d38288a9f17ec7c7bcd3a975fb71a2db8bfd974dbf --> <!-- ralph-base:afa492e233868bcf4799bb62943baa28017938f6 --> <!-- ralph-head:074945e50672da8afa6ec874a1556fe59b819f37 --> <!-- ralph-case:ab9588b55146157eaac83316bd3609f59457a45bb007ea862743f66ba64f1a0d --> **🟠 Minor · `bitcoin-chainstate` mislabels a failed block write as a duplicate** The experimental `bitcoin-chainstate` demo now prints “Block is a duplicate” for a first-time block whose write fails, extending its pre-existing misclassification of validation failures. Location: [`src/validation.cpp:4471`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/074945e50672da8afa6ec874a1556fe59b819f37/src/validation.cpp#L4471>) (head). **🔵 Suggestion · The `new_block` API docs still describe receipt rather than storage** The `ProcessNewBlock` and kernel API docs still describe first receipt or processing, although a first-time block whose write fails now leaves `new_block` false. Location: [`src/validation.cpp:4471`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/074945e50672da8afa6ec874a1556fe59b819f37/src/validation.cpp#L4471>) (head). <!-- Review tier: sensitive --> --- Reviewed: [`074945e50672`](<https://git.fish.foo/bitcoin/bitcoin/commit/074945e50672da8afa6ec874a1556fe59b819f37>) · [Review report](<https://review.fish.foo/report/37028-074945e50672da8afa6ec874a1556fe59b819f37-3393-1.html>) · [Previous reports](<https://review.fish.foo/traces/37028/>) [permalink](<https://review.fish.foo/report/37028-074945e50672da8afa6ec874a1556fe59b819f37-3393-1.html>)
Conradgabe commented 2026-12-01 20:42:08 +00:00 (Migrated from github.com)

tACK 074945e506

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.

tACK 074945e50672da8afa6ec874a1556fe59b819f37 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 commented 2026-12-02 15:32:36 +00:00 (Migrated from github.com)

tACK 074945e506

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.

tACK 074945e50672da8afa6ec874a1556fe59b819f37 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 in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!37028
No description provided.