Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Network selector #1729

Merged
merged 10 commits into from
Mar 11, 2019
Merged

Network selector #1729

merged 10 commits into from
Mar 11, 2019

Conversation

cryptocode
Copy link
Contributor

@cryptocode cryptocode commented Feb 15, 2019

Closes #1099

A new CLI option is added:

--network live|beta|test

Example of using a livenet-compiled wallet to run on betanet:

./nano_wallet --network beta --data_path MyBetaDirectory

This is a CLI option instead of a config option because the config-file may not exist yet.

The ACTIVE_NETWORK build flag is still there to define the default value if no network option is present. As a result, RC builds for beta don't require a network option, so startup scripts, etc should work as before.

As discussed in #1099, some other projects use flags such as -testnet, but those mean sightly different things. A --network flag makes it clear that we don't follow any other projects' network naming standard and it mirrors how we choose network at compile-time (this doesn't seem like an option regular users will employ)

Implementation details:

  • The main function of tests forces testnet. Hence, tests can be run even when compiled for live- or betanet.
  • Any option whose value depends on network is now placed in config.hpp in the appropriate class.
  • Ledger constants are moved to config.hpp as well. Reason is these constants depend on the selected network, and initialization-order of globals in different translation units is unspecified.
  • The node and a few other classes have a nano::network_params member where the per-network values can be queried.
  • For freestanding functions, a static local is used for the params. A singleton could have been used, but we may want to inject params everywhere in the future (and perhaps remove freestanding functions) and a singleton would make that harder.
  • For network constants used as default function arguments (bound at compile-time), an overload without the argument is created which forwards to the original. One such example is work_generate_blocking (nano::uint256_union const &, uint64_t = nano::work_pool::publish_threshold);
  • Globals such as nano::genesis_amount used to depend on the compile-time network value. These are now only available for tests, which enforces the testnet. Since only tests include testutil.hpp, any attempts to use these in the node results in a compile error. As a result, this PR contains almost no changes to tests (initially there was a network_params in system, etc, but that meant a huge amount of changes with no gain)

Tests pass and it appears to sync fine on both networks.

@cryptocode cryptocode added this to the V19.0 milestone Feb 15, 2019
@cryptocode cryptocode self-assigned this Feb 15, 2019
@guilhermelawless
Copy link
Contributor

Does the data path change to /NanoBeta by default if a live net node is compiled and only --network beta is given?

What are the consequences if an already complete beta database is provided by accident to a live net node?

@cryptocode
Copy link
Contributor Author

cryptocode commented Feb 15, 2019

@guilhermelawless If you pick the wrong database, an error is logged and the node exits (that's already the case). The data path should probably change to defaults if you don't supply a path; I'll change it so that the network is checked before data_path. Thanks.

@cryptocode cryptocode force-pushed the network-selector branch 2 times, most recently from 89b8739 to ea5e10f Compare February 17, 2019 14:23
@cryptocode cryptocode merged commit bab4474 into nanocurrency:master Mar 11, 2019
@cryptocode cryptocode deleted the network-selector branch March 11, 2019 15:10
@zhyatt zhyatt added documentation This item indicates the need for or supplies updated or expanded documentation and removed documentation This item indicates the need for or supplies updated or expanded documentation labels Jul 10, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Easy way to switch between beta/live network
5 participants