Skip to content

Commit abd5f46

Browse files
committedSep 18, 2024··
the ugliest hack ever
leveldb supports prefixing querying , seems mdbx does not so just write an empty hash value to fake the prefix querying leveldb was doing before
1 parent ec03b63 commit abd5f46

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed
 

‎src/dbwrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ MDBXWrapper::MDBXWrapper(const DBParams& params)
438438

439439
// initialize the mdbx environment.
440440
DBContext().env = mdbx::env_managed(params.path, DBContext().create_params, DBContext().operate_params);
441-
441+
442442
auto txn = DBContext().env.start_read();
443443
DBContext().map = txn.open_map(nullptr, mdbx::key_mode::usual, mdbx::value_mode::single);
444444
txn.commit();

‎src/node/blockstorage.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ bool BlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockFi
8989
for (const CBlockIndex* bi : blockinfo) {
9090
batch.Write(std::make_pair(DB_BLOCK_INDEX, bi->GetBlockHash()), CDiskBlockIndex{bi});
9191
}
92+
batch.Write(std::make_pair(DB_BLOCK_INDEX, uint256()), CDiskBlockIndex());
9293
return m_db->WriteBatch(batch, true);
9394
}
9495

@@ -112,6 +113,9 @@ bool BlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, s
112113
AssertLockHeld(::cs_main);
113114
std::unique_ptr<CDBIteratorBase> pcursor(m_db->NewIterator());
114115
pcursor->Seek(std::make_pair(DB_BLOCK_INDEX, uint256()));
116+
// assert(pcursor->Valid());
117+
// hack: skip the dummy value and start at the next one
118+
if (pcursor->Valid()) pcursor->Next();
115119

116120
// Load m_block_index
117121
while (pcursor->Valid()) {

0 commit comments

Comments
 (0)
Please sign in to comment.