Skip to content

Commit a17df4f

Browse files
committed
[fuzz] Use batch funding in full_stack_target
To potentially get more test coverage
1 parent a3c4fe9 commit a17df4f

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

fuzz/src/full_stack.rs

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -629,33 +629,48 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
629629
}
630630
},
631631
10 => {
632-
'outer_loop: for funding_generation in pending_funding_generation.drain(..) {
633-
let mut tx = Transaction { version: 0, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
634-
value: funding_generation.2, script_pubkey: funding_generation.3,
635-
}] };
636-
let funding_output = 'search_loop: loop {
637-
let funding_txid = tx.txid();
638-
if let None = loss_detector.txids_confirmed.get(&funding_txid) {
639-
let outpoint = OutPoint { txid: funding_txid, index: 0 };
640-
for chan in channelmanager.list_channels() {
641-
if chan.funding_txo == Some(outpoint) {
642-
tx.version += 1;
643-
continue 'search_loop;
644-
}
632+
let mut tx = Transaction { version: 0, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() };
633+
let mut channels = Vec::new();
634+
for funding_generation in pending_funding_generation.drain(..) {
635+
let txout = TxOut {
636+
value: funding_generation.2, script_pubkey: funding_generation.3,
637+
};
638+
if !tx.output.contains(&txout) {
639+
tx.output.push(txout);
640+
channels.push((funding_generation.0, funding_generation.1));
641+
}
642+
}
643+
// Once we switch to V2 channel opens we should be able to drop this entirely as
644+
// channel_ids no longer change when we set the funding tx.
645+
'search_loop: loop {
646+
if tx.version > 0xff {
647+
break;
648+
}
649+
let funding_txid = tx.txid();
650+
if loss_detector.txids_confirmed.get(&funding_txid).is_none() {
651+
let outpoint = OutPoint { txid: funding_txid, index: 0 };
652+
for chan in channelmanager.list_channels() {
653+
if chan.channel_id == ChannelId::v1_from_funding_outpoint(outpoint) {
654+
tx.version += 1;
655+
continue 'search_loop;
645656
}
646-
break outpoint;
647-
}
648-
tx.version += 1;
649-
if tx.version > 0xff {
650-
continue 'outer_loop;
651657
}
652-
};
653-
if let Err(e) = channelmanager.funding_transaction_generated(&funding_generation.0, &funding_generation.1, tx.clone()) {
658+
break;
659+
}
660+
tx.version += 1;
661+
}
662+
if tx.version <= 0xff && !channels.is_empty() {
663+
let chans = channels.iter().map(|(a, b)| (a, b)).collect::<Vec<_>>();
664+
if let Err(e) = channelmanager.batch_funding_transaction_generated(&chans, tx.clone()) {
654665
// It's possible the channel has been closed in the mean time, but any other
655666
// failure may be a bug.
656667
if let APIError::ChannelUnavailable { .. } = e { } else { panic!(); }
657668
}
658-
pending_funding_signatures.insert(funding_output, tx);
669+
let funding_txid = tx.txid();
670+
for idx in 0..tx.output.len() {
671+
let outpoint = OutPoint { txid: funding_txid, index: idx as u16 };
672+
pending_funding_signatures.insert(outpoint, tx.clone());
673+
}
659674
}
660675
},
661676
11 => {

0 commit comments

Comments
 (0)