Skip to content

index: prevent race by calling 'CustomInit' prior setting 'synced' flag - #27720

Merged
achow101 merged 1 commit into
bitcoin:masterfrom
furszy:2023_index_init_race_bugfix
May 31, 2023
Merged

achow101 merged 1 commit into
bitcoin:masterfrom
furszy:2023_index_init_race_bugfix

Conversation

@furszy

@furszy furszy commented May 22, 2023 •

Copy link
Copy Markdown
Member

Decoupled from #27607.

Fixed a potential race condition in master (not possible so far) that could become an actual issue soon.
Where the index's CustomAppend method could be called (from BlockConnected) before its
CustomInit method, causing the index to try to update itself before it is initialized.

This could happen because we set the index m_synced flag (which enables BlockConnected events)
before calling to the child class init function (CustomInit). So, for example, the block filter index could
process a block before initialize the next filter position field and end up overwriting the first stored filter.

This race was introduced in bef4e40 from #25494.

The 'm_synced' flag enables 'BlockConnected' events to be processed by
the index. If we set the flag before calling 'CustomInit', we could be
dispatching a block connected event to an uninitialized index child
class.

e.g. BlockFilterIndex, initializes the next filter position
inside 'CustomInit'. So, if `CustomInit` is not called prior receiving
the block event, the index will use 'next_filter_position=0' which
overwrites the first filter in disk.
@DrahtBot

DrahtBot commented May 22, 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 mzumsande, TheCharlatan, achow101

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #27596 (assumeutxo (2) by jamesob)

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.

@mzumsande mzumsande 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.

Code review ACK 3126454

@fanquake
fanquake requested a review from ryanofsky May 24, 2023 08:16

@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.

Nice, ACK 3126454

@achow101

Copy link
Copy Markdown
Member

ACK 3126454

@achow101
achow101 merged commit 3a83d44 into bitcoin:master May 31, 2023
@furszy furszy mentioned this pull request Jan 4, 2024
7 of 18 tasks
@furszy
furszy deleted the 2023_index_init_race_bugfix branch February 3, 2024 15:40
@bitcoin bitcoin locked and limited conversation to collaborators Feb 2, 2025
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