@@ -25,6 +25,7 @@ use crate::ln::chan_utils;
25
25
use crate :: ln:: chan_utils:: {
26
26
shared_anchor_script_pubkey, HTLCOutputInCommitment , ANCHOR_INPUT_WITNESS_WEIGHT ,
27
27
HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT , HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT ,
28
+ P2A_ANCHOR_INPUT_WITNESS_WEIGHT ,
28
29
} ;
29
30
use crate :: ln:: types:: ChannelId ;
30
31
use crate :: prelude:: * ;
@@ -669,6 +670,16 @@ where
669
670
commitment_tx : & Transaction , commitment_tx_fee_sat : u64 ,
670
671
anchor_descriptor : & AnchorDescriptor ,
671
672
) -> 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
+
672
683
// First, check if the commitment transaction has sufficient fees on its own.
673
684
let commitment_tx_feerate_sat_per_1000_weight = compute_feerate_sat_per_1000_weight (
674
685
commitment_tx_fee_sat,
@@ -689,7 +700,7 @@ where
689
700
let commitment_tx_fee_sat = Amount :: from_sat ( commitment_tx_fee_sat) ;
690
701
anchor_utxo. value += commitment_tx_fee_sat;
691
702
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 ;
693
704
let mut package_and_fixed_input_satisfaction_weight =
694
705
starting_package_and_fixed_input_satisfaction_weight;
695
706
@@ -714,8 +725,14 @@ where
714
725
)
715
726
. await ?;
716
727
728
+ let version = if channel_type. supports_anchor_zero_fee_commitments ( ) {
729
+ Version :: non_standard ( 3 )
730
+ } else {
731
+ Version :: TWO
732
+ } ;
733
+
717
734
let mut anchor_tx = Transaction {
718
- version : Version :: TWO ,
735
+ version,
719
736
lock_time : LockTime :: ZERO , // TODO: Use next best height.
720
737
input : vec ! [ anchor_descriptor. unsigned_tx_input( ) ] ,
721
738
output : vec ! [ ] ,
@@ -724,7 +741,7 @@ where
724
741
let input_satisfaction_weight: u64 =
725
742
coin_selection. confirmed_utxos . iter ( ) . map ( |utxo| utxo. satisfaction_weight ) . sum ( ) ;
726
743
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;
728
745
let total_input_amount = must_spend_amount
729
746
+ coin_selection. confirmed_utxos . iter ( ) . map ( |utxo| utxo. output . value ) . sum ( ) ;
730
747
@@ -780,18 +797,21 @@ where
780
797
log_debug ! ( self . logger, "Signing anchor transaction {}" , anchor_txid) ;
781
798
anchor_tx = self . utxo_source . sign_psbt ( anchor_psbt) . await ?;
782
799
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
+ }
795
815
796
816
#[ cfg( debug_assertions) ]
797
817
{
0 commit comments