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.

This commit is contained in:
clemahieu 2017-08-04 13:14:08 -05:00
commit 8d2768f8d2
2 changed files with 18 additions and 1 deletions

View file

@ -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 <rai::send_block> (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);

View file

@ -2350,7 +2350,7 @@ void rai::block_store::unchecked_cache_flush (MDB_txn * transaction_a)
std::vector <std::shared_ptr <rai::block>> rai::block_store::unchecked_get (MDB_txn * transaction_a, rai::block_hash const & hash_a)
{
std::vector <std::shared_ptr <rai::block>> 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);
}