diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index 6172a145..8ea8d622 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -29,10 +29,12 @@ void nano::add_node_options (boost::program_options::options_description & descr ("account_key", "Get the public key for ") ("vacuum", "Compact database. If data_path is missing, the database in data directory is compacted.") ("snapshot", "Compact database and create snapshot, functions similar to vacuum but does not replace the existing database") - ("unchecked_clear", "Clear unchecked blocks") ("data_path", boost::program_options::value (), "Use the supplied path as the data directory") - ("delete_node_id", "Delete the node ID in the database") ("clear_send_ids", "Remove all send IDs from the database (dangerous: not intended for production use)") + ("delete_node_id", "Delete the node ID in the database") + ("online_weight_clear", "Clear online weight history records") + ("peer_clear", "Clear online peers database dump") + ("unchecked_clear", "Clear unchecked blocks") ("diagnostics", "Run internal diagnostics") ("key_create", "Generates a adhoc random keypair and prints it to stdout") ("key_expand", "Derive public key and account number from ") @@ -163,9 +165,19 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map } if (vm.count ("clear_send_ids")) { - auto transaction (node.node->store.tx_begin_write ()); + auto transaction (node.node->wallets.tx_begin_write ()); node.node->wallets.clear_send_ids (transaction); } + if (vm.count ("online_weight_clear")) + { + auto transaction (node.node->store.tx_begin_write ()); + node.node->store.online_weight_clear (transaction); + } + if (vm.count ("peer_clear")) + { + auto transaction (node.node->store.tx_begin_write ()); + node.node->store.peer_clear (transaction); + } success = node.node->copy_with_compaction (vacuum_path); } @@ -219,9 +231,19 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map } if (vm.count ("clear_send_ids")) { - auto transaction (node.node->store.tx_begin_write ()); + auto transaction (node.node->wallets.tx_begin_write ()); node.node->wallets.clear_send_ids (transaction); } + if (vm.count ("online_weight_clear")) + { + auto transaction (node.node->store.tx_begin_write ()); + node.node->store.online_weight_clear (transaction); + } + if (vm.count ("peer_clear")) + { + auto transaction (node.node->store.tx_begin_write ()); + node.node->store.peer_clear (transaction); + } success = node.node->copy_with_compaction (snapshot_path); } if (success) @@ -262,10 +284,26 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map { boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as ()) : nano::working_path (); inactive_node node (data_path); - auto transaction (node.node->store.tx_begin_write ()); + auto transaction (node.node->wallets.tx_begin_write ()); node.node->wallets.clear_send_ids (transaction); std::cerr << "Send IDs deleted" << std::endl; } + else if (vm.count ("online_weight_clear")) + { + boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as ()) : nano::working_path (); + inactive_node node (data_path); + auto transaction (node.node->store.tx_begin_write ()); + node.node->store.online_weight_clear (transaction); + std::cerr << "Onine weight records are removed" << std::endl; + } + else if (vm.count ("peer_clear")) + { + boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as ()) : nano::working_path (); + inactive_node node (data_path); + auto transaction (node.node->store.tx_begin_write ()); + node.node->store.peer_clear (transaction); + std::cerr << "Database peers are removed" << std::endl; + } else if (vm.count ("diagnostics")) { inactive_node node (data_path); diff --git a/nano/node/lmdb.cpp b/nano/node/lmdb.cpp index f55beec5..6ffffd97 100644 --- a/nano/node/lmdb.cpp +++ b/nano/node/lmdb.cpp @@ -2180,6 +2180,12 @@ size_t nano::mdb_store::online_weight_count (nano::transaction const & transacti return online_weight_stats.ms_entries; } +void nano::mdb_store::online_weight_clear (nano::transaction const & transaction_a) +{ + auto status (mdb_drop (env.tx (transaction_a), online_weight, 0)); + release_assert (status == 0); +} + void nano::mdb_store::flush (nano::transaction const & transaction_a) { { diff --git a/nano/node/lmdb.hpp b/nano/node/lmdb.hpp index 8ff7ed66..fbaedb76 100644 --- a/nano/node/lmdb.hpp +++ b/nano/node/lmdb.hpp @@ -244,6 +244,7 @@ public: nano::store_iterator online_weight_begin (nano::transaction const &) override; nano::store_iterator online_weight_end () override; size_t online_weight_count (nano::transaction const &) const override; + void online_weight_clear (nano::transaction const &) override; std::mutex cache_mutex; std::unordered_map> vote_cache_l1; diff --git a/nano/secure/blockstore.hpp b/nano/secure/blockstore.hpp index 166bc86a..de36ce12 100644 --- a/nano/secure/blockstore.hpp +++ b/nano/secure/blockstore.hpp @@ -293,6 +293,7 @@ public: virtual nano::store_iterator online_weight_begin (nano::transaction const &) = 0; virtual nano::store_iterator online_weight_end () = 0; virtual size_t online_weight_count (nano::transaction const &) const = 0; + virtual void online_weight_clear (nano::transaction const &) = 0; virtual void version_put (nano::transaction const &, int) = 0; virtual int version_get (nano::transaction const &) = 0;