From 99d5b835461c5689843efb8508035855a53ed43d Mon Sep 17 00:00:00 2001 From: PiRK Date: Mon, 23 Jan 2023 16:08:15 +0100 Subject: [PATCH] Require CBlockIndex::GetUndoPos() to hold mutex cs_main Summary: This is a partial backport of [[https://github.com/bitcoin/bitcoin/pull/22932 | core#22932]] https://github.com/bitcoin/bitcoin/pull/22932/commits/572393448b4d32f91b92edc84b4200ab52d62422 Depends on D13032 Test Plan: With clang and DEBUG: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D13033 --- src/blockindex.h | 3 ++- src/node/blockstorage.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/blockindex.h b/src/blockindex.h index a774a40375..04163d8c69 100644 --- a/src/blockindex.h +++ b/src/blockindex.h @@ -121,7 +121,8 @@ class CBlockIndex { return ret; } - FlatFilePos GetUndoPos() const { + FlatFilePos GetUndoPos() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { + AssertLockHeld(::cs_main); FlatFilePos ret; if (nStatus.hasUndo()) { ret.nFile = nFile; diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 3b49382563..df52066e4f 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -480,7 +480,8 @@ static bool UndoWriteToDisk(const CBlockUndo &blockundo, FlatFilePos &pos, } 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__); }