Skip to content

Commit

Permalink
fix merkle data racing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyShi22 committed Jan 18, 2024
1 parent 1a059a2 commit 3de96ac
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions bcos-ledger/src/libledger/Ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ static std::shared_ptr<std::vector<h256>> getMerkleTreeFromCache(int64_t blockNu
else
{
merkleTree = merkleTreePtr.get();
LEDGER_LOG(DEBUG) << LOG_BADGE(cacheName) << LOG_DESC("Hit cache")
LEDGER_LOG(DEBUG) << LOG_BADGE(cacheName) << LOG_DESC("Hit ptr cache")
<< LOG_KV("blockNumber", blockNumber);
}
}
Expand All @@ -1491,13 +1491,20 @@ static std::shared_ptr<std::vector<h256>> getMerkleTreeFromCache(int64_t blockNu
merkle.template generateMerkle(hashesRange, *newMerkleTree);
{
RecursiveGuard l(mutex);
*merkleTree = std::move(*newMerkleTree);
if (!merkleTree->empty())
{
LEDGER_LOG(DEBUG) << LOG_BADGE(cacheName) << LOG_DESC("Hit cache")
<< LOG_KV("blockNumber", blockNumber);
}
else
{
*merkleTree = std::move(*newMerkleTree);
LEDGER_LOG(DEBUG)
<< LOG_BADGE(cacheName)
<< LOG_DESC("Failed to hit the cache and build a new Merkel tree from scratch")
<< LOG_KV("blockNumber", blockNumber);
}
}

LEDGER_LOG(DEBUG) << LOG_BADGE(cacheName)
<< LOG_DESC(
"Failed to hit the cache and build a new Merkel tree from scratch")
<< LOG_KV("blockNumber", blockNumber);
}

return merkleTree;
Expand Down

0 comments on commit 3de96ac

Please sign in to comment.