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 2/n] Prune g_chainman usage in mempool-related validation functions #20750

Conversation

dongcarl
Copy link
Contributor

@dongcarl dongcarl commented Dec 22, 2020

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

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 22, 2020

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.

@DrahtBot
Copy link
Contributor

🕵️ @sipa @fjahr have been requested to review this pull request as specified in the REVIEWERS file.

@jnewbery
Copy link
Contributor

jnewbery commented Feb 1, 2021

#20749 is merged. Rebase please 🙂

@dongcarl dongcarl force-pushed the 2020-09-reduce-validation-mempool-ccsactiveglobal-usage branch from 5803d30 to 8d435f2 Compare February 1, 2021 16:55
@dongcarl
Copy link
Contributor Author

dongcarl commented Feb 1, 2021

Pushed 5803d30 -> 8d435f2

Copy link
Member

@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.

Approach ACK, did a first parse on each commit.

Side-question, what's your heuristic to divide your bundles ?

src/validation.cpp Outdated Show resolved Hide resolved
src/test/validation_block_tests.cpp Outdated Show resolved Hide resolved
src/txmempool.cpp Outdated Show resolved Hide resolved
@dongcarl dongcarl force-pushed the 2020-09-reduce-validation-mempool-ccsactiveglobal-usage branch from 15f0042 to e8ae1db Compare February 18, 2021 19:55
@dongcarl
Copy link
Contributor Author

Pushed 15f0042 -> e8ae1db

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

ACK e8ae1db 📣

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

ACK e8ae1db864b09a47c736631e6cd3f5ec17929850 📣
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgMzwwAsEQvRsGjLFTPiwkdMs4DZSXcqw2e+bK/3idvLQRv6sJ7vqrS5W3UIqH4
POgM2H1pz6rbusNlvyXaeNIG/C+RGniPVKf0pBwPrK+Wo/PRpTMMTPyl9cUh3hfB
Xb4HhOCux29lfYNQNFUVq7+O9k2hj9634Q5QCNZkE988rIiGZt6hYc38RIMcSeY7
LU6Pbbc7P7eembZfocL2nVonunPvZij0mLmILc3JWX/jt4C3IqJ6uiQP56ALb08d
gUMuyuQibGz6ptK9S5XeLr2/YyTYt7Z5UNCGZtJyxshFA5MdAxcDhMKQZhs2dW1K
w2jtnuWVWFfHgaU1OvsTjaKmLP8UsCwD4QxJzIgaUgFX//5eWBTN60nyvLVp5Ara
0KndogF/nMxu1KXgVcD7R+LuJiSOJivBX8So9l9wtWwTZdBhb8gybTani25Ef2I4
oB0BSi0GsJlhyvSKBjkvxpzlnf1ofDJ9b6Mid9Z/PgUI50rIO2JixDU5WgXoBvRd
ikxxBzeX
=XgwZ
-----END PGP SIGNATURE-----

Timestamp of file with hash 4c3078abec10b46f834a4805961a34857896683a0701dfcccf98cc987f6a924e -

return CheckFinalTx(::ChainActive().Tip(), tx, flags);
}

bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags)
Copy link
Member

Choose a reason for hiding this comment

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

nit in d015eaa: For new code it would be good to use the new style (& is left-attaching). 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. Also, in the comment in this function, you'll need to replace ::ChainActive().Height()+1 as well? Finally, the next two commits could just be squashed into this one?

Copy link
Contributor Author

@dongcarl dongcarl Feb 19, 2021

Choose a reason for hiding this comment

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

Right, this makes sense. I'm going to put this nit off until the next bundle so that I don't invalidate ACKs if that's alright with you! I added it as a "Note to self" in the next bundle.

