Skip to content

Commit

Permalink
Fix race condition in unchecked_map where a block may be asynchronous…
Browse files Browse the repository at this point in the history
…ly inserted and a dependency satisfied while a block is waiting to be placed in the unchecked table.

This change checks if the dependency has been satisfied before placing it in the unchecked map.
  • Loading branch information
clemahieu committed Feb 1, 2023
1 parent 16e5ccf commit a1e359b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion nano/node/unchecked_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ void nano::unchecked_map::run ()

void nano::unchecked_map::insert_impl (nano::write_transaction const & transaction, nano::hash_or_account const & dependency, nano::unchecked_info const & info)
{
// Check if block dependency has been satisfied while waiting to be placed in the unchecked map
if (store.block.exists (transaction, dependency.as_block_hash ()))
{
satisfied (info);
return;
}
nano::lock_guard<std::recursive_mutex> lock{ entries_mutex };
// Check if we should be using memory but the memory container hasn't been constructed i.e. we're transitioning from disk to memory.
if (entries == nullptr && use_memory ())
Expand All @@ -221,7 +227,7 @@ void nano::unchecked_map::insert_impl (nano::write_transaction const & transacti
}
if (entries == nullptr)
{
store.unchecked.put (transaction, dependency, { info.block });
store.unchecked.put (transaction, dependency, info);
}
else
{
Expand Down

0 comments on commit a1e359b

Please # to comment.