Skip to content

Conversation

Empact
Copy link
Contributor

@Empact Empact commented Jul 12, 2018

By moving gArgs references out of chainparamsbase.cpp.

Note both chainparams.cpp, bitcoin-cli.cpp, and all callers of
SetupChainParamsBaseOptions include util.h

@Empact Empact force-pushed the chainparamsbase-circ branch from bbc6d2d to 6640590 Compare July 12, 2018 05:55
@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 12, 2018

Note to reviewers: This pull request conflicts with the following ones:

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.

@l2a5b1
Copy link
Contributor

l2a5b1 commented Jul 12, 2018

+1 for going after another dependency cycle :)

Extracting MakeUnique seems like a good thing to do.

Does it make sense to refactor the dependency of util on chainparamsbase?

#include <chainparamsbase.h>

This relationship seems the crux to the circular dependency to me. Imoutil should have as little dependencies as possible.

@Empact
Copy link
Contributor Author

Empact commented Jul 12, 2018

Agree on minimizing util, but seems removing chainparamsbase would be a bigger job, since ArgsManager uses CBaseChainParams, and ArgsManager is the bulk of util.

@Empact Empact changed the title Fix the chainparamsbase -> util -> chainparamsbase circular dependency [moveonly] Fix the chainparamsbase -> util circular dependency Jul 13, 2018
@Empact Empact force-pushed the chainparamsbase-circ branch from 6640590 to 3461ebd Compare July 17, 2018 17:45
@Empact
Copy link
Contributor Author

Empact commented Jul 17, 2018

Dropped the third commit and extracted #13690 for easier review. Maybe start with that?

maflcko pushed a commit that referenced this pull request Jul 17, 2018
33539cb Extract MakeUnique into utilmemory.h (Ben Woosley)

Pull request description:

  And use it to reduce chainparamsbase.cpp's and remove interfaces/handler.cpp's reliance on util.h
  This is a step toward fixing the chainparamsbase -> util circular dependency.

  Confirmed no need for the util.h include via iwyu and visual inspection.
  Extracted from #13639 for easier review.

Tree-SHA512: 61cbf9eafb68c3e3706d21c70aeb0586a85364dad32cc49c2d40e963ac3b2c44424ad1522788a0a6b2a689fd9294ebce4482a392ceb88a94eabe09a84f070ce4
@Empact Empact force-pushed the chainparamsbase-circ branch 2 times, most recently from 0504a02 to 6ebcfab Compare July 17, 2018 19:15
@Empact
Copy link
Contributor Author

Empact commented Jul 17, 2018

Rebased for #13690

@Empact Empact force-pushed the chainparamsbase-circ branch from 6ebcfab to a216630 Compare July 17, 2018 20:25
@Empact
Copy link
Contributor Author

Empact commented Jul 17, 2018

Ran clang-format

@Empact Empact force-pushed the chainparamsbase-circ branch from a216630 to 73219c8 Compare July 20, 2018 16:37
@Empact
Copy link
Contributor Author

Empact commented Jul 20, 2018

Rebased for #13695

@sipa
Copy link
Member

sipa commented Jul 20, 2018

I don't think moving the arguments for chain selection to util is the right solution here.

Why does util depend on knowing something about chain parameters anyway? It's supposed to be a bunch of utility functions.

@maflcko
Copy link
Member

maflcko commented Jul 20, 2018

What about moving argsmanager to a separate module?

@Empact
Copy link
Contributor Author

Empact commented Jul 20, 2018

I'll look into that, thanks!

These two were being set together in all cases. Using just one removes the
internal reliance of chainparamsbase on gArgs in this case.

Instead expose GetRPCPort and GetDataDir methods, which can be called with
the m_network name stored by gArgs.
@Empact Empact force-pushed the chainparamsbase-circ branch 3 times, most recently from 253e66b to af5754e Compare July 28, 2018 07:16
@Empact
Copy link
Contributor Author

Empact commented Jul 28, 2018

Ok I looked deeper into this and moved to a more comprehensive approach. The story is, there exist an m_network attribute in ArgsManager, and a globalChainBaseParams variable that drives BaseParams(). These are functionally redundant based on the fact that they are always set together. Given that the base params are only two: rpc port and data dir name, we can simply pass the m_network value to a method that returns the port or dir name relative to that network.

This is functionally equivalent and simpler in implementation than the prior alternative. While chainparams has a justification for doing its setup once (the voluminous setup), the mapping for chainparamsbase is trivial.

What remains of CBaseChainParams is just a namespace for the network name
strings.
@Empact Empact force-pushed the chainparamsbase-circ branch from af5754e to 5194e16 Compare July 28, 2018 08:02
@Empact Empact force-pushed the chainparamsbase-circ branch from 5194e16 to 0579015 Compare July 28, 2018 08:46
@Empact
Copy link
Contributor Author

Empact commented Jul 28, 2018

A possible follow-up - replacing the string-based handling with an enum class: https://github.com/Empact/bitcoin/compare/chainparamsbase-circ...Empact:chain-enum-class?expand=1

These options are intimately tied to ArgsManager::GetChainName, so their
presence here makes sense, and moving them removes the final cause for a
circular dependency between util and chainparamsbase.
@Empact Empact force-pushed the chainparamsbase-circ branch from 0579015 to 9847689 Compare August 24, 2018 00:17
@Empact
Copy link
Contributor Author

Empact commented Aug 24, 2018

@sipa you're right, that's much cleaner. Closing in favor of #14045

@Empact Empact closed this Aug 24, 2018
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 19, 2020
33539cb Extract MakeUnique into utilmemory.h (Ben Woosley)

Pull request description:

  And use it to reduce chainparamsbase.cpp's and remove interfaces/handler.cpp's reliance on util.h
  This is a step toward fixing the chainparamsbase -> util circular dependency.

  Confirmed no need for the util.h include via iwyu and visual inspection.
  Extracted from bitcoin#13639 for easier review.

Tree-SHA512: 61cbf9eafb68c3e3706d21c70aeb0586a85364dad32cc49c2d40e963ac3b2c44424ad1522788a0a6b2a689fd9294ebce4482a392ceb88a94eabe09a84f070ce4
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 24, 2020
33539cb Extract MakeUnique into utilmemory.h (Ben Woosley)

Pull request description:

  And use it to reduce chainparamsbase.cpp's and remove interfaces/handler.cpp's reliance on util.h
  This is a step toward fixing the chainparamsbase -> util circular dependency.

  Confirmed no need for the util.h include via iwyu and visual inspection.
  Extracted from bitcoin#13639 for easier review.

Tree-SHA512: 61cbf9eafb68c3e3706d21c70aeb0586a85364dad32cc49c2d40e963ac3b2c44424ad1522788a0a6b2a689fd9294ebce4482a392ceb88a94eabe09a84f070ce4
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 27, 2020
33539cb Extract MakeUnique into utilmemory.h (Ben Woosley)

Pull request description:

  And use it to reduce chainparamsbase.cpp's and remove interfaces/handler.cpp's reliance on util.h
  This is a step toward fixing the chainparamsbase -> util circular dependency.

  Confirmed no need for the util.h include via iwyu and visual inspection.
  Extracted from bitcoin#13639 for easier review.

Tree-SHA512: 61cbf9eafb68c3e3706d21c70aeb0586a85364dad32cc49c2d40e963ac3b2c44424ad1522788a0a6b2a689fd9294ebce4482a392ceb88a94eabe09a84f070ce4
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jul 27, 2020
33539cb Extract MakeUnique into utilmemory.h (Ben Woosley)

Pull request description:

  And use it to reduce chainparamsbase.cpp's and remove interfaces/handler.cpp's reliance on util.h
  This is a step toward fixing the chainparamsbase -> util circular dependency.

  Confirmed no need for the util.h include via iwyu and visual inspection.
  Extracted from bitcoin#13639 for easier review.

Tree-SHA512: 61cbf9eafb68c3e3706d21c70aeb0586a85364dad32cc49c2d40e963ac3b2c44424ad1522788a0a6b2a689fd9294ebce4482a392ceb88a94eabe09a84f070ce4
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jul 27, 2020
33539cb Extract MakeUnique into utilmemory.h (Ben Woosley)

Pull request description:

  And use it to reduce chainparamsbase.cpp's and remove interfaces/handler.cpp's reliance on util.h
  This is a step toward fixing the chainparamsbase -> util circular dependency.

  Confirmed no need for the util.h include via iwyu and visual inspection.
  Extracted from bitcoin#13639 for easier review.

Tree-SHA512: 61cbf9eafb68c3e3706d21c70aeb0586a85364dad32cc49c2d40e963ac3b2c44424ad1522788a0a6b2a689fd9294ebce4482a392ceb88a94eabe09a84f070ce4
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
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.

6 participants