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