@@ -768,9 +768,9 @@ impl CommitmentTransaction {
768
768
// Also keeps track of auxiliary HTLC data and returns it along with the mutated and sorted HTLCs.
769
769
// This allows the caller to match the HTLC output index with the auxiliary data.
770
770
// This auxiliary data is not stored in this object.
771
- pub ( crate ) fn new_with_auxiliary_htlc_data < T : Copy > ( commitment_number : u64 , to_broadcaster_value_sat : u64 , to_countersignatory_value_sat : u64 , keys : TxCreationKeys , feerate_per_kw : u32 , htlcs_with_aux : Vec < ( HTLCOutputInCommitment , T ) > , channel_parameters : & DirectedChannelTransactionParameters , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> ( CommitmentTransaction , Vec < ( HTLCOutputInCommitment , T ) > ) {
771
+ pub ( crate ) fn new_with_auxiliary_htlc_data < T > ( commitment_number : u64 , to_broadcaster_value_sat : u64 , to_countersignatory_value_sat : u64 , keys : TxCreationKeys , feerate_per_kw : u32 , htlcs : Vec < HTLCOutputInCommitment > , aux : Vec < T > , channel_parameters : & DirectedChannelTransactionParameters , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> ( CommitmentTransaction , Vec < ( HTLCOutputInCommitment , T ) > ) {
772
772
// Sort outputs and populate output indices while keeping track of the auxiliary data
773
- let mut txouts = Self :: do_build_outputs ( & keys, to_broadcaster_value_sat, to_countersignatory_value_sat, & htlcs_with_aux , channel_parameters, & secp_ctx) . unwrap ( ) ;
773
+ let mut txouts = Self :: do_build_outputs ( & keys, to_broadcaster_value_sat, to_countersignatory_value_sat, & htlcs , aux , channel_parameters, & secp_ctx) . unwrap ( ) ;
774
774
let mut result_htlcs_with_aux = Vec :: new ( ) ;
775
775
let mut htlcs = Vec :: new ( ) ;
776
776
for ( idx, mut out) in txouts. drain ( ..) . enumerate ( ) {
@@ -822,13 +822,14 @@ impl CommitmentTransaction {
822
822
}
823
823
824
824
fn build_outputs < T : secp256k1:: Signing + secp256k1:: Verification > ( & self , channel_parameters : & DirectedChannelTransactionParameters , secp_ctx : & Secp256k1 < T > ) -> Result < Vec < ( TxOut , Script ) > , ( ) > {
825
- let htlcs = self . htlcs . iter ( ) . map ( |h| ( h. clone ( ) , ( ) ) ) . collect ( ) ;
826
- let mut txouts = Self :: do_build_outputs ( & self . keys , self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & htlcs, channel_parameters, secp_ctx) ?;
825
+ let mut aux = Vec :: with_capacity ( self . htlcs . len ( ) ) ;
826
+ aux. resize ( self . htlcs . len ( ) , ( ) ) ;
827
+ let mut txouts = Self :: do_build_outputs ( & self . keys , self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & self . htlcs , aux, channel_parameters, secp_ctx) ?;
827
828
let outs = txouts. drain ( ..) . map ( |( out, ( s, _) ) | ( out, s) ) . collect ( ) ;
828
829
Ok ( outs)
829
830
}
830
831
831
- fn do_build_outputs < T : Copy , S : secp256k1:: Signing + secp256k1:: Verification > ( keys : & TxCreationKeys , to_broadcaster_value_sat : u64 , to_countersignatory_value_sat : u64 , htlcs : & Vec < ( HTLCOutputInCommitment , T ) > , channel_parameters : & DirectedChannelTransactionParameters , secp_ctx : & Secp256k1 < S > ) -> Result < Vec < ( TxOut , ( Script , Option < ( HTLCOutputInCommitment , T ) > ) ) > , ( ) > {
832
+ fn do_build_outputs < T , S : secp256k1:: Signing + secp256k1:: Verification > ( keys : & TxCreationKeys , to_broadcaster_value_sat : u64 , to_countersignatory_value_sat : u64 , htlcs : & Vec < HTLCOutputInCommitment > , aux : Vec < T > , channel_parameters : & DirectedChannelTransactionParameters , secp_ctx : & Secp256k1 < S > ) -> Result < Vec < ( TxOut , ( Script , Option < ( HTLCOutputInCommitment , T ) > ) ) > , ( ) > {
832
833
let ( broadcaster_pubkeys, countersignatory_pubkeys) = channel_parameters. pubkeys ( ) ;
833
834
let contest_delay = channel_parameters. contest_delay ( ) ;
834
835
@@ -873,13 +874,13 @@ impl CommitmentTransaction {
873
874
) ) ;
874
875
}
875
876
876
- for ( htlc, t) in htlcs {
877
+ for ( htlc, t) in htlcs. iter ( ) . zip ( aux ) {
877
878
let script = chan_utils:: get_htlc_redeemscript ( & htlc, & keys) ;
878
879
let txout = TxOut {
879
880
script_pubkey : script. to_v0_p2wsh ( ) ,
880
881
value : htlc. amount_msat / 1000 ,
881
882
} ;
882
- txouts. push ( ( txout, ( script, Some ( ( htlc. clone ( ) , * t) ) ) ) ) ;
883
+ txouts. push ( ( txout, ( script, Some ( ( htlc. clone ( ) , t) ) ) ) ) ;
883
884
}
884
885
885
886
// Sort output in BIP-69 order (amount, scriptPubkey). Tie-breaks based on HTLC
0 commit comments