Remove json config code (#3655)

* Remove json config code

This improves compile/test times a bit. The json->toml upgrade paths are removed as well. In the unlikely case someone needs to upgrade from v19.x and earlier, the solution is to run a v2x node (prior to this change) to perform the upgrade.

Closes #3530

* Remove stat_config json deserialization as well

* Remove stat_config header's deserialize_json and jsonconfig::read_and_update
This commit is contained in:
cryptocode 2022-01-13 00:02:09 +01:00 committed by GitHub
commit 016f15bd0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 1 additions and 1419 deletions

View file

@ -1,4 +1,3 @@
#include <nano/lib/jsonconfig.hpp>
#include <nano/lib/logger_mt.hpp>
#include <nano/node/logging.hpp>
#include <nano/secure/utility.hpp>
@ -12,52 +11,6 @@
using namespace std::chrono_literals;
TEST (logging, serialization)
{
auto path (nano::unique_path ());
nano::logging logging1;
logging1.init (path);
logging1.ledger_logging_value = !logging1.ledger_logging_value;
logging1.ledger_duplicate_logging_value = !logging1.ledger_duplicate_logging_value;
logging1.network_logging_value = !logging1.network_logging_value;
logging1.network_timeout_logging_value = !logging1.network_timeout_logging_value;
logging1.network_message_logging_value = !logging1.network_message_logging_value;
logging1.network_publish_logging_value = !logging1.network_publish_logging_value;
logging1.network_packet_logging_value = !logging1.network_packet_logging_value;
logging1.network_keepalive_logging_value = !logging1.network_keepalive_logging_value;
logging1.network_node_id_handshake_logging_value = !logging1.network_node_id_handshake_logging_value;
logging1.node_lifetime_tracing_value = !logging1.node_lifetime_tracing_value;
logging1.insufficient_work_logging_value = !logging1.insufficient_work_logging_value;
logging1.bulk_pull_logging_value = !logging1.bulk_pull_logging_value;
logging1.work_generation_time_value = !logging1.work_generation_time_value;
logging1.log_to_cerr_value = !logging1.log_to_cerr_value;
logging1.max_size = 10;
logging1.min_time_between_log_output = 100ms;
nano::jsonconfig tree;
logging1.serialize_json (tree);
nano::logging logging2;
logging2.init (path);
bool upgraded (false);
ASSERT_FALSE (logging2.deserialize_json (upgraded, tree));
ASSERT_FALSE (upgraded);
ASSERT_EQ (logging1.ledger_logging_value, logging2.ledger_logging_value);
ASSERT_EQ (logging1.ledger_duplicate_logging_value, logging2.ledger_duplicate_logging_value);
ASSERT_EQ (logging1.network_logging_value, logging2.network_logging_value);
ASSERT_EQ (logging1.network_timeout_logging_value, logging2.network_timeout_logging_value);
ASSERT_EQ (logging1.network_message_logging_value, logging2.network_message_logging_value);
ASSERT_EQ (logging1.network_publish_logging_value, logging2.network_publish_logging_value);
ASSERT_EQ (logging1.network_packet_logging_value, logging2.network_packet_logging_value);
ASSERT_EQ (logging1.network_keepalive_logging_value, logging2.network_keepalive_logging_value);
ASSERT_EQ (logging1.network_node_id_handshake_logging_value, logging2.network_node_id_handshake_logging_value);
ASSERT_EQ (logging1.node_lifetime_tracing_value, logging2.node_lifetime_tracing_value);
ASSERT_EQ (logging1.insufficient_work_logging_value, logging2.insufficient_work_logging_value);
ASSERT_EQ (logging1.bulk_pull_logging_value, logging2.bulk_pull_logging_value);
ASSERT_EQ (logging1.work_generation_time_value, logging2.work_generation_time_value);
ASSERT_EQ (logging1.log_to_cerr_value, logging2.log_to_cerr_value);
ASSERT_EQ (logging1.max_size, logging2.max_size);
ASSERT_EQ (logging1.min_time_between_log_output, logging2.min_time_between_log_output);
}
TEST (logger, changing_time_interval)
{
auto path1 (nano::unique_path ());
@ -152,4 +105,4 @@ TEST (logger, stable_filename)
// Reset the logger
logging.release_file_sink ();
nano::logging ().init (path);
}
}

View file

