mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 23:54:22 +01:00
bitcoin: fix tx weight calculation when there are no witnesses, but will be.
We had an out-by-two error when calculating weights, because we grab weights on unsigned txs. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
4dafeede5c
commit
59f1749967
13
bitcoin/tx.c
13
bitcoin/tx.c
@@ -457,7 +457,18 @@ size_t wally_tx_weight(const struct wally_tx *wtx)
|
||||
|
||||
size_t bitcoin_tx_weight(const struct bitcoin_tx *tx)
|
||||
{
|
||||
return wally_tx_weight(tx->wtx);
|
||||
size_t extra;
|
||||
size_t num_witnesses;
|
||||
|
||||
/* If we don't have witnesses *yet*, libwally doesn't encode
|
||||
* in BIP 141 style, omitting the flag and marker bytes */
|
||||
wally_tx_get_witness_count(tx->wtx, &num_witnesses);
|
||||
if (num_witnesses == 0)
|
||||
extra = 2;
|
||||
else
|
||||
extra = 0;
|
||||
|
||||
return extra + wally_tx_weight(tx->wtx);
|
||||
}
|
||||
|
||||
void wally_txid(const struct wally_tx *wtx, struct bitcoin_txid *txid)
|
||||
|
||||
Reference in New Issue
Block a user