HomePhabricator

refactor: Remove confusing BlockIndex global

Description

refactor: Remove confusing BlockIndex global

Summary:

The global ::BlockIndex() is problematic for several reasons:

  • It returns a mutable reference to the block tree, without the appropriate lock annotation (m_block_index is guarded by cs_main). The current code is fine, but in the future this might lead to accidental races and data corruption.
  • The rpc server shouldn't rely on node globals, but rather a context that is passed in to the RPC method.
  • Tests might want to spin up their own block tree, and thus should also not rely on a single global.

Fix all issues by removing the global

This is a backport of core#19413

Test Plan: ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

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

Details

Provenance
MarcoFalke <falke.marco@gmail.com>Authored on Jun 29 2020, 14:30
PiRKCommitted on May 26 2021, 13:27
PiRKPushed on May 26 2021, 13:27
Reviewer
Restricted Project
Differential Revision
D9581: refactor: Remove confusing BlockIndex global
Parents
rABCa1dde39651d4: Drop unused CDBWrapper methods
Branches
Unknown
Tags
Unknown