Skip to content

Conversation

dongcarl
Copy link
Contributor

@dongcarl dongcarl commented Apr 18, 2022

Split off from #22564 per Marco's suggestion: #22564 (comment)

This is basically the move-mostly parts of #22564. The overall intent is to move mutable globals manually reset by ::UnloadBlockIndex into appropriate structs such that they are cleared at the appropriate times. Please read #22564's description for more rationale.

In summary , this PR moves:

  1. pindexBestHeader -> ChainstateManager::m_best_header
  2. fHavePruned -> BlockManager::m_have_pruned

Now BlockManager::LoadBlockIndex() will ACTUALLY only load BlockMan
members.

[META] In a later commit, pindexBestHeader will be moved to ChainMan as
       a member

-----

Code Reviewer Notes

Call graph of relevant functions:

ChainstateManager::LoadBlockIndex() <-- Moved to
    calls BlockManager::LoadBlockIndexDB()
        which calls BlockManager::LoadBlockIndex() <-- Moved from

There is only one call to each of inner functions, meaning that no
behavior is changing.
@ajtowns
Copy link
Contributor

ajtowns commented Apr 18, 2022

"most-mostly" -> "move-mostly" ?

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

  • #24571 (p2p: Prevent block index fingerprinting by sending additional getheaders messages by dergoegge)
  • #24543 (net processing: Move remaining globals into PeerManagerImpl by dergoegge)
  • #24171 (p2p: Sync chain more readily from inbound peers during IBD by sdaftuar)
  • #23599 (Tidy up RPCTxSerializationFlags by MarcoFalke)
  • #21726 (Improve Indices on pruned nodes via prune blockers by fjahr)
  • #20030 (validation: Remove useless call to mempool->clear() by MarcoFalke)
  • #19888 (rpc, test: Improve getblockstats for unspendables by fjahr)

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

@ajtowns ajtowns left a comment

Choose a reason for hiding this comment

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

ACK 7b434e7 ; code review only

  • 5d67017 validation: Load pindexBestHeader in ChainMan
    • Could make BlockManager::LoadBlockIndex private
    • validation.h: LoadBlockIndex does not need to be a friend of ChainstateManager ?
  • c51e611 move-mostly: Make pindexBestHeader a ChainMan member
  • d66a2c0 style-only: Miscellaneous whitespace changes
  • 8cc5f5c Clear pindexBestHeader in ChainstateManager::Unload()
  • c32b9d8 move-mostly: Make fHavePruned a BlockMan member
    • Seems like fHavePruned should someday be private to blockman and the pruning logic should move from CChainState::FlushStateToDisk to blockman
  • 4032fc9 Clear fHavePruned in BlockManager::Unload()
  • 7b434e7 scripted-diff: Rename pindexBestHeader, fHavePruned

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.

review ACK 7b434e7 🌜

Show signature

Signature:

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

review ACK 7b434e7d6bc5ea92b14694375ac4d429e644e61d 🌜
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUhK5AwAnnxOI4tcYCP4IleWGvPN536u+3aq40UauEOEzMSOcfqOzRjfZqpBAqwC
GBvAzOjwaTAkG6S6H77mLAPxDGZZB2GdUWFT1RqMd1GRJmhyeer9wtqQ/NATvETg
qKUoJiCn5o1xZEOkTMgkAJyUJ8vkVF2UxjL/AbeAu3l79/Qzh527vUQ+s7xsR0Pe
fSfJQlrxqaB1p3yrwdsZwEYN2g+nzDIz3xEKG7P2sGoY9Vboh8FqggJW1+LOJfYE
/STQmMjcWGLFzQzUa5lUD64WT5dHruXrLgoJQ+jlOFfNd89he07ybmN8mP91Iu2I
ZNucJcKDoDQVJHIz/vSNWltIeTNfc/Xxj54gCW6N6IUSyRr4uzs9aVkToacWO5kP
e+1hT8EK5gn0an0NWxQmS2PBmsgrAZ/AeenrDuaMkYl5DjBe70v7rX6IG7/kbHu3
d3/pqVWzugeA+LH6XUyt1a0TdH1JEX6IgQo6N06a1i2WzVOpG/Ol4TY4jonziIHy
5/TITCQv
=Uk9X
-----END PGP SIGNATURE-----

@maflcko
Copy link
Member

maflcko commented Apr 19, 2022

In reply to #24909 (review) private and friend:

Seems unrelated to the commits here, see #24917

[META] In the next commit, we move the clearing of pindexBestHeader to
       ChainstateManager::Unload()
...of touched lines and surrounding
-----

Code Reviewer Notes

Call graph of relevant functions:

UnloadBlockIndex() <-- Moved from
    calls ChainstateManager::Unload() <-- Moved to

Safe because ChainstateManager::Unload() is called only by
UnloadBlockIndex() and no other callers.
[META] In the next commit, we move the clearing of fHavePruned to
       BlockManager::Unload()
-----

Code Reviewer Notes

Call graph of relevant functions:

UnloadBlockIndex() <-- Moved from
    calls ChainstateManager::Unload()
        which calls BlockManager::Unload() <-- Moved to

So calling UnloadBlockIndex() would still run this moved code. The code
will also now run when ~BlockManager gets called, which makes sense.
...to m_best_header and m_have_pruned

-BEGIN VERIFY SCRIPT-
find_regex="\bpindexBestHeader\b" \
    && git grep -l -E "$find_regex" -- src \
        | xargs sed -i -E "s@$find_regex@m_best_header@g"
find_regex="\bfHavePruned\b" \
    && git grep -l -E "$find_regex" -- src \
        | xargs sed -i -E "s@$find_regex@m_have_pruned@g"
-END VERIFY SCRIPT-
@dongcarl dongcarl force-pushed the 2022-04-kirby-p3-pre branch from 7b434e7 to f0a2fb3 Compare April 19, 2022 18:39
@dongcarl
Copy link
Contributor Author

Pushed 7b434e7 -> f0a2fb3

  • Addressed all if {} comments

@dongcarl
Copy link
Contributor Author

@ajtowns

Seems like fHavePruned should someday be private to blockman and the pruning logic should move from CChainState::FlushStateToDisk to blockman

Looks reasonable at first glance, perhaps you wanna open an issue for that?

@ajtowns
Copy link
Contributor

ajtowns commented Apr 20, 2022

ACK f0a2fb3 -- code review only

@maflcko
Copy link
Member

maflcko commented Apr 20, 2022

kirby ACK f0a2fb3 😋

Show signature

Signature:

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

kirby ACK f0a2fb3c5dbf3c4bec7faf934baff3e723734b3f 😋
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjhaAwAmXnXA0Who3Rfgotbw/O9rKr6Yf2XxjGSxmW8JYWxbC0HsT72v/PjMOnQ
ofXjbI3dkZjTL4fE4jsyenMpSLTMbghvirhnSgVYpTY/pUKHeF4s/5ZXp7rpItaf
3ZcMmluRI7e2xzcuSIRRrGkvcpNQEjfoqfPrIyTnpABYbOyeV7pzWq7+QbM5OBgg
xyiBXPsDf+T1jHjRAsbAbH5/eQdA1B+VdqCjcEn/A27kfmHlSJKx7CNzP4vwTODK
YYi2hu3cGLdjLGZlfYu2dX4YQbpXxImGJ94+tQhZIZZN9f+8nMFd+L0Qeeka5voQ
ZImElHgcs38dVQ+pJSgjZtN3it2KIl1OA/kU1xMxyHQWG+qhzKvawmrd8QCRxGYj
3a2GQAOK+2MJa3q6Jq31+Dd46zXm23tgvQdzY2zeySPJz+4IS+Yibu8yWWJjSo/Z
RB66PlDNW8Exyx57mPsVEbO2gJvZi7kI52lgncDnNi0aQ+s/Q3MIUar9OCTcNmv6
LdqFVdTh
=MEJR
-----END PGP SIGNATURE-----

@maflcko maflcko merged commit dbdc83a into bitcoin:master Apr 20, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 22, 2022
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 24, 2023
Summary:
Now BlockManager::LoadBlockIndex() will ACTUALLY only load BlockMan
members.

[META] In a later commit, pindexBestHeader will be moved to ChainMan as  a member

-----

Code Reviewer Notes

Call graph of relevant functions:

`ChainstateManager::LoadBlockIndex()`<-- Moved to
 calls `BlockManager::LoadBlockIndexDB()`
 which calls `BlockManager::LoadBlockIndex()` <-- Moved from

There is only one call to each of inner functions, meaning that no
behavior is changing.

This is a partial backport of [[bitcoin/bitcoin#24909 | core#24909]]
bitcoin/bitcoin@5d67017

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13043
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 24, 2023
Summary:
[META] In the next commit, we move the clearing of pindexBestHeader to ChainstateManager::Unload()

This is a partial backport of [[bitcoin/bitcoin#24909 | core#24909]]
bitcoin/bitcoin@0d567da

Depends on D13043

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13044
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 24, 2023
Summary:
-----

Code Reviewer Notes

Call graph of relevant functions:

`UnloadBlockIndex()` <-- Moved from
calls `ChainstateManager::Unload()` <-- Moved to

Safe because `ChainstateManager::Unload()` is called only by
`UnloadBlockIndex()` and no other callers.

This is a partial backport of [[bitcoin/bitcoin#24909 | core#24909]]
bitcoin/bitcoin@c965241

Depends on D13044

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13045
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 24, 2023
Summary:
[META] In the next commit, we move the clearing of fHavePruned to  BlockManager::Unload()

This is a partial backport of [[bitcoin/bitcoin#24909 | core#24909]]
bitcoin/bitcoin@3308ecd

Depends on D13045

Test Plan: `ninja all check-all bench-bitcoin`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13046
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 24, 2023
Summary:
-----

Code Reviewer Notes

Call graph of relevant functions:

`UnloadBlockIndex()` <-- Moved from
calls `ChainstateManager::Unload()`
which calls `BlockManager::Unload()` <-- Moved to

So calling UnloadBlockIndex() would still run this moved code. The code
will also now run when ~BlockManager gets called, which makes sense.

This is a partial backport of [[bitcoin/bitcoin#24909 | core#24909]]
bitcoin/bitcoin@a401402

Depends on D13046

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13047
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 24, 2023
…and m_have_pruned

Summary:
```
-BEGIN VERIFY SCRIPT-
find_regex="\bpindexBestHeader\b" \
    && git grep -l -E "$find_regex" -- src \
        | xargs sed -i -E "s@$find_regex@m_best_header@g"
find_regex="\bfHavePruned\b" \
    && git grep -l -E "$find_regex" -- src \
        | xargs sed -i -E "s@$find_regex@m_have_pruned@g"
-END VERIFY SCRIPT-
```

This concludes backport of [[bitcoin/bitcoin#24909 | core#24909]]
bitcoin/bitcoin@f0a2fb3

Depends on D13047

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13048
@bitcoin bitcoin locked and limited conversation to collaborators Apr 20, 2023
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.

5 participants