mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
Fix weight calculation, rename cost->weight.
Reported-by: Jon Griffiths Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
26957fce07
commit
de0777cb2c
4 changed files with 10 additions and 7 deletions
|
@ -260,14 +260,17 @@ static void push_measure(const void *data, size_t len, void *lenp)
|
|||
*(size_t *)lenp += len;
|
||||
}
|
||||
|
||||
size_t measure_tx_cost(const struct bitcoin_tx *tx)
|
||||
size_t measure_tx_weight(const struct bitcoin_tx *tx)
|
||||
{
|
||||
size_t non_witness_len = 0, witness_len = 0;
|
||||
push_tx(tx, push_measure, &non_witness_len, false);
|
||||
if (uses_witness(tx))
|
||||
if (uses_witness(tx)) {
|
||||
push_witnesses(tx, push_measure, &witness_len);
|
||||
/* Include BIP 144 marker and flag bytes in witness length */
|
||||
witness_len += 2;
|
||||
}
|
||||
|
||||
/* Witness bytes only push 1/4 of normal bytes, for cost. */
|
||||
/* Normal bytes weigh 4 times more than Witness bytes */
|
||||
return non_witness_len * 4 + witness_len;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,8 +47,8 @@ void sha256_tx_for_sig(struct sha256_double *h, const struct bitcoin_tx *tx,
|
|||
/* Linear bytes of tx. */
|
||||
u8 *linearize_tx(const tal_t *ctx, const struct bitcoin_tx *tx);
|
||||
|
||||
/* Get cost of tx in (x4 of non-witness bytecount). */
|
||||
size_t measure_tx_cost(const struct bitcoin_tx *tx);
|
||||
/* Get weight of tx in Sipa. */
|
||||
size_t measure_tx_weight(const struct bitcoin_tx *tx);
|
||||
|
||||
/* Allocate a tx: you just need to fill in inputs and outputs (they're
|
||||
* zeroed with inputs' sequence_number set to FFFFFFFF) */
|
||||
|
|
|
@ -1786,7 +1786,7 @@ static bool better_closing_fee(struct peer *peer, const struct bitcoin_tx *tx)
|
|||
" vs previous %"PRIu64, fee, last_fee);
|
||||
|
||||
/* Weight once we add in sigs. */
|
||||
weight = measure_tx_cost(tx) + 74 * 2;
|
||||
weight = measure_tx_weight(tx) + 74 * 2;
|
||||
|
||||
min_fee = get_feerate(peer->ld->topology, FEERATE_SLOW) * weight / 1000;
|
||||
if (fee < min_fee) {
|
||||
|
|
|
@ -236,7 +236,7 @@ static struct bitcoin_tx *tx_to_us(const tal_t *ctx,
|
|||
&our_wallet_pubkey);
|
||||
|
||||
/* Worst-case sig is 73 bytes */
|
||||
fee = feerate_per_kw * (measure_tx_cost(tx)
|
||||
fee = feerate_per_kw * (measure_tx_weight(tx)
|
||||
+ 1 + 3 + 73 + 0 + tal_len(wscript))
|
||||
/ 1000;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue