From 5b6bcca32a8b6e5a926888131af5c42203af055f Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 4 Aug 2018 12:37:39 +0000 Subject: [PATCH 1/3] wallet2: fix checking the wrong vector when adding hashes The two vectors should be the same size anyway, so add an assert to catch any case where they aren't --- src/wallet/wallet2.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 9deaad09b..7ef49c27d 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1976,9 +1976,11 @@ void wallet2::pull_and_parse_next_blocks(uint64_t start_height, uint64_t &blocks { drop_from_short_history(short_chain_history, 3); + THROW_WALLET_EXCEPTION_IF(prev_blocks.size() != prev_parsed_blocks.size(), error::wallet_internal_error, "size mismatch"); + // prepend the last 3 blocks, should be enough to guard against a block or two's reorg std::vector::const_reverse_iterator i = prev_parsed_blocks.rbegin(); - for (size_t n = 0; n < std::min((size_t)3, prev_blocks.size()); ++n) + for (size_t n = 0; n < std::min((size_t)3, prev_parsed_blocks.size()); ++n) { short_chain_history.push_front(i->hash); ++i; From b219c24c3a2576161b7eb58120123b278c5b1be7 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 4 Aug 2018 12:38:55 +0000 Subject: [PATCH 2/3] wallet2: trim hash chain after fast refresh of hashes This ensures it can't end up filled with the actual placeholders --- src/wallet/wallet2.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 7ef49c27d..8da62c76d 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2292,6 +2292,7 @@ void wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, while (missing_blocks-- > 0) m_blockchain.push_back(crypto::null_hash); // maybe a bit suboptimal, but deque won't do huge reallocs like vector m_blockchain.push_back(m_checkpoints.get_points().at(checkpoint_height)); + m_blockchain.trim(checkpoint_height); short_chain_history.clear(); get_short_chain_history(short_chain_history); } From 62511df622262ed1fcb73c3092f0c072ed93cc00 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 4 Aug 2018 12:41:15 +0000 Subject: [PATCH 3/3] wallet2: fix refresh retry when a block/tx fails to parse It would switch to a new set of blocks and fail, getting out of sync with the hash chain in the process --- src/wallet/wallet2.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 8da62c76d..f4b6708fc 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2498,10 +2498,6 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo break; } - // switch to the new blocks from the daemon - blocks_start_height = next_blocks_start_height; - blocks = std::move(next_blocks); - parsed_blocks = std::move(next_parsed_blocks); first = false; // handle error from async fetching thread @@ -2509,6 +2505,11 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo { throw std::runtime_error("proxy exception in refresh thread"); } + + // switch to the new blocks from the daemon + blocks_start_height = next_blocks_start_height; + blocks = std::move(next_blocks); + parsed_blocks = std::move(next_parsed_blocks); } catch (const std::exception&) {