refactor: Fix the chainparamsbase -> util circular dependency #14045

pull Empact wants to merge 2 commits into bitcoin:master from Empact:chain-params-base-circ changing 6 files +100 −89
  1. Empact commented at 8:40 AM on August 24, 2018: member

    By making BaseParams() responsible for holding the current chain name, and layering ArgsManager atop it.

    Without this both m_network of ArgsManager and globalChainBaseParams track the current chain, leading to circular dependencies between them.

  2. Empact cross-referenced this on Aug 24, 2018 from issue [refactor] Fix the chainparamsbase -> util circular dependency by Empact
  3. DrahtBot commented at 8:42 AM on August 24, 2018: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #16508 (Disallow double negation syntax (-nofoo=0) for options by hebasto)
    • #16411 (Signet support by kallewoof)
    • #16097 (Refactor: Add Flags enum to ArgsManager class by hebasto)
    • #16060 (Bury bip9 deployments by jnewbery)
    • #15934 (Separate settings merging from parsing by ryanofsky)
    • #8994 (Testchains: Introduce custom chain whose constructor... by jtimon)

    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.

  4. Empact force-pushed on Aug 24, 2018
  5. Empact renamed this:
    Break the chainparamsbase -> util circular dependency
    refactor: Fix the chainparamsbase -> util circular dependency
    on Aug 24, 2018
  6. DrahtBot cross-referenced this on Aug 24, 2018 from issue refactor: Removal of circular dependency between index/txindex, validation and index/base by mgrychow
  7. practicalswift commented at 9:16 AM on August 24, 2018: contributor

    Concept ACK

    Let’s get rid of all circular dependencies! :-)

  8. DrahtBot cross-referenced this on Aug 24, 2018 from issue util: Add [[nodiscard]] to all {Decode,Parse}[...](...) functions returning bool by practicalswift
  9. in src/chainparamsbase.cpp:39 in d1e653c2e0 outdated
      37 |          throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
      38 |  }
      39 |  
      40 | +bool BaseParamsSelected()
      41 | +{
      42 | +    return globalChainBaseParams.get() != nullptr;
    


    domob1812 commented at 2:45 PM on August 24, 2018:

    Small nit: Smart pointers (std::unique_ptr in this case) allow direct comparison against nullptr. So there's no need to call get.


    Empact commented at 8:30 PM on August 24, 2018:

    Fixed πŸ‘

  10. in src/chainparamsbase.h:48 in d1e653c2e0 outdated
      42 | @@ -40,9 +43,9 @@ class CBaseChainParams
      43 |  std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain);
      44 |  
      45 |  /**
      46 | - *Set the arguments for chainparams
      47 | + * @return true if BaseParams have been selected, false if not
      48 |   */
      49 | -void SetupChainParamsBaseOptions();
      50 | +bool BaseParamsSelected();
    


    domob1812 commented at 2:46 PM on August 24, 2018:

    Nit: This can be const, I assume.


    Empact commented at 8:30 PM on August 24, 2018:

    Assume you mean const member, but it's not a member function, so no object to be const on.


    domob1812 commented at 9:59 AM on August 25, 2018:

    Oh yes indeed - I somehow thought this was a member.

  11. domob1812 approved
  12. domob1812 commented at 2:47 PM on August 24, 2018: contributor

    utACK d1e653c2e028c3342cdae4be81e423f96db89214 with a few style nits.

  13. Empact force-pushed on Aug 24, 2018
  14. Empact force-pushed on Aug 24, 2018
  15. Empact force-pushed on Aug 24, 2018
  16. Empact force-pushed on Aug 24, 2018
  17. Empact commented at 11:55 PM on August 24, 2018: member

    Fixed tests. ~Note I had to guard ArgsManagerHelper::NetworkArg calls with a test for a leading - as NetworkArg asserts against the absence, while values without - are tested for in util_tests. Could drop those tests instead, but this seems coherent.~

  18. Empact force-pushed on Aug 25, 2018
  19. Empact force-pushed on Aug 25, 2018
  20. Empact commented at 12:58 AM on August 25, 2018: member

    On second thought, removed the --less test and asserted against --less options in the relevant calls. Note that --less options are skipped over in ParseParameters.

  21. Empact force-pushed on Aug 26, 2018
  22. DrahtBot added the label Needs rebase on Aug 30, 2018
  23. Empact force-pushed on Sep 1, 2018
  24. DrahtBot removed the label Needs rebase on Sep 1, 2018
  25. DrahtBot cross-referenced this on Sep 1, 2018 from issue Minor style enhancement in documentation by fedsten
  26. Empact force-pushed on Sep 1, 2018
  27. Empact force-pushed on Sep 2, 2018
  28. DrahtBot cross-referenced this on Sep 6, 2018 from issue fix various uses of inline by arvidn
  29. DrahtBot cross-referenced this on Sep 10, 2018 from issue Don't edit Chainparams after initialization by jtimon
  30. DrahtBot cross-referenced this on Sep 24, 2018 from issue Use non-throwing type-safe ChainType where possible by MarcoFalke
  31. DrahtBot added the label Needs rebase on Sep 24, 2018
  32. Empact force-pushed on Sep 25, 2018
  33. DrahtBot removed the label Needs rebase on Sep 25, 2018
  34. Empact force-pushed on Sep 25, 2018
  35. Empact force-pushed on Sep 25, 2018
  36. DrahtBot cross-referenced this on Oct 20, 2018 from issue Testchains: Introduce custom chain whose constructor... by jtimon
  37. in src/util.cpp:976 in a590d6d932 outdated
     972 | @@ -978,6 +973,14 @@ std::string ArgsManager::GetChainName() const
     973 |      return CBaseChainParams::MAIN;
     974 |  }
     975 |  
     976 | +void SetupChainParamsBaseOptions()
    


    jtimon commented at 4:26 PM on October 22, 2018:

    Bike-shed: renamed to SetupChainParamsOptions, these are all chainparams options there are.


    Empact commented at 11:13 AM on December 14, 2018:

    Done πŸ‘

  38. jtimon approved
  39. jtimon commented at 4:34 PM on October 22, 2018: contributor

    Didn't look much at the tests, but the code looks good to me, utACK a590d6d932c3645b138f0c1726cfa78ecd0b434d

  40. DrahtBot cross-referenced this on Oct 23, 2018 from issue Move util files to directory by jimpo
  41. DrahtBot added the label Needs rebase on Nov 5, 2018
  42. Empact force-pushed on Nov 6, 2018
  43. DrahtBot removed the label Needs rebase on Nov 6, 2018
  44. Empact renamed this:
    refactor: Fix the chainparamsbase -> util circular dependency
    WIP: refactor: Fix the chainparamsbase -> util circular dependency
    on Nov 12, 2018
  45. DrahtBot added the label Needs rebase on Nov 15, 2018
  46. Empact force-pushed on Dec 13, 2018
  47. DrahtBot removed the label Needs rebase on Dec 13, 2018
  48. Empact force-pushed on Dec 14, 2018
  49. Empact renamed this:
    WIP: refactor: Fix the chainparamsbase -> util circular dependency
    refactor: Fix the chainparamsbase -> util circular dependency
    on Dec 14, 2018
  50. Empact force-pushed on Dec 14, 2018
  51. Empact force-pushed on Dec 16, 2018
  52. Empact force-pushed on Dec 18, 2018
  53. Empact force-pushed on Jan 7, 2019
  54. fanquake added the label Refactoring on Jan 8, 2019
  55. DrahtBot added the label Needs rebase on Feb 21, 2019
  56. Empact force-pushed on Mar 4, 2019
  57. DrahtBot removed the label Needs rebase on Mar 4, 2019
  58. Empact force-pushed on Mar 9, 2019
  59. Empact force-pushed on Mar 9, 2019
  60. DrahtBot added the label Needs rebase on Apr 19, 2019
  61. Move SetupChainParamsBaseOptions to util
    These options are intimately tied to ArgsManager, so their
    presence here makes sense, and moving them removes a final cause for a
    circular dependency between util and chainparamsbase.
    3ced0b5ce0
  62. Make CBaseChainParams responsible for holding the chain name
    And call into BaseParams from ArgsManager. Introduce BaseParamsSelected
    as it's necessary to prevent access to BaseParams prior to selection.
    
    This eliminates the chainparamsbase -> util -> chainparamsbase
    circular dependency.
    
    Note I had to guard ArgsManagerHelper::NetworkArg calls with a test for a
    leading '-' as NetworkArg asserts against the alternative, while values without
    - are tested for in the util_tests.
    764106e079
  63. Empact force-pushed on Jun 5, 2019
  64. Empact commented at 11:58 AM on June 5, 2019: member

    Rebased

  65. DrahtBot removed the label Needs rebase on Jun 5, 2019
  66. in src/test/util_tests.cpp:783 in 764106e079
     779 | @@ -774,7 +780,7 @@ BOOST_FIXTURE_TEST_CASE(util_ArgsMerge, ArgsMergeTestingSetup)
     780 |      // Results file is formatted like:
     781 |      //
     782 |      //   <input> || <IsArgSet/IsArgNegated/GetArg output> | <GetArgs output> | <GetUnsuitable output>
     783 | -    BOOST_CHECK_EQUAL(out_sha_hex, "b835eef5977d69114eb039a976201f8c7121f34fe2b7ea2b73cafb516e5c9dc8");
     784 | +    BOOST_CHECK_EQUAL(out_sha_hex, "6e84c6b6a1702f5c2247d175e7e1ad76c342be58b95bf2b7ed7e271d38197a14");
    


    ryanofsky commented at 10:45 AM on June 6, 2019:

    Are the changes here expected? I don't think they look right. It looks like wallet settings in the top-level of the config file (not in the test section) are now no longer ignored when testnet is enabled.

    DIfferences in results.txt before and after this change look like:

    -net=test wallet=c1 wallet=c2 || unset | ignored -wallet
    +net=test wallet=c1 wallet=c2 || c1 | c1 c2
    ...
    -net=test wallet=c1 wallet=c2 || unset | ignored -wallet
    +net=test wallet=c1 wallet=c2 || c1 | c1 c2
    ...
    

    If this is not intended, it might just be a bug in the test setup, like the parser.m_network = network; line above no longer having an effect, instead of a real bug.

  67. MarcoFalke commented at 1:47 PM on June 6, 2019: member

    I wrote a feedback a few months ago, not sure if it still applies:

    Base params are always selected when the program is running. Only very early in the init sequence (when the chain was not selected) we'd have to (and should) skip the steps that involve the chain name. Imo this is better solved by passing a bool into IsArg*(..., bool net_specific=true), that is set to true by default but only in the few calls during init set to false. E.g. would have to pass it down in HelpRequested...

    No strong opinion, though

  68. DrahtBot commented at 4:27 PM on August 2, 2019: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->Needs rebase

  69. DrahtBot added the label Needs rebase on Aug 2, 2019
  70. DrahtBot commented at 7:37 AM on July 14, 2020: contributor

    There hasn't been much activity lately and the patch still needs rebase, so I am closing this for now. Please let me know when you want to continue working on this, so the pull request can be re-opened.

  71. DrahtBot closed this on Jul 14, 2020

  72. bitcoin locked this on Feb 15, 2022

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: 2026-05-20 06:54 UTC

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