You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rpc: check block index before reading block / undo data
This avoids low-level log errors that are supposed to only occur when
there is an actual problem with the block on disk missing unexpectedly,
but not in the case where the block and/or undo data are expected not to be there.
It changes behavior such that in the first case (block index indicates
data is available but retrieving it fails) an error is thrown.
It also adjusts a functional tests that tried to simulate not
having undo data (but having block data) by deleting the undo file.
This situation should occur reality because block and undo data are pruned together.
Instead, test this situation with a block that hasn't been connected.
if (have_undo && !blockman.UndoReadFromDisk(blockUndo, blockindex)) {
206
+
throwJSONRPCError(RPC_INTERNAL_ERROR, "Undo data expected but can't be read. This could be due to disk corruption or a conflict with a pruning event.");
207
+
}
206
208
for (size_t i = 0; i < block.vtx.size(); ++i) {
207
209
const CTransactionRef& tx = block.vtx.at(i);
208
210
// coinbase transaction (i.e. i == 0) doesn't have undo data
if (!chainman.m_blockman.UndoReadFromDisk(blockUndo, *blockindex)) {
413
+
throwJSONRPCError(RPC_INTERNAL_ERROR, "Undo data expected but can't be read. This could be due to disk corruption or a conflict with a pruning event.");
414
+
}
415
+
if (!chainman.m_blockman.ReadBlockFromDisk(block, *blockindex)) {
416
+
throwJSONRPCError(RPC_INTERNAL_ERROR, "Block data expected but can't be read. This could be due to disk corruption or a conflict with a pruning event.");
417
+
}
413
418
414
419
CTxUndo* undoTX {nullptr};
415
420
auto it = std::find_if(block.vtx.begin(), block.vtx.end(), [tx](CTransactionRef t){ return *t == *tx; });
# Move instead of deleting so we can restore chain state afterwards
623
625
move_block_file('rev00000.dat', 'rev_wrong')
624
626
625
-
assert_fee_not_in_block(2)
626
-
assert_fee_not_in_block(3)
627
-
assert_vin_does_not_contain_prevout(2)
628
-
assert_vin_does_not_contain_prevout(3)
627
+
assert_raises_rpc_error(-32603, "Undo data expected but can't be read. This could be due to disk corruption or a conflict with a pruning event.", lambda: node.getblock(blockhash, 2))
628
+
assert_raises_rpc_error(-32603, "Undo data expected but can't be read. This could be due to disk corruption or a conflict with a pruning event.", lambda: node.getblock(blockhash, 3))
0 commit comments