diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 31afd0b9e..26680c3da 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -116,7 +116,7 @@ namespace tools void crop(size_t height) { m_blockchain.resize(height - m_offset); } void clear() { m_offset = 0; m_blockchain.clear(); } bool empty() const { return m_blockchain.empty() && m_offset == 0; } - void trim(size_t height) { while (height > m_offset+1 && m_blockchain.size() > 1) { m_blockchain.pop_front(); ++m_offset; } m_blockchain.shrink_to_fit(); } + void trim(size_t height) { while (height > m_offset && m_blockchain.size() > 1) { m_blockchain.pop_front(); ++m_offset; } m_blockchain.shrink_to_fit(); } void refill(const crypto::hash &hash) { m_blockchain.push_back(hash); --m_offset; } template diff --git a/tests/unit_tests/hashchain.cpp b/tests/unit_tests/hashchain.cpp index 0fa0f784a..e764f6afc 100644 --- a/tests/unit_tests/hashchain.cpp +++ b/tests/unit_tests/hashchain.cpp @@ -122,7 +122,7 @@ TEST(hashchain, trim) ASSERT_EQ(hashchain.size(), 3); ASSERT_EQ(hashchain[2], make_hash(3)); hashchain.trim(3); - ASSERT_EQ(hashchain.offset(), 3); + ASSERT_EQ(hashchain.offset(), 2); // never gets it empty ASSERT_EQ(hashchain.size(), 3); ASSERT_FALSE(hashchain.empty()); ASSERT_EQ(hashchain.genesis(), make_hash(1));