From 751077c6e25e010cff85fe9793a8c5b843350f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Tue, 1 Apr 2025 15:46:23 +0200 Subject: [PATCH] Coins: Add `kHeader` to `CDBBatch::size_estimate` The initialization of the manual `size_estimate` in `CDBBatch::Clear()` is corrected from `0` to `kHeader` (LevelDB's fixed batch header size). This aligns the manual estimate with LevelDB's actual size immediately after clearing, fixing discrepancies that would otherwise be caught by tests in the next commit (e.g., `coins_tests`, `validation_chainstatemanager_tests`). --- src/dbwrapper.cpp | 8 ++++++-- src/dbwrapper.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index b3faff10cea..f4935c4f357 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -158,14 +158,18 @@ struct CDBBatch::WriteBatchImpl { CDBBatch::CDBBatch(const CDBWrapper& _parent) : parent{_parent}, - m_impl_batch{std::make_unique()} {}; + m_impl_batch{std::make_unique()} +{ + Clear(); +}; CDBBatch::~CDBBatch() = default; void CDBBatch::Clear() { m_impl_batch->batch.Clear(); - size_estimate = 0; + assert(m_impl_batch->batch.ApproximateSize() == kHeader); + size_estimate = kHeader; // TODO remove } void CDBBatch::WriteImpl(std::span key, DataStream& ssValue) diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 98446361e4e..1ff7dc1d2ee 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -75,6 +75,8 @@ class CDBBatch friend class CDBWrapper; private: + static constexpr size_t kHeader{12}; // See: src/leveldb/db/write_batch.cc#L27 + const CDBWrapper &parent; struct WriteBatchImpl;