@@ -167,6 +167,8 @@ pub struct StaticPaymentOutputDescriptor {
167167 ///
168168 /// Added as optional, but always `Some` if the descriptor was produced in v0.0.117 or later.
169169 pub channel_transaction_parameters : Option < ChannelTransactionParameters > ,
170+ /// Witness weight
171+ pub witness_weight : u64 ,
170172}
171173
172174impl StaticPaymentOutputDescriptor {
@@ -184,27 +186,22 @@ impl StaticPaymentOutputDescriptor {
184186 }
185187 } )
186188 }
187-
188- /// The maximum length a well-formed witness spending one of these should have.
189- /// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
190- /// shorter.
191- pub fn max_witness_length ( & self ) -> u64 {
192- if self . channel_transaction_parameters . as_ref ( ) . map_or ( false , |p| p. supports_anchors ( ) ) {
193- let witness_script_weight = 1 /* pubkey push */ + 33 /* pubkey */ +
194- 1 /* OP_CHECKSIGVERIFY */ + 1 /* OP_1 */ + 1 /* OP_CHECKSEQUENCEVERIFY */ ;
195- 1 /* num witness items */ + 1 /* sig push */ + 73 /* sig including sighash flag */ +
196- 1 /* witness script push */ + witness_script_weight
197- } else {
198- P2WPKH_WITNESS_WEIGHT
199- }
200- }
201189}
202190impl_writeable_tlv_based ! ( StaticPaymentOutputDescriptor , {
203191 ( 0 , outpoint, required) ,
204192 ( 2 , output, required) ,
205193 ( 4 , channel_keys_id, required) ,
206194 ( 6 , channel_value_satoshis, required) ,
207195 ( 7 , channel_transaction_parameters, option) ,
196+ // Don't break downgrades ?
197+ ( 9 , witness_weight, ( default_value,
198+ if channel_transaction_parameters. as_ref( ) . map_or( false , |p: & ChannelTransactionParameters | p. supports_anchors( ) ) {
199+ let witness_script_weight = 1 /* pubkey push */ + 33 /* pubkey */ + 1 /* OP_CHECKSIGVERIFY */ + 1 /* OP_1 */ + 1 /* OP_CHECKSEQUENCEVERIFY */ ;
200+ 1 /* num witness items */ + 1 /* sig push */ + 73 /* sig including sighash flag */ + 1 /* witness script push */ + witness_script_weight
201+ } else {
202+ P2WPKH_WITNESS_WEIGHT
203+ } )
204+ ) ,
208205} ) ;
209206
210207/// Describes the necessary information to spend a spendable output.
@@ -468,7 +465,7 @@ impl SpendableOutputDescriptor {
468465 sequence,
469466 witness : Witness :: new ( ) ,
470467 } ) ;
471- witness_weight += descriptor. max_witness_length ( ) ;
468+ witness_weight += descriptor. witness_weight ;
472469 #[ cfg( feature = "grind_signatures" ) ]
473470 {
474471 // Guarantees a low R signature
@@ -1088,6 +1085,21 @@ pub trait ChannelSigner {
10881085 fn get_holder_anchor_input_witness_weight ( & self ) -> u64 {
10891086 ANCHOR_INPUT_WITNESS_WEIGHT
10901087 }
1088+
1089+ /// Gets the weight of the witness that spends a `to_remote` output
1090+ fn get_to_remote_witness_weight ( & self ) -> u64 {
1091+ // The maximum length a well-formed witness spending one of these should have.
1092+ // Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
1093+ // shorter.
1094+ if self . get_channel_parameters ( ) . as_ref ( ) . map_or ( false , |p| p. supports_anchors ( ) ) {
1095+ let witness_script_weight = 1 /* pubkey push */ + 33 /* pubkey */ +
1096+ 1 /* OP_CHECKSIGVERIFY */ + 1 /* OP_1 */ + 1 /* OP_CHECKSEQUENCEVERIFY */ ;
1097+ 1 /* num witness items */ + 1 /* sig push */ + 73 /* sig including sighash flag */ +
1098+ 1 /* witness script push */ + witness_script_weight
1099+ } else {
1100+ P2WPKH_WITNESS_WEIGHT
1101+ }
1102+ }
10911103}
10921104
10931105/// Specifies the recipient of an invoice.
0 commit comments