@@ -751,7 +751,7 @@ impl Channel {
751
751
/// generated by the peer which proposed adding the HTLCs, and thus we need to understand both
752
752
/// which peer generated this transaction and "to whom" this transaction flows.
753
753
#[ inline]
754
- fn build_commitment_transaction ( & self , commitment_number : u64 , keys : & TxCreationKeys , local : bool , generated_by_local : bool , feerate_per_kw : u64 ) -> ( Transaction , Vec < HTLCOutputInCommitment > ) {
754
+ fn build_commitment_transaction ( & self , commitment_number : u64 , keys : & TxCreationKeys , local : bool , generated_by_local : bool , feerate_per_kw : u64 ) -> ( Transaction , Vec < ( HTLCOutputInCommitment , Option < HTLCSource > ) > ) {
755
755
let obscured_commitment_transaction_number = self . get_commitment_transaction_number_obscure_factor ( ) ^ ( INITIAL_COMMITMENT_NUMBER - commitment_number) ;
756
756
757
757
let txins = {
@@ -765,30 +765,30 @@ impl Channel {
765
765
ins
766
766
} ;
767
767
768
- let mut txouts: Vec < ( TxOut , Option < HTLCOutputInCommitment > ) > = Vec :: with_capacity ( self . pending_inbound_htlcs . len ( ) + self . pending_outbound_htlcs . len ( ) + 2 ) ;
768
+ let mut txouts: Vec < ( TxOut , Option < ( HTLCOutputInCommitment , Option < HTLCSource > ) > ) > = Vec :: with_capacity ( self . pending_inbound_htlcs . len ( ) + self . pending_outbound_htlcs . len ( ) + 2 ) ;
769
769
770
770
let dust_limit_satoshis = if local { self . our_dust_limit_satoshis } else { self . their_dust_limit_satoshis } ;
771
771
let mut remote_htlc_total_msat = 0 ;
772
772
let mut local_htlc_total_msat = 0 ;
773
773
let mut value_to_self_msat_offset = 0 ;
774
774
775
775
macro_rules! add_htlc_output {
776
- ( $htlc: expr, $outbound: expr) => {
776
+ ( $htlc: expr, $outbound: expr, $source : expr ) => {
777
777
if $outbound == local { // "offered HTLC output"
778
778
if $htlc. amount_msat / 1000 >= dust_limit_satoshis + ( feerate_per_kw * HTLC_TIMEOUT_TX_WEIGHT / 1000 ) {
779
779
let htlc_in_tx = get_htlc_in_commitment!( $htlc, true ) ;
780
780
txouts. push( ( TxOut {
781
781
script_pubkey: chan_utils:: get_htlc_redeemscript( & htlc_in_tx, & keys) . to_v0_p2wsh( ) ,
782
782
value: $htlc. amount_msat / 1000
783
- } , Some ( htlc_in_tx) ) ) ;
783
+ } , Some ( ( htlc_in_tx, $source ) ) ) ) ;
784
784
}
785
785
} else {
786
786
if $htlc. amount_msat / 1000 >= dust_limit_satoshis + ( feerate_per_kw * HTLC_SUCCESS_TX_WEIGHT / 1000 ) {
787
787
let htlc_in_tx = get_htlc_in_commitment!( $htlc, false ) ;
788
788
txouts. push( ( TxOut { // "received HTLC output"
789
789
script_pubkey: chan_utils:: get_htlc_redeemscript( & htlc_in_tx, & keys) . to_v0_p2wsh( ) ,
790
790
value: $htlc. amount_msat / 1000
791
- } , Some ( htlc_in_tx) ) ) ;
791
+ } , Some ( ( htlc_in_tx, $source ) ) ) ) ;
792
792
}
793
793
}
794
794
}
@@ -804,7 +804,7 @@ impl Channel {
804
804
} ;
805
805
806
806
if include {
807
- add_htlc_output ! ( htlc, false ) ;
807
+ add_htlc_output ! ( htlc, false , None ) ;
808
808
remote_htlc_total_msat += htlc. amount_msat ;
809
809
} else {
810
810
match & htlc. state {
@@ -830,7 +830,7 @@ impl Channel {
830
830
} ;
831
831
832
832
if include {
833
- add_htlc_output ! ( htlc, true ) ;
833
+ add_htlc_output ! ( htlc, true , Some ( htlc . source . clone ( ) ) ) ;
834
834
local_htlc_total_msat += htlc. amount_msat ;
835
835
} else {
836
836
match htlc. state {
@@ -901,12 +901,12 @@ impl Channel {
901
901
transaction_utils:: sort_outputs ( & mut txouts) ;
902
902
903
903
let mut outputs: Vec < TxOut > = Vec :: with_capacity ( txouts. len ( ) ) ;
904
- let mut htlcs_used: Vec < HTLCOutputInCommitment > = Vec :: with_capacity ( txouts. len ( ) ) ;
904
+ let mut htlcs_used: Vec < ( HTLCOutputInCommitment , Option < HTLCSource > ) > = Vec :: with_capacity ( txouts. len ( ) ) ;
905
905
for ( idx, out) in txouts. drain ( ..) . enumerate ( ) {
906
906
outputs. push ( out. 0 ) ;
907
- if let Some ( out_htlc) = out. 1 {
908
- htlcs_used . push ( out_htlc) ;
909
- htlcs_used. last_mut ( ) . unwrap ( ) . transaction_output_index = idx as u32 ;
907
+ if let Some ( mut out_htlc) = out. 1 {
908
+ out_htlc. 0 . transaction_output_index = idx as u32 ;
909
+ htlcs_used. push ( ( out_htlc . 0 , out_htlc . 1 ) ) ;
910
910
}
911
911
}
912
912
@@ -1692,7 +1692,7 @@ impl Channel {
1692
1692
new_local_commitment_txn. push ( local_commitment_tx. 0 . clone ( ) ) ;
1693
1693
1694
1694
let mut htlcs_and_sigs = Vec :: with_capacity ( local_commitment_tx. 1 . len ( ) ) ;
1695
- for ( idx, ref htlc) in local_commitment_tx. 1 . iter ( ) . enumerate ( ) {
1695
+ for ( idx, & ( ref htlc, ref htlc_source ) ) in local_commitment_tx. 1 . iter ( ) . enumerate ( ) {
1696
1696
let mut htlc_tx = self . build_htlc_transaction ( & local_commitment_txid, htlc, true , & local_keys, feerate_per_kw) ;
1697
1697
let htlc_redeemscript = chan_utils:: get_htlc_redeemscript ( & htlc, & local_keys) ;
1698
1698
let htlc_sighash = Message :: from_slice ( & bip143:: SighashComponents :: new ( & htlc_tx) . sighash_all ( & htlc_tx. input [ 0 ] , & htlc_redeemscript, htlc. amount_msat / 1000 ) [ ..] ) . unwrap ( ) ;
@@ -1704,7 +1704,7 @@ impl Channel {
1704
1704
} else {
1705
1705
self . create_htlc_tx_signature ( & htlc_tx, htlc, & local_keys) ?. 1
1706
1706
} ;
1707
- htlcs_and_sigs. push ( ( ( * htlc) . clone ( ) , msg. htlc_signatures [ idx] , htlc_sig) ) ;
1707
+ htlcs_and_sigs. push ( ( ( * htlc) . clone ( ) , msg. htlc_signatures [ idx] , htlc_sig, ( * htlc_source ) . clone ( ) ) ) ;
1708
1708
}
1709
1709
1710
1710
let next_per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & self . build_local_commitment_secret ( self . cur_local_commitment_transaction_number - 1 ) ) ;
@@ -3221,7 +3221,7 @@ impl Channel {
3221
3221
3222
3222
/// Only fails in case of bad keys. Used for channel_reestablish commitment_signed generation
3223
3223
/// when we shouldn't change HTLC/channel state.
3224
- fn send_commitment_no_state_update ( & self ) -> Result < ( msgs:: CommitmentSigned , ( Transaction , Vec < HTLCOutputInCommitment > ) ) , ChannelError > {
3224
+ fn send_commitment_no_state_update ( & self ) -> Result < ( msgs:: CommitmentSigned , ( Transaction , Vec < ( HTLCOutputInCommitment , Option < HTLCSource > ) > ) ) , ChannelError > {
3225
3225
let funding_script = self . get_funding_redeemscript ( ) ;
3226
3226
3227
3227
let mut feerate_per_kw = self . feerate_per_kw ;
@@ -3239,7 +3239,7 @@ impl Channel {
3239
3239
3240
3240
let mut htlc_sigs = Vec :: new ( ) ;
3241
3241
3242
- for ref htlc in remote_commitment_tx. 1 . iter ( ) {
3242
+ for & ( ref htlc, _ ) in remote_commitment_tx. 1 . iter ( ) {
3243
3243
let htlc_tx = self . build_htlc_transaction ( & remote_commitment_txid, htlc, false , & remote_keys, feerate_per_kw) ;
3244
3244
let htlc_redeemscript = chan_utils:: get_htlc_redeemscript ( & htlc, & remote_keys) ;
3245
3245
let htlc_sighash = Message :: from_slice ( & bip143:: SighashComponents :: new ( & htlc_tx) . sighash_all ( & htlc_tx. input [ 0 ] , & htlc_redeemscript, htlc. amount_msat / 1000 ) [ ..] ) . unwrap ( ) ;
@@ -3960,7 +3960,7 @@ mod tests {
3960
3960
let htlc_basepoint = PublicKey :: from_secret_key ( & secp_ctx, & chan. local_keys . htlc_base_key ) ;
3961
3961
let keys = TxCreationKeys :: new ( & secp_ctx, & per_commitment_point, & delayed_payment_base, & htlc_basepoint, & chan. their_revocation_basepoint . unwrap ( ) , & chan. their_payment_basepoint . unwrap ( ) , & chan. their_htlc_basepoint . unwrap ( ) ) . unwrap ( ) ;
3962
3962
3963
- let mut unsigned_tx: ( Transaction , Vec < HTLCOutputInCommitment > ) ;
3963
+ let mut unsigned_tx: ( Transaction , Vec < ( HTLCOutputInCommitment , Option < HTLCSource > ) > ) ;
3964
3964
3965
3965
macro_rules! test_commitment {
3966
3966
( $their_sig_hex: expr, $our_sig_hex: expr, $tx_hex: expr) => {
@@ -3980,7 +3980,7 @@ mod tests {
3980
3980
( $htlc_idx: expr, $their_sig_hex: expr, $our_sig_hex: expr, $tx_hex: expr ) => {
3981
3981
let remote_signature = Signature :: from_der( & secp_ctx, & hex:: decode( $their_sig_hex) . unwrap( ) [ ..] ) . unwrap( ) ;
3982
3982
3983
- let ref htlc = unsigned_tx. 1 [ $htlc_idx] ;
3983
+ let ( ref htlc, _ ) = unsigned_tx. 1 [ $htlc_idx] ;
3984
3984
let mut htlc_tx = chan. build_htlc_transaction( & unsigned_tx. 0 . txid( ) , & htlc, true , & keys, chan. feerate_per_kw) ;
3985
3985
let htlc_redeemscript = chan_utils:: get_htlc_redeemscript( & htlc, & keys) ;
3986
3986
let htlc_sighash = Message :: from_slice( & bip143:: SighashComponents :: new( & htlc_tx) . sighash_all( & htlc_tx. input[ 0 ] , & htlc_redeemscript, htlc. amount_msat / 1000 ) [ ..] ) . unwrap( ) ;
0 commit comments