Page MenuHomePhabricator

refactor: Remove confusing BlockIndex global
ClosedPublic

Authored by PiRK on May 25 2021, 15:34.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC721672a587a2: 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

Event Timeline

PiRK requested review of this revision.May 25 2021, 15:34
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/rpc/blockchain.cpp
1648

actove => active

This revision is now accepted and ready to land.May 25 2021, 20:22