File tree Expand file tree Collapse file tree 3 files changed +9
-6
lines changed Expand file tree Collapse file tree 3 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -893,7 +893,8 @@ size_t bitcoin_tx_input_sig_weight(void)
893
893
/* Input weight */
894
894
size_t bitcoin_tx_input_weight (bool p2sh , size_t witness_weight )
895
895
{
896
- size_t weight = witness_weight ;
896
+ /* We assume < 253 witness elements */
897
+ size_t weight = 1 + witness_weight ;
897
898
898
899
/* Input weight: txid + index + sequence */
899
900
weight += (32 + 4 + 4 ) * 4 ;
@@ -914,8 +915,8 @@ size_t bitcoin_tx_input_weight(bool p2sh, size_t witness_weight)
914
915
915
916
size_t bitcoin_tx_simple_input_witness_weight (void )
916
917
{
917
- /* Account for witness (1 byte count + sig + key) */
918
- return 1 + ( bitcoin_tx_input_sig_weight () + 1 + 33 ) ;
918
+ /* Account for witness (sig + key) */
919
+ return bitcoin_tx_input_sig_weight () + 1 + 33 ;
919
920
}
920
921
921
922
/* We only do segwit inputs, and we assume witness is sig + key */
Original file line number Diff line number Diff line change @@ -315,7 +315,9 @@ size_t bitcoin_tx_output_weight(size_t outscript_len);
315
315
/* Weight to push sig on stack. */
316
316
size_t bitcoin_tx_input_sig_weight (void );
317
317
318
- /* Segwit input, but with parameter for witness weight (size) */
318
+ /* Segwit input, but with parameter for witness weight (size).
319
+ * witness_weight must include the varint_size() for each witness element,
320
+ * but not the varint_size() for the number of elements. */
319
321
size_t bitcoin_tx_input_weight (bool p2sh , size_t witness_weight );
320
322
321
323
/* The witness weight for a simple (sig + key) input */
Original file line number Diff line number Diff line change @@ -186,9 +186,9 @@ static void trim_maximum_feerate(struct amount_sat funding,
186
186
* * `txin[0]` script bytes: 0
187
187
* * `txin[0]` witness: `0 <signature_for_pubkey1> <signature_for_pubkey2>`
188
188
*/
189
- /* Account for witness (1 byte count + 1 empty + sig + sig) */
189
+ /* Account for witness (1 empty + sig + sig) */
190
190
assert (tal_count (commitment -> inputs ) == 1 );
191
- weight += bitcoin_tx_input_weight (false, 1 + 1 + 2 * bitcoin_tx_input_sig_weight ());
191
+ weight += bitcoin_tx_input_weight (false, 1 + 2 * bitcoin_tx_input_sig_weight ());
192
192
193
193
for (size_t i = 0 ; i < tal_count (commitment -> outputs ); i ++ ) {
194
194
struct amount_asset amt ;
You can’t perform that action at this time.
0 commit comments