@ -1,4 +1,3 @@
#include <nano/lib/jsonconfig.hpp>
#include <nano/node/election.hpp>
#include <nano/node/transport/udp.hpp>
#include <nano/test_common/network.hpp>
@ -15,11 +14,6 @@
using namespace std::chrono_literals;
namespace
{
void add_required_children_node_config_tree (nano::jsonconfig & tree);
}
TEST (node, null_account)
{
auto const & null_account = nano::account::null ();
@ -585,240 +579,6 @@ TEST (node, confirm_locked)
system.nodes[0]->network.flood_block (block);
}
TEST (node_config, serialization)
{
auto path (nano::unique_path ());
nano::logging logging1;
logging1.init (path);
nano::node_config config1 (100, logging1);
config1.bootstrap_fraction_numerator = 10;
config1.receive_minimum = 10;
config1.online_weight_minimum = 10;
config1.password_fanout = 20;
config1.enable_voting = false;
config1.callback_address = "dev";
config1.callback_port = 10;
config1.callback_target = "dev";
nano::jsonconfig tree;
config1.serialize_json (tree);
nano::logging logging2;
logging2.init (path);
logging2.node_lifetime_tracing_value = !logging2.node_lifetime_tracing_value;
nano::node_config config2 (50, logging2);
ASSERT_NE (config2.bootstrap_fraction_numerator, config1.bootstrap_fraction_numerator);
ASSERT_NE (config2.peering_port, config1.peering_port);
ASSERT_NE (config2.logging.node_lifetime_tracing_value, config1.logging.node_lifetime_tracing_value);
ASSERT_NE (config2.online_weight_minimum, config1.online_weight_minimum);
ASSERT_NE (config2.password_fanout, config1.password_fanout);
ASSERT_NE (config2.enable_voting, config1.enable_voting);
ASSERT_NE (config2.callback_address, config1.callback_address);
ASSERT_NE (config2.callback_port, config1.callback_port);
ASSERT_NE (config2.callback_target, config1.callback_target);
ASSERT_FALSE (tree.get_optional<std::string> ("epoch_block_link"));
ASSERT_FALSE (tree.get_optional<std::string> ("epoch_block_signer"));
bool upgraded (false);
ASSERT_FALSE (config2.deserialize_json (upgraded, tree));
ASSERT_FALSE (upgraded);
ASSERT_EQ (config2.bootstrap_fraction_numerator, config1.bootstrap_fraction_numerator);
ASSERT_EQ (config2.peering_port, config1.peering_port);
ASSERT_EQ (config2.logging.node_lifetime_tracing_value, config1.logging.node_lifetime_tracing_value);
ASSERT_EQ (config2.online_weight_minimum, config1.online_weight_minimum);
ASSERT_EQ (config2.password_fanout, config1.password_fanout);
ASSERT_EQ (config2.enable_voting, config1.enable_voting);
ASSERT_EQ (config2.callback_address, config1.callback_address);
ASSERT_EQ (config2.callback_port, config1.callback_port);
ASSERT_EQ (config2.callback_target, config1.callback_target);
}
TEST (node_config, v17_values)
{
nano::jsonconfig tree;
add_required_children_node_config_tree (tree);
auto path (nano::unique_path ());
auto upgraded (false);
nano::node_config config;
config.logging.init (path);
// Check config is correct
{
tree.put ("tcp_io_timeout", 1);
tree.put ("pow_sleep_interval", 0);
tree.put ("external_address", "::1");
tree.put ("external_port", 0);
tree.put ("tcp_incoming_connections_max", 1);
tree.put ("vote_generator_delay", 50);
tree.put ("vote_generator_threshold", 3);
nano::jsonconfig txn_tracking_l;
txn_tracking_l.put ("enable", false);
txn_tracking_l.put ("min_read_txn_time", 0);
txn_tracking_l.put ("min_write_txn_time", 0);
txn_tracking_l.put ("ignore_writes_below_block_processor_max_time", true);
nano::jsonconfig diagnostics_l;
diagnostics_l.put_child ("txn_tracking", txn_tracking_l);
tree.put_child ("diagnostics", diagnostics_l);
tree.put ("use_memory_pools", true);
tree.put ("confirmation_history_size", 2048);
tree.put ("active_elections_size", 50000);
tree.put ("bandwidth_limit", 10485760);
tree.put ("conf_height_processor_batch_min_time", 0);
}
config.deserialize_json (upgraded, tree);
ASSERT_FALSE (upgraded);
ASSERT_EQ (config.tcp_io_timeout.count (), 1);
ASSERT_EQ (config.pow_sleep_interval.count (), 0);
ASSERT_EQ (config.external_address, "::1");
ASSERT_EQ (config.external_port, 0);
ASSERT_EQ (config.tcp_incoming_connections_max, 1);
ASSERT_FALSE (config.diagnostics_config.txn_tracking.enable);
ASSERT_EQ (config.diagnostics_config.txn_tracking.min_read_txn_time.count (), 0);
ASSERT_EQ (config.diagnostics_config.txn_tracking.min_write_txn_time.count (), 0);
ASSERT_TRUE (config.diagnostics_config.txn_tracking.ignore_writes_below_block_processor_max_time);
ASSERT_TRUE (config.use_memory_pools);
ASSERT_EQ (config.confirmation_history_size, 2048);
ASSERT_EQ (config.active_elections_size, 50000);
ASSERT_EQ (config.bandwidth_limit, 10485760);
ASSERT_EQ (config.conf_height_processor_batch_min_time.count (), 0);
// Check config is correct with other values
tree.put ("tcp_io_timeout", std::numeric_limits<unsigned long>::max () - 100);
tree.put ("pow_sleep_interval", std::numeric_limits<unsigned long>::max () - 100);
tree.put ("external_address", "::ffff:192.168.1.1");
tree.put ("external_port", std::numeric_limits<uint16_t>::max () - 1);
tree.put ("tcp_incoming_connections_max", std::numeric_limits<unsigned>::max ());
tree.put ("vote_generator_delay", std::numeric_limits<unsigned long>::max () - 100);
tree.put ("vote_generator_threshold", 10);
nano::jsonconfig txn_tracking_l;
txn_tracking_l.put ("enable", true);
txn_tracking_l.put ("min_read_txn_time", 1234);
txn_tracking_l.put ("min_write_txn_time", std::numeric_limits<unsigned>::max ());
txn_tracking_l.put ("ignore_writes_below_block_processor_max_time", false);
nano::jsonconfig diagnostics_l;
diagnostics_l.replace_child ("txn_tracking", txn_tracking_l);
tree.replace_child ("diagnostics", diagnostics_l);
tree.put ("use_memory_pools", false);
tree.put ("confirmation_history_size", std::numeric_limits<unsigned long long>::max ());
tree.put ("active_elections_size", std::numeric_limits<unsigned long long>::max ());
tree.put ("bandwidth_limit", std::numeric_limits<size_t>::max ());
tree.put ("conf_height_processor_batch_min_time", 500);
upgraded = false;
config.deserialize_json (upgraded, tree);
ASSERT_FALSE (upgraded);
ASSERT_EQ (config.tcp_io_timeout.count (), std::numeric_limits<unsigned long>::max () - 100);
ASSERT_EQ (config.pow_sleep_interval.count (), std::numeric_limits<unsigned long>::max () - 100);
ASSERT_EQ (config.external_address, "::ffff:192.168.1.1");
ASSERT_EQ (config.external_port, std::numeric_limits<uint16_t>::max () - 1);
ASSERT_EQ (config.tcp_incoming_connections_max, std::numeric_limits<unsigned>::max ());
ASSERT_EQ (config.vote_generator_delay.count (), std::numeric_limits<unsigned long>::max () - 100);
ASSERT_EQ (config.vote_generator_threshold, 10);
ASSERT_TRUE (config.diagnostics_config.txn_tracking.enable);
ASSERT_EQ (config.diagnostics_config.txn_tracking.min_read_txn_time.count (), 1234);
ASSERT_EQ (config.tcp_incoming_connections_max, std::numeric_limits<unsigned>::max ());
ASSERT_EQ (config.diagnostics_config.txn_tracking.min_write_txn_time.count (), std::numeric_limits<unsigned>::max ());
ASSERT_FALSE (config.diagnostics_config.txn_tracking.ignore_writes_below_block_processor_max_time);
ASSERT_FALSE (config.use_memory_pools);
ASSERT_EQ (config.confirmation_history_size, std::numeric_limits<unsigned long long>::max ());
ASSERT_EQ (config.active_elections_size, std::numeric_limits<unsigned long long>::max ());
ASSERT_EQ (config.bandwidth_limit, std::numeric_limits<size_t>::max ());
ASSERT_EQ (config.conf_height_processor_batch_min_time.count (), 500);
}
TEST (node_config, v17_v18_upgrade)
{
auto path (nano::unique_path ());
nano::jsonconfig tree;
add_required_children_node_config_tree (tree);
tree.put ("version", "17");
auto upgraded (false);
nano::node_config config;
config.logging.init (path);
// Initial values for configs that should be upgraded
config.active_elections_size = 50000;
config.vote_generator_delay = 500ms;
// These config options should not be present
ASSERT_FALSE (tree.get_optional_child ("backup_before_upgrade"));
ASSERT_FALSE (tree.get_optional_child ("work_watcher_period"));
config.deserialize_json (upgraded, tree);
// These configs should have been upgraded
ASSERT_EQ (100, tree.get<unsigned> ("vote_generator_delay"));
ASSERT_EQ (10000, tree.get<unsigned long long> ("active_elections_size"));
// The config options should be added after the upgrade
ASSERT_TRUE (!!tree.get_optional_child ("backup_before_upgrade"));
ASSERT_TRUE (!!tree.get_optional_child ("work_watcher_period"));
ASSERT_TRUE (upgraded);
auto version (tree.get<std::string> ("version"));
// Check version is updated
ASSERT_GT (std::stoull (version), 17);
}
TEST (node_config, v18_values)
{
nano::jsonconfig tree;
add_required_children_node_config_tree (tree);
auto path (nano::unique_path ());
auto upgraded (false);
nano::node_config config;
config.logging.init (path);
// Check config is correct
{
tree.put ("active_elections_size", 10000);
tree.put ("vote_generator_delay", 100);
tree.put ("backup_before_upgrade", true);
}
config.deserialize_json (upgraded, tree);
ASSERT_FALSE (upgraded);
ASSERT_EQ (config.active_elections_size, 10000);
ASSERT_EQ (config.vote_generator_delay.count (), 100);
ASSERT_EQ (config.backup_before_upgrade, true);
// Check config is correct with other values
tree.put ("active_elections_size", 5);
tree.put ("vote_generator_delay", std::numeric_limits<unsigned long>::max () - 100);
tree.put ("backup_before_upgrade", false);
upgraded = false;
config.deserialize_json (upgraded, tree);
ASSERT_FALSE (upgraded);
ASSERT_EQ (config.active_elections_size, 5);
ASSERT_EQ (config.vote_generator_delay.count (), std::numeric_limits<unsigned long>::max () - 100);
ASSERT_EQ (config.backup_before_upgrade, false);
}
// Regression test to ensure that deserializing includes changes node via get_required_child
TEST (node_config, required_child)
{
auto path (nano::unique_path ());
nano::logging logging1;
nano::logging logging2;
logging1.init (path);
nano::jsonconfig tree;
nano::jsonconfig logging_l;
logging1.serialize_json (logging_l);
tree.put_child ("logging", logging_l);
auto child_l (tree.get_required_child ("logging"));
child_l.put<bool> ("flush", !logging1.flush);
bool upgraded (false);
logging2.deserialize_json (upgraded, child_l);
ASSERT_NE (logging1.flush, logging2.flush);
}
TEST (node_config, random_rep)
{
auto path (nano::unique_path ());
@ -829,148 +589,6 @@ TEST (node_config, random_rep)
ASSERT_NE (config1.preconfigured_representatives.end (), std::find (config1.preconfigured_representatives.begin (), config1.preconfigured_representatives.end (), rep));
}
TEST (node_config, unsupported_version_upgrade)
{
auto path (nano::unique_path ());
nano::logging logging1;
logging1.init (path);
nano::node_config node_config (100, logging1);
nano::jsonconfig config;
node_config.serialize_json (config);
config.put ("version", "16"); // Version 16 and earlier is no longer supported for direct upgrade
nano::node_config node_config1;
bool upgraded{ false };
auto err = node_config1.deserialize_json (upgraded, config);
ASSERT_FALSE (upgraded);
ASSERT_TRUE (err);
}
class json_initial_value_test final
{
public:
explicit json_initial_value_test (std::string const & text_a) :
text (text_a)
{
}
nano::error serialize_json (nano::jsonconfig & json)
{
json.put ("thing", text);
return json.get_error ();
}
std::string text;
};
class json_upgrade_test final
{
public:
nano::error deserialize_json (bool & upgraded, nano::jsonconfig & json)
{
if (!json.empty ())
{
auto text_l (json.get<std::string> ("thing"));
if (text_l == "junktest" || text_l == "created")
{
upgraded = true;
text_l = "changed";
json.put ("thing", text_l);
}
if (text_l == "error")
{
json.get_error () = nano::error_common::generic;
}
text = text_l;
}
else
{
upgraded = true;
text = "created";
json.put ("thing", text);
}
return json.get_error ();
}
std::string text;
};
/** Both create and upgrade via read_and_update() */
TEST (json, create_and_upgrade)
{
auto path (nano::unique_path ());
nano::jsonconfig json;
json_upgrade_test object1;
ASSERT_FALSE (json.read_and_update (object1, path));
ASSERT_EQ ("created", object1.text);
nano::jsonconfig json2;
json_upgrade_test object2;
ASSERT_FALSE (json2.read_and_update (object2, path));
ASSERT_EQ ("changed", object2.text);
}
/** Create config manually, then upgrade via read_and_update() with multiple calls to test idempotence */
TEST (json, upgrade_from_existing)
{
auto path (nano::unique_path ());
nano::jsonconfig json;
json_initial_value_test junktest ("junktest");
junktest.serialize_json (json);
json.write (path);
json_upgrade_test object1;
ASSERT_FALSE (json.read_and_update (object1, path));
ASSERT_EQ ("changed", object1.text);
ASSERT_FALSE (json.read_and_update (object1, path));
ASSERT_EQ ("changed", object1.text);
}
/** Test that backups are made only when there is an upgrade */
TEST (json, backup)
{
auto dir (nano::unique_path ());
namespace fs = boost::filesystem;
fs::create_directory (dir);
auto path = dir / dir.leaf ();
// Create json file
nano::jsonconfig json;
json_upgrade_test object1;
ASSERT_FALSE (json.read_and_update (object1, path));
ASSERT_EQ ("created", object1.text);
/** Returns 'dir' if backup file cannot be found */
auto get_backup_path = [&dir] () {
for (fs::directory_iterator itr (dir); itr != fs::directory_iterator (); ++itr)
{
if (itr->path ().filename ().string ().find ("_backup_") != std::string::npos)
{
return itr->path ();
}
}
return dir;
};
auto get_file_count = [&dir] () {
return std::count_if (boost::filesystem::directory_iterator (dir), boost::filesystem::directory_iterator (), static_cast<bool (*) (boost::filesystem::path const &)> (boost::filesystem::is_regular_file));
};
// There should only be the original file in this directory
ASSERT_EQ (get_file_count (), 1);
ASSERT_EQ (get_backup_path (), dir);
// Upgrade, check that there is a backup which matches the first object
ASSERT_FALSE (json.read_and_update (object1, path));
ASSERT_EQ (get_file_count (), 2);
ASSERT_NE (get_backup_path (), path);
// Check there is a backup which has the same contents as the original file
nano::jsonconfig json1;
ASSERT_FALSE (json1.read (get_backup_path ()));
ASSERT_EQ (json1.get<std::string> ("thing"), "created");
// Try and upgrade an already upgraded file, should not create any backups
ASSERT_FALSE (json.read_and_update (object1, path));
ASSERT_EQ (get_file_count (), 2);
}
TEST (node_flags, disable_tcp_realtime)
{
nano::system system;
@ -4840,21 +4458,3 @@ TEST (node, pruning_depth)
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (send1->hash ())); // true for pruned
ASSERT_TRUE (node1.ledger.block_or_pruned_exists (send2->hash ()));
}
namespace
{
void add_required_children_node_config_tree (nano::jsonconfig & tree)
{
nano::logging logging1;
nano::jsonconfig logging_l;
logging1.serialize_json (logging_l);
tree.put_child ("logging", logging_l);
nano::jsonconfig preconfigured_peers_l;
tree.put_child ("preconfigured_peers", preconfigured_peers_l);
nano::jsonconfig preconfigured_representatives_l;
tree.put_child ("preconfigured_representatives", preconfigured_representatives_l);
nano::jsonconfig work_peers_l;
tree.put_child ("work_peers", work_peers_l);
tree.put ("version", std::to_string (nano::node_config::json_version ()));
}
}

