Skip to content

Commit

Permalink
Allow CLI --config values for inactive node tests (#2594)
Browse files Browse the repository at this point in the history
  • Loading branch information
SergiySW authored Mar 2, 2020
1 parent 5dac531 commit 90f1c86
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
5 changes: 0 additions & 5 deletions nano/nano_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ int main (int argc, char * const * argv)
std::cerr << flags_ec.message () << std::endl;
std::exit (1);
}
auto config (vm.find ("config"));
if (config != vm.end ())
{
flags.config_overrides = config->second.as<std::vector<std::string>> ();
}
daemon.run (data_path, flags);
}
else if (vm.count ("debug_block_count"))
Expand Down
11 changes: 3 additions & 8 deletions nano/nano_wallet/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ nano::error read_wallet_config (nano::wallet_config & config_a, boost::filesyste
}
}

int run_wallet (QApplication & application, int argc, char * const * argv, boost::filesystem::path const & data_path, std::vector<std::string> const & config_overrides, nano::node_flags const & flags)
int run_wallet (QApplication & application, int argc, char * const * argv, boost::filesystem::path const & data_path, nano::node_flags const & flags)
{
int result (0);
nano_qt::eventloop_processor processor;
Expand All @@ -81,7 +81,7 @@ int run_wallet (QApplication & application, int argc, char * const * argv, boost
nano::daemon_config config (data_path);
nano::wallet_config wallet_config;

auto error = nano::read_node_config_toml (data_path, config, config_overrides);
auto error = nano::read_node_config_toml (data_path, config, flags.config_overrides);
if (!error)
{
error = read_wallet_config (wallet_config, data_path);
Expand Down Expand Up @@ -331,12 +331,7 @@ int main (int argc, char * const * argv)
{
throw std::runtime_error (flags_ec.message ());
}
auto config (vm.find ("config"));
if (config != vm.end ())
{
flags.config_overrides = config->second.as<std::vector<std::string>> ();
}
result = run_wallet (application, argc, argv, data_path, config_overrides, flags);
result = run_wallet (application, argc, argv, data_path, flags);
}
catch (std::exception const & e)
{
Expand Down
6 changes: 6 additions & 0 deletions nano/node/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ std::error_code nano::update_flags (nano::node_flags & flags_a, boost::program_o
{
flags_a.vote_processor_capacity = vote_processor_capacity_it->second.as<size_t> ();
}
// Config overriding
auto config (vm.find ("config"));
if (config != vm.end ())
{
flags_a.config_overrides = config->second.as<std::vector<std::string>> ();
}
return ec;
}

Expand Down
19 changes: 18 additions & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <nano/lib/threading.hpp>
#include <nano/lib/tomlconfig.hpp>
#include <nano/lib/utility.hpp>
#include <nano/node/common.hpp>
#include <nano/node/node.hpp>
Expand Down Expand Up @@ -1355,7 +1356,23 @@ peering_port (peering_port_a)
nano::set_secure_perm_directory (path, error_chmod);
logging.max_size = std::numeric_limits<std::uintmax_t>::max ();
logging.init (path);
node = std::make_shared<nano::node> (*io_context, peering_port, path, alarm, logging, work, node_flags);
// Config overriding
nano::node_config config (peering_port, logging);
std::stringstream config_overrides_stream;
for (auto const & entry : node_flags.config_overrides)
{
config_overrides_stream << entry << std::endl;
}
config_overrides_stream << std::endl;
nano::tomlconfig toml;
toml.read (config_overrides_stream);
auto error = config.deserialize_toml (toml);
if (error)
{
std::cerr << "Error deserializing --config option" << std::endl;
std::exit (1);
}
node = std::make_shared<nano::node> (*io_context, path, alarm, config, work, node_flags);
node->active.stop ();
}

Expand Down

0 comments on commit 90f1c86

Please sign in to comment.