Skip to content

Conversation

@jtimon
Copy link
Contributor

@jtimon jtimon commented Jun 4, 2015

Make some strings translatable when they weren't.
Don't duplicate error or help translation strings related to chainparams.

@jtimon
Copy link
Contributor Author

jtimon commented Jun 21, 2015

Needed rebase. Also replaced GetParamsHelpMessages with AppendParamsHelpMessages, which optionally takes a showDebugHelp boolean.

@jtimon jtimon force-pushed the chainparams-dry branch from 08c2d1a to 102e7d5 Compare June 21, 2015 18:33
@jtimon
Copy link
Contributor Author

jtimon commented Jun 25, 2015

@theuni this may interact with your code.

@jtimon
Copy link
Contributor Author

jtimon commented Jun 25, 2015

Closing for now to reduce noise

@jtimon
Copy link
Contributor Author

jtimon commented Jul 6, 2015

Great. MAX_NETWORK_TYPES is removed in the second commit.

@rustyrussell
Copy link
Contributor

Ack (tested).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move away from a switch case construct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't switch on a string...

@jgarzik
Copy link
Contributor

jgarzik commented Jul 7, 2015

General approach OK. Comments:

  • Still repeating a chain lookup in chainparams.cpp & chainparamsbase.cpp
  • Only now it is worse because it is a more expensive (now duplicated) string comparison
  • Seeing this duplication hints that a table-driven approach, with each string inside the param struct, is superior to manually administered case statements (& duplicated) of chain strings.

Seems like you want find_chain_by_string(), returns id, which can be passed around efficiently as 'network' -- which is consistent with what the rest of the code does now.

@rustyrussell
Copy link
Contributor

@jgarzik since each param has a strNetworkID which is exactly the same as the CBaseChainParams constants introduced, I think a set would be the simplest.

Re-introducing an intermediate type would defeat the point of these patches for me, which is to allow me to easily create a new testnet. I've been hacking bitcoind to run a megablocks testnet, for example.

But I like the simplicity of the patch's mechanical translation; easy to review. A lookup mechanism on top could work well as a new patch.

@jtimon
Copy link
Contributor Author

jtimon commented Jul 7, 2015

  • Still repeating a chain lookup in chainparams.cpp & chainparamsbase.cpp
  • Only now it is worse because it is a more expensive (now duplicated) string comparison

Yes, the string comparison is more expensive, but it's done on init or tests, so I think it's fine.
What do you mean by "now duplicated". Can you point out what exactly am I duplicating here?

-Seeing this duplication hints that a table-driven approach, with each string inside the param struct, is superior to manually administered case statements (& duplicated) of chain strings.
Seems like you want find_chain_by_string(), returns id, which can be passed around efficiently as 'network' -- which is consistent with what the rest of the code does now.

@jgarzik I'm not sure I understand your suggestion.
You mean a function like CBaseChainParams::Network networkEnumFromChainName(std::string)?
That doesn't remove the duplicated switch/elifs for chainparams and basechainparams. The problem here with that duplication is having base chainparams in the first place. This is not doing anything against or in favor to that. I believe we could move the datadir to regular chainparams and have users select the bitcoin-cli port manually instead of indirectly through -testnet and -regtest. Anyway, that would belong in another PR.
Anyway, this PR was open without replacing the enum with a string. I could reopen that again, but it's cleaner this way and there's many other things that require that replacement in #6382 .

@jtimon
Copy link
Contributor Author

jtimon commented Jul 28, 2015

