Skip to content

validation: add missing insert to m_dirty_blockindex - #27905

Merged
fanquake merged 1 commit into
bitcoin:masterfrom
mzumsande:202306_dirty_blockindex
Jun 21, 2023
Merged

fanquake merged 1 commit into
bitcoin:masterfrom
mzumsande:202306_dirty_blockindex

Conversation

@mzumsande

Copy link
Copy Markdown
Contributor

When the status of a block index is changed, we must add it to m_dirty_blockindex or the change might not get persisted to disk.
This is missing from one spot in FindMostWorkChain(), where BLOCK_FAILED_CHILD is set.
Since we have code that later sets missing BLOCK_FAILED_CHILD during the next startup, I don't think that this can lead to bad block indexes in practice, but I still think it's worth fixing.

@DrahtBot

DrahtBot commented Jun 16, 2023 •

Copy link
Copy Markdown
Contributor

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

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK TheCharlatan, stickies-v

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

...in FindMostWorkChain(). Before this, it was possible that the change
to the block index wouldn't be persisted to disk.
@mzumsande
mzumsande force-pushed the 202306_dirty_blockindex branch from 1f33a84 to e639364 Compare June 16, 2023 21:26

@sedited sedited left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK e639364

@fanquake
fanquake requested a review from stickies-v June 21, 2023 10:29

@stickies-v stickies-v left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK e639364

Couldn't find any other instances of CBlockIndex::nStatus updates not being added to m_dirty_blockindex. As pointed out by mzumsande, I think indeed this should be corrected nicely upon startup since LoadBlockIndex() iterates from start->end, as opposed to the reverse end->start being done here.

@fanquake
fanquake merged commit d23cdf6 into bitcoin:master Jun 21, 2023
@mzumsande
mzumsande deleted the 202306_dirty_blockindex branch June 21, 2023 18:21
@Sjors

Sjors commented Jul 29, 2023 •

Copy link
Copy Markdown
Member

Should we make nStatus private and only allow writing to it through a helper method that marks the index entry dirty?

luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Aug 16, 2023
...in FindMostWorkChain(). Before this, it was possible that the change
to the block index wouldn't be persisted to disk.

Github-Pull: bitcoin#27905
Rebased-From: e639364
@mzumsande

Copy link
Copy Markdown
Contributor Author

Should we make nStatus private and only allow writing to it through a helper method that marks the index entry dirty?

Would be nice if we didn't have to remember, I think there would be a few complications:

  • CBlockIndex is an object that can exist and be updateable independent from whether it's part of our block index database - I could imagine there are spots that update its members that don't require marking it dirty.
  • Do we only want to mark nStatus private, and leave all other members public? If it's the latter, then it could become quite a big change...

@bitcoin bitcoin locked and limited conversation to collaborators Aug 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants