index: prevent race by calling ‘CustomInit’ prior setting ‘synced’ flag #27720

pull furszy wants to merge 1 commits into bitcoin:master from furszy:2023_index_init_race_bugfix changing 1 files +15 −13
  1. furszy commented at 4:08 pm on May 22, 2023: 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 https://github.com/bitcoin/bitcoin/commit/bef4e405f3de2718dfee279a9abff4daf016da26 from #25494.

  2. index: prevent race by calling 'CustomInit' prior setting 'synced' flag
    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.
    3126454dcf
  3. DrahtBot commented at 4:08 pm on May 22, 2023: 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.

  4. DrahtBot added the label UTXO Db and Indexes on May 22, 2023
  5. mzumsande commented at 10:17 pm on May 23, 2023: contributor
    Code review ACK 3126454dcfa1dd29bb66500d5f2b5261684d6c58
  6. fanquake requested review from ryanofsky on May 24, 2023
  7. TheCharlatan approved
  8. TheCharlatan commented at 11:38 am on May 25, 2023: contributor
    Nice, ACK 3126454dcfa1dd29bb66500d5f2b5261684d6c58
  9. fanquake assigned ryanofsky on May 25, 2023
  10. achow101 commented at 5:45 pm on May 31, 2023: member
    ACK 3126454dcfa1dd29bb66500d5f2b5261684d6c58
  11. achow101 merged this on May 31, 2023
  12. achow101 closed this on May 31, 2023

  13. sidhujag referenced this in commit 9ec40ffad2 on May 31, 2023
  14. furszy deleted the branch on Feb 3, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-21 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me