Add --clear_send_ids (#1163)

This commit is contained in:
Lee Bousfield 2018-09-10 14:45:10 -05:00 committed by Roy Keene
commit 75b465201f
3 changed files with 26 additions and 0 deletions

View file

@ -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<std::string> (), "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 <key>")
@ -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<std::string> ()) : 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);

View file

@ -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<rai::uint128_t>::max ();
rai::uint128_t const rai::wallets::high_priority = std::numeric_limits<rai::uint128_t>::max () - 1;

View file

@ -175,6 +175,7 @@ public:
void foreach_representative (rai::transaction const &, std::function<void(rai::public_key const &, rai::raw_key const &)> const &);
bool exists (rai::transaction const &, rai::public_key const &);
void stop ();
void clear_send_ids (rai::transaction const &);
std::function<void(bool)> observer;
std::unordered_map<rai::uint256_union, std::shared_ptr<rai::wallet>> items;
std::multimap<rai::uint128_t, std::function<void()>, std::greater<rai::uint128_t>> actions;