@@ -634,33 +634,46 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
634
634
}
635
635
} ,
636
636
10 => {
637
- ' outer_loop: for funding_generation in pending_funding_generation. drain ( ..) {
638
- let mut tx = Transaction { version : 0 , lock_time : LockTime :: ZERO , input : Vec :: new ( ) , output : vec ! [ TxOut {
639
- value: funding_generation. 2 , script_pubkey: funding_generation. 3 ,
640
- } ] } ;
641
- let funding_output = ' search_loop: loop {
642
- let funding_txid = tx. txid ( ) ;
643
- if let None = loss_detector. txids_confirmed . get ( & funding_txid) {
644
- let outpoint = OutPoint { txid : funding_txid, index : 0 } ;
645
- for chan in channelmanager. list_channels ( ) {
646
- if chan. funding_txo == Some ( outpoint) {
647
- tx. version += 1 ;
648
- continue ' search_loop;
649
- }
637
+ let mut tx = Transaction { version : 0 , lock_time : LockTime :: ZERO , input : Vec :: new ( ) , output : Vec :: new ( ) } ;
638
+ let mut channels = Vec :: new ( ) ;
639
+ for funding_generation in pending_funding_generation. drain ( ..) {
640
+ let txout = TxOut {
641
+ value : funding_generation. 2 , script_pubkey : funding_generation. 3 ,
642
+ } ;
643
+ if !tx. output . contains ( & txout) {
644
+ tx. output . push ( txout) ;
645
+ channels. push ( ( funding_generation. 0 , funding_generation. 1 ) ) ;
646
+ }
647
+ }
648
+ ' search_loop: loop {
649
+ if tx. version > 0xff {
650
+ break ;
651
+ }
652
+ let funding_txid = tx. txid ( ) ;
653
+ if loss_detector. txids_confirmed . get ( & funding_txid) . is_none ( ) {
654
+ let outpoint = OutPoint { txid : funding_txid, index : 0 } ;
655
+ for chan in channelmanager. list_channels ( ) {
656
+ if chan. channel_id == outpoint. to_channel_id ( ) {
657
+ tx. version += 1 ;
658
+ continue ' search_loop;
650
659
}
651
- break outpoint;
652
- }
653
- tx. version += 1 ;
654
- if tx. version > 0xff {
655
- continue ' outer_loop;
656
660
}
657
- } ;
658
- if let Err ( e) = channelmanager. funding_transaction_generated ( & funding_generation. 0 , & funding_generation. 1 , tx. clone ( ) ) {
661
+ break ;
662
+ }
663
+ tx. version += 1 ;
664
+ }
665
+ if tx. version <= 0xff && !channels. is_empty ( ) {
666
+ let chans = channels. iter ( ) . map ( |( a, b) | ( a, b) ) . collect :: < Vec < _ > > ( ) ;
667
+ if let Err ( e) = channelmanager. batch_funding_transaction_generated ( & chans, tx. clone ( ) ) {
659
668
// It's possible the channel has been closed in the mean time, but any other
660
669
// failure may be a bug.
661
670
if let APIError :: ChannelUnavailable { .. } = e { } else { panic ! ( ) ; }
662
671
}
663
- pending_funding_signatures. insert ( funding_output, tx) ;
672
+ let funding_txid = tx. txid ( ) ;
673
+ for idx in 0 ..tx. output . len ( ) {
674
+ let outpoint = OutPoint { txid : funding_txid, index : idx as u16 } ;
675
+ pending_funding_signatures. insert ( outpoint, tx. clone ( ) ) ;
676
+ }
664
677
}
665
678
} ,
666
679
11 => {
0 commit comments