@@ -20,7 +20,7 @@ use crate::io_extras::sink;
2020use crate :: ln:: channel:: ANCHOR_OUTPUT_VALUE_SATOSHI ;
2121use crate :: ln:: types:: ChannelId ;
2222use crate :: ln:: chan_utils;
23- use crate :: ln:: chan_utils:: { ANCHOR_INPUT_WITNESS_WEIGHT , HTLCOutputInCommitment } ;
23+ use crate :: ln:: chan_utils:: HTLCOutputInCommitment ;
2424use crate :: prelude:: * ;
2525use crate :: sign:: {
2626 ChannelDerivationParameters , ChannelSigner , HTLCDescriptor , SignerProvider , P2WPKH_WITNESS_WEIGHT ,
@@ -608,14 +608,17 @@ where
608608 & self , claim_id : ClaimId , package_target_feerate_sat_per_1000_weight : u32 ,
609609 commitment_tx : & Transaction , commitment_tx_fee_sat : u64 , anchor_descriptor : & AnchorDescriptor ,
610610 ) -> Result < ( ) , ( ) > {
611+ let signer = anchor_descriptor. derive_channel_signer ( & self . signer_provider ) ;
612+ let anchor_input_witness_weight = signer. get_holder_anchor_input_witness_weight ( ) ;
613+
611614 // Our commitment transaction already has fees allocated to it, so we should take them into
612615 // account. We do so by pretending the commitment transaction's fee and weight are part of
613616 // the anchor input.
614617 let mut anchor_utxo = anchor_descriptor. previous_utxo ( ) ;
615618 let commitment_tx_fee_sat = Amount :: from_sat ( commitment_tx_fee_sat) ;
616619 anchor_utxo. value += commitment_tx_fee_sat;
617620 let starting_package_and_fixed_input_satisfaction_weight =
618- commitment_tx. weight ( ) . to_wu ( ) + ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT ;
621+ commitment_tx. weight ( ) . to_wu ( ) + anchor_input_witness_weight + EMPTY_SCRIPT_SIG_WEIGHT ;
619622 let mut package_and_fixed_input_satisfaction_weight =
620623 starting_package_and_fixed_input_satisfaction_weight;
621624
@@ -640,7 +643,7 @@ where
640643 output : vec ! [ ] ,
641644 } ;
642645
643- let total_satisfaction_weight = ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT +
646+ let total_satisfaction_weight = anchor_input_witness_weight + EMPTY_SCRIPT_SIG_WEIGHT +
644647 coin_selection. confirmed_utxos . iter ( ) . map ( |utxo| utxo. satisfaction_weight ) . sum :: < u64 > ( ) ;
645648 let total_input_amount = must_spend_amount +
646649 coin_selection. confirmed_utxos . iter ( ) . map ( |utxo| utxo. output . value ) . sum ( ) ;
@@ -686,7 +689,6 @@ where
686689 log_debug ! ( self . logger, "Signing anchor transaction {}" , anchor_txid) ;
687690 anchor_tx = self . utxo_source . sign_psbt ( anchor_psbt) ?;
688691
689- let signer = anchor_descriptor. derive_channel_signer ( & self . signer_provider ) ;
690692 anchor_tx = signer. spend_holder_anchor_input ( & anchor_tx, 0 , & self . secp ) ?;
691693
692694 #[ cfg( debug_assertions) ] {
@@ -857,7 +859,7 @@ mod tests {
857859 use super :: * ;
858860
859861 use crate :: io:: Cursor ;
860- use crate :: ln:: chan_utils:: ChannelTransactionParameters ;
862+ use crate :: ln:: chan_utils:: { ANCHOR_INPUT_WITNESS_WEIGHT , ChannelTransactionParameters } ;
861863 use crate :: util:: ser:: Readable ;
862864 use crate :: util:: test_utils:: { TestBroadcaster , TestLogger } ;
863865 use crate :: sign:: KeysManager ;
0 commit comments