Skip to content

Commit a1c3627

Browse files
committed
[fuzz] Assert that omitting missing transactions always fails block reconstruction
1 parent a8ac61a commit a1c3627

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/test/fuzz/partially_downloaded_block.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ FUZZ_TARGET_INIT(partially_downloaded_block, initialize_pdb)
8282
auto init_status{pdb.InitData(cmpctblock, extra_txn)};
8383

8484
std::vector<CTransactionRef> missing;
85+
// Whether we skipped a transaction that should be included in `missing`.
86+
// FillBlock should never return READ_STATUS_OK if that is the case.
87+
bool skipped_missing{false};
8588
for (size_t i = 0; i < cmpctblock.BlockTxCount(); i++) {
8689
// If init_status == READ_STATUS_OK then a available transaction in the
8790
// compact block (i.e. IsTxAvailable(i) == true) implies that we marked
@@ -97,6 +100,8 @@ FUZZ_TARGET_INIT(partially_downloaded_block, initialize_pdb)
97100
if (!pdb.IsTxAvailable(i) && !skip) {
98101
missing.push_back(block->vtx[i]);
99102
}
103+
104+
skipped_missing |= (!pdb.IsTxAvailable(i) && skip);
100105
}
101106

102107
// Mock CheckBlock
@@ -123,6 +128,7 @@ FUZZ_TARGET_INIT(partially_downloaded_block, initialize_pdb)
123128
auto fill_status{pdb.FillBlock(reconstructed_block, missing)};
124129
switch (fill_status) {
125130
case READ_STATUS_OK:
131+
assert(!skipped_missing);
126132
assert(!fail_check_block);
127133
assert(block->GetHash() == reconstructed_block.GetHash());
128134
break;

0 commit comments

Comments
 (0)