Skip to content

Commit 0e90b5d

Browse files
committed
f - Batch pending tx confirmations into a single block
1 parent 642baa6 commit 0e90b5d

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

fuzz/src/chanmon_consistency.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,45 @@ impl ChainState {
246246
self.pending_txs.push(tx);
247247
}
248248

249-
/// Confirm pending transactions, selecting deterministically among conflicting RBF candidates.
250-
/// Sorting by txid before confirming means the winner depends on the fuzz input (which
251-
/// determines tx content and thus txid), while `confirm_tx` rejects double-spends so only one
252-
/// conflicting tx confirms.
249+
/// Confirm pending transactions in a single block, selecting deterministically among
250+
/// conflicting RBF candidates. Sorting by txid ensures the winner is determined by fuzz input
251+
/// content. Transactions that double-spend an already-confirmed outpoint are skipped.
253252
fn confirm_pending_txs(&mut self) {
254253
let mut txs = std::mem::take(&mut self.pending_txs);
255254
txs.sort_by_key(|tx| tx.compute_txid());
255+
256+
let mut confirmed = Vec::new();
257+
let mut spent_outpoints = Vec::new();
256258
for tx in txs {
257-
self.confirm_tx(tx);
259+
let txid = tx.compute_txid();
260+
if self.confirmed_txids.contains(&txid) {
261+
continue;
262+
}
263+
if tx.input.iter().any(|input| {
264+
self.is_outpoint_spent(&input.previous_output)
265+
|| spent_outpoints.contains(&input.previous_output)
266+
}) {
267+
continue;
268+
}
269+
self.confirmed_txids.insert(txid);
270+
for input in &tx.input {
271+
spent_outpoints.push(input.previous_output);
272+
}
273+
confirmed.push(tx);
274+
}
275+
276+
if confirmed.is_empty() {
277+
return;
278+
}
279+
280+
let prev_hash = self.blocks.last().unwrap().0.block_hash();
281+
let header = create_dummy_header(prev_hash, 42);
282+
self.blocks.push((header, confirmed));
283+
284+
for _ in 0..5 {
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, Vec::new()));
258288
}
259289
}
260290

0 commit comments

Comments
 (0)