Only load BlockMan in BlockMan member functions #24515

pull dongcarl wants to merge 7 commits into bitcoin:master from dongcarl:2022-03-kirby-p2.5 changing 10 files +155 −130
  1. dongcarl commented at 11:24 pm on March 9, 2022: member

    The only important commit is “Only load BlockMan in BlockMan member functions”, everything else is all just small style changes.

    Here’s the commit message, reproduced:

    0This commit effectively splits the "load block index itself" logic from
    1"derive Chainstate variables from loaded block index" logic.
    2
    3This means that BlockManager::LoadBlockIndex{,DB} will only load what's
    4relevant to the BlockManager.
    
  2. refactor: more const annotations for uses of CBlockIndex* 5be9ee3c54
  3. style-only: Various blockstorage.cpp cleanups 3bbb6fea05
  4. DrahtBot added the label Block storage on Mar 10, 2022
  5. DrahtBot added the label RPC/REST/ZMQ on Mar 10, 2022
  6. DrahtBot added the label UTXO Db and Indexes on Mar 10, 2022
  7. DrahtBot added the label Validation on Mar 10, 2022
  8. MarcoFalke removed the label UTXO Db and Indexes on Mar 10, 2022
  9. MarcoFalke removed the label RPC/REST/ZMQ on Mar 10, 2022
  10. MarcoFalke removed the label Validation on Mar 10, 2022
  11. MarcoFalke removed the label Block storage on Mar 10, 2022
  12. MarcoFalke added the label Refactoring on Mar 10, 2022
  13. MarcoFalke added the label Block storage on Mar 10, 2022
  14. in src/node/blockstorage.cpp:228 in 6741a6957a outdated
    226     for (auto& [_, block_index] : m_block_index) {
    227-        vSortedByHeight.push_back(std::make_pair(block_index.nHeight, &block_index));
    228+        vSortedByHeight.push_back(&block_index);
    229     }
    230-    sort(vSortedByHeight.begin(), vSortedByHeight.end());
    231+    sort(vSortedByHeight.begin(), vSortedByHeight.end(),
    


    MarcoFalke commented at 7:06 am on March 10, 2022:
    is this std::sort? If yes, maybe switch to that while touching

    dongcarl commented at 11:38 pm on March 15, 2022:
    Fixed in 28ba0313eac37e4a900b7e97af7169ce999c4024
  15. in src/node/blockstorage.cpp:236 in 6741a6957a outdated
    236     // Find start of assumed-valid region.
    237     int first_assumed_valid_height = std::numeric_limits<int>::max();
    238 
    239-    for (const auto& [height, block] : vSortedByHeight) {
    240-        if (block->IsAssumedValid()) {
    241+    for (CBlockIndex* pindex : vSortedByHeight) {
    


    MarcoFalke commented at 7:09 am on March 10, 2022:
    maybe add the const right here in this commit to avoid a separate commit for a single keyword? Also, could keep the symbol name block to reduce the diff by one line :sweat_smile:

    ryanofsky commented at 7:07 pm on March 14, 2022:

    In commit “style-only: No need for std::pair for vSortedByHeight” (6741a6957a240e9a0cdbd73df95f247b449e7b72)

    This is fine but I don’t really get it. Previous commit is renaming a pindex to block_index, this one is renaming a block variable to pindex. If these cleanups were consolidated into one commit, it’d be easier to see if the changes were consistent. (Also of the names I like simple block the best).


    dongcarl commented at 11:48 pm on March 15, 2022:
    Absorbed into 42e56d9b188f97c077ed2269e24acc0be35ece17
  16. in src/validation.cpp:4094 in f5a20039a4 outdated
    4090+        std::vector<CBlockIndex*> vSortedByHeight;
    4091+        vSortedByHeight.reserve(m_blockman.m_block_index.size());
    4092+        for (auto& [_, block_index] : m_blockman.m_block_index) {
    4093+            vSortedByHeight.push_back(&block_index);
    4094+        }
    4095+        sort(vSortedByHeight.begin(), vSortedByHeight.end(),
    


    MarcoFalke commented at 7:10 am on March 10, 2022:
    same

    dongcarl commented at 11:47 pm on March 15, 2022:
    Fixed in 28ba0313eac37e4a900b7e97af7169ce999c4024
  17. MarcoFalke approved
  18. MarcoFalke commented at 10:22 am on March 10, 2022: member
    LGTM
  19. ajtowns commented at 3:26 pm on March 10, 2022: member
    (Ditto what @MarcoFalke said)
  20. DrahtBot commented at 6:36 am on March 11, 2022: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #24582 (Move txoutproof RPCs to txoutproof.cpp by MarcoFalke)
    • #24456 (blockman: Properly guard blockfile members by dongcarl)
    • #24230 (indexes: Stop using node internal types and locking cs_main, improve sync logic by ryanofsky)
    • #22564 (refactor: Move mutable globals cleared in ::UnloadBlockIndex to BlockManager by dongcarl)
    • #21726 (Improve Indices on pruned nodes via prune blockers 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.

  21. ryanofsky commented at 5:05 pm on March 14, 2022: member
    The main thing this PR seems to be doing is moving chainstate->setBlockIndexCandidates filling code out of block-manager to chainstate-manager. This seems like it makes sense because you would expect block manager just to deal with low level blocks and not know anything about chain states or validation. Would be good to have @jamesob concept ACK since he added most of the code that’s moving
  22. in src/validation.cpp:4097 in f5a20039a4 outdated
    4093+            vSortedByHeight.push_back(&block_index);
    4094+        }
    4095+        sort(vSortedByHeight.begin(), vSortedByHeight.end(),
    4096+             [](const CBlockIndex* pa, const CBlockIndex* pb) {
    4097+                 return pa->nHeight < pb->nHeight;
    4098+             });
    


    ryanofsky commented at 6:34 pm on March 14, 2022:

    In commit “Only load BlockMan in BlockMan member functions” (f5a20039a4a140679981943fa2e645ded687d14e)

    IMO, it would be better to add a std::vector<CBlockIndex*> GetSortedByHeight(BlockManager&) or similar helper function instead of duplicating this code.


    dongcarl commented at 11:48 pm on March 15, 2022:
    See 28ba0313eac37e4a900b7e97af7169ce999c4024 and f865cf8ded2b2fbc82a6fbc41226d991909a6880
  23. ryanofsky approved
  24. ryanofsky commented at 7:10 pm on March 14, 2022: member
    Code review ACK af44e85b920055be4c3f724000a17f9d8d31d5ae. Ignore minor comments unless you feel like addressing them
  25. dongcarl force-pushed on Mar 15, 2022
  26. style-only: No need for std::pair for vSortedByHeight
    ...since the height information in already in CBlockIndex* and we can
    use an easy custom sorter.
    42e56d9b18
  27. Only load BlockMan in BlockMan member functions
    This commit effectively splits the "load block index itself" logic from
    "derive Chainstate variables from loaded block index" logic.
    
    This means that BlockManager::LoadBlockIndex{,DB} will only load what's
    relevant to the BlockManager.
    
    I strongly recommend reviewing with the following git-diff flags:
      --color-moved=dimmed_zebra --color-moved-ws=allow-indentation-change
    c600ee3816
  28. move-only: Move CBlockIndexWorkComparator to blockstorage
    ...it's declared in blockstorage.h
    12eb05df63
  29. Add and use CBlockIndexHeightOnlyComparator
    ...also use std::sort for clarity
    28ba0313ea
  30. Add and use BlockManager::GetAllBlockIndices f865cf8ded
  31. dongcarl force-pushed on Mar 15, 2022
  32. dongcarl commented at 11:49 pm on March 15, 2022: member

    Pushed af44e85b920055be4c3f724000a17f9d8d31d5ae to f865cf8ded2b2fbc82a6fbc41226d991909a6880

    • Addressed all outstanding minor comments
  33. MarcoFalke approved
  34. MarcoFalke commented at 10:07 am on March 16, 2022: member

    review ACK f865cf8ded2b2fbc82a6fbc41226d991909a6880 🗂

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3review ACK f865cf8ded2b2fbc82a6fbc41226d991909a6880 🗂
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUg0DAv/VZj7G6Rp0qriCmTSDHrk21I938vrPa39hBPwQ9GU3DpaKPoIth5mj2Vl
     8jMREh59ZzqKKorCPa0RdcVaRyiVPTRup0EOSi0b9qwIQREr1pumfJb1Mir9HJtCY
     9WbLA/sj1YGuXpIUvWAEUkKE56vpLVahWnSx5jd9QFO0DBWbfQ3iHWj/Soc5EBxEV
    105pquK8ceeWyZxN7NKHWwKZegfjMmuPvmrr1HVfFB9qwjzYIsJk7Hv83PXbTHNzMa
    11OBBxlGy6o/anN1w+iS6tflGCzmTgxXXWKROlm2pCDAgOJZi4FyM2vj/V/9XM4E4F
    12RghIzqLltFmVJwvRV7x/o0Ahf3QHsez5TIl8JvFxVjBAwPP6WW2cbUQnXJRGrpho
    13oIUVnBf/r5iZCImOGzCkslm5oBDmWHCGi2jscPcdIQAcQNrusIN2jy4OrWxVAYFw
    14fjORBHiWF1TnQElKrfBurviwt+LO8SZFcjtTm7ZN4BGFFknCGgUBD9hqP9GB6mzt
    15Tu78aGDd
    16=BBgB
    17-----END PGP SIGNATURE-----
    
  35. ajtowns commented at 8:54 pm on March 16, 2022: member
    ACK f865cf8ded2b2fbc82a6fbc41226d991909a6880 ; code review only
  36. MarcoFalke merged this on Mar 17, 2022
  37. MarcoFalke closed this on Mar 17, 2022

  38. sidhujag referenced this in commit 003384d78e on Mar 18, 2022
  39. Fabcien referenced this in commit 5c7e567e1d on Jan 23, 2023
  40. Fabcien referenced this in commit cecbcba200 on Jan 23, 2023
  41. Fabcien referenced this in commit 3d50222404 on Jan 23, 2023
  42. Fabcien referenced this in commit 2aa2529f4a on Jan 23, 2023
  43. Fabcien referenced this in commit e225f7080c on Jan 23, 2023
  44. DrahtBot locked this on Mar 17, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-22 00:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me