Skip to content

Conversation

furszy
Copy link
Member

@furszy furszy commented May 22, 2023

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
Copy link
Contributor

DrahtBot commented May 22, 2023

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.

Copy link
Contributor

@mzumsande mzumsande left a comment

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
Copy link
Contributor

@TheCharlatan TheCharlatan left a comment

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
Member

ACK 3126454

@achow101 achow101 merged commit 3a83d44 into bitcoin:master May 31, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 31, 2023
…r setting 'synced' flag

3126454 index: prevent race by calling 'CustomInit' prior setting 'synced' flag (furszy)

Pull request description:

  Decoupled from bitcoin#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 bitcoin@bef4e40 from bitcoin#25494.

ACKs for top commit:
  achow101:
    ACK 3126454
  mzumsande:
    Code review ACK 3126454
  TheCharlatan:
    Nice, ACK 3126454

Tree-SHA512: 7a53fed1d2035cb4c1f331d6ee9f92d499b6cbb618ea534c6440f5a45ff9b3ac4dcff5fb4b88937f45a0be249e3a9c6dc6c3ac77180f12ae25fc56856ba39735
@furszy furszy mentioned this pull request Jan 4, 2024
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