Skip to content

Commit 1ead2b6

Browse files
committed
f - Batch pending tx confirmations into a single block
1 parent 4f5de12 commit 1ead2b6

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,45 @@ impl ChainState {
251251
self.pending_txs.push(tx);
252252
}
253253

254-
/// Confirm pending transactions, selecting deterministically among conflicting RBF candidates.
255-
/// Sorting by txid before confirming means the winner depends on the fuzz input (which
256-
/// determines tx content and thus txid), while `confirm_tx` rejects double-spends so only one
257-
/// conflicting tx confirms.
254+
/// Confirm pending transactions in a single block, selecting deterministically among
255+
/// conflicting RBF candidates. Sorting by txid ensures the winner is determined by fuzz input
256+
/// content. Transactions that double-spend an already-confirmed outpoint are skipped.
258257
fn confirm_pending_txs(&mut self) {
259258
let mut txs = std::mem::take(&mut self.pending_txs);
260259
txs.sort_by_key(|tx| tx.compute_txid());
260+
261+
let mut confirmed = Vec::new();
262+
let mut spent_outpoints = Vec::new();
261263
for tx in txs {
262-
self.confirm_tx(tx);
264+
let txid = tx.compute_txid();
265+
if self.confirmed_txids.contains(&txid) {
266+
continue;
267+
}
268+
if tx.input.iter().any(|input| {
269+
self.is_outpoint_spent(&input.previous_output)
270+
|| spent_outpoints.contains(&input.previous_output)
271+
}) {
272+
continue;
273+
}
274+
self.confirmed_txids.insert(txid);
275+
for input in &tx.input {
276+
spent_outpoints.push(input.previous_output);
277+
}
278+
confirmed.push(tx);
279+
}
280+
281+
if confirmed.is_empty() {
282+
return;
283+
}
284+
285+
let prev_hash = self.blocks.last().unwrap().0.block_hash();
286+
let header = create_dummy_header(prev_hash, 42);
287+
self.blocks.push((header, confirmed));
288+
289+
for _ in 0..5 {
290+
let prev_hash = self.blocks.last().unwrap().0.block_hash();
291+
let header = create_dummy_header(prev_hash, 42);
292+
self.blocks.push((header, Vec::new()));
263293
}
264294
}
265295

0 commit comments

Comments
 (0)