EDIT (after reverting #6077 ):
This (and thus #6382) should fail the compilation if merged after #6077, I will rebase both: but don't merge this now.

@jtimon
Copy link
Contributor Author

jtimon commented Aug 20, 2015

ping @theuni . This should be useful for #6526 just like it's useful for #6382

@jtimon
Copy link
Contributor Author

jtimon commented Aug 21, 2015

Rebased and fixed (see #6077 (comment) ).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This last line is outdated. That behaviour moved to the separate generate RPC call.

@sipa
Copy link
Member

sipa commented Aug 26, 2015

Untested ACK

@theuni
Copy link
Member

theuni commented Aug 26, 2015

ut ACK

@jtimon
Copy link
Contributor Author

jtimon commented Aug 26, 2015

Fixed @sipa 's nit.

@jgarzik
Copy link
Contributor

jgarzik commented Sep 16, 2015

ut ACK - though this pushes the bounds of my refactor size-o-meter for end-user utility versus source code disturbance ;p

@dcousens
Copy link
Contributor

utACK

@jtimon
Copy link
Contributor Author

jtimon commented Sep 17, 2015

For more context on more long-term utility of this change see #6382 (needs rebase on top of #6672 ).

@jtimon
Copy link
Contributor Author

jtimon commented Sep 22, 2015

ping

@apoelstra
Copy link
Contributor

ut ACK. I'm not concerned about string comparisons on init.

With #6382 NACK'd there is less direct utility to this patch, but I like the deduplication of the error handling. (The whole "selecting chainparams" area of the code can be frustrating to read because it has a lot of redundancy like this.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options help that is only shown with debugHelp should not be translated (see doc/translation_strings_policy.md)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know that, thanks. I will correct it.

@laanwj
Copy link
Member

laanwj commented Oct 20, 2015

ut ACK

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I believe this is an initialization error rather than an internal error. But the initialization errors translation in init.o::AppInit2() seems inconsistent (some times they are translated, some times they aren't).
@laanwj can you help us here?

Also remove SelectBaseParamsFromCommandLine and SelectParamsFromCommandLine
@jtimon
Copy link
Contributor Author

jtimon commented Oct 20, 2015

Updated without translating errors or messages that are only shown when debugHelp is true (solved @laanwj and @MarcoFalke 's nits).

@laanwj laanwj merged commit 55a8975 into bitcoin:master Oct 20, 2015
laanwj added a commit that referenced this pull request Oct 20, 2015
55a8975 Chainparams: Translations: DRY: options and error strings (Jorge Timón)
f3525e2 Chainparams: Replace CBaseChainParams::Network enum with string constants (suggested by Wladimir) (Jorge Timón)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it, why such stuff is alway reintroduced or even used at all:
Should be: catch (const std::exception& e)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault. I would have changed it if someone had nit it on time.

zkbot added a commit to zcash/zcash that referenced this pull request Mar 21, 2018
Misc upstream PRs

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6077
  - Second commit only (first was already applied to 0.11.X and then reverted)
- bitcoin/bitcoin#6284
- bitcoin/bitcoin#6489
- bitcoin/bitcoin#6462
- bitcoin/bitcoin#6647
- bitcoin/bitcoin#6235
- bitcoin/bitcoin#6905
- bitcoin/bitcoin#6780
  - Excluding second commit (QT) and third commit (requires bitcoin/bitcoin#6993)
- bitcoin/bitcoin#6961
  - Excluding QT parts, and a small `src/policy/policy.cpp` change which depends on a bunch of other PRs, which we'll have to remember to come back to.
- bitcoin/bitcoin#7044
- bitcoin/bitcoin#8856
- bitcoin/bitcoin#9002

Part of #2074 and #2132.
zkbot added a commit to zcash/zcash that referenced this pull request Dec 4, 2019
Misc upstream PRs

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6077
  - Second commit only (first was already applied to 0.11.X and then reverted)
- bitcoin/bitcoin#6284
- bitcoin/bitcoin#6489
- bitcoin/bitcoin#6235
- bitcoin/bitcoin#6905
- bitcoin/bitcoin#6780
  - Excluding second commit (QT) and third commit (requires bitcoin/bitcoin#6993)
- bitcoin/bitcoin#6961
  - Excluding QT parts, and a small `src/policy/policy.cpp` change which depends on a bunch of other PRs, which we'll have to remember to come back to.
- bitcoin/bitcoin#7044
- bitcoin/bitcoin#8856
- bitcoin/bitcoin#9002

Part of #2074 and #2132.
furszy referenced this pull request in PIVX-Project/PIVX Feb 10, 2021
…cture

d1244f3 Fix UB in CChainParams unique_ptr subclasses destructor. (furszy)
cf20f43 Chainparams: Get rid of CChainParams& Params(std::string) (Jorge Timón)
eeea862 Chainparams: Use a regular factory for creating chainparams (Jorge Timón)
f9d585a More zerocoin unused functions and classes cleanup. (furszy)
029ce7b pivx-cli align -rpcport help message to init.cpp help message. (furszy)
3431977 Chainparams: Translations: DRY: options and error strings  Also remove SelectBaseParamsFromCommandLine and SelectParamsFromCommandLin (Jorge Timón)
ce7a792 Removed unused AreBaseParamsConfigured() (furszy)
508fec1 Chainparams: Replace CBaseChainParams::Network enum with string constants (furszy)
2a1f16c Chainparams: CTestNetParams and CRegTestParams extend directly from CChainParams (furszy)
0ed1a48 Refactor `Params().NetworkID() == CBaseChainParams::TESTNET` for IsTestnet() direct call. (furszy)

Pull request description:

  Made several updates to the base chain params structure and further cleanups over the zerocoin code:

  * Replaced `CBaseChainParams::Network` enum with string constants and unified better the network selection error + network help message (adaptation of dashpay#6235).
  * Removed unused NetworkID field from chain params (dashpay#5598).
  * Improved the network params creation using a proper factory (adaptation of bitcoin#8855).
  * Cleaned almost all the zerocoin related functions inside `zerocoin.h/cpp` and `zpivchain.h/cpp`.

ACKs for top commit:
  random-zebra:
    ACK d1244f3
  Fuzzbawls:
    ACK d1244f3

Tree-SHA512: c7ecb34045f9e14dc60130d3f7142c2f32c4c16f5678e871036db0b513ec3c416762a2464ff0d50383a50d345ea90f2c5958284657479c2becaaf9bf3936fcd3
@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.

10 participants