View file

@ -1,6 +1,5 @@
#include <nano/crypto_lib/random_pool.hpp>
#include <nano/lib/blocks.hpp>
#include <nano/lib/jsonconfig.hpp>
#include <nano/lib/logger_mt.hpp>
#include <nano/lib/timer.hpp>
#include <nano/lib/work.hpp>
@ -115,21 +114,6 @@ TEST (work, opencl)
}
}
TEST (work, opencl_config)
{
nano::opencl_config config1;
config1.platform = 1;
config1.device = 2;
config1.threads = 3;
nano::jsonconfig tree;
config1.serialize_json (tree);
nano::opencl_config config2;
ASSERT_FALSE (config2.deserialize_json (tree));
ASSERT_EQ (1, config2.platform);
ASSERT_EQ (2, config2.device);
ASSERT_EQ (3, config2.threads);
}
TEST (work, difficulty)
{
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };

View file

@ -280,16 +280,6 @@ bool running_within_valgrind ()
return (RUNNING_ON_VALGRIND > 0);
}
std::string get_config_path (boost::filesystem::path const & data_path)
{
return (data_path / "config.json").string ();
}
std::string get_rpc_config_path (boost::filesystem::path const & data_path)
{
return (data_path / "rpc_config.json").string ();
}
std::string get_node_toml_config_path (boost::filesystem::path const & data_path)
{
return (data_path / "config-node.toml").string ();

View file

@ -281,8 +281,6 @@ public:
uint8_t const protocol_version_min = 0x12;
};
std::string get_config_path (boost::filesystem::path const & data_path);
std::string get_rpc_config_path (boost::filesystem::path const & data_path);
std::string get_node_toml_config_path (boost::filesystem::path const & data_path);
std::string get_rpc_toml_config_path (boost::filesystem::path const & data_path);
std::string get_access_toml_config_path (boost::filesystem::path const & data_path);

View file

