aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2021-09-09 18:48:22 +0200
committerJon Atack <jon@atack.com>2022-01-25 20:43:22 +0100
commit572393448b4d32f91b92edc84b4200ab52d62422 (patch)
tree853d70a4fc427391ff7389f51e5ab9cf178adbc0
parent2e557ced2830fc54476e598d52225f1679205e7d (diff)
Require CBlockIndex::GetUndoPos() to hold mutex cs_main
-rw-r--r--src/chain.h3
-rw-r--r--src/node/blockstorage.cpp3
2 files changed, 4 insertions, 2 deletions
diff --git a/src/chain.h b/src/chain.h
index 534f226f28..fc89599bd1 100644
--- a/src/chain.h
+++ b/src/chain.h
@@ -237,8 +237,9 @@ public:
return ret;
}
- FlatFilePos GetUndoPos() const
+ FlatFilePos GetUndoPos() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
{
+ AssertLockHeld(::cs_main);
FlatFilePos ret;
if (nStatus & BLOCK_HAVE_UNDO) {
ret.nFile = nFile;
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index 526100f1b2..2c18ee0c7d 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -513,7 +513,8 @@ static bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const
bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex)
{
- FlatFilePos pos = pindex->GetUndoPos();
+ const FlatFilePos pos{WITH_LOCK(::cs_main, return pindex->GetUndoPos())};
+
if (pos.IsNull()) {
return error("%s: no undo data available", __func__);
}