From 9d39546390fa2483ba23bd80204a6fc42aa33192 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Thu, 22 Jun 2017 15:49:17 -0500 Subject: [PATCH] Iterating through duplicate keys for unchecked blocks. --- rai/secure.cpp | 12 +++++++++++- rai/secure.hpp | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/rai/secure.cpp b/rai/secure.cpp index 556d9581..e610e771 100644 --- a/rai/secure.cpp +++ b/rai/secure.cpp @@ -1477,6 +1477,16 @@ rai::store_iterator & rai::store_iterator::operator ++ () return *this; } +void rai::store_iterator::next_dup () +{ + assert (cursor != nullptr); + auto status (mdb_cursor_get (cursor, ¤t.first, ¤t.second, MDB_NEXT_DUP)); + if (status == MDB_NOTFOUND) + { + current.clear (); + } +} + rai::store_iterator & rai::store_iterator::operator = (rai::store_iterator && other_a) { if (cursor != nullptr) @@ -2346,7 +2356,7 @@ void rai::block_store::unchecked_put (MDB_txn * transaction_a, rai::block_hash c std::vector > rai::block_store::unchecked_get (MDB_txn * transaction_a, rai::block_hash const & hash_a) { std::vector > result; - for (auto i (unchecked_begin (transaction_a, hash_a)), n (unchecked_begin (transaction_a, hash_a.number () + 1)); i != n && rai::block_hash (i->first) == hash_a; ++i) + for (auto i (unchecked_begin (transaction_a, hash_a)), n (unchecked_end ()); i != n && rai::block_hash (i->first) == hash_a; i.next_dup ()) { rai::bufferstream stream (reinterpret_cast (i->second.mv_data), i->second.mv_size); result.push_back (rai::deserialize_block (stream)); diff --git a/rai/secure.hpp b/rai/secure.hpp index 4c4c558b..d51f750c 100644 --- a/rai/secure.hpp +++ b/rai/secure.hpp @@ -273,6 +273,7 @@ public: store_iterator (rai::store_iterator const &) = delete; ~store_iterator (); rai::store_iterator & operator ++ (); + void next_dup(); rai::store_iterator & operator = (rai::store_iterator &&); rai::store_iterator & operator = (rai::store_iterator const &) = delete; rai::store_entry & operator -> ();