channeld: use amount_sat/amount_msat.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-02-21 14:15:55 +10:30
parent 93dcd5fed7
commit bb00deeea4
13 changed files with 354 additions and 223 deletions

View File

@@ -3,6 +3,7 @@
#define LIGHTNING_COMMON_INITIAL_COMMIT_TX_H
#include "config.h"
#include <bitcoin/pubkey.h>
#include <common/amount.h>
#include <common/htlc.h>
struct keyset;
@@ -18,8 +19,8 @@ u64 commit_number_obscurer(const struct pubkey *opener_payment_basepoint,
const struct pubkey *accepter_payment_basepoint);
/* Helper to calculate the base fee if we have this many htlc outputs */
static inline u64 commit_tx_base_fee_sat(u32 feerate_per_kw,
size_t num_untrimmed_htlcs)
static inline struct amount_sat commit_tx_base_fee(u32 feerate_per_kw,
size_t num_untrimmed_htlcs)
{
u64 weight;
@@ -44,26 +45,20 @@ static inline u64 commit_tx_base_fee_sat(u32 feerate_per_kw,
* 3. Multiply `feerate_per_kw` by `weight`, divide by 1000 (rounding
* down).
*/
return (feerate_per_kw * weight / 1000);
}
static inline u64 commit_tx_base_fee_msat(u32 feerate_per_kw,
size_t num_untrimmed_htlcs)
{
return commit_tx_base_fee_sat(feerate_per_kw, num_untrimmed_htlcs)
* 1000;
return amount_tx_fee(feerate_per_kw, weight);
}
/**
* initial_commit_tx: create (unsigned) commitment tx to spend the funding tx output
* @ctx: context to allocate transaction and @htlc_map from.
* @funding_txid, @funding_out, @funding_satoshis: funding outpoint.
* @funding_txid, @funding_out, @funding: funding outpoint.
* @funder: is the LOCAL or REMOTE paying the fee?
* @keyset: keys derived for this commit tx.
* @feerate_per_kw: feerate to use
* @dust_limit_satoshis: dust limit below which to trim outputs.
* @self_pay_msat: amount to pay directly to self
* @other_pay_msat: amount to pay directly to the other side
* @dust_limit: dust limit below which to trim outputs.
* @self_pay: amount to pay directly to self
* @other_pay: amount to pay directly to the other side
* @self_reserve: reserve the other side insisted we have
* @obscured_commitment_number: number to encode in commitment transaction
* @side: side to generate commitment transaction for.
*
@@ -74,21 +69,23 @@ static inline u64 commit_tx_base_fee_msat(u32 feerate_per_kw,
struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
const struct bitcoin_txid *funding_txid,
unsigned int funding_txout,
u64 funding_satoshis,
struct amount_sat funding,
enum side funder,
u16 to_self_delay,
const struct keyset *keyset,
u32 feerate_per_kw,
u64 dust_limit_satoshis,
u64 self_pay_msat,
u64 other_pay_msat,
u64 self_reserve_msat,
struct amount_sat dust_limit,
struct amount_msat self_pay,
struct amount_msat other_pay,
struct amount_sat self_reserve,
u64 obscured_commitment_number,
enum side side);
/* try_subtract_fee - take away this fee from the funder (and return true), or all if insufficient (and return false). */
bool try_subtract_fee(enum side funder, enum side side,
u64 base_fee_msat, u64 *self_msat, u64 *other_msat);
struct amount_sat base_fee,
struct amount_msat *self,
struct amount_msat *other);
/* Generate the witness script for the to-self output:
* scriptpubkey_p2wsh(ctx, wscript) gives the scriptpubkey */