@@ -26,7 +26,7 @@ use crate::ln::chan_utils::{
2626use crate :: ln:: features:: ChannelTypeFeatures ;
2727use crate :: ln:: PaymentPreimage ;
2828use crate :: prelude:: * ;
29- use crate :: sign:: { ChannelSigner , EcdsaChannelSigner , SignerProvider } ;
29+ use crate :: sign:: { ChannelSigner , EcdsaChannelSigner , SignerProvider , WriteableEcdsaChannelSigner } ;
3030use crate :: sync:: Mutex ;
3131use crate :: util:: logger:: Logger ;
3232
@@ -102,9 +102,9 @@ impl AnchorDescriptor {
102102 }
103103
104104 /// 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
106106 where
107- SP :: Target : SignerProvider
107+ SP :: Target : SignerProvider < Signer = S >
108108 {
109109 let mut signer = signer_provider. derive_channel_signer (
110110 self . channel_derivation_parameters . value_satoshis ,
@@ -211,9 +211,9 @@ impl HTLCDescriptor {
211211 }
212212
213213 /// 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
215215 where
216- SP :: Target : SignerProvider
216+ SP :: Target : SignerProvider < Signer = S >
217217 {
218218 let mut signer = signer_provider. derive_channel_signer (
219219 self . channel_derivation_parameters . value_satoshis ,
@@ -464,12 +464,12 @@ pub trait CoinSelectionSource {
464464 /// which UTXOs to double spend is left to the implementation, but it must strive to keep the
465465 /// set of other claims being double spent to a minimum.
466466 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 ] ,
468468 target_feerate_sat_per_1000_weight : u32 ,
469469 ) -> Result < CoinSelection , ( ) > ;
470470 /// Signs and provides the full witness for all inputs within the transaction known to the
471471 /// 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 , ( ) > ;
473473}
474474
475475/// An alternative to [`CoinSelectionSource`] that can be implemented and used along [`Wallet`] to
@@ -483,7 +483,7 @@ pub trait WalletSource {
483483 /// Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
484484 /// the transaction known to the wallet (i.e., any provided via
485485 /// [`WalletSource::list_confirmed_utxos`]).
486- fn sign_tx ( & self , tx : & mut Transaction ) -> Result < ( ) , ( ) > ;
486+ fn sign_tx ( & self , tx : Transaction ) -> Result < Transaction , ( ) > ;
487487}
488488
489489/// A wrapper over [`WalletSource`] that implements [`CoinSelection`] by preferring UTXOs that would
@@ -600,7 +600,7 @@ where
600600 L :: Target : Logger
601601{
602602 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 ] ,
604604 target_feerate_sat_per_1000_weight : u32 ,
605605 ) -> Result < CoinSelection , ( ) > {
606606 let utxos = self . source . list_confirmed_utxos ( ) ?;
@@ -629,7 +629,7 @@ where
629629 . or_else ( |_| do_coin_selection ( true , true ) )
630630 }
631631
632- fn sign_tx ( & self , tx : & mut Transaction ) -> Result < ( ) , ( ) > {
632+ fn sign_tx ( & self , tx : Transaction ) -> Result < Transaction , ( ) > {
633633 self . source . sign_tx ( tx)
634634 }
635635}
@@ -726,7 +726,7 @@ where
726726 satisfaction_weight: commitment_tx. weight( ) as u64 + ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT ,
727727 } ] ;
728728 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,
730730 ) ?;
731731
732732 let mut anchor_tx = Transaction {
@@ -748,7 +748,8 @@ where
748748 let unsigned_tx_weight = anchor_tx. weight ( ) as u64 - ( anchor_tx. input . len ( ) as u64 * EMPTY_SCRIPT_SIG_WEIGHT ) ;
749749
750750 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+
752753 let signer = anchor_descriptor. derive_channel_signer ( & self . signer_provider ) ;
753754 let anchor_sig = signer. sign_holder_anchor_input ( & anchor_tx, 0 , & self . secp ) ?;
754755 anchor_tx. input [ 0 ] . witness = anchor_descriptor. tx_input_witness ( & anchor_sig) ;
@@ -799,20 +800,24 @@ where
799800
800801 log_debug ! ( self . logger, "Peforming coin selection for HTLC transaction targeting {} sat/kW" ,
801802 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 > ( ) ;
802806 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,
804808 ) ?;
805809 #[ cfg( debug_assertions) ]
806810 let total_satisfaction_weight =
807811 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 ;
809813 self . process_coin_selection ( & mut htlc_tx, coin_selection) ;
810814
811815 #[ cfg( debug_assertions) ]
812816 let unsigned_tx_weight = htlc_tx. weight ( ) as u64 - ( htlc_tx. input . len ( ) as u64 * EMPTY_SCRIPT_SIG_WEIGHT ) ;
813817
814818 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+
816821 let mut signers = BTreeMap :: new ( ) ;
817822 for ( idx, htlc_descriptor) in htlc_descriptors. iter ( ) . enumerate ( ) {
818823 let signer = signers. entry ( htlc_descriptor. channel_derivation_parameters . keys_id )
0 commit comments