Merge pull request #10573

a00b7dd blockchain_db: fix remove_block     * remove_block should set the cursor before deletion (0xFFFC0000)
This commit is contained in:
tobtoht
2026-05-10 17:45:50 +00:00
+5 -1
View File
@@ -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()));
}