@@ -25,6 +25,7 @@ use crate::ln::chan_utils;
2525use crate :: ln:: chan_utils:: {
2626 shared_anchor_script_pubkey, HTLCOutputInCommitment , ANCHOR_INPUT_WITNESS_WEIGHT ,
2727 HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT , HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT ,
28+ P2A_ANCHOR_INPUT_WITNESS_WEIGHT ,
2829} ;
2930use crate :: ln:: types:: ChannelId ;
3031use crate :: prelude:: * ;
@@ -669,6 +670,16 @@ where
669670 commitment_tx : & Transaction , commitment_tx_fee_sat : u64 ,
670671 anchor_descriptor : & AnchorDescriptor ,
671672 ) -> Result < ( ) , ( ) > {
673+ let channel_type = & anchor_descriptor
674+ . channel_derivation_parameters
675+ . transaction_parameters
676+ . channel_type_features ;
677+ let anchor_input_witness_weight = if channel_type. supports_anchor_zero_fee_commitments ( ) {
678+ P2A_ANCHOR_INPUT_WITNESS_WEIGHT
679+ } else {
680+ ANCHOR_INPUT_WITNESS_WEIGHT
681+ } ;
682+
672683 // First, check if the commitment transaction has sufficient fees on its own.
673684 let commitment_tx_feerate_sat_per_1000_weight = compute_feerate_sat_per_1000_weight (
674685 commitment_tx_fee_sat,
@@ -689,7 +700,7 @@ where
689700 let commitment_tx_fee_sat = Amount :: from_sat ( commitment_tx_fee_sat) ;
690701 anchor_utxo. value += commitment_tx_fee_sat;
691702 let starting_package_and_fixed_input_satisfaction_weight =
692- commitment_tx. weight ( ) . to_wu ( ) + ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT ;
703+ commitment_tx. weight ( ) . to_wu ( ) + anchor_input_witness_weight + EMPTY_SCRIPT_SIG_WEIGHT ;
693704 let mut package_and_fixed_input_satisfaction_weight =
694705 starting_package_and_fixed_input_satisfaction_weight;
695706
@@ -714,8 +725,14 @@ where
714725 )
715726 . await ?;
716727
728+ let version = if channel_type. supports_anchor_zero_fee_commitments ( ) {
729+ Version :: non_standard ( 3 )
730+ } else {
731+ Version :: TWO
732+ } ;
733+
717734 let mut anchor_tx = Transaction {
718- version : Version :: TWO ,
735+ version,
719736 lock_time : LockTime :: ZERO , // TODO: Use next best height.
720737 input : vec ! [ anchor_descriptor. unsigned_tx_input( ) ] ,
721738 output : vec ! [ ] ,
@@ -724,7 +741,7 @@ where
724741 let input_satisfaction_weight: u64 =
725742 coin_selection. confirmed_utxos . iter ( ) . map ( |utxo| utxo. satisfaction_weight ) . sum ( ) ;
726743 let total_satisfaction_weight =
727- ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT + input_satisfaction_weight;
744+ anchor_input_witness_weight + EMPTY_SCRIPT_SIG_WEIGHT + input_satisfaction_weight;
728745 let total_input_amount = must_spend_amount
729746 + coin_selection. confirmed_utxos . iter ( ) . map ( |utxo| utxo. output . value ) . sum ( ) ;
730747
@@ -780,18 +797,21 @@ where
780797 log_debug ! ( self . logger, "Signing anchor transaction {}" , anchor_txid) ;
781798 anchor_tx = self . utxo_source . sign_psbt ( anchor_psbt) . await ?;
782799
783- let signer = self
784- . signer_provider
785- . derive_channel_signer ( anchor_descriptor. channel_derivation_parameters . keys_id ) ;
786- let channel_parameters =
787- & anchor_descriptor. channel_derivation_parameters . transaction_parameters ;
788- let anchor_sig = signer. sign_holder_keyed_anchor_input (
789- channel_parameters,
790- & anchor_tx,
791- 0 ,
792- & self . secp ,
793- ) ?;
794- anchor_tx. input [ 0 ] . witness = anchor_descriptor. tx_input_witness ( & anchor_sig) ;
800+ // No need to produce any witness to spend P2A anchors
801+ if channel_type. supports_anchors_zero_fee_htlc_tx ( ) {
802+ let signer = self
803+ . signer_provider
804+ . derive_channel_signer ( anchor_descriptor. channel_derivation_parameters . keys_id ) ;
805+ let channel_parameters =
806+ & anchor_descriptor. channel_derivation_parameters . transaction_parameters ;
807+ let anchor_sig = signer. sign_holder_keyed_anchor_input (
808+ channel_parameters,
809+ & anchor_tx,
810+ 0 ,
811+ & self . secp ,
812+ ) ?;
813+ anchor_tx. input [ 0 ] . witness = anchor_descriptor. tx_input_witness ( & anchor_sig) ;
814+ }
795815
796816 #[ cfg( debug_assertions) ]
797817 {
0 commit comments