aboutsummaryrefslogtreecommitdiff
path: root/src/node/blockstorage.h
diff options
context:
space:
mode:
authormruddy <6440430+mruddy@users.noreply.github.com>2022-04-14 18:44:34 -0400
committermruddy <6440430+mruddy@users.noreply.github.com>2022-05-07 07:11:29 -0400
commitbcb0cacac28e98a39dc856c574a0872fe17059e9 (patch)
treefe1cc8fb1af65d3a1e2ae1a4ff79139af15f734c /src/node/blockstorage.h
parent59ac8bacd573891d84e8ab96ff43ea12bd266f26 (diff)
reindex, log, test: fixes #21379
This fixes a blk file size calculation made during reindex that results in increased blk file malformity. The fix is to avoid double counting the size of the serialization header during reindex. This adds a unit test to reproduce the bug before the fix and to ensure that it does not recur. These changes include a log message change also so as to not be as alarming. This is a common and recoverable data corruption. These messages can now be filtered by the debug log reindex category.
Diffstat (limited to 'src/node/blockstorage.h')
-rw-r--r--src/node/blockstorage.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
index 488713dbd8..8e49254e76 100644
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -44,6 +44,9 @@ static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
/** The maximum size of a blk?????.dat file (since 0.8) */
static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
+/** Size of header written by WriteBlockToDisk before a serialized CBlock */
+static constexpr size_t BLOCK_SERIALIZATION_HEADER_SIZE = CMessageHeader::MESSAGE_START_SIZE + sizeof(unsigned int);
+
extern std::atomic_bool fImporting;
extern std::atomic_bool fReindex;
/** Pruning-related variables and constants */
@@ -171,6 +174,7 @@ public:
bool WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex* pindex, const CChainParams& chainparams)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+ /** Store block on disk. If dbp is not nullptr, then it provides the known position of the block within a block file on disk. */
FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp);
/** Calculate the amount of disk space the block & undo files currently use */