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. DrahtBot commented at 8:42 am on August 24, 2018: 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:

    • #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.

  3. Empact force-pushed on Aug 24, 2018
  4. Empact renamed this:
    Break the chainparamsbase -> util circular dependency
    refactor: Fix the chainparamsbase -> util circular dependency
    on Aug 24, 2018
  5. practicalswift commented at 9:16 am on August 24, 2018: contributor

    Concept ACK

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

  6. 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 πŸ‘
  7. 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.
  8. domob1812 approved
  9. domob1812 commented at 2:47 pm on August 24, 2018: contributor
    utACK d1e653c2e028c3342cdae4be81e423f96db89214 with a few style nits.
  10. Empact force-pushed on Aug 24, 2018
  11. Empact force-pushed on Aug 24, 2018
  12. Empact force-pushed on Aug 24, 2018
  13. Empact force-pushed on Aug 24, 2018
  14. 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.
  15. Empact force-pushed on Aug 25, 2018
  16. Empact force-pushed on Aug 25, 2018
  17. Empact commented at 0: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.
  18. Empact force-pushed on Aug 26, 2018
  19. DrahtBot added the label Needs rebase on Aug 30, 2018
  20. Empact force-pushed on Sep 1, 2018
  21. DrahtBot removed the label Needs rebase on Sep 1, 2018
  22. Empact force-pushed on Sep 1, 2018
  23. Empact force-pushed on Sep 2, 2018
  24. DrahtBot added the label Needs rebase on Sep 24, 2018
  25. Empact force-pushed on Sep 25, 2018
  26. DrahtBot removed the label Needs rebase on Sep 25, 2018
  27. Empact force-pushed on Sep 25, 2018
  28. Empact force-pushed on Sep 25, 2018
  29. 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 πŸ‘
  30. jtimon approved
  31. 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
  32. DrahtBot added the label Needs rebase on Nov 5, 2018
  33. Empact force-pushed on Nov 6, 2018
  34. DrahtBot removed the label Needs rebase on Nov 6, 2018
  35. Empact renamed this:
    refactor: Fix the chainparamsbase -> util circular dependency
    WIP: refactor: Fix the chainparamsbase -> util circular dependency
    on Nov 12, 2018
  36. DrahtBot added the label Needs rebase on Nov 15, 2018
  37. Empact force-pushed on Dec 13, 2018
  38. DrahtBot removed the label Needs rebase on Dec 13, 2018
  39. Empact force-pushed on Dec 14, 2018
  40. Empact renamed this:
    WIP: refactor: Fix the chainparamsbase -> util circular dependency
    refactor: Fix the chainparamsbase -> util circular dependency
    on Dec 14, 2018
  41. Empact force-pushed on Dec 14, 2018
  42. Empact force-pushed on Dec 16, 2018
  43. Empact force-pushed on Dec 18, 2018
  44. Empact force-pushed on Jan 7, 2019
  45. fanquake added the label Refactoring on Jan 8, 2019
  46. DrahtBot added the label Needs rebase on Feb 21, 2019
  47. Empact force-pushed on Mar 4, 2019
  48. DrahtBot removed the label Needs rebase on Mar 4, 2019
  49. Empact force-pushed on Mar 9, 2019
  50. Empact force-pushed on Mar 9, 2019
  51. DrahtBot added the label Needs rebase on Apr 19, 2019
  52. 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
  53. 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
  54. Empact force-pushed on Jun 5, 2019
  55. Empact commented at 11:58 am on June 5, 2019: member
    Rebased
  56. DrahtBot removed the label Needs rebase on Jun 5, 2019
  57. 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:

    0-net=test wallet=c1 wallet=c2 || unset | ignored -wallet
    1+net=test wallet=c1 wallet=c2 || c1 | c1 c2
    2...
    3-net=test wallet=c1 wallet=c2 || unset | ignored -wallet
    4+net=test wallet=c1 wallet=c2 || c1 | c1 c2
    5...
    

    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.

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

  59. DrahtBot commented at 4:27 pm on August 2, 2019: member
  60. DrahtBot added the label Needs rebase on Aug 2, 2019
  61. DrahtBot commented at 7:37 am on July 14, 2020: member
    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.
  62. DrahtBot closed this on Jul 14, 2020

  63. DrahtBot 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: 2024-12-18 18:12 UTC

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