diff --git a/rai/node/cli.cpp b/rai/node/cli.cpp index a2acd2d6..783c0ca2 100644 --- a/rai/node/cli.cpp +++ b/rai/node/cli.cpp @@ -32,6 +32,7 @@ void rai::add_node_options (boost::program_options::options_description & descri ("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)") ("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 ") @@ -159,6 +160,11 @@ std::error_code rai::handle_node_options (boost::program_options::variables_map auto transaction (node.node->store.tx_begin_write ()); node.node->store.delete_node_id (transaction); } + if (vm.count ("clear_send_ids")) + { + auto transaction (node.node->store.tx_begin_write ()); + node.node->wallets.clear_send_ids (transaction); + } success = node.node->copy_with_compaction (vacuum_path); } @@ -206,6 +212,11 @@ std::error_code rai::handle_node_options (boost::program_options::variables_map auto transaction (node.node->store.tx_begin_write ()); node.node->store.delete_node_id (transaction); } + if (vm.count ("clear_send_ids")) + { + auto transaction (node.node->store.tx_begin_write ()); + node.node->wallets.clear_send_ids (transaction); + } success = node.node->copy_with_compaction (snapshot_path); } if (success) @@ -238,6 +249,14 @@ std::error_code rai::handle_node_options (boost::program_options::variables_map node.node->store.delete_node_id (transaction); std::cerr << "Deleted Node ID" << std::endl; } + else if (vm.count ("clear_send_ids")) + { + boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as ()) : rai::working_path (); + inactive_node node (data_path); + auto transaction (node.node->store.tx_begin_write ()); + node.node->wallets.clear_send_ids (transaction); + std::cerr << "Send IDs deleted" << std::endl; + } else if (vm.count ("diagnostics")) { inactive_node node (data_path); diff --git a/rai/node/wallet.cpp b/rai/node/wallet.cpp index 8edf2e33..bb6bdda7 100644 --- a/rai/node/wallet.cpp +++ b/rai/node/wallet.cpp @@ -1429,6 +1429,12 @@ rai::transaction rai::wallets::tx_begin (bool write_a) return env.tx_begin (write_a); } +void rai::wallets::clear_send_ids (rai::transaction const & transaction_a) +{ + auto status (mdb_drop (env.tx (transaction_a), send_action_ids, 0)); + assert (status == 0); +} + rai::uint128_t const rai::wallets::generate_priority = std::numeric_limits::max (); rai::uint128_t const rai::wallets::high_priority = std::numeric_limits::max () - 1; diff --git a/rai/node/wallet.hpp b/rai/node/wallet.hpp index 39837ecf..7b854102 100644 --- a/rai/node/wallet.hpp +++ b/rai/node/wallet.hpp @@ -175,6 +175,7 @@ public: void foreach_representative (rai::transaction const &, std::function const &); bool exists (rai::transaction const &, rai::public_key const &); void stop (); + void clear_send_ids (rai::transaction const &); std::function observer; std::unordered_map> items; std::multimap, std::greater> actions;