@@ -26,7 +26,7 @@ use crate::ln::chan_utils::{
26
26
use crate :: ln:: features:: ChannelTypeFeatures ;
27
27
use crate :: ln:: PaymentPreimage ;
28
28
use crate :: prelude:: * ;
29
- use crate :: sign:: { ChannelSigner , EcdsaChannelSigner , SignerProvider } ;
29
+ use crate :: sign:: { ChannelSigner , EcdsaChannelSigner , SignerProvider , WriteableEcdsaChannelSigner } ;
30
30
use crate :: sync:: Mutex ;
31
31
use crate :: util:: logger:: Logger ;
32
32
@@ -102,9 +102,9 @@ impl AnchorDescriptor {
102
102
}
103
103
104
104
/// Derives the channel signer required to sign the anchor input.
105
- pub fn derive_channel_signer < SP : Deref > ( & self , signer_provider : & SP ) -> < SP :: Target as SignerProvider > :: Signer
105
+ pub fn derive_channel_signer < S : WriteableEcdsaChannelSigner , SP : Deref > ( & self , signer_provider : & SP ) -> S
106
106
where
107
- SP :: Target : SignerProvider
107
+ SP :: Target : SignerProvider < Signer = S >
108
108
{
109
109
let mut signer = signer_provider. derive_channel_signer (
110
110
self . channel_derivation_parameters . value_satoshis ,
@@ -211,9 +211,9 @@ impl HTLCDescriptor {
211
211
}
212
212
213
213
/// Derives the channel signer required to sign the HTLC input.
214
- pub fn derive_channel_signer < SP : Deref > ( & self , signer_provider : & SP ) -> < SP :: Target as SignerProvider > :: Signer
214
+ pub fn derive_channel_signer < S : WriteableEcdsaChannelSigner , SP : Deref > ( & self , signer_provider : & SP ) -> S
215
215
where
216
- SP :: Target : SignerProvider
216
+ SP :: Target : SignerProvider < Signer = S >
217
217
{
218
218
let mut signer = signer_provider. derive_channel_signer (
219
219
self . channel_derivation_parameters . value_satoshis ,
@@ -464,12 +464,12 @@ pub trait CoinSelectionSource {
464
464
/// which UTXOs to double spend is left to the implementation, but it must strive to keep the
465
465
/// set of other claims being double spent to a minimum.
466
466
fn select_confirmed_utxos (
467
- & self , claim_id : ClaimId , must_spend : & [ Input ] , must_pay_to : & [ TxOut ] ,
467
+ & self , claim_id : ClaimId , must_spend : Vec < Input > , must_pay_to : & [ TxOut ] ,
468
468
target_feerate_sat_per_1000_weight : u32 ,
469
469
) -> Result < CoinSelection , ( ) > ;
470
470
/// Signs and provides the full witness for all inputs within the transaction known to the
471
471
/// trait (i.e., any provided via [`CoinSelectionSource::select_confirmed_utxos`]).
472
- fn sign_tx ( & self , tx : & mut Transaction ) -> Result < ( ) , ( ) > ;
472
+ fn sign_tx ( & self , tx : Transaction ) -> Result < Transaction , ( ) > ;
473
473
}
474
474
475
475
/// An alternative to [`CoinSelectionSource`] that can be implemented and used along [`Wallet`] to
@@ -483,7 +483,7 @@ pub trait WalletSource {
483
483
/// Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
484
484
/// the transaction known to the wallet (i.e., any provided via
485
485
/// [`WalletSource::list_confirmed_utxos`]).
486
- fn sign_tx ( & self , tx : & mut Transaction ) -> Result < ( ) , ( ) > ;
486
+ fn sign_tx ( & self , tx : Transaction ) -> Result < Transaction , ( ) > ;
487
487
}
488
488
489
489
/// A wrapper over [`WalletSource`] that implements [`CoinSelection`] by preferring UTXOs that would
@@ -600,7 +600,7 @@ where
600
600
L :: Target : Logger
601
601
{
602
602
fn select_confirmed_utxos (
603
- & self , claim_id : ClaimId , must_spend : & [ Input ] , must_pay_to : & [ TxOut ] ,
603
+ & self , claim_id : ClaimId , must_spend : Vec < Input > , must_pay_to : & [ TxOut ] ,
604
604
target_feerate_sat_per_1000_weight : u32 ,
605
605
) -> Result < CoinSelection , ( ) > {
606
606
let utxos = self . source . list_confirmed_utxos ( ) ?;
@@ -629,7 +629,7 @@ where
629
629
. or_else ( |_| do_coin_selection ( true , true ) )
630
630
}
631
631
632
- fn sign_tx ( & self , tx : & mut Transaction ) -> Result < ( ) , ( ) > {
632
+ fn sign_tx ( & self , tx : Transaction ) -> Result < Transaction , ( ) > {
633
633
self . source . sign_tx ( tx)
634
634
}
635
635
}
@@ -726,7 +726,7 @@ where
726
726
satisfaction_weight: commitment_tx. weight( ) as u64 + ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT ,
727
727
} ] ;
728
728
let coin_selection = self . utxo_source . select_confirmed_utxos (
729
- claim_id, & must_spend, & [ ] , anchor_target_feerate_sat_per_1000_weight,
729
+ claim_id, must_spend, & [ ] , anchor_target_feerate_sat_per_1000_weight,
730
730
) ?;
731
731
732
732
let mut anchor_tx = Transaction {
@@ -748,7 +748,8 @@ where
748
748
let unsigned_tx_weight = anchor_tx. weight ( ) as u64 - ( anchor_tx. input . len ( ) as u64 * EMPTY_SCRIPT_SIG_WEIGHT ) ;
749
749
750
750
log_debug ! ( self . logger, "Signing anchor transaction {}" , anchor_txid) ;
751
- self . utxo_source . sign_tx ( & mut anchor_tx) ?;
751
+ anchor_tx = self . utxo_source . sign_tx ( anchor_tx) ?;
752
+
752
753
let signer = anchor_descriptor. derive_channel_signer ( & self . signer_provider ) ;
753
754
let anchor_sig = signer. sign_holder_anchor_input ( & anchor_tx, 0 , & self . secp ) ?;
754
755
anchor_tx. input [ 0 ] . witness = anchor_descriptor. tx_input_witness ( & anchor_sig) ;
@@ -799,20 +800,24 @@ where
799
800
800
801
log_debug ! ( self . logger, "Peforming coin selection for HTLC transaction targeting {} sat/kW" ,
801
802
target_feerate_sat_per_1000_weight) ;
803
+ #[ cfg( debug_assertions) ]
804
+ let must_spend_satisfaction_weight =
805
+ must_spend. iter ( ) . map ( |input| input. satisfaction_weight ) . sum :: < u64 > ( ) ;
802
806
let coin_selection = self . utxo_source . select_confirmed_utxos (
803
- claim_id, & must_spend, & htlc_tx. output , target_feerate_sat_per_1000_weight,
807
+ claim_id, must_spend, & htlc_tx. output , target_feerate_sat_per_1000_weight,
804
808
) ?;
805
809
#[ cfg( debug_assertions) ]
806
810
let total_satisfaction_weight =
807
811
coin_selection. confirmed_utxos . iter ( ) . map ( |utxo| utxo. satisfaction_weight ) . sum :: < u64 > ( ) +
808
- must_spend . iter ( ) . map ( |input| input . satisfaction_weight ) . sum :: < u64 > ( ) ;
812
+ must_spend_satisfaction_weight ;
809
813
self . process_coin_selection ( & mut htlc_tx, coin_selection) ;
810
814
811
815
#[ cfg( debug_assertions) ]
812
816
let unsigned_tx_weight = htlc_tx. weight ( ) as u64 - ( htlc_tx. input . len ( ) as u64 * EMPTY_SCRIPT_SIG_WEIGHT ) ;
813
817
814
818
log_debug ! ( self . logger, "Signing HTLC transaction {}" , htlc_tx. txid( ) ) ;
815
- self . utxo_source . sign_tx ( & mut htlc_tx) ?;
819
+ htlc_tx = self . utxo_source . sign_tx ( htlc_tx) ?;
820
+
816
821
let mut signers = BTreeMap :: new ( ) ;
817
822
for ( idx, htlc_descriptor) in htlc_descriptors. iter ( ) . enumerate ( ) {
818
823
let signer = signers. entry ( htlc_descriptor. channel_derivation_parameters . keys_id )
0 commit comments