HomePhabricator

indexes, refactor: Remove CBlockIndex* uses in index Init methods

Description

indexes, refactor: Remove CBlockIndex* uses in index Init methods

Summary:

Replace overriden index Init() methods that use the best block
CBlockIndex* pointer with pure CustomInit() callbacks that are passed
the block hash and height.

This gets rid of more CBlockIndex* pointer uses so indexes can work
outside the bitcoin-node process. It also simplifies the initialization
call sequence so index implementations are not responsible for
initializing the base class.

There is a slight change in behavior here since now the best block
pointer is loaded and checked before the custom index init functions are
called instead of while they are called.

https://github.com/bitcoin/bitcoin/pull/25494/commits/bef4e405f3de2718dfee279a9abff4daf016da26

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.

https://github.com/bitcoin/bitcoin/pull/27720/commits/3126454dcfa1dd29bb66500d5f2b5261684d6c58

This is a backport of core#27720

Depends on D17721

Test Plan: ninja all check-all

Reviewers: #bitcoin_abc, roqqit

Reviewed By: #bitcoin_abc, roqqit

Subscribers: roqqit

Differential Revision: https://reviews.bitcoinabc.org/D17722

Details

Provenance
Ryan Ofsky <ryan@ofsky.org>Authored on Jan 17 2022, 23:36
PiRKCommitted on Fri, Feb 28, 20:13
PiRKPushed on Fri, Feb 28, 20:13
Reviewer
Restricted Project
Differential Revision
D17722: indexes, refactor: Remove CBlockIndex* uses in index Init methods
Parents
rABCef4a1052f5f0: indexes, refactor: Remove CBlockIndex* uses in coinstatsindex LookUpOne function
Branches
Unknown
Tags
Unknown