From 0a6cb30d625fa66f8d54ae06bae966ac7f434f8d Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 17 Mar 2019 10:31:44 +0000 Subject: wallet: flush output cache upon reorg Fixes output usage tracking --- src/wallet/wallet2.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/wallet/wallet2.cpp') diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 11be8fd6e..90b7c9fa9 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2399,7 +2399,7 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector= 10) + if (m_track_uses && (!output_tracker_cache || output_tracker_cache->empty()) && next_blocks.size() >= 10) output_tracker_cache = create_output_tracker_cache(); // switch to the new blocks from the daemon @@ -3130,7 +3130,7 @@ bool wallet2::get_rct_distribution(uint64_t &start_height, std::vector return true; } //---------------------------------------------------------------------------------------------------- -void wallet2::detach_blockchain(uint64_t height) +void wallet2::detach_blockchain(uint64_t height, std::map, size_t> *output_tracker_cache) { LOG_PRINT_L0("Detaching blockchain on height " << height); @@ -3152,6 +3152,15 @@ void wallet2::detach_blockchain(uint64_t height) } } + for (transfer_details &td: m_transfers) + { + while (!td.m_uses.empty() && td.m_uses.back().first >= height) + td.m_uses.pop_back(); + } + + if (output_tracker_cache) + output_tracker_cache->clear(); + auto it = std::find_if(m_transfers.begin(), m_transfers.end(), [&](const transfer_details& td){return td.m_block_height >= height;}); size_t i_start = it - m_transfers.begin(); -- cgit v1.2.3