MarcoFalke
commented at 5:05 pm on September 24, 2018:
member
Currently we use string constants to select different chain rules (e.g “main” or “test”). The obvious downsides are that any function that accepts such a string needs to check if it is one of the known ones and return a runtime error when not found.
This check can be done at compile time by using a switch statement on an enum class.
To not refactor all the existing code, this first introduces the type-safe enum class ChainType and then runs a scripted diff on all instances where we can benefit from the new class. I intend to remove the throwing and now deprecated methods that pass around the string in a future patch.
MarcoFalke added the label
Refactoring
on Sep 24, 2018
practicalswift
commented at 5:37 pm on September 24, 2018:
contributor
Concept ACK
Nice!
DrahtBot
commented at 8:39 pm on September 24, 2018:
member
#14494 (Error if # is used in rpcpassword in conf by MeshCollider)
#14489 (refactor: Drop boost::thread and boost::chrono by ken2812221)
#14437 (Refactor: Start to separate wallet from node 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.
MarcoFalke force-pushed
on Sep 24, 2018
MarcoFalke force-pushed
on Sep 26, 2018
MarcoFalke force-pushed
on Sep 26, 2018
MarcoFalke force-pushed
on Sep 26, 2018
MarcoFalke force-pushed
on Sep 26, 2018
MarcoFalke force-pushed
on Sep 26, 2018
MarcoFalke force-pushed
on Sep 26, 2018
MarcoFalke renamed this:
scripted-diff: Use non-throwing type-safe ChainType where possible
Use non-throwing type-safe ChainType where possible
on Sep 26, 2018
MarcoFalke force-pushed
on Sep 26, 2018
MarcoFalke force-pushed
on Sep 26, 2018
chainparams: Add type safe enum class ChainTyped341856cf0
scripted-diff: Use non-throwing type-safe ChainType where possible
Use non-throwing chain selection calls where possiblefab4f8a196
MarcoFalke force-pushed
on Sep 26, 2018
MarcoFalke force-pushed
on Sep 26, 2018
MarcoFalke force-pushed
on Sep 26, 2018
practicalswift
commented at 7:36 am on September 27, 2018:
contributor
What about adding the NODISCARD/[[nodiscard]] attribute to bool ParseChainType(const std::string& str, ChainType& chain) to guarantee that all future callers make use of the return code?
See #13815 for NODISCARD which enables [[nodiscard]] (or equivalent) without having to wait for C++17.
DrahtBot
commented at 5:00 am on September 28, 2018:
member
jtimon
commented at 2:55 pm on October 20, 2018:
contributor
why not a macro or a simple const string in chainbaseparams.h ?
I think the problem I see is the string cannot be used in certain place now (ie chainparams.cpp for setting strNetworkID and in qt/networkstyle.cpp for setting network_styles) only comes from the fact that the strings are not constants but static attributes in the class.
The errors thrown are only thrown during initialization and some of them would disappear with #8994 I’m not sure this adds much value.
qa: Add tests for invalid chain selections8c0eabf5b5
MarcoFalke force-pushed
on Oct 21, 2018
MarcoFalke
commented at 1:50 am on October 21, 2018:
member
Closing for now, but I think in the longer term we should get rid of exceptions (especially during initialization, where we currently use a string to explicitly pass up errors).
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-23 12:12 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me