mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
blockstorage: do not flush block to disk if it is already there
test: ensure we can reindex from read-only block files now
This commit is contained in:
parent
d14c7286b6
commit
dfcef536d0
2 changed files with 17 additions and 16 deletions
|
@ -906,7 +906,6 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne
|
||||||
if (!fKnown) {
|
if (!fKnown) {
|
||||||
LogPrint(BCLog::BLOCKSTORAGE, "Leaving block file %i: %s (onto %i) (height %i)\n",
|
LogPrint(BCLog::BLOCKSTORAGE, "Leaving block file %i: %s (onto %i) (height %i)\n",
|
||||||
last_blockfile, m_blockfile_info[last_blockfile].ToString(), nFile, nHeight);
|
last_blockfile, m_blockfile_info[last_blockfile].ToString(), nFile, nHeight);
|
||||||
}
|
|
||||||
|
|
||||||
// Do not propagate the return code. The flush concerns a previous block
|
// Do not propagate the return code. The flush concerns a previous block
|
||||||
// and undo file that has already been written to. If a flush fails
|
// and undo file that has already been written to. If a flush fails
|
||||||
|
@ -920,6 +919,7 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne
|
||||||
"Failed to flush previous block file %05i (finalize=%i, finalize_undo=%i) before opening new block file %05i\n",
|
"Failed to flush previous block file %05i (finalize=%i, finalize_undo=%i) before opening new block file %05i\n",
|
||||||
last_blockfile, !fKnown, finalize_undo, nFile);
|
last_blockfile, !fKnown, finalize_undo, nFile);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// No undo data yet in the new file, so reset our undo-height tracking.
|
// No undo data yet in the new file, so reset our undo-height tracking.
|
||||||
m_blockfile_cursors[chain_type] = BlockfileCursor{nFile};
|
m_blockfile_cursors[chain_type] = BlockfileCursor{nFile};
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ class BlockstoreReindexTest(BitcoinTestFramework):
|
||||||
opreturn = "6a"
|
opreturn = "6a"
|
||||||
nulldata = fastprune_blockfile_size * "ff"
|
nulldata = fastprune_blockfile_size * "ff"
|
||||||
self.generateblock(self.nodes[0], output=f"raw({opreturn}{nulldata})", transactions=[])
|
self.generateblock(self.nodes[0], output=f"raw({opreturn}{nulldata})", transactions=[])
|
||||||
|
block_count = self.nodes[0].getblockcount()
|
||||||
self.stop_node(0)
|
self.stop_node(0)
|
||||||
|
|
||||||
assert (self.nodes[0].chain_path / "blocks" / "blk00000.dat").exists()
|
assert (self.nodes[0].chain_path / "blocks" / "blk00000.dat").exists()
|
||||||
|
@ -73,10 +74,10 @@ class BlockstoreReindexTest(BitcoinTestFramework):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if undo_immutable:
|
if undo_immutable:
|
||||||
self.log.info("Attempt to restart and reindex the node with the unwritable block file")
|
self.log.debug("Attempt to restart and reindex the node with the unwritable block file")
|
||||||
with self.nodes[0].assert_debug_log(expected_msgs=['FlushStateToDisk', 'failed to open file'], unexpected_msgs=[]):
|
with self.nodes[0].wait_for_debug_log([b"Reindexing finished"]):
|
||||||
self.nodes[0].assert_start_raises_init_error(extra_args=['-reindex', '-fastprune'],
|
self.start_node(0, extra_args=['-reindex', '-fastprune'])
|
||||||
expected_msg="Error: A fatal internal error occurred, see debug.log for details")
|
assert block_count == self.nodes[0].getblockcount()
|
||||||
undo_immutable()
|
undo_immutable()
|
||||||
|
|
||||||
filename.chmod(0o777)
|
filename.chmod(0o777)
|
||||||
|
|
Loading…
Add table
Reference in a new issue