From a00b7dd505dffa61c5c7796302177cd5fcc8c481 Mon Sep 17 00:00:00 2001 From: 0xFFFC0000 <0xFFFC0000@proton.me> Date: Mon, 31 Mar 2025 08:54:36 +0000 Subject: [PATCH] blockchain_db: fix remove_block * remove_block should set the cursor before deletion --- src/blockchain_db/lmdb/db_lmdb.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index ff44923ff..45addff03 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -880,9 +880,13 @@ void BlockchainLMDB::remove_block() if ((result = mdb_cursor_del(m_cur_block_heights, 0))) throw1(DB_ERROR(lmdb_error("Failed to add removal of block height by hash to db transaction: ", result).c_str())); + MDB_val block_val; + // Use MDB_SET to position the cursor directly at the key + // If this fails, the DB is inconsistent (info/height exists, but block data doesn't) + if ((result = mdb_cursor_get(m_cur_blocks, &k, &block_val, MDB_SET))) + throw1(DB_ERROR(lmdb_error("Failed to locate block data for removal: ", result).c_str())); if ((result = mdb_cursor_del(m_cur_blocks, 0))) throw1(DB_ERROR(lmdb_error("Failed to add removal of block to db transaction: ", result).c_str())); - if ((result = mdb_cursor_del(m_cur_block_info, 0))) throw1(DB_ERROR(lmdb_error("Failed to add removal of block info to db transaction: ", result).c_str())); }