Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Jun 29, 2020

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

@maflcko
Copy link
Member Author

maflcko commented Jun 29, 2020

The --word-diff-regex=. git option might come in handy during review

@laanwj
Copy link
Member

laanwj commented Jun 29, 2020

Nice change, good to get rid of an valdiation global, and it's surprisingly low impact.

ACK fa82d84

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Light code review ACK fa82d84 I agree that that this is a nice change

@maflcko maflcko closed this Jun 29, 2020
@maflcko maflcko reopened this Jun 29, 2020
@DrahtBot
Copy link
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

@practicalswift
Copy link
Contributor

Concept ACK

@maflcko maflcko force-pushed the 2006-noBlockIndexGlobal branch from fa82d84 to fa0dfdf Compare June 30, 2020 00:29
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK fa0dfdf.

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-ACK fa0dfdf

@maflcko maflcko merged commit 915ac8a into bitcoin:master Jul 3, 2020
@maflcko maflcko deleted the 2006-noBlockIndexGlobal branch July 3, 2020 11:39
domob1812 added a commit to domob1812/namecoin-core that referenced this pull request Jul 6, 2020
Some Namecoin code is still broken by the upstream change in
bitcoin/bitcoin#19413, which will be fixed
in a separate follow-up commit.
domob1812 added a commit to domob1812/namecoin-core that referenced this pull request Jul 6, 2020
Properly pass down a ChainstateManager to the parts of the Namecoin
code that need it (mostly validation of the coin database and the
mempool, which is partly based on block heights).

This fixes the breakages introduced by the upstream removal of the
global BlockIndex in bitcoin/bitcoin#19413.
domob1812 added a commit to domob1812/namecoin-core that referenced this pull request Jul 6, 2020
Properly pass down a ChainstateManager to the parts of the Namecoin
code that need it (mostly validation of the coin database and the
mempool, which is partly based on block heights).

This fixes the breakages introduced by the upstream removal of the
global BlockIndex in bitcoin/bitcoin#19413.
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 26, 2021
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 [[bitcoin/bitcoin#19413 | 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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants