@@ -67,6 +67,8 @@ pub struct HTLCDescriptor {
67
67
pub commitment_txid : Txid ,
68
68
/// The number of the commitment transaction in which the HTLC output lives.
69
69
pub per_commitment_number : u64 ,
70
+ /// The point that maps to the number of the commitment transaction in which the HTLC output lives.
71
+ pub per_commitment_point : PublicKey ,
70
72
/// The details of the HTLC as it appears in the commitment transaction.
71
73
pub htlc : HTLCOutputInCommitment ,
72
74
/// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
@@ -85,17 +87,15 @@ impl HTLCDescriptor {
85
87
86
88
/// Returns the delayed output created as a result of spending the HTLC output in the commitment
87
89
/// transaction.
88
- pub fn tx_output < C : secp256k1:: Signing + secp256k1:: Verification > (
89
- & self , per_commitment_point : & PublicKey , secp : & Secp256k1 < C >
90
- ) -> TxOut {
90
+ pub fn tx_output < C : secp256k1:: Signing + secp256k1:: Verification > ( & self , secp : & Secp256k1 < C > ) -> TxOut {
91
91
let channel_params = self . signer_descriptor . channel_parameters . as_holder_broadcastable ( ) ;
92
92
let broadcaster_keys = channel_params. broadcaster_pubkeys ( ) ;
93
93
let counterparty_keys = channel_params. countersignatory_pubkeys ( ) ;
94
94
let broadcaster_delayed_key = chan_utils:: derive_public_key (
95
- secp, per_commitment_point, & broadcaster_keys. delayed_payment_basepoint
95
+ secp, & self . per_commitment_point , & broadcaster_keys. delayed_payment_basepoint
96
96
) ;
97
97
let counterparty_revocation_key = chan_utils:: derive_public_revocation_key (
98
- secp, per_commitment_point, & counterparty_keys. revocation_basepoint
98
+ secp, & self . per_commitment_point , & counterparty_keys. revocation_basepoint
99
99
) ;
100
100
chan_utils:: build_htlc_output (
101
101
0 /* feerate_per_kw */ , channel_params. contest_delay ( ) , & self . htlc , true /* opt_anchors */ ,
@@ -104,20 +104,18 @@ impl HTLCDescriptor {
104
104
}
105
105
106
106
/// Returns the witness script of the HTLC output in the commitment transaction.
107
- pub fn witness_script < C : secp256k1:: Signing + secp256k1:: Verification > (
108
- & self , per_commitment_point : & PublicKey , secp : & Secp256k1 < C >
109
- ) -> Script {
107
+ pub fn witness_script < C : secp256k1:: Signing + secp256k1:: Verification > ( & self , secp : & Secp256k1 < C > ) -> Script {
110
108
let channel_params = self . signer_descriptor . channel_parameters . as_holder_broadcastable ( ) ;
111
109
let broadcaster_keys = channel_params. broadcaster_pubkeys ( ) ;
112
110
let counterparty_keys = channel_params. countersignatory_pubkeys ( ) ;
113
111
let broadcaster_htlc_key = chan_utils:: derive_public_key (
114
- secp, per_commitment_point, & broadcaster_keys. htlc_basepoint
112
+ secp, & self . per_commitment_point , & broadcaster_keys. htlc_basepoint
115
113
) ;
116
114
let counterparty_htlc_key = chan_utils:: derive_public_key (
117
- secp, per_commitment_point, & counterparty_keys. htlc_basepoint
115
+ secp, & self . per_commitment_point , & counterparty_keys. htlc_basepoint
118
116
) ;
119
117
let counterparty_revocation_key = chan_utils:: derive_public_revocation_key (
120
- secp, per_commitment_point, & counterparty_keys. revocation_basepoint
118
+ secp, & self . per_commitment_point , & counterparty_keys. revocation_basepoint
121
119
) ;
122
120
chan_utils:: get_htlc_redeemscript_with_explicit_keys (
123
121
& self . htlc , true /* opt_anchors */ , & broadcaster_htlc_key, & counterparty_htlc_key,
@@ -669,31 +667,15 @@ where
669
667
fn build_htlc_tx (
670
668
& self , claim_id : ClaimId , target_feerate_sat_per_1000_weight : u32 ,
671
669
htlc_descriptors : & [ HTLCDescriptor ] , tx_lock_time : PackedLockTime ,
672
- ) -> Result < ( Transaction , HashMap < [ u8 ; 32 ] , < SP :: Target as SignerProvider > :: Signer > ) , ( ) > {
670
+ ) -> Result < Transaction , ( ) > {
673
671
let mut tx = Transaction {
674
672
version : 2 ,
675
673
lock_time : tx_lock_time,
676
674
input : vec ! [ ] ,
677
675
output : vec ! [ ] ,
678
676
} ;
679
- // Unfortunately, we need to derive the signer for each HTLC ahead of time to obtain its
680
- // input.
681
- let mut signers = HashMap :: new ( ) ;
682
677
let mut must_spend = Vec :: with_capacity ( htlc_descriptors. len ( ) ) ;
683
678
for htlc_descriptor in htlc_descriptors {
684
- let signer = signers. entry ( htlc_descriptor. signer_descriptor . channel_keys_id )
685
- . or_insert_with ( || {
686
- let mut signer = self . signer_provider . derive_channel_signer (
687
- htlc_descriptor. signer_descriptor . channel_value_satoshis ,
688
- htlc_descriptor. signer_descriptor . channel_keys_id ,
689
- ) ;
690
- signer. provide_channel_parameters ( & htlc_descriptor. signer_descriptor . channel_parameters ) ;
691
- signer
692
- } ) ;
693
- let per_commitment_point = signer. get_per_commitment_point (
694
- htlc_descriptor. per_commitment_number , & self . secp
695
- ) ;
696
-
697
679
let htlc_input = htlc_descriptor. unsigned_tx_input ( ) ;
698
680
must_spend. push ( Input {
699
681
outpoint : htlc_input. previous_output . clone ( ) ,
@@ -704,15 +686,15 @@ where
704
686
} ,
705
687
} ) ;
706
688
tx. input . push ( htlc_input) ;
707
- let htlc_output = htlc_descriptor. tx_output ( & per_commitment_point , & self . secp ) ;
689
+ let htlc_output = htlc_descriptor. tx_output ( & self . secp ) ;
708
690
tx. output . push ( htlc_output) ;
709
691
}
710
692
711
693
let coin_selection = self . utxo_source . select_confirmed_utxos (
712
694
claim_id, & must_spend, & tx. output , target_feerate_sat_per_1000_weight,
713
695
) ?;
714
696
self . process_coin_selection ( & mut tx, coin_selection) ;
715
- Ok ( ( tx , signers ) )
697
+ Ok ( tx )
716
698
}
717
699
718
700
/// Handles a [`BumpTransactionEvent::HTLCResolution`] event variant by producing a
@@ -721,20 +703,21 @@ where
721
703
& self , claim_id : ClaimId , target_feerate_sat_per_1000_weight : u32 ,
722
704
htlc_descriptors : & [ HTLCDescriptor ] , tx_lock_time : PackedLockTime ,
723
705
) -> Result < ( ) , ( ) > {
724
- let ( mut htlc_tx, signers ) = self . build_htlc_tx (
706
+ let mut htlc_tx = self . build_htlc_tx (
725
707
claim_id, target_feerate_sat_per_1000_weight, htlc_descriptors, tx_lock_time,
726
708
) ?;
727
709
728
710
self . utxo_source . sign_tx ( & mut htlc_tx) ?;
729
711
for ( idx, htlc_descriptor) in htlc_descriptors. iter ( ) . enumerate ( ) {
730
- let signer = signers. get ( & htlc_descriptor. signer_descriptor . channel_keys_id ) . unwrap ( ) ;
712
+ let mut signer = self . signer_provider . derive_channel_signer (
713
+ htlc_descriptor. signer_descriptor . channel_value_satoshis ,
714
+ htlc_descriptor. signer_descriptor . channel_keys_id ,
715
+ ) ;
716
+ signer. provide_channel_parameters ( & htlc_descriptor. signer_descriptor . channel_parameters ) ;
731
717
let htlc_sig = signer. sign_holder_htlc_transaction (
732
718
& htlc_tx, idx, htlc_descriptor, & self . secp
733
719
) ?;
734
- let per_commitment_point = signer. get_per_commitment_point (
735
- htlc_descriptor. per_commitment_number , & self . secp
736
- ) ;
737
- let witness_script = htlc_descriptor. witness_script ( & per_commitment_point, & self . secp ) ;
720
+ let witness_script = htlc_descriptor. witness_script ( & self . secp ) ;
738
721
htlc_tx. input [ idx] . witness = htlc_descriptor. tx_input_witness ( & htlc_sig, & witness_script) ;
739
722
}
740
723
0 commit comments