Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bundle 3/n] Prune remaining g_chainman usage in validation functions #21055

Merged

Conversation

dongcarl
Copy link
Contributor

@dongcarl dongcarl commented Feb 1, 2021

Overall PR: #20158 (tree-wide: De-globalize ChainstateManager)

Based on:

Note to reviewers:

  1. This bundle may apparently introduce usage of g_chainman or ::Chain(state|)Active() globals, but these are resolved later on in the overall PR. Commits of overall PR
  2. There may be seemingly obvious local references to ChainstateManager or other validation objects which are not being used in callers of the current function in question, this is done intentionally to keep each commit centered around one function/method to ease review and to make the overall change systematic. We don't assume anything about our callers. Rest assured that once we are considering that particular caller in later commits, we will use the obvious local references. Commits of overall PR
  3. When changing a function/method that has many callers (e.g. LookupBlockIndex with 55 callers), it is sometimes easier (and less error-prone) to use a scripted-diff. When doing so, there will be 3 commits in sequence so that every commit compiles like so:
    1. Add new_function, make old_function a wrapper of new_function, divert all calls to old_function to new_function in the local module only
    2. Scripted-diff to divert all calls to old_function to new_function in the rest of the codebase
    3. Remove old_function

Note to self:

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 1, 2021

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.

Copy link
Contributor

@ryanofsky ryanofsky 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 f5ee2f3

@@ -4112,11 +4112,12 @@ void BlockManager::Unload() {
m_block_index.clear();
}

bool static LoadBlockIndexDB(ChainstateManager& chainman, const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
bool CChainState::LoadBlockIndexDB(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Copy link
Contributor

Choose a reason for hiding this comment

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

In commit "validation: Move LoadBlockIndexDB to CChainState" (fa730f7)

It seems chainman variable wasn't really needed here, just the chainman.m_blockman member, so this might make more sense as a BlockManager method instead of CChainState method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately we need setBlockIndexCandidates which is a member off CChainState... If you think LoadBlockIndexDB makes more sense logically as a method of BlockManager rather than CChainState we can pass in the setBlockIndexCandidates. Let me know!

Copy link
Contributor

Choose a reason for hiding this comment

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

re: #21055 (comment)

Unfortunately we need setBlockIndexCandidates which is a member off CChainState... If you think LoadBlockIndexDB makes more sense logically as a method of BlockManager rather than CChainState we can pass in the setBlockIndexCandidates. Let me know!

Thanks, I didn't recognize the setBlockIndexCandidates access. Proposed change sounds reasonable, but I don't actually know too much about it and it would seem good to tackle as a followup not changing here.

src/net_processing.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@ariard ariard left a comment

Choose a reason for hiding this comment

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

See about the maybe missing assert otherwise code review ACK f5ee2f3

@@ -4973,24 +4973,6 @@ CBlockFileInfo* GetBlockFileInfo(size_t n)
return &vinfoBlockFile.at(n);
}

ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos)
{
LOCK(cs_main);
Copy link
Contributor

Choose a reason for hiding this comment

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

This global was introduced by d23f6c6. At that commit, the globalVersionBitsTipState's unique callerBIP9SoftForkDesc didn't require cs_main locking.

Those methods were refactored by 3862e47, where the new BIP9SoftForkDescPushBack did require the lock. I think since then this lock has been useless and could have been substituted by an annotation.

So not a concern to get rid of them.

src/net_processing.cpp Outdated Show resolved Hide resolved
@dongcarl
Copy link
Contributor Author

Pushed f5ee2f3 -> eb8f8e4

  • Rebased on master

Note: Have not yet addressed review.

@dongcarl dongcarl force-pushed the 2020-09-reduce-validation-ccsactiveglobal-usage branch from eb8f8e4 to 914e9d3 Compare February 18, 2021 20:48
@dongcarl
Copy link
Contributor Author

@jnewbery
Copy link
Contributor

Concept ACK. This may need rebase now that #20750 is merged.

@dongcarl dongcarl force-pushed the 2020-09-reduce-validation-ccsactiveglobal-usage branch from ef83bb8 to e11b649 Compare March 3, 2021 19:56
@dongcarl
Copy link
Contributor Author

dongcarl commented Mar 3, 2021

@laanwj
Copy link
Member

laanwj commented Mar 4, 2021

Code review ACK e11b649

@laanwj laanwj merged commit 702cfc8 into bitcoin:master Mar 4, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 4, 2021
Copy link
Contributor

@ryanofsky ryanofsky 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 e11b649. Changes since last review: rebase, two new commits adding null assert and lock assert, replacing mempool check coins and spendheight arguments

laanwj added a commit that referenced this pull request Mar 11, 2021
…ent modules

a67983c net_processing: Add review-only assertion to PeerManager (Carl Dong)
272d993 scripted-diff: net_processing: Use existing chainman (Carl Dong)
021a04a net_processing: Move some static functions to PeerManager (Carl Dong)
91c5b68 node/ifaces: ChainImpl: Use existing NodeContext member (Carl Dong)
8a1d580 node/ifaces: NodeImpl: Use existing NodeContext member (Carl Dong)
4cde4a7 node: Use existing NodeContext (Carl Dong)
106bcd4 node/coinstats: Pass in BlockManager to GetUTXOStats (Carl Dong)
2c3ba00 miner: Pass in blockman to ::RegenerateCommitments (Carl Dong)
2afcf24 miner: Remove old CreateNewBlock w/o chainstate param (Carl Dong)
46b7f29 scripted-diff: Invoke CreateNewBlock with chainstate (Carl Dong)
d0de61b miner: Pass in chainstate to BlockAssembler::CreateNewBlock (Carl Dong)
a04aac4 validation: Remove extraneous LoadGenesisBlock function prototype (Carl Dong)

Pull request description:

  Overall PR: #20158 (tree-wide: De-globalize ChainstateManager)

  Based on:
  - [x] #21055 | [Bundle 3/n] Prune g_chainman usage in mempool-related validation functions

  Note to reviewers:
  1. This bundle may _apparently_ introduce usage of `g_chainman` or `::Chain(state|)Active()` globals, but these are resolved later on in the overall PR. [Commits of overall PR](https://github.com/bitcoin/bitcoin/pull/20158/commits)
  2. There may be seemingly obvious local references to `ChainstateManager` or other validation objects which are not being used in callers of the current function in question, this is done intentionally to **_keep each commit centered around one function/method_** to ease review and to make the overall change systematic. We don't assume anything about our callers. Rest assured that once we are considering that particular caller in later commits, we will use the obvious local references. [Commits of overall PR](https://github.com/bitcoin/bitcoin/pull/20158/commits)
  3. When changing a function/method that has many callers (e.g. `LookupBlockIndex` with 55 callers), it is sometimes easier (and less error-prone) to use a scripted-diff. When doing so, there will be 3 commits in sequence so that every commit compiles like so:
  1. Add `new_function`, make `old_function` a wrapper of `new_function`, divert all calls to `old_function` to `new_function` **in the local module only**
  2. Scripted-diff to divert all calls to `old_function` to `new_function` **in the rest of the codebase**
  3. Remove `old_function`

ACKs for top commit:
  laanwj:
    Code review ACK a67983c
  ryanofsky:
    Code review ACK a67983c. Only change since last review new first commit fixing header declaration, and rebase
  glozow:
    code review ACK a67983c

Tree-SHA512: dce182a18b88be80cbf50978d4ba8fa6ab0f01e861d09bae0ae9364051bb78f9334859d164b185b07f1d70a583e739557fab6d820cac8c37b3855b85c2a6771b
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 17, 2022
Summary:
...also update comments to remove mention of ::ChainActive()

From: bitcoin/bitcoin#20750 (comment)

> Also, what about passing a const reference instead of a pointer? I
> know this is only theoretical, but previously if the tip was nullptr,
> then Height() evaluated to -1, now it evaluates to UB

Note: in Bitcoin ABC, there was already a check for `active_chain_tip == nullptr`, but only for `nMedianPastTime`. A few lines above we accessed the pointer to get the `nHeight` without checking first (potential UB introduced in D11191).

This is a backport of [[bitcoin/bitcoin#21055 | core#21055]] [1/16]
bitcoin/bitcoin@9da106b

Test Plan:
```
cmake -GNinja .. \
  -DCMAKE_BUILD_TYPE=Debug \
  -DENABLE_SANITIZERS=undefined

ninja check check-functional
```

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11205
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 17, 2022
Summary:
This is a backport of [[bitcoin/bitcoin#21055 | core#21055]] [2/16] and [[bitcoin/bitcoin#21270 | core#21270]] [1/12]
bitcoin/bitcoin@4927c9e
bitcoin/bitcoin@a04aac4

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11206
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 17, 2022
Summary:
Note: `FinalizeBlock` was already addressed in D6861

This is a backport of [[bitcoin/bitcoin#21055 | core#21055]] [3/16]
bitcoin/bitcoin@a3ba08b

Depends on D11206

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11207
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 17, 2022
Summary:
Note: I used this opportunity to reorder the function parameters and match the ones used by Core.

This is a backport of [[bitcoin/bitcoin#21055 | core#21055]] [4/16]
bitcoin/bitcoin@4bada76

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11209
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 17, 2022
Summary:
This is a backport of [[bitcoin/bitcoin#21055 | core#21055]] [5/16]
bitcoin/bitcoin@63e4c73

Depends on D11209

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11210
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 17, 2022
Summary:
Tip: versionbitscache is currently a global so we didn't need to pass it  in to any of ::VersionBitsTip*'s callers

Notes:
 - I had to restore `versionbitscache` in validation.h, removed in D2783.
 - `VersionBitsBlockState` was not used anywhere. It was introduced and used in D5282, then `minerfund.cpp` was deleted then added again but without using that function.

This is a backport of [[bitcoin/bitcoin#21055 | core#21055]] [6/16]
bitcoin/bitcoin@31eac50

Depends on D11210

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11211
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 18, 2022
Summary:
This is a backport of [[bitcoin/bitcoin#21055 | core#21055]] [7/16]
bitcoin/bitcoin@2bdf37f

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11212
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 18, 2022
Summary:
Notes:
 - `InvalidChainFound` was already moved to `CChainState` in D7573
 - `CheckForkWarningConditionsOnNewFork` was removed by core in [[bitcoin/bitcoin#19905 | core#19905]] because it doesn't work, but in Bitcoin ABC it was fixed in D1950.

This is a backport of [[bitcoin/bitcoin#21055 | core#21055]] [8/16]
bitcoin/bitcoin@8b99efb

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11213
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 18, 2022
Summary:
CChainState needed cuz setBlockIndexCandidates

This is a backport of [[bitcoin/bitcoin#21055 | core#21055]] [9/16]
bitcoin/bitcoin@8cdb2f7

Depends on D11213

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11214
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 18, 2022
Summary:
This is a backport of [[bitcoin/bitcoin#21055 | core#21055]] [10/16]
bitcoin/bitcoin@1fb7b2c

Depends on D11214

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11215
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 18, 2022
Summary:
This is the only instance where validation reaches for something outside of it.

This is a backport of [[bitcoin/bitcoin#21055 | core#21055]] [11/16]
bitcoin/bitcoin@4744efc

Depends on D11215

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11216
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 18, 2022
Summary:
This is a backport of [[bitcoin/bitcoin#21055 | core#21055]] [12/16]
bitcoin/bitcoin@a9d28bc

Depends on D11216

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11219
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 18, 2022
Summary:
This is a backport of [[bitcoin/bitcoin#21055 | core#21055]] [13/16]
bitcoin/bitcoin@fee7334

Depends on D11219

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11220
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 21, 2022
Summary:
instead of recursively locking unconditionally

This concludes backport of [[bitcoin/bitcoin#21055 | core#21055]] [16/16]
bitcoin/bitcoin@e11b649

Depends on D11221

Test Plan:
With debug and clang:

`ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11222
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Aug 12, 2022
9376a6d refactor: make active_chain_tip a reference (Aurèle Oulès)

Pull request description:

  This PR fixes a TODO introduced in bitcoin#21055.

  Makes `active_chain_tip` argument in `CheckFinalTxAtTip` function a reference instead of a pointer.

ACKs for top commit:
  dongcarl:
    ACK 9376a6d

Tree-SHA512: c36d1769e0b9598b7f79334704b26b73e958d54caa3bd7e4eff954f3964fcf3f5e3a44a5a760497afad51b76e1614c86314fe035e4083c855e3574a620de7f4d
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 12, 2022
9376a6d refactor: make active_chain_tip a reference (Aurèle Oulès)

Pull request description:

  This PR fixes a TODO introduced in bitcoin#21055.

  Makes `active_chain_tip` argument in `CheckFinalTxAtTip` function a reference instead of a pointer.

ACKs for top commit:
  dongcarl:
    ACK 9376a6d

Tree-SHA512: c36d1769e0b9598b7f79334704b26b73e958d54caa3bd7e4eff954f3964fcf3f5e3a44a5a760497afad51b76e1614c86314fe035e4083c855e3574a620de7f4d
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 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.

9 participants