@@ -356,7 +356,7 @@ void CTxMemPool::AddTransactionsUpdated(unsigned int n)
void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate)
{
// Add to memory pool without checking anything.
// Used by AcceptToMemoryPool(), which DOES do
// Used by AcceptToMemoryPool(::ChainstateActive(), ), which DOES do
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe exclude this file from the scripted diff? Also nit: git comes with an exclude syntax for files, so you don't have to use grep -v

Copy link
Contributor Author

@dongcarl dongcarl Feb 19, 2021

Choose a reason for hiding this comment

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

Yeah the git syntax was confusing so I wanted to just use grep since it's more commonly used 😬. I will make this change if there are other substantial changes that requires a push!

@glozow
Copy link
Member

glozow commented Feb 19, 2021

reACK e8ae1db via git range-diff 15f0042...e8ae1db, only change is fixing ATMP call from conflict

@maflcko maflcko merged commit 828bb77 into bitcoin:master Feb 20, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 20, 2021
dongcarl added a commit to dongcarl/bitcoin that referenced this pull request Feb 22, 2021
...also update comments to remove mention of ::ChainActive()

From: 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
laanwj added a commit that referenced this pull request Mar 4, 2021
…tion functions

e11b649 validation: CVerifyDB::VerifyDB: Use locking annotation (Carl Dong)
03f75c4 validation: Use existing chain member in CChainState::LoadGenesisBlock (Carl Dong)
5e4af77 validation: Use existing chain member in CChainState::AcceptBlock (Carl Dong)
fee7334 validation: Pass in chain to FindBlockPos+SaveBlockToDisk (Carl Dong)
a9d28bc validation: Use *this in CChainState::ActivateBestChainStep (Carl Dong)
4744efc validation: Pass in chainstate to CTxMemPool::check (Carl Dong)
1fb7b2c validation: Use *this in CChainState::InvalidateBlock (Carl Dong)
8cdb2f7 validation: Move LoadBlockIndexDB to CChainState (Carl Dong)
8b99efb validation: Move invalid block handling to CChainState (Carl Dong)
2bdf37f validation: Pass in chainstate to CVerifyDB::VerifyDB (Carl Dong)
31eac50 validation: Remove global ::VersionBitsTip{State,SinceHeight,Statistics} (Carl Dong)
63e4c73 validation: Pass in chainstate to ::PruneBlockFilesManual (Carl Dong)
4bada76 validation: Pass in chainstate to UpdateTip (Carl Dong)
a3ba08b validation: Remove global ::{{Precious,Invalidate}Block,ResetBlockFailureFlags} (Carl Dong)
4927c9e validation: Remove global ::LoadGenesisBlock (Carl Dong)
9da106b validation: Check chain tip is non-null in CheckFinalTx (Carl Dong)

Pull request description:

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

  Based on:
  - [x] #20750 | [Bundle 2/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`

  Note to self:
  - [x] Address: #20750 (comment)

ACKs for top commit:
  laanwj:
    Code review ACK e11b649

Tree-SHA512: 205a451a741e32f17d5966de289f2f5a3f0817738c0087b70ff4755ddd217b53d01050ed396669bda2b1d216a88d927b9778777f9ff95ab1fe20e59c5f341776
theStack pushed a commit to theStack/bitcoin that referenced this pull request Mar 5, 2021
...also update comments to remove mention of ::ChainActive()

From: 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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 16, 2022
Summary:
PR title: Prune g_chainman usage in mempool-related validation functions (tree-wide: De-globalize ChainstateManager)

This is a backport of [[bitcoin/bitcoin#20750 | core#20750]] [1/19]
bitcoin/bitcoin@d1f932b

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11189
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 16, 2022
Summary:
This is a backport of [[bitcoin/bitcoin#20750 | core#20750]] [2/19]
bitcoin/bitcoin@252b489#i
Depends on D11189

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11190
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 16, 2022
…ntBlock

Summary:
This is a backport of [[bitcoin/bitcoin#20750 | core#20750]] [3, 4 & 5/19]
bitcoin/bitcoin@d015eaa

bitcoin/bitcoin@7031cf8

bitcoin/bitcoin@577b774

Depends on D11190

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11191
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#20750 | core#20750]] [6/17]
bitcoin/bitcoin@4c15942

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11192
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#20750 | core#20750]] [7/17]
bitcoin/bitcoin@d8a8163

Depends on D11192

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11193
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#20750 | core#20750]] [8/17]
bitcoin/bitcoin@3a205c4

Depends on D11193

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11194
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#20750 | core#20750]] [9/17]
bitcoin/bitcoin@d0da7ea

Depends on D11194

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11195
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#20750 | core#20750]] [10, 11, 12 & 13/17]
bitcoin/bitcoin@229bc37

bitcoin/bitcoin@3704433

bitcoin/bitcoin@417dafc

bitcoin/bitcoin@120aaba

Depends on D11195

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11196
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#20750 | core#20750]] [14/17]
bitcoin/bitcoin@71734c6

Depends on D11196

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11201
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 17, 2022
Summary:
Several other parameters are now redundant since they can be safely
obtained from the chainstate given that ::cs_main is locked. These are
now removed.

This is a backport of [[bitcoin/bitcoin#20750 | core#20750]] [15/17]
bitcoin/bitcoin@7142018

Depends on D11201

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11202
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#20750 | core#20750]] [16/17]
bitcoin/bitcoin@0a9a24d

Depends on D11202

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11203
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 17, 2022
Summary:
This concludes backport of [[bitcoin/bitcoin#20750 | core#20750]] [17/17]
bitcoin/bitcoin@8c82481

Depends on D11203

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11204
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
@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.

None yet

8 participants