@ -1,37 +1,6 @@
#include <nano/lib/diagnosticsconfig.hpp>
#include <nano/lib/jsonconfig.hpp>
#include <nano/lib/tomlconfig.hpp>
nano::error nano::diagnostics_config::serialize_json (nano::jsonconfig & json) const
{
nano::jsonconfig txn_tracking_l;
txn_tracking_l.put ("enable", txn_tracking.enable);
txn_tracking_l.put ("min_read_txn_time", txn_tracking.min_read_txn_time.count ());
txn_tracking_l.put ("min_write_txn_time", txn_tracking.min_write_txn_time.count ());
txn_tracking_l.put ("ignore_writes_below_block_processor_max_time", txn_tracking.ignore_writes_below_block_processor_max_time);
json.put_child ("txn_tracking", txn_tracking_l);
return json.get_error ();
}
nano::error nano::diagnostics_config::deserialize_json (nano::jsonconfig & json)
{
auto txn_tracking_l (json.get_optional_child ("txn_tracking"));
if (txn_tracking_l)
{
txn_tracking_l->get_optional<bool> ("enable", txn_tracking.enable);
auto min_read_txn_time_l = static_cast<unsigned long> (txn_tracking.min_read_txn_time.count ());
txn_tracking_l->get_optional ("min_read_txn_time", min_read_txn_time_l);
txn_tracking.min_read_txn_time = std::chrono::milliseconds (min_read_txn_time_l);
auto min_write_txn_time_l = static_cast<unsigned long> (txn_tracking.min_write_txn_time.count ());
txn_tracking_l->get_optional ("min_write_txn_time", min_write_txn_time_l);
txn_tracking.min_write_txn_time = std::chrono::milliseconds (min_write_txn_time_l);
txn_tracking_l->get_optional<bool> ("ignore_writes_below_block_processor_max_time", txn_tracking.ignore_writes_below_block_processor_max_time);
}
return json.get_error ();
}
nano::error nano::diagnostics_config::serialize_toml (nano::tomlconfig & toml) const
{
nano::tomlconfig txn_tracking_l;

View file

@ -22,8 +22,6 @@ public:
class diagnostics_config final
{
public:
nano::error serialize_json (nano::jsonconfig &) const;
nano::error deserialize_json (nano::jsonconfig &);
nano::error serialize_toml (nano::tomlconfig &) const;
nano::error deserialize_toml (nano::tomlconfig &);

View file

@ -30,43 +30,6 @@ public:
jsonconfig ();
jsonconfig (boost::property_tree::ptree & tree_a, std::shared_ptr<nano::error> const & error_a = nullptr);
nano::error & read (boost::filesystem::path const & path_a);
/**
* Reads a json object from the stream and if it was changed, write the object back to the stream.
* @return nano::error&, including a descriptive error message if the config file is malformed.
*/
template <typename T>
nano::error & read_and_update (T & object, boost::filesystem::path const & path_a)
{
auto file_exists (boost::filesystem::exists (path_a));
read (path_a);
if (!*error)
{
std::fstream stream;
auto updated (false);
*error = object.deserialize_json (updated, *this);
if (!*error && updated)
{
// Before updating the config file during an upgrade make a backup first
if (file_exists)
{
create_backup_file (path_a);
}
stream.open (path_a.string (), std::ios_base::out | std::ios_base::trunc);
try
{
write_json (stream);
}
catch (std::runtime_error const & ex)
{
*error = ex;
}
stream.close ();
}
}
return *error;
}
void write (boost::filesystem::path const & path_a);
void write (std::ostream & stream_a) const;
void read (std::istream & stream_a);

View file

@ -1,35 +1,10 @@
#include <nano/boost/asio/ip/address_v6.hpp>
#include <nano/lib/config.hpp>
#include <nano/lib/jsonconfig.hpp>
#include <nano/lib/rpcconfig.hpp>
#include <nano/lib/tomlconfig.hpp>
#include <boost/dll/runtime_symbol_info.hpp>
nano::error nano::rpc_secure_config::serialize_json (nano::jsonconfig & json) const
{
json.put ("enable", enable);
json.put ("verbose_logging", verbose_logging);
json.put ("server_key_passphrase", server_key_passphrase);
json.put ("server_cert_path", server_cert_path);
json.put ("server_key_path", server_key_path);
json.put ("server_dh_path", server_dh_path);
json.put ("client_certs_path", client_certs_path);
return json.get_error ();
}
nano::error nano::rpc_secure_config::deserialize_json (nano::jsonconfig & json)
{
json.get_required<bool> ("enable", enable);
json.get_required<bool> ("verbose_logging", verbose_logging);
json.get_required<std::string> ("server_key_passphrase", server_key_passphrase);
json.get_required<std::string> ("server_cert_path", server_cert_path);
json.get_required<std::string> ("server_key_path", server_key_path);
json.get_required<std::string> ("server_dh_path", server_dh_path);
json.get_required<std::string> ("client_certs_path", client_certs_path);
return json.get_error ();
}
nano::error nano::rpc_secure_config::serialize_toml (nano::tomlconfig & toml) const
{
toml.put ("enable", enable, "Enable or disable TLS support.\ntype:bool");
@ -68,63 +43,6 @@ nano::rpc_config::rpc_config (nano::network_constants & network_constants, uint1
{
}
nano::error nano::rpc_config::serialize_json (nano::jsonconfig & json) const
{
json.put ("version", json_version ());
json.put ("address", address);
json.put ("port", port);
json.put ("enable_control", enable_control);
json.put ("max_json_depth", max_json_depth);
json.put ("max_request_size", max_request_size);
nano::jsonconfig rpc_process_l;
rpc_process_l.put ("version", rpc_process.json_version ());
rpc_process_l.put ("io_threads", rpc_process.io_threads);
rpc_process_l.put ("ipc_address", rpc_process.ipc_address);
rpc_process_l.put ("ipc_port", rpc_process.ipc_port);
rpc_process_l.put ("num_ipc_connections", rpc_process.num_ipc_connections);
json.put_child ("process", rpc_process_l);
return json.get_error ();
}
nano::error nano::rpc_config::deserialize_json (bool & upgraded_a, nano::jsonconfig & json)
{
if (!json.empty ())
{
auto rpc_secure_l (json.get_optional_child ("secure"));
if (rpc_secure_l)
{
secure.deserialize_json (*rpc_secure_l);
}
boost::asio::ip::address_v6 address_l;
json.get_required<boost::asio::ip::address_v6> ("address", address_l, boost::asio::ip::address_v6::loopback ());
address = address_l.to_string ();
json.get_optional<uint16_t> ("port", port);
json.get_optional<bool> ("enable_control", enable_control);
json.get_optional<uint8_t> ("max_json_depth", max_json_depth);
json.get_optional<uint64_t> ("max_request_size", max_request_size);
auto rpc_process_l (json.get_optional_child ("process"));
if (rpc_process_l)
{
rpc_process_l->get_optional<unsigned> ("io_threads", rpc_process.io_threads);
rpc_process_l->get_optional<uint16_t> ("ipc_port", rpc_process.ipc_port);
boost::asio::ip::address_v6 ipc_address_l;
rpc_process_l->get_optional<boost::asio::ip::address_v6> ("ipc_address", ipc_address_l);
rpc_process.ipc_address = ipc_address_l.to_string ();
rpc_process_l->get_optional<unsigned> ("num_ipc_connections", rpc_process.num_ipc_connections);
}
}
else
{
upgraded_a = true;
serialize_json (json);
}
return json.get_error ();
}
nano::error nano::rpc_config::serialize_toml (nano::tomlconfig & toml) const
{
toml.put ("address", address, "Bind address for the RPC server.\ntype:string,ip");
@ -196,45 +114,7 @@ namespace nano
nano::error read_rpc_config_toml (boost::filesystem::path const & data_path_a, nano::rpc_config & config_a, std::vector<std::string> const & config_overrides)
{
nano::error error;
auto json_config_path = nano::get_rpc_config_path (data_path_a);
auto toml_config_path = nano::get_rpc_toml_config_path (data_path_a);
if (boost::filesystem::exists (json_config_path))
{
if (boost::filesystem::exists (toml_config_path))
{
error = "Both json and toml rpc configuration files exists. "
"Either remove the config.json file and restart, or remove "
"the config-rpc.toml file to start migration on next launch.";
}
else
{
// Migrate
nano::rpc_config config_json_l{ config_a.rpc_process.network_constants };
error = read_and_update_rpc_config (data_path_a, config_json_l);
if (!error)
{
nano::tomlconfig toml_l;
config_json_l.serialize_toml (toml_l);
// Only write out non-default values
nano::rpc_config config_defaults_l{ config_a.rpc_process.network_constants };
nano::tomlconfig toml_defaults_l;
config_defaults_l.serialize_toml (toml_defaults_l);
toml_l.erase_default_values (toml_defaults_l);
if (!toml_l.empty ())
{
toml_l.write (toml_config_path);
boost::system::error_code error_chmod;
nano::set_secure_perm_file (toml_config_path, error_chmod);
}
auto backup_path = data_path_a / "rpc_config_backup_toml_migration.json";
boost::filesystem::rename (json_config_path, backup_path);
}
}
}
// Parse and deserialize
nano::tomlconfig toml;
@ -267,16 +147,6 @@ nano::error read_rpc_config_toml (boost::filesystem::path const & data_path_a, n
return error;
}
nano::error read_and_update_rpc_config (boost::filesystem::path const & data_path, nano::rpc_config & config_a)
{
boost::system::error_code error_chmod;
nano::jsonconfig json;
auto config_path = nano::get_rpc_config_path (data_path);
auto error (json.read_and_update (config_a, config_path));
nano::set_secure_perm_file (config_path, error_chmod);
return error;
}
std::string get_default_rpc_filepath ()
{
boost::system::error_code err;

View file

@ -18,7 +18,6 @@ namespace filesystem
namespace nano
{
class jsonconfig;
class tomlconfig;
class tls_config;
@ -29,8 +28,6 @@ class tls_config;
class rpc_secure_config final
{
public:
nano::error serialize_json (nano::jsonconfig &) const;
nano::error deserialize_json (nano::jsonconfig &);
nano::error serialize_toml (nano::tomlconfig &) const;
nano::error deserialize_toml (nano::tomlconfig &);
@ -61,10 +58,6 @@ public:
uint16_t ipc_port{ network_constants.default_ipc_port };
unsigned num_ipc_connections{ (network_constants.is_live_network () || network_constants.is_test_network ()) ? 8u : network_constants.is_beta_network () ? 4u
: 1u };
static unsigned json_version ()
{
return 1;
}
};
class rpc_logging_config final
@ -78,8 +71,6 @@ class rpc_config final
public:
explicit rpc_config (nano::network_constants & network_constants);
explicit rpc_config (nano::network_constants & network_constants, uint16_t, bool);
nano::error serialize_json (nano::jsonconfig &) const;
nano::error deserialize_json (bool & upgraded_a, nano::jsonconfig &);
nano::error serialize_toml (nano::tomlconfig &) const;
nano::error deserialize_toml (nano::tomlconfig &);
@ -93,14 +84,9 @@ public:
nano::rpc_logging_config rpc_logging;
/** Optional TLS config */
std::shared_ptr<nano::tls_config> tls_config;
static unsigned json_version ()
{
return 1;
}
};
nano::error read_rpc_config_toml (boost::filesystem::path const & data_path_a, nano::rpc_config & config_a, std::vector<std::string> const & config_overrides = std::vector<std::string> ());
nano::error read_and_update_rpc_config (boost::filesystem::path const & data_path, nano::rpc_config & config_a);
std::string get_default_rpc_filepath ();
}

View file

@ -10,36 +10,6 @@
#include <fstream>
#include <sstream>
nano::error nano::stat_config::deserialize_json (nano::jsonconfig & json)
{
auto sampling_l (json.get_optional_child ("sampling"));
if (sampling_l)
{
sampling_l->get<bool> ("enabled", sampling_enabled);
sampling_l->get<size_t> ("capacity", capacity);
sampling_l->get<size_t> ("interval", interval);
}
auto log_l (json.get_optional_child ("log"));
if (log_l)
{
log_l->get<bool> ("headers", log_headers);
log_l->get<size_t> ("interval_counters", log_interval_counters);
log_l->get<size_t> ("interval_samples", log_interval_samples);
log_l->get<size_t> ("rotation_count", log_rotation_count);
log_l->get<std::string> ("filename_counters", log_counters_filename);
log_l->get<std::string> ("filename_samples", log_samples_filename);
// Don't allow specifying the same file name for counter and samples logs
if (log_counters_filename == log_samples_filename)
{
json.get_error ().set ("The statistics counter and samples config values must be different");
}
}
return json.get_error ();
}
nano::error nano::stat_config::deserialize_toml (nano::tomlconfig & toml)
{
auto sampling_l (toml.get_optional_child ("sampling"));

View file

@ -26,7 +26,6 @@ class stat_config final
{
public:
/** Reads the JSON statistics node */
nano::error deserialize_json (nano::jsonconfig & json);
nano::error deserialize_toml (nano::tomlconfig & toml);
nano::error serialize_toml (nano::tomlconfig & toml) const;

View file

@ -71,137 +71,11 @@ nano::error nano::daemon_config::deserialize_toml (nano::tomlconfig & toml)
return toml.get_error ();
}
nano::error nano::daemon_config::serialize_json (nano::jsonconfig & json)
{
json.put ("version", json_version ());
json.put ("rpc_enable", rpc_enable);
nano::jsonconfig rpc_l;
rpc.serialize_json (rpc_l);
json.put_child ("rpc", rpc_l);
nano::jsonconfig node_l;
node.serialize_json (node_l);
nano::jsonconfig node (node_l);
json.put_child ("node", node);
json.put ("opencl_enable", opencl_enable);
nano::jsonconfig opencl_l;
opencl.serialize_json (opencl_l);
json.put_child ("opencl", opencl_l);
return json.get_error ();
}
nano::error nano::daemon_config::deserialize_json (bool & upgraded_a, nano::jsonconfig & json)
{
try
{
if (!json.empty ())
{
json.get_optional<bool> ("rpc_enable", rpc_enable);
auto rpc_l (json.get_required_child ("rpc"));
if (!rpc.deserialize_json (upgraded_a, rpc_l, data_path))
{
auto node_l (json.get_required_child ("node"));
if (!json.get_error ())
{
node.deserialize_json (upgraded_a, node_l);
}
}
if (!json.get_error ())
{
json.get_required<bool> ("opencl_enable", opencl_enable);
auto opencl_l (json.get_required_child ("opencl"));
if (!json.get_error ())
{
opencl.deserialize_json (opencl_l);
}
}
}
else
{
upgraded_a = true;
serialize_json (json);
}
}
catch (std::runtime_error const & ex)
{
json.get_error () = ex;
}
return json.get_error ();
}
nano::error nano::read_node_config_toml (boost::filesystem::path const & data_path_a, nano::daemon_config & config_a, std::vector<std::string> const & config_overrides)
{
nano::error error;
auto json_config_path = nano::get_config_path (data_path_a);
auto toml_config_path = nano::get_node_toml_config_path (data_path_a);
auto toml_qt_config_path = nano::get_qtwallet_toml_config_path (data_path_a);
if (boost::filesystem::exists (json_config_path))
{
if (boost::filesystem::exists (toml_config_path))
{
error = "Both json and toml node configuration files exists. "
"Either remove the config.json file and restart, or remove "
"the config-node.toml file to start migration on next launch.";
}
else
{
// Migrate
nano::daemon_config config_old_l;
nano::jsonconfig json;
read_and_update_daemon_config (data_path_a, config_old_l, json);
error = json.get_error ();
// Move qt wallet entries to wallet config file
if (!error && json.has_key ("wallet") && json.has_key ("account"))
{
if (!boost::filesystem::exists (toml_config_path))
{
nano::wallet_config wallet_conf;
error = wallet_conf.parse (json.get<std::string> ("wallet"), json.get<std::string> ("account"));
if (!error)
{
nano::tomlconfig wallet_toml_l;
wallet_conf.serialize_toml (wallet_toml_l);
wallet_toml_l.write (toml_qt_config_path);
boost::system::error_code error_chmod;
nano::set_secure_perm_file (toml_qt_config_path, error_chmod);
}
}
else
{
std::cout << "Not migrating wallet and account as wallet config file already exists" << std::endl;
}
}
if (!error)
{
nano::tomlconfig toml_l;
config_old_l.serialize_toml (toml_l);
// Only write out non-default values
nano::daemon_config config_defaults_l;
nano::tomlconfig toml_defaults_l;
config_defaults_l.serialize_toml (toml_defaults_l);
toml_l.erase_default_values (toml_defaults_l);
if (!toml_l.empty ())
{
toml_l.write (toml_config_path);
boost::system::error_code error_chmod;
nano::set_secure_perm_file (toml_config_path, error_chmod);
}
auto backup_path = data_path_a / "config_backup_toml_migration.json";
boost::filesystem::rename (json_config_path, backup_path);
}
}
}
// Parse and deserialize
nano::tomlconfig toml;
@ -233,12 +107,3 @@ nano::error nano::read_node_config_toml (boost::filesystem::path const & data_pa
return error;
}
nano::error nano::read_and_update_daemon_config (boost::filesystem::path const & data_path, nano::daemon_config & config_a, nano::jsonconfig & json_a)
{
boost::system::error_code error_chmod;
auto config_path = nano::get_config_path (data_path);
auto error (json_a.read_and_update (config_a, config_path));
nano::set_secure_perm_file (config_path, error_chmod);
return error;
}

View file

@ -10,15 +10,12 @@
namespace nano
{
class jsonconfig;
class tomlconfig;
class daemon_config
{
public:
daemon_config () = default;
daemon_config (boost::filesystem::path const & data_path, nano::network_params & network_params);
nano::error deserialize_json (bool &, nano::jsonconfig &);
nano::error serialize_json (nano::jsonconfig &);
nano::error deserialize_toml (nano::tomlconfig &);
nano::error serialize_toml (nano::tomlconfig &);
bool rpc_enable{ false };
@ -28,12 +25,7 @@ public:
nano::opencl_config opencl;
nano::node_pow_server_config pow_server;
boost::filesystem::path data_path;
unsigned json_version () const
{
return 2;
}
};
nano::error read_node_config_toml (boost::filesystem::path const &, nano::daemon_config & config_a, std::vector<std::string> const & config_overrides = std::vector<std::string> ());
nano::error read_and_update_daemon_config (boost::filesystem::path const &, nano::daemon_config & config_a, nano::jsonconfig & json_a);
}

View file

@ -65,55 +65,3 @@ nano::error nano::ipc::ipc_config::deserialize_toml (nano::tomlconfig & toml)
return toml.get_error ();
}
nano::error nano::ipc::ipc_config::serialize_json (nano::jsonconfig & json) const
{
nano::jsonconfig tcp_l;
// Only write out experimental config values if they're previously set explicitly in the config file
if (transport_tcp.io_threads >= 0)
{
tcp_l.put ("io_threads", transport_tcp.io_threads);
}
tcp_l.put ("enable", transport_tcp.enabled);
tcp_l.put ("port", transport_tcp.port);
tcp_l.put ("io_timeout", transport_tcp.io_timeout);
json.put_child ("tcp", tcp_l);
nano::jsonconfig domain_l;
domain_l.put ("version", transport_domain.json_version ());
if (transport_domain.io_threads >= 0)
{
domain_l.put ("io_threads", transport_domain.io_threads);
}
domain_l.put ("enable", transport_domain.enabled);
domain_l.put ("allow_unsafe", transport_domain.allow_unsafe);
domain_l.put ("path", transport_domain.path);
domain_l.put ("io_timeout", transport_domain.io_timeout);
json.put_child ("local", domain_l);
return json.get_error ();
}
nano::error nano::ipc::ipc_config::deserialize_json (bool & upgraded_a, nano::jsonconfig & json)
{
auto tcp_l (json.get_optional_child ("tcp"));
if (tcp_l)
{
tcp_l->get_optional<long> ("io_threads", transport_tcp.io_threads, -1);
tcp_l->get_optional<bool> ("allow_unsafe", transport_tcp.allow_unsafe);
tcp_l->get<bool> ("enable", transport_tcp.enabled);
tcp_l->get<uint16_t> ("port", transport_tcp.port);
tcp_l->get<std::size_t> ("io_timeout", transport_tcp.io_timeout);
}
auto domain_l (json.get_optional_child ("local"));
if (domain_l)
{
domain_l->get_optional<long> ("io_threads", transport_domain.io_threads, -1);
domain_l->get_optional<bool> ("allow_unsafe", transport_domain.allow_unsafe);
domain_l->get<bool> ("enable", transport_domain.enabled);
domain_l->get<std::string> ("path", transport_domain.path);
domain_l->get<std::size_t> ("io_timeout", transport_domain.io_timeout);
}
return json.get_error ();
}

View file

@ -7,7 +7,6 @@
namespace nano
{
class jsonconfig;
class tomlconfig;
namespace ipc
{
@ -41,11 +40,6 @@ namespace ipc
* this value will be conditional on OS.
*/
std::string path{ "/tmp/nano" };
unsigned json_version () const
{
return 1;
}
};
/** TCP specific transport config */
@ -70,8 +64,6 @@ namespace ipc
transport_tcp{ network_constants }
{
}
nano::error deserialize_json (bool & upgraded_a, nano::jsonconfig & json_a);
nano::error serialize_json (nano::jsonconfig & json) const;
nano::error deserialize_toml (nano::tomlconfig & toml_a);
nano::error serialize_toml (nano::tomlconfig & toml) const;
ipc_config_domain_socket transport_domain;

View file

@ -216,95 +216,6 @@ nano::error nano::logging::deserialize_toml (nano::tomlconfig & toml)
return toml.get_error ();
}
nano::error nano::logging::serialize_json (nano::jsonconfig & json) const
{
json.put ("version", json_version ());
json.put ("ledger", ledger_logging_value);
json.put ("ledger_duplicate", ledger_duplicate_logging_value);
json.put ("vote", vote_logging_value);
json.put ("rep_crawler", rep_crawler_logging_value);
json.put ("network", network_logging_value);
json.put ("network_timeout", network_timeout_logging_value);
json.put ("network_message", network_message_logging_value);
json.put ("network_publish", network_publish_logging_value);
json.put ("network_packet", network_packet_logging_value);
json.put ("network_keepalive", network_keepalive_logging_value);
json.put ("network_node_id_handshake", network_node_id_handshake_logging_value);
json.put ("network_telemetry_logging", network_telemetry_logging_value);
json.put ("network_rejected_logging", network_rejected_logging_value);
json.put ("node_lifetime_tracing", node_lifetime_tracing_value);
json.put ("insufficient_work", insufficient_work_logging_value);
json.put ("log_ipc", log_ipc_value);
json.put ("bulk_pull", bulk_pull_logging_value);
json.put ("work_generation_time", work_generation_time_value);
json.put ("upnp_details", upnp_details_logging_value);
json.put ("timing", timing_logging_value);
json.put ("log_to_cerr", log_to_cerr_value);
json.put ("max_size", max_size);
json.put ("rotation_size", rotation_size);
json.put ("flush", flush);
json.put ("min_time_between_output", min_time_between_log_output.count ());
json.put ("single_line_record", single_line_record_value);
return json.get_error ();
}
bool nano::logging::upgrade_json (unsigned version_a, nano::jsonconfig & json)
{
json.put ("version", json_version ());
switch (version_a)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
throw std::runtime_error ("logging_config version is unsupported for upgrade. Upgrade to a v19, v20 or v21 node first, or delete the config and ledger files");
case 7:
json.put ("single_line_record", single_line_record_value);
case 8:
break;
default:
throw std::runtime_error ("Unknown logging_config version");
break;
}
return version_a < json_version ();
}
nano::error nano::logging::deserialize_json (bool & upgraded_a, nano::jsonconfig & json)
{
int version_l{ 1 };
json.get_required<int> ("version", version_l);
upgraded_a |= upgrade_json (version_l, json);
json.get<bool> ("ledger", ledger_logging_value);
json.get<bool> ("ledger_duplicate", ledger_duplicate_logging_value);
json.get<bool> ("vote", vote_logging_value);
json.get<bool> ("rep_crawler", rep_crawler_logging_value);
json.get<bool> ("network", network_logging_value);
json.get<bool> ("network_timeout", network_timeout_logging_value);
json.get<bool> ("network_message", network_message_logging_value);
json.get<bool> ("network_publish", network_publish_logging_value);
json.get<bool> ("network_packet", network_packet_logging_value);
json.get<bool> ("network_keepalive", network_keepalive_logging_value);
json.get<bool> ("network_node_id_handshake", network_node_id_handshake_logging_value);
json.get<bool> ("node_lifetime_tracing", node_lifetime_tracing_value);
json.get<bool> ("insufficient_work", insufficient_work_logging_value);
json.get<bool> ("log_ipc", log_ipc_value);
json.get<bool> ("bulk_pull", bulk_pull_logging_value);
json.get<bool> ("work_generation_time", work_generation_time_value);
json.get<bool> ("upnp_details", upnp_details_logging_value);
json.get<bool> ("timing", timing_logging_value);
json.get<bool> ("log_to_cerr", log_to_cerr_value);
json.get<bool> ("flush", flush);
json.get<bool> ("single_line_record", single_line_record_value);
json.get<uintmax_t> ("max_size", max_size);
json.get<uintmax_t> ("rotation_size", rotation_size);
uintmax_t min_time_between_log_output_raw;
json.get<uintmax_t> ("min_time_between_output", min_time_between_log_output_raw);
min_time_between_log_output = std::chrono::milliseconds (min_time_between_log_output_raw);
return json.get_error ();
}
bool nano::logging::ledger_logging () const
{
return ledger_logging_value;

View file

@ -33,15 +33,11 @@ namespace filesystem
namespace nano
{
class tomlconfig;
class jsonconfig;
class logging final
{
public:
nano::error serialize_json (nano::jsonconfig &) const;
nano::error deserialize_json (bool &, nano::jsonconfig &);
nano::error serialize_toml (nano::tomlconfig &) const;
nano::error deserialize_toml (nano::tomlconfig &);
bool upgrade_json (unsigned, nano::jsonconfig &);
bool ledger_logging () const;
bool ledger_duplicate_logging () const;
bool ledger_rollback_logging () const;
@ -103,10 +99,6 @@ public:
std::chrono::milliseconds min_time_between_log_output{ 5 };
bool single_line_record_value{ false };
static void release_file_sink ();
unsigned json_version () const
{
return 8;
}
private:
static boost::shared_ptr<boost::log::sinks::synchronous_sink<boost::log::sinks::text_file_backend>> file_sink;

View file

@ -5,18 +5,6 @@
#include <boost/property_tree/ptree.hpp>
nano::error nano::node_rpc_config::serialize_json (nano::jsonconfig & json) const
{
json.put ("version", json_version ());
json.put ("enable_sign_hash", enable_sign_hash);
nano::jsonconfig child_process_l;
child_process_l.put ("enable", child_process.enable);
child_process_l.put ("rpc_path", child_process.rpc_path);
json.put_child ("child_process", child_process_l);
return json.get_error ();
}
nano::error nano::node_rpc_config::serialize_toml (nano::tomlconfig & toml) const
{
toml.put ("enable_sign_hash", enable_sign_hash, "Allow or disallow signing of hashes.\ntype:bool");
@ -43,20 +31,6 @@ nano::error nano::node_rpc_config::deserialize_toml (nano::tomlconfig & toml)
return toml.get_error ();
}
nano::error nano::node_rpc_config::deserialize_json (bool & upgraded_a, nano::jsonconfig & json, boost::filesystem::path const & data_path)
{
json.get_optional<bool> ("enable_sign_hash", enable_sign_hash);
auto child_process_l (json.get_optional_child ("child_process"));
if (child_process_l)
{
child_process_l->get_optional<bool> ("enable", child_process.enable);
child_process_l->get_optional<std::string> ("rpc_path", child_process.rpc_path);
}
return json.get_error ();
}
void nano::node_rpc_config::set_request_callback (std::function<void (boost::property_tree::ptree const &)> callback_a)
{
request_callback = std::move (callback_a);

View file

@ -27,17 +27,11 @@ public:
class node_rpc_config final
{
public:
nano::error serialize_json (nano::jsonconfig &) const;
nano::error deserialize_json (bool & upgraded_a, nano::jsonconfig &, boost::filesystem::path const & data_path);
nano::error serialize_toml (nano::tomlconfig & toml) const;
nano::error deserialize_toml (nano::tomlconfig & toml);
bool enable_sign_hash{ false };
nano::rpc_child_process_config child_process;
static unsigned json_version ()
{
return 1;
}
// Used in tests to ensure requests are modified in specific cases
void set_request_callback (std::function<void (boost::property_tree::ptree const &)>);

View file

@ -452,289 +452,6 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml)
return toml.get_error ();
}
nano::error nano::node_config::serialize_json (nano::jsonconfig & json) const
{
json.put ("version", json_version ());
json.put ("peering_port", peering_port);
json.put ("bootstrap_fraction_numerator", bootstrap_fraction_numerator);
json.put ("receive_minimum", receive_minimum.to_string_dec ());
nano::jsonconfig logging_l;
logging.serialize_json (logging_l);
json.put_child ("logging", logging_l);
nano::jsonconfig work_peers_l;
for (auto i (work_peers.begin ()), n (work_peers.end ()); i != n; ++i)
{
work_peers_l.push (boost::str (boost::format ("%1%:%2%") % i->first % i->second));
}
json.put_child ("work_peers", work_peers_l);
nano::jsonconfig preconfigured_peers_l;
for (auto i (preconfigured_peers.begin ()), n (preconfigured_peers.end ()); i != n; ++i)
{
preconfigured_peers_l.push (*i);
}
json.put_child (preconfigured_peers_key, preconfigured_peers_l);
nano::jsonconfig preconfigured_representatives_l;
for (auto i (preconfigured_representatives.begin ()), n (preconfigured_representatives.end ()); i != n; ++i)
{
preconfigured_representatives_l.push (i->to_account ());
}
json.put_child ("preconfigured_representatives", preconfigured_representatives_l);
json.put ("online_weight_minimum", online_weight_minimum.to_string_dec ());
json.put ("password_fanout", password_fanout);
json.put ("io_threads", io_threads);
json.put ("network_threads", network_threads);
json.put ("work_threads", work_threads);
json.put (signature_checker_threads_key, signature_checker_threads);
json.put ("enable_voting", enable_voting);
json.put ("bootstrap_connections", bootstrap_connections);
json.put ("bootstrap_connections_max", bootstrap_connections_max);
json.put ("callback_address", callback_address);
json.put ("callback_port", callback_port);
json.put ("callback_target", callback_target);
json.put ("block_processor_batch_max_time", block_processor_batch_max_time.count ());
json.put ("allow_local_peers", allow_local_peers);
json.put ("vote_minimum", vote_minimum.to_string_dec ());
json.put ("vote_generator_delay", vote_generator_delay.count ());
json.put ("vote_generator_threshold", vote_generator_threshold);
json.put ("unchecked_cutoff_time", unchecked_cutoff_time.count ());
json.put ("tcp_io_timeout", tcp_io_timeout.count ());
json.put ("pow_sleep_interval", pow_sleep_interval.count ());
json.put ("external_address", external_address);
json.put ("external_port", external_port);
json.put ("tcp_incoming_connections_max", tcp_incoming_connections_max);
json.put ("use_memory_pools", use_memory_pools);
json.put ("rep_crawler_weight_minimum", online_weight_minimum.to_string_dec ());
nano::jsonconfig websocket_l;
websocket_config.serialize_json (websocket_l);
json.put_child ("websocket", websocket_l);
nano::jsonconfig ipc_l;
ipc_config.serialize_json (ipc_l);
json.put_child ("ipc", ipc_l);
nano::jsonconfig diagnostics_l;
diagnostics_config.serialize_json (diagnostics_l);
json.put_child ("diagnostics", diagnostics_l);
json.put ("confirmation_history_size", confirmation_history_size);
json.put ("active_elections_size", active_elections_size);
json.put ("bandwidth_limit", bandwidth_limit);
json.put ("backup_before_upgrade", backup_before_upgrade);
json.put ("work_watcher_period", 5);
return json.get_error ();
}
bool nano::node_config::upgrade_json (unsigned version_a, nano::jsonconfig & json)
{
json.put ("version", json_version ());
switch (version_a)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
throw std::runtime_error ("node_config version unsupported for upgrade. Upgrade to a v19, v20 or v21 node first, or delete the config and ledger files");
case 17:
{
json.put ("active_elections_size", 10000); // Update value
json.put ("vote_generator_delay", 100); // Update value
json.put ("backup_before_upgrade", backup_before_upgrade);
json.put ("work_watcher_period", 5);
}
case 18:
break;
default:
throw std::runtime_error ("Unknown node_config version");
}
return version_a < json_version ();
}
nano::error nano::node_config::deserialize_json (bool & upgraded_a, nano::jsonconfig & json)
{
try
{
auto version_l (json.get<unsigned> ("version"));
upgraded_a |= upgrade_json (version_l, json);
auto logging_l (json.get_required_child ("logging"));
logging.deserialize_json (upgraded_a, logging_l);
work_peers.clear ();
auto work_peers_l (json.get_required_child ("work_peers"));
work_peers_l.array_entries<std::string> ([this] (std::string entry) {
auto port_position (entry.rfind (':'));
bool result = port_position == -1;
if (!result)
{
auto port_str (entry.substr (port_position + 1));
uint16_t port;
result |= parse_port (port_str, port);
if (!result)
{
auto address (entry.substr (0, port_position));
this->work_peers.emplace_back (address, port);
}
}
});
auto preconfigured_peers_l (json.get_required_child (preconfigured_peers_key));
preconfigured_peers.clear ();
preconfigured_peers_l.array_entries<std::string> ([this] (std::string entry) {
preconfigured_peers.push_back (entry);
});
auto preconfigured_representatives_l (json.get_required_child ("preconfigured_representatives"));
preconfigured_representatives.clear ();
preconfigured_representatives_l.array_entries<std::string> ([this, &json] (std::string entry) {
nano::account representative{};
if (representative.decode_account (entry))
{
json.get_error ().set ("Invalid representative account: " + entry);
}
preconfigured_representatives.push_back (representative);
});
if (preconfigured_representatives.empty ())
{
json.get_error ().set ("At least one representative account must be set");
}
auto stat_config_l (json.get_optional_child ("statistics"));
if (stat_config_l)
{
stat_config.deserialize_json (stat_config_l.get ());
}
auto receive_minimum_l (json.get<std::string> ("receive_minimum"));
if (receive_minimum.decode_dec (receive_minimum_l))
{
json.get_error ().set ("receive_minimum contains an invalid decimal amount");
}
auto online_weight_minimum_l (json.get<std::string> ("online_weight_minimum"));
if (online_weight_minimum.decode_dec (online_weight_minimum_l))
{
json.get_error ().set ("online_weight_minimum contains an invalid decimal amount");
}
auto rep_crawler_weight_minimum_l (json.get<std::string> ("rep_crawler_weight_minimum"));
if (rep_crawler_weight_minimum.decode_dec (rep_crawler_weight_minimum_l))
{
json.get_error ().set ("rep_crawler_weight_minimum contains an invalid decimal amount");
}
auto vote_minimum_l (json.get<std::string> ("vote_minimum"));
if (vote_minimum.decode_dec (vote_minimum_l))
{
json.get_error ().set ("vote_minimum contains an invalid decimal amount");
}
auto delay_l = vote_generator_delay.count ();
json.get ("vote_generator_delay", delay_l);
vote_generator_delay = std::chrono::milliseconds (delay_l);
json.get<unsigned> ("vote_generator_threshold", vote_generator_threshold);
auto block_processor_batch_max_time_l (json.get<unsigned long> ("block_processor_batch_max_time"));
block_processor_batch_max_time = std::chrono::milliseconds (block_processor_batch_max_time_l);
auto unchecked_cutoff_time_l = static_cast<unsigned long> (unchecked_cutoff_time.count ());
json.get ("unchecked_cutoff_time", unchecked_cutoff_time_l);
unchecked_cutoff_time = std::chrono::seconds (unchecked_cutoff_time_l);
auto tcp_io_timeout_l = static_cast<unsigned long> (tcp_io_timeout.count ());
json.get ("tcp_io_timeout", tcp_io_timeout_l);
tcp_io_timeout = std::chrono::seconds (tcp_io_timeout_l);
auto ipc_config_l (json.get_optional_child ("ipc"));
if (ipc_config_l)
{
ipc_config.deserialize_json (upgraded_a, ipc_config_l.get ());
}
auto websocket_config_l (json.get_optional_child ("websocket"));
if (websocket_config_l)
{
websocket_config.deserialize_json (websocket_config_l.get ());
}
auto diagnostics_config_l (json.get_optional_child ("diagnostics"));
if (diagnostics_config_l)
{
diagnostics_config.deserialize_json (diagnostics_config_l.get ());
}
json.get<uint16_t> ("peering_port", peering_port);
json.get<unsigned> ("bootstrap_fraction_numerator", bootstrap_fraction_numerator);
json.get<unsigned> ("password_fanout", password_fanout);
json.get<unsigned> ("io_threads", io_threads);
json.get<unsigned> ("work_threads", work_threads);
json.get<unsigned> ("network_threads", network_threads);
json.get<unsigned> ("bootstrap_connections", bootstrap_connections);
json.get<unsigned> ("bootstrap_connections_max", bootstrap_connections_max);
json.get<std::string> ("callback_address", callback_address);
json.get<uint16_t> ("callback_port", callback_port);
json.get<std::string> ("callback_target", callback_target);
json.get<bool> ("enable_voting", enable_voting);
json.get<bool> ("allow_local_peers", allow_local_peers);
json.get<unsigned> (signature_checker_threads_key, signature_checker_threads);
boost::asio::ip::address_v6 external_address_l;
json.get<boost::asio::ip::address_v6> ("external_address", external_address_l);
external_address = external_address_l.to_string ();
json.get<uint16_t> ("external_port", external_port);
json.get<unsigned> ("tcp_incoming_connections_max", tcp_incoming_connections_max);
auto pow_sleep_interval_l (pow_sleep_interval.count ());
json.get (pow_sleep_interval_key, pow_sleep_interval_l);
pow_sleep_interval = std::chrono::nanoseconds (pow_sleep_interval_l);
json.get<bool> ("use_memory_pools", use_memory_pools);
json.get<std::size_t> ("confirmation_history_size", confirmation_history_size);
json.get<std::size_t> ("active_elections_size", active_elections_size);
json.get<std::size_t> ("bandwidth_limit", bandwidth_limit);
json.get<bool> ("backup_before_upgrade", backup_before_upgrade);
auto conf_height_processor_batch_min_time_l (conf_height_processor_batch_min_time.count ());
json.get ("conf_height_processor_batch_min_time", conf_height_processor_batch_min_time_l);
conf_height_processor_batch_min_time = std::chrono::milliseconds (conf_height_processor_batch_min_time_l);
// Validate ranges
if (password_fanout < 16 || password_fanout > 1024 * 1024)
{
json.get_error ().set ("password_fanout must be a number between 16 and 1048576");
}
if (io_threads == 0)
{
json.get_error ().set ("io_threads must be non-zero");
}
if (active_elections_size <= 250 && !network_params.network.is_dev_network ())
{
json.get_error ().set ("active_elections_size must be greater than 250");
}
if (bandwidth_limit > std::numeric_limits<std::size_t>::max ())
{
json.get_error ().set ("bandwidth_limit unbounded = 0, default = 10485760, max = 18446744073709551615");
}
if (vote_generator_threshold < 1 || vote_generator_threshold > 11)
{
json.get_error ().set ("vote_generator_threshold must be a number between 1 and 11");
}
}
catch (std::runtime_error const & ex)
{
json.get_error ().set (ex.what ());
}
return json.get_error ();
}
std::string nano::node_config::serialize_frontiers_confirmation (nano::frontiers_confirmation_mode mode_a) const
{
switch (mode_a)

View file

@ -3,7 +3,6 @@
#include <nano/lib/config.hpp>
#include <nano/lib/diagnosticsconfig.hpp>
#include <nano/lib/errors.hpp>
#include <nano/lib/jsonconfig.hpp>
#include <nano/lib/lmdbconfig.hpp>
#include <nano/lib/numbers.hpp>
#include <nano/lib/rocksdbconfig.hpp>
@ -36,8 +35,6 @@ class node_config
public:
node_config (nano::network_params & network_params = nano::dev::network_params);
node_config (uint16_t, nano::logging const &, nano::network_params & network_params = nano::dev::network_params);
nano::error serialize_json (nano::jsonconfig &) const;
nano::error deserialize_json (bool &, nano::jsonconfig &);
nano::error serialize_toml (nano::tomlconfig &) const;
nano::error deserialize_toml (nano::tomlconfig &);
bool upgrade_json (unsigned, nano::jsonconfig &);
@ -110,11 +107,6 @@ public:
nano::frontiers_confirmation_mode deserialize_frontiers_confirmation (std::string const &);
/** Entry is ignored if it cannot be parsed as a valid address:port */
void deserialize_address (std::string const &, std::vector<std::pair<std::string, uint16_t>> &) const;
static unsigned json_version ()
{
return 18;
}
};
class node_flags final

View file

@ -9,22 +9,6 @@ nano::opencl_config::opencl_config (unsigned platform_a, unsigned device_a, unsi
{
}
nano::error nano::opencl_config::serialize_json (nano::jsonconfig & json) const
{
json.put ("platform", platform);
json.put ("device", device);
json.put ("threads", threads);
return json.get_error ();
}
nano::error nano::opencl_config::deserialize_json (nano::jsonconfig & json)
{
json.get_optional<unsigned> ("platform", platform);
json.get_optional<unsigned> ("device", device);
json.get_optional<unsigned> ("threads", threads);
return json.get_error ();
}
nano::error nano::opencl_config::serialize_toml (nano::tomlconfig & toml) const
{
toml.put ("platform", platform);

View file

@ -4,15 +4,12 @@
namespace nano
{
class jsonconfig;
class tomlconfig;
class opencl_config
{
public:
opencl_config () = default;
opencl_config (unsigned, unsigned, unsigned);
nano::error serialize_json (nano::jsonconfig &) const;
nano::error deserialize_json (nano::jsonconfig &);
nano::error serialize_toml (nano::tomlconfig &) const;
nano::error deserialize_toml (nano::tomlconfig &);
unsigned platform{ 0 };

View file

@ -1,5 +1,4 @@
#include <nano/boost/asio/ip/address_v6.hpp>
#include <nano/lib/jsonconfig.hpp>
#include <nano/lib/tomlconfig.hpp>
#include <nano/node/websocketconfig.hpp>
@ -27,21 +26,3 @@ nano::error nano::websocket::config::deserialize_toml (nano::tomlconfig & toml)
toml.get<uint16_t> ("port", port);
return toml.get_error ();
}
nano::error nano::websocket::config::serialize_json (nano::jsonconfig & json) const
{
json.put ("enable", enabled);
json.put ("address", address);
json.put ("port", port);
return json.get_error ();
}
nano::error nano::websocket::config::deserialize_json (nano::jsonconfig & json)
{
json.get<bool> ("enable", enabled);
boost::asio::ip::address_v6 address_l;
json.get_required<boost::asio::ip::address_v6> ("address", address_l, boost::asio::ip::address_v6::loopback ());
address = address_l.to_string ();
json.get<uint16_t> ("port", port);
return json.get_error ();
}

View file

@ -7,7 +7,6 @@
namespace nano
{
class jsonconfig;
class tomlconfig;
class tls_config;
namespace websocket
@ -17,8 +16,6 @@ namespace websocket
{
public:
config (nano::network_constants & network_constants);
nano::error deserialize_json (nano::jsonconfig & json_a);
nano::error serialize_json (nano::jsonconfig & json) const;
nano::error deserialize_toml (nano::tomlconfig & toml_a);
nano::error serialize_toml (nano::tomlconfig & toml) const;
nano::network_constants & network_constants;

View file

@ -5592,40 +5592,6 @@ TEST (rpc, in_process)
ASSERT_EQ ("0", pending_text);
}
TEST (rpc_config, serialization)
{
nano::rpc_config config1{ nano::dev::network_params.network };
config1.address = boost::asio::ip::address_v6::any ().to_string ();
config1.port = 10;
config1.enable_control = true;
config1.max_json_depth = 10;
config1.rpc_process.io_threads = 2;
config1.rpc_process.ipc_address = boost::asio::ip::address_v6::any ().to_string ();
config1.rpc_process.ipc_port = 2000;
config1.rpc_process.num_ipc_connections = 99;
nano::jsonconfig tree;
config1.serialize_json (tree);
nano::rpc_config config2{ nano::dev::network_params.network };
ASSERT_NE (config2.address, config1.address);
ASSERT_NE (config2.port, config1.port);
ASSERT_NE (config2.enable_control, config1.enable_control);
ASSERT_NE (config2.max_json_depth, config1.max_json_depth);
ASSERT_NE (config2.rpc_process.io_threads, config1.rpc_process.io_threads);
ASSERT_NE (config2.rpc_process.ipc_address, config1.rpc_process.ipc_address);
ASSERT_NE (config2.rpc_process.ipc_port, config1.rpc_process.ipc_port);
ASSERT_NE (config2.rpc_process.num_ipc_connections, config1.rpc_process.num_ipc_connections);
bool upgraded{ false };
config2.deserialize_json (upgraded, tree);
ASSERT_EQ (config2.address, config1.address);
ASSERT_EQ (config2.port, config1.port);
ASSERT_EQ (config2.enable_control, config1.enable_control);
ASSERT_EQ (config2.max_json_depth, config1.max_json_depth);
ASSERT_EQ (config2.rpc_process.io_threads, config1.rpc_process.io_threads);
ASSERT_EQ (config2.rpc_process.ipc_address, config1.rpc_process.ipc_address);
ASSERT_EQ (config2.rpc_process.ipc_port, config1.rpc_process.ipc_port);
ASSERT_EQ (config2.rpc_process.num_ipc_connections, config1.rpc_process.num_ipc_connections);
}
TEST (rpc, deprecated_account_format)
{
nano::system system;