refactor: Remove need to pass chainparams to BlockManager methods #27570

pull maflcko wants to merge 3 commits into bitcoin:master from maflcko:2305-blockman-chain-params- changing 9 files +53 −31
  1. maflcko commented at 10:40 am on May 4, 2023: member

    Seems confusing to pass chainparams to each method individually, when the params can’t change anyway for the whole lifetime of the block manager, and also must be equal to the ones used by the chainstate manager.

    Fix this issue by removing them from the methods and instead storing a reference once in a member field.

  2. DrahtBot commented at 10:40 am on May 4, 2023: contributor

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK dergoegge, TheCharlatan

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #27576 (kernel: Remove args, chainparams, chainparamsbase from kernel library by TheCharlatan)
    • #27491 (refactor: Move chain constants to the util library by TheCharlatan)
    • #27125 (refactor, kernel: Decouple ArgsManager from blockstorage by TheCharlatan)
    • #27006 (reduce cs_main scope, guard block index ’nFile’ under a local mutex by furszy)
    • #15606 (assumeutxo by jamesob)

    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.

  3. DrahtBot added the label Refactoring on May 4, 2023
  4. maflcko renamed this:
    refactor: Remove need to pass chainparams from BlockManager methods
    refactor: Remove need to pass chainparams to BlockManager methods
    on May 4, 2023
  5. DrahtBot added the label CI failed on May 4, 2023
  6. dergoegge commented at 12:54 pm on May 4, 2023: member

    Concept ACK

    Should we do the same for Consensus::Params?

  7. maflcko commented at 1:53 pm on May 4, 2023: member

    Should we do the same for Consensus::Params?

    Yes, this is what this pull is doing.

  8. DrahtBot removed the label CI failed on May 4, 2023
  9. in src/node/blockstorage.h:152 in fa1e7fb6ba outdated
    147@@ -147,6 +148,9 @@ class BlockManager
    148         : m_prune_mode{opts.prune_target > 0},
    149           m_opts{std::move(opts)} {};
    150 
    151+    const CChainParams& GetParams() const { return m_opts.chainparams; }
    152+    const Consensus::Params& GetConsensus() const { return m_opts.chainparams.GetConsensus(); }
    


    dergoegge commented at 2:49 pm on May 4, 2023:
    Could these be private?

    maflcko commented at 3:00 pm on May 4, 2023:

    Yes, but why?

    • They are also public in chainman (consistency)
    • They return a read-only const reference, so there should be no risk
    • Making them public now avoids code churn in the future when they need to be made public

    dergoegge commented at 3:22 pm on May 4, 2023:

    I feel like in the long run, only having one way of getting the params would be the consistent thing to do. Storing a public reference to the params on various components seems weird given that the params are already a global (might as well use the global directly then?).

    Also, why should these getters be part of the public interface for the block storage? Doesn’t seem right to me.


    maflcko commented at 5:31 pm on May 4, 2023:
    I guess I disagree, but made private for now to close the discussion for now
  10. dergoegge commented at 2:52 pm on May 4, 2023: member

    Yes, this is what this pull is doing.

    Sorry, I was confused because Consensus::Params are stil being passed to ReadBlockFromDisk.

  11. Sosyetekadir commented at 4:59 pm on May 4, 2023: none
    Sosyete
  12. Sosyetekadir approved
  13. bitcoin deleted a comment on May 4, 2023
  14. Add BlockManagerOpts::chainparams reference
    and use it in blockstorage.cpp
    facdb8b331
  15. Replace pindex pointer with block reference
    pindex can not be nullptr, so document that, and clear it up in the next
    commit.
    fa3f74a40e
  16. Remove unused chainparams from BlockManager methods
    Also, replace pointer with reference while touching the signature.
    fa5d7c39eb
  17. maflcko force-pushed on May 4, 2023
  18. maflcko commented at 5:53 pm on May 4, 2023: member
    They are not members of the class BlockManager, so fixing them is non-trivial and should happen in a follow-up.
  19. dergoegge commented at 5:55 pm on May 4, 2023: member

    They are not members of the class BlockManager, so fixing them is non-trivial and should happen in a follow-up.

    Ugh for some reason I thought #27125 was already merged🤦

  20. dergoegge approved
  21. dergoegge commented at 10:29 am on May 5, 2023: member
    Code review ACK fa5d7c39eb992467e43b12db213b27913374fb83
  22. fanquake requested review from TheCharlatan on May 5, 2023
  23. in src/test/blockmanager_tests.cpp:24 in fa5d7c39eb
    20@@ -21,23 +21,26 @@ BOOST_FIXTURE_TEST_SUITE(blockmanager_tests, BasicTestingSetup)
    21 BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos)
    22 {
    23     const auto params {CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN)};
    24-    BlockManager blockman{{}};
    25+    node::BlockManager::Options blockman_opts{
    


    TheCharlatan commented at 11:20 am on May 5, 2023:
    Nit: Can be const (here and elsewhere) and skip the node:: namespacing, since it is imported above. If this is merged before #27125 I will follow-up there.

    maflcko commented at 11:40 am on May 5, 2023:

    I left it mutable to make it less code-churn to run ApplyArgsManOptions in the future, which you called in 27125 at some point, but no longer in the current state.

    I’ll remove node:: in the next push or maybe a follow-up.

  24. TheCharlatan approved
  25. TheCharlatan commented at 11:23 am on May 5, 2023: contributor

    ACK fa5d7c39eb992467e43b12db213b27913374fb83

    Thank you for following up so quickly!

  26. fanquake commented at 4:14 pm on May 5, 2023: member
    cc @jamesob, this is going to conflict with #15606.
  27. jamesob commented at 4:22 pm on May 5, 2023: contributor

    Is this some kind of dependency for libbitcoinkernel or for something other than general tidy-up impulses? If so, feel free to merge - assumeutxo is fresh in my brain and handling the rebase won’t be so painful as a result.

    Otherwise, wouldn’t mind this getting shelved for later. But really no big deal either way. I’d say if you’re going to merge do it soon so that I can manage the rebase with fresh context.

  28. fanquake commented at 4:32 pm on May 5, 2023: member

    Is this some kind of dependency for libbitcoinkernel or for something other than general tidy-up impulses?

    It spawned out of here: #27125 (review). If you’re happy to rebase over then I’m just going to go-ahead and merge this now. @TheCharlatan can then address any of his own comments as part of #27125 (which is also going to conflict with 15606, so probably worth having a look there as well.)

  29. fanquake merged this on May 5, 2023
  30. fanquake closed this on May 5, 2023

  31. sidhujag referenced this in commit ededab96c2 on May 5, 2023
  32. maflcko deleted the branch on May 6, 2023
  33. Fabcien referenced this in commit d893f446d0 on Apr 19, 2024
  34. Fabcien referenced this in commit 5cfdcd1e6f on Apr 19, 2024
  35. bitcoin locked this on Oct 24, 2024

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-11-21 18:12 UTC

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