From 8d2768f8d2547414cd87ae0f1a54c0af7cda8215 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Fri, 4 Aug 2017 13:14:08 -0500 Subject: [PATCH] Search for the hash we're looking for instead of starting at the beginning. This would also cause unchecked_get to miss blocks in the cache if they weren't the first iterated item. --- rai/core_test/block_store.cpp | 17 +++++++++++++++++ rai/secure.cpp | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/rai/core_test/block_store.cpp b/rai/core_test/block_store.cpp index 3b59e886..4f872984 100644 --- a/rai/core_test/block_store.cpp +++ b/rai/core_test/block_store.cpp @@ -193,6 +193,23 @@ TEST (bootstrap, simple) ASSERT_TRUE (block4.empty ()); } +TEST (unchecked, multiple) +{ + bool init (false); + rai::block_store store (init, rai::unique_path ()); + ASSERT_TRUE (!init); + auto block1 (std::make_shared (4, 1, 2, rai::keypair ().prv, 4, 5)); + rai::transaction transaction (store.environment, nullptr, true); + auto block2 (store.unchecked_get (transaction, block1->previous ())); + ASSERT_TRUE (block2.empty ()); + store.unchecked_put (transaction, block1->previous (), block1); + store.unchecked_put (transaction, block1->source (), block1); + auto block3 (store.unchecked_get (transaction, block1->previous ())); + ASSERT_FALSE (block3.empty ()); + auto block4 (store.unchecked_get (transaction, block1->source ())); + ASSERT_FALSE (block4.empty ()); +} + TEST (checksum, simple) { bool init (false); diff --git a/rai/secure.cpp b/rai/secure.cpp index be8afb66..1ddf8d4d 100644 --- a/rai/secure.cpp +++ b/rai/secure.cpp @@ -2350,7 +2350,7 @@ void rai::block_store::unchecked_cache_flush (MDB_txn * transaction_a) std::vector > rai::block_store::unchecked_get (MDB_txn * transaction_a, rai::block_hash const & hash_a) { std::vector > result; - for (auto i (unchecked_cache.begin ()), n (unchecked_cache.end ()); i != n && i->first == hash_a; ++i) + for (auto i (unchecked_cache.find (hash_a)), n (unchecked_cache.end ()); i != n && i->first == hash_a; ++i) { result.push_back (i->second); }