Skip to content

Commit 751077c

Browse files
committed
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`).
1 parent 0dc74c9 commit 751077c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/dbwrapper.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,18 @@ struct CDBBatch::WriteBatchImpl {
158158

159159
CDBBatch::CDBBatch(const CDBWrapper& _parent)
160160
: parent{_parent},
161-
m_impl_batch{std::make_unique<CDBBatch::WriteBatchImpl>()} {};
161+
m_impl_batch{std::make_unique<CDBBatch::WriteBatchImpl>()}
162+
{
163+
Clear();
164+
};
162165

163166
CDBBatch::~CDBBatch() = default;
164167

165168
void CDBBatch::Clear()
166169
{
167170
m_impl_batch->batch.Clear();
168-
size_estimate = 0;
171+
assert(m_impl_batch->batch.ApproximateSize() == kHeader);
172+
size_estimate = kHeader; // TODO remove
169173
}
170174

171175
void CDBBatch::WriteImpl(std::span<const std::byte> key, DataStream& ssValue)

src/dbwrapper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class CDBBatch
7575
friend class CDBWrapper;
7676

7777
private:
78+
static constexpr size_t kHeader{12}; // See: src/leveldb/db/write_batch.cc#L27
79+
7880
const CDBWrapper &parent;
7981

8082
struct WriteBatchImpl;

0 commit comments

Comments
 (0)