Browse Source

feerate: use u32 everywhere.

The wire protocol uses this, in the assumption that we'll never see feerates
in excess of 4294967 satoshi per kiloweight.

So let's use that consistently internally as well.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
f1e4cad9d4
  1. 6
      channeld/commit_tx.c
  2. 4
      channeld/commit_tx.h
  3. 2
      channeld/full_channel.c
  4. 10
      channeld/full_channel.h
  5. 5
      channeld/test/run-full_channel.c
  6. 4
      common/htlc_tx.c
  7. 12
      common/htlc_tx.h
  8. 2
      common/initial_channel.c
  9. 2
      common/initial_channel.h
  10. 2
      common/initial_commit_tx.c
  11. 4
      common/initial_commit_tx.h
  12. 8
      lightningd/bitcoind.c
  13. 4
      lightningd/bitcoind.h
  14. 13
      lightningd/chaintopology.c
  15. 8
      lightningd/chaintopology.h
  16. 25
      lightningd/options.c
  17. 23
      lightningd/test/run-commit_tx.c
  18. 2
      onchaind/onchain.c
  19. 2
      onchaind/onchain_wire.csv
  20. 2
      wallet/wallet.c

6
channeld/commit_tx.c

@ -12,7 +12,7 @@
#endif #endif
static bool trim(const struct htlc *htlc, static bool trim(const struct htlc *htlc,
u64 feerate_per_kw, u64 dust_limit_satoshis, u32 feerate_per_kw, u64 dust_limit_satoshis,
enum side side) enum side side)
{ {
u64 htlc_fee; u64 htlc_fee;
@ -42,7 +42,7 @@ static bool trim(const struct htlc *htlc,
} }
size_t commit_tx_num_untrimmed(const struct htlc **htlcs, size_t commit_tx_num_untrimmed(const struct htlc **htlcs,
u64 feerate_per_kw, u64 dust_limit_satoshis, u32 feerate_per_kw, u64 dust_limit_satoshis,
enum side side) enum side side)
{ {
size_t i, n; size_t i, n;
@ -92,7 +92,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
enum side funder, enum side funder,
u16 to_self_delay, u16 to_self_delay,
const struct keyset *keyset, const struct keyset *keyset,
u64 feerate_per_kw, u32 feerate_per_kw,
u64 dust_limit_satoshis, u64 dust_limit_satoshis,
u64 self_pay_msat, u64 self_pay_msat,
u64 other_pay_msat, u64 other_pay_msat,

4
channeld/commit_tx.h

@ -20,7 +20,7 @@ struct sha256_double;
* received HTLCs. * received HTLCs.
*/ */
size_t commit_tx_num_untrimmed(const struct htlc **htlcs, size_t commit_tx_num_untrimmed(const struct htlc **htlcs,
u64 feerate_per_kw, u64 dust_limit_satoshis, u32 feerate_per_kw, u64 dust_limit_satoshis,
enum side side); enum side side);
/** /**
@ -49,7 +49,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
enum side funder, enum side funder,
u16 to_self_delay, u16 to_self_delay,
const struct keyset *keyset, const struct keyset *keyset,
u64 feerate_per_kw, u32 feerate_per_kw,
u64 dust_limit_satoshis, u64 dust_limit_satoshis,
u64 self_pay_msat, u64 self_pay_msat,
u64 other_pay_msat, u64 other_pay_msat,

2
channeld/full_channel.c

@ -398,7 +398,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
* `feerate_per_kw` while maintaining its channel reserve. * `feerate_per_kw` while maintaining its channel reserve.
*/ */
if (channel->funder == htlc_owner(htlc)) { if (channel->funder == htlc_owner(htlc)) {
u64 feerate = view->feerate_per_kw; u32 feerate = view->feerate_per_kw;
u64 dust = dust_limit_satoshis(channel, recipient); u64 dust = dust_limit_satoshis(channel, recipient);
size_t untrimmed; size_t untrimmed;

10
channeld/full_channel.h

@ -74,8 +74,8 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
* This is the fee rate we actually care about, if we're going to check * This is the fee rate we actually care about, if we're going to check
* whether it's actually too low. * whether it's actually too low.
*/ */
uint32_t actual_feerate(const struct channel *channel, u32 actual_feerate(const struct channel *channel,
const struct signature *theirsig); const struct signature *theirsig);
enum channel_add_err { enum channel_add_err {
/* All OK! */ /* All OK! */
@ -175,14 +175,14 @@ enum channel_remove_err channel_fulfill_htlc(struct channel *channel,
* *
* This is not exact! To check if their offer is valid, use can_afford_feerate. * This is not exact! To check if their offer is valid, use can_afford_feerate.
*/ */
u64 approx_max_feerate(const struct channel *channel); u32 approx_max_feerate(const struct channel *channel);
/** /**
* can_afford_feerate: could the initiator pay for the fee at fee_rate? * can_afford_feerate: could the initiator pay for the fee at fee_rate?
* @channel: The channel state * @channel: The channel state
* @feerate_per_kw: the new fee rate proposed * @feerate_per_kw: the new fee rate proposed
*/ */
bool can_afford_feerate(const struct channel *channel, u64 feerate_per_kw); bool can_afford_feerate(const struct channel *channel, u32 feerate_per_kw);
/** /**
* adjust_fee: Change fee rate. * adjust_fee: Change fee rate.
@ -190,7 +190,7 @@ bool can_afford_feerate(const struct channel *channel, u64 feerate_per_kw);
* @feerate_per_kw: fee in satoshi per 1000 bytes. * @feerate_per_kw: fee in satoshi per 1000 bytes.
* @side: which side to adjust. * @side: which side to adjust.
*/ */
void adjust_fee(struct channel *channel, u64 feerate_per_kw, enum side side); void adjust_fee(struct channel *channel, u32 feerate_per_kw, enum side side);
/** /**
* channel_sending_commit: commit all remote outstanding changes. * channel_sending_commit: commit all remote outstanding changes.

5
channeld/test/run-full_channel.c

@ -77,7 +77,7 @@ static struct bitcoin_tx *tx_from_hex(const tal_t *ctx, const char *hex)
* ... * ...
* local_feerate_per_kw: 9651936 * local_feerate_per_kw: 9651936
*/ */
static u64 feerates[] = { static u32 feerates[] = {
647, 648, 647, 648,
2069, 2070, 2069, 2070,
2194, 2195, 2194, 2195,
@ -304,7 +304,8 @@ int main(void)
struct sha256_double funding_txid; struct sha256_double funding_txid;
/* We test from both sides. */ /* We test from both sides. */
struct channel *lchannel, *rchannel; struct channel *lchannel, *rchannel;
u64 funding_amount_satoshi, feerate_per_kw; u64 funding_amount_satoshi;
u32 feerate_per_kw;
unsigned int funding_output_index; unsigned int funding_output_index;
struct keyset keyset; struct keyset keyset;
struct pubkey local_funding_pubkey, remote_funding_pubkey; struct pubkey local_funding_pubkey, remote_funding_pubkey;

4
common/htlc_tx.c

@ -76,7 +76,7 @@ struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
unsigned int commit_output_number, unsigned int commit_output_number,
u64 htlc_msatoshi, u64 htlc_msatoshi,
u16 to_self_delay, u16 to_self_delay,
u64 feerate_per_kw, u32 feerate_per_kw,
const struct keyset *keyset) const struct keyset *keyset)
{ {
/* BOLT #3: /* BOLT #3:
@ -122,7 +122,7 @@ struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
u64 htlc_msatoshi, u64 htlc_msatoshi,
u32 cltv_expiry, u32 cltv_expiry,
u16 to_self_delay, u16 to_self_delay,
u64 feerate_per_kw, u32 feerate_per_kw,
const struct keyset *keyset) const struct keyset *keyset)
{ {
/* BOLT #3: /* BOLT #3:

12
common/htlc_tx.h

@ -8,7 +8,7 @@ struct preimage;
struct pubkey; struct pubkey;
struct sha256_double; struct sha256_double;
static inline u64 htlc_timeout_fee(u64 feerate_per_kw) static inline u64 htlc_timeout_fee(u32 feerate_per_kw)
{ {
/* BOLT #3: /* BOLT #3:
* *
@ -17,10 +17,10 @@ static inline u64 htlc_timeout_fee(u64 feerate_per_kw)
* 1. Multiply `feerate_per_kw` by 663 and divide by 1000 (rounding * 1. Multiply `feerate_per_kw` by 663 and divide by 1000 (rounding
* down). * down).
*/ */
return feerate_per_kw * 663 / 1000; return feerate_per_kw * 663ULL / 1000;
} }
static inline u64 htlc_success_fee(u64 feerate_per_kw) static inline u64 htlc_success_fee(u32 feerate_per_kw)
{ {
/* BOLT #3: /* BOLT #3:
* *
@ -29,7 +29,7 @@ static inline u64 htlc_success_fee(u64 feerate_per_kw)
* 1. Multiply `feerate_per_kw` by 703 and divide by 1000 (rounding * 1. Multiply `feerate_per_kw` by 703 and divide by 1000 (rounding
* down). * down).
*/ */
return feerate_per_kw * 703 / 1000; return feerate_per_kw * 703ULL / 1000;
} }
/* Create HTLC-success tx to spend a received HTLC commitment tx /* Create HTLC-success tx to spend a received HTLC commitment tx
@ -39,7 +39,7 @@ struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
unsigned int commit_output_number, unsigned int commit_output_number,
u64 htlc_msatoshi, u64 htlc_msatoshi,
u16 to_self_delay, u16 to_self_delay,
u64 feerate_per_kw, u32 feerate_per_kw,
const struct keyset *keyset); const struct keyset *keyset);
/* Fill in the witness for HTLC-success tx produced above. */ /* Fill in the witness for HTLC-success tx produced above. */
@ -60,7 +60,7 @@ struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
u64 htlc_msatoshi, u64 htlc_msatoshi,
u32 cltv_expiry, u32 cltv_expiry,
u16 to_self_delay, u16 to_self_delay,
u64 feerate_per_kw, u32 feerate_per_kw,
const struct keyset *keyset); const struct keyset *keyset);
/* Fill in the witness for HTLC-timeout tx produced above. */ /* Fill in the witness for HTLC-timeout tx produced above. */

2
common/initial_channel.c

@ -105,7 +105,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
static char *fmt_channel_view(const tal_t *ctx, const struct channel_view *view) static char *fmt_channel_view(const tal_t *ctx, const struct channel_view *view)
{ {
return tal_fmt(ctx, "{ feerate_per_kw=%"PRIu64"," return tal_fmt(ctx, "{ feerate_per_kw=%"PRIu32","
" owed_local=%"PRIu64"," " owed_local=%"PRIu64","
" owed_remote=%"PRIu64" }", " owed_remote=%"PRIu64" }",
view->feerate_per_kw, view->feerate_per_kw,

2
common/initial_channel.h

@ -20,7 +20,7 @@ struct fulfilled_htlc;
/* View from each side */ /* View from each side */
struct channel_view { struct channel_view {
/* Current feerate in satoshis per 1000 weight. */ /* Current feerate in satoshis per 1000 weight. */
u64 feerate_per_kw; u32 feerate_per_kw;
/* How much is owed to each side (includes pending changes) */ /* How much is owed to each side (includes pending changes) */
u64 owed_msat[NUM_SIDES]; u64 owed_msat[NUM_SIDES];

2
common/initial_commit_tx.c

@ -61,7 +61,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
enum side funder, enum side funder,
u16 to_self_delay, u16 to_self_delay,
const struct keyset *keyset, const struct keyset *keyset,
u64 feerate_per_kw, u32 feerate_per_kw,
u64 dust_limit_satoshis, u64 dust_limit_satoshis,
u64 self_pay_msat, u64 self_pay_msat,
u64 other_pay_msat, u64 other_pay_msat,

4
common/initial_commit_tx.h

@ -19,7 +19,7 @@ u64 commit_number_obscurer(const struct pubkey *opener_payment_basepoint,
const struct pubkey *accepter_payment_basepoint); const struct pubkey *accepter_payment_basepoint);
/* Helper to calculate the base fee if we have this many htlc outputs */ /* Helper to calculate the base fee if we have this many htlc outputs */
static inline u64 commit_tx_base_fee(u64 feerate_per_kw, static inline u64 commit_tx_base_fee(u32 feerate_per_kw,
size_t num_untrimmed_htlcs) size_t num_untrimmed_htlcs)
{ {
u64 weight; u64 weight;
@ -73,7 +73,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
enum side funder, enum side funder,
u16 to_self_delay, u16 to_self_delay,
const struct keyset *keyset, const struct keyset *keyset,
u64 feerate_per_kw, u32 feerate_per_kw,
u64 dust_limit_satoshis, u64 dust_limit_satoshis,
u64 self_pay_msat, u64 self_pay_msat,
u64 other_pay_msat, u64 other_pay_msat,

8
lightningd/bitcoind.c

@ -264,10 +264,10 @@ struct estimatefee {
const u32 *blocks; const u32 *blocks;
const char **estmode; const char **estmode;
void (*cb)(struct bitcoind *bitcoind, const u64 satoshi_per_kw[], void (*cb)(struct bitcoind *bitcoind, const u32 satoshi_per_kw[],
void *); void *);
void *arg; void *arg;
u64 *satoshi_per_kw; u32 *satoshi_per_kw;
}; };
static void do_one_estimatefee(struct bitcoind *bitcoind, static void do_one_estimatefee(struct bitcoind *bitcoind,
@ -312,7 +312,7 @@ void bitcoind_estimate_fees_(struct bitcoind *bitcoind,
const u32 blocks[], const char *estmode[], const u32 blocks[], const char *estmode[],
size_t num_estimates, size_t num_estimates,
void (*cb)(struct bitcoind *bitcoind, void (*cb)(struct bitcoind *bitcoind,
const u64 satoshi_per_kw[], void *), const u32 satoshi_per_kw[], void *),
void *arg) void *arg)
{ {
struct estimatefee *efee = tal(bitcoind, struct estimatefee); struct estimatefee *efee = tal(bitcoind, struct estimatefee);
@ -323,7 +323,7 @@ void bitcoind_estimate_fees_(struct bitcoind *bitcoind,
0); 0);
efee->cb = cb; efee->cb = cb;
efee->arg = arg; efee->arg = arg;
efee->satoshi_per_kw = tal_arr(efee, u64, num_estimates); efee->satoshi_per_kw = tal_arr(efee, u32, num_estimates);
do_one_estimatefee(bitcoind, efee); do_one_estimatefee(bitcoind, efee);
} }

4
lightningd/bitcoind.h

@ -59,7 +59,7 @@ void bitcoind_estimate_fees_(struct bitcoind *bitcoind,
const u32 blocks[], const char *estmode[], const u32 blocks[], const char *estmode[],
size_t num_estimates, size_t num_estimates,
void (*cb)(struct bitcoind *bitcoind, void (*cb)(struct bitcoind *bitcoind,
const u64 satoshi_per_kw[], void *), const u32 satoshi_per_kw[], void *),
void *arg); void *arg);
#define bitcoind_estimate_fees(bitcoind_, blocks, estmode, num, cb, arg) \ #define bitcoind_estimate_fees(bitcoind_, blocks, estmode, num, cb, arg) \
@ -67,7 +67,7 @@ void bitcoind_estimate_fees_(struct bitcoind *bitcoind,
typesafe_cb_preargs(void, void *, \ typesafe_cb_preargs(void, void *, \
(cb), (arg), \ (cb), (arg), \
struct bitcoind *, \ struct bitcoind *, \
const u64 *), \ const u32 *), \
(arg)) (arg))
void bitcoind_sendrawtx_(struct bitcoind *bitcoind, void bitcoind_sendrawtx_(struct bitcoind *bitcoind,

13
lightningd/chaintopology.c

@ -300,11 +300,11 @@ static const char *feerate_name(enum feerate feerate)
/* We sanitize feerates if necessary to put them in descending order. */ /* We sanitize feerates if necessary to put them in descending order. */
static void update_feerates(struct bitcoind *bitcoind, static void update_feerates(struct bitcoind *bitcoind,
const u64 *satoshi_per_kw, const u32 *satoshi_per_kw,
struct chain_topology *topo) struct chain_topology *topo)
{ {
for (size_t i = 0; i < NUM_FEERATES; i++) { for (size_t i = 0; i < NUM_FEERATES; i++) {
log_debug(topo->log, "%s feerate %"PRIu64" (was %"PRIu64")", log_debug(topo->log, "%s feerate %u (was %u)",
feerate_name(i), feerate_name(i),
satoshi_per_kw[i], topo->feerate[i]); satoshi_per_kw[i], topo->feerate[i]);
topo->feerate[i] = satoshi_per_kw[i]; topo->feerate[i] = satoshi_per_kw[i];
@ -314,8 +314,7 @@ static void update_feerates(struct bitcoind *bitcoind,
for (size_t j = 0; j < i; j++) { for (size_t j = 0; j < i; j++) {
if (topo->feerate[j] < topo->feerate[i]) { if (topo->feerate[j] < topo->feerate[i]) {
log_unusual(topo->log, log_unusual(topo->log,
"Feerate %s (%"PRIu64") above" "Feerate %s (%u) above %s (%u)",
" %s (%"PRIu64")",
feerate_name(i), topo->feerate[i], feerate_name(i), topo->feerate[i],
feerate_name(j), topo->feerate[j]); feerate_name(j), topo->feerate[j]);
topo->feerate[j] = topo->feerate[i]; topo->feerate[j] = topo->feerate[i];
@ -486,10 +485,10 @@ u32 get_block_height(const struct chain_topology *topo)
} }
/* We may only have estimate for 2 blocks, for example. Extrapolate. */ /* We may only have estimate for 2 blocks, for example. Extrapolate. */
static u64 guess_feerate(const struct chain_topology *topo, enum feerate feerate) static u32 guess_feerate(const struct chain_topology *topo, enum feerate feerate)
{ {
size_t i = 0; size_t i = 0;
u64 rate = 0; u32 rate = 0;
/* We assume each one is half the previous. */ /* We assume each one is half the previous. */
for (i = 0; i < feerate; i++) { for (i = 0; i < feerate; i++) {
@ -513,7 +512,7 @@ static u64 guess_feerate(const struct chain_topology *topo, enum feerate feerate
return rate; return rate;
} }
u64 get_feerate(const struct chain_topology *topo, enum feerate feerate) u32 get_feerate(const struct chain_topology *topo, enum feerate feerate)
{ {
if (topo->override_fee_rate) { if (topo->override_fee_rate) {
log_debug(topo->log, "Forcing fee rate, ignoring estimate"); log_debug(topo->log, "Forcing fee rate, ignoring estimate");

8
lightningd/chaintopology.h

@ -89,7 +89,7 @@ struct chain_topology {
struct block *root; struct block *root;
struct block *tip; struct block *tip;
struct block_map block_map; struct block_map block_map;
u64 feerate[NUM_FEERATES]; u32 feerate[NUM_FEERATES];
bool startup; bool startup;
/* Where to log things. */ /* Where to log things. */
@ -111,10 +111,10 @@ struct chain_topology {
struct list_head outgoing_txs; struct list_head outgoing_txs;
/* Force a partiular fee rate regardless of estimatefee (satoshis/kb) */ /* Force a partiular fee rate regardless of estimatefee (satoshis/kb) */
u64 *override_fee_rate; u32 *override_fee_rate;
/* What fee we use if estimatefee fails (satoshis/kb) */ /* What fee we use if estimatefee fails (satoshis/kb) */
u64 default_fee_rate; u32 default_fee_rate;
/* Transactions/txos we are watching. */ /* Transactions/txos we are watching. */
struct txwatch_hash txwatches; struct txwatch_hash txwatches;
@ -146,7 +146,7 @@ size_t get_tx_depth(const struct chain_topology *topo,
u32 get_block_height(const struct chain_topology *topo); u32 get_block_height(const struct chain_topology *topo);
/* Get fee rate in satoshi per kiloweight. */ /* Get fee rate in satoshi per kiloweight. */
u64 get_feerate(const struct chain_topology *topo, enum feerate feerate); u32 get_feerate(const struct chain_topology *topo, enum feerate feerate);
/* Broadcast a single tx, and rebroadcast as reqd (copies tx). /* Broadcast a single tx, and rebroadcast as reqd (copies tx).
* If failed is non-NULL, call that and don't rebroadcast. */ * If failed is non-NULL, call that and don't rebroadcast. */

25
lightningd/options.c

@ -54,22 +54,6 @@ static void tal_freefn(void *ptr)
#define TIME_FROM_MSEC(msec) \ #define TIME_FROM_MSEC(msec) \
{ { .tv_nsec = ((msec) % 1000) * 1000000, .tv_sec = (msec) / 1000 } } { { .tv_nsec = ((msec) % 1000) * 1000000, .tv_sec = (msec) / 1000 } }
static char *opt_set_u64(const char *arg, u64 *u)
{
char *endp;
unsigned long long l;
/* This is how the manpage says to do it. Yech. */
errno = 0;
l = strtoull(arg, &endp, 0);
if (*endp || !arg[0])
return tal_fmt(NULL, "'%s' is not a number", arg);
*u = l;
if (errno || *u != l)
return tal_fmt(NULL, "'%s' is out of range", arg);
return NULL;
}
static char *opt_set_u32(const char *arg, u32 *u) static char *opt_set_u32(const char *arg, u32 *u)
{ {
char *endp; char *endp;
@ -130,11 +114,6 @@ static char *opt_add_ipaddr(const char *arg, struct lightningd *ld)
return tal_fmt(NULL, "Unable to parse IP address '%s'", arg); return tal_fmt(NULL, "Unable to parse IP address '%s'", arg);
} }
static void opt_show_u64(char buf[OPT_SHOW_LEN], const u64 *u)
{
snprintf(buf, OPT_SHOW_LEN, "%"PRIu64, *u);
}
static void opt_show_u32(char buf[OPT_SHOW_LEN], const u32 *u) static void opt_show_u32(char buf[OPT_SHOW_LEN], const u32 *u)
{ {
snprintf(buf, OPT_SHOW_LEN, "%"PRIu32, *u); snprintf(buf, OPT_SHOW_LEN, "%"PRIu32, *u);
@ -197,7 +176,7 @@ static char *opt_set_alias(const char *arg, struct lightningd *ld)
static char *opt_set_fee_rates(const char *arg, struct chain_topology *topo) static char *opt_set_fee_rates(const char *arg, struct chain_topology *topo)
{ {
tal_free(topo->override_fee_rate); tal_free(topo->override_fee_rate);
topo->override_fee_rate = tal_arr(topo, u64, 3); topo->override_fee_rate = tal_arr(topo, u32, 3);
for (size_t i = 0; i < tal_count(topo->override_fee_rate); i++) { for (size_t i = 0; i < tal_count(topo->override_fee_rate); i++) {
char *endp; char *endp;
@ -249,7 +228,7 @@ static void config_register_opts(struct lightningd *ld)
opt_register_arg("--override-fee-rates", opt_set_fee_rates, NULL, opt_register_arg("--override-fee-rates", opt_set_fee_rates, NULL,
ld->topology, ld->topology,
"Force a specific rates (immediate/normal/slow) in satoshis per kb regardless of estimated fees"); "Force a specific rates (immediate/normal/slow) in satoshis per kb regardless of estimated fees");
opt_register_arg("--default-fee-rate", opt_set_u64, opt_show_u64, opt_register_arg("--default-fee-rate", opt_set_u32, opt_show_u32,
&ld->topology->default_fee_rate, &ld->topology->default_fee_rate,
"Satoshis per kb if can't estimate fees"); "Satoshis per kb if can't estimate fees");
opt_register_arg("--cltv-delta", opt_set_u32, opt_show_u32, opt_register_arg("--cltv-delta", opt_set_u32, opt_show_u32,

23
lightningd/test/run-commit_tx.c

@ -204,7 +204,7 @@ static void report_htlcs(const struct bitcoin_tx *tx,
const struct pubkey *remotekey, const struct pubkey *remotekey,
const struct pubkey *remote_htlckey, const struct pubkey *remote_htlckey,
const struct pubkey *remote_revocation_key, const struct pubkey *remote_revocation_key,
u64 feerate_per_kw) u32 feerate_per_kw)
{ {
tal_t *tmpctx = tal_tmpctx(NULL); tal_t *tmpctx = tal_tmpctx(NULL);
size_t i, n; size_t i, n;
@ -336,7 +336,7 @@ static void report(struct bitcoin_tx *tx,
const struct pubkey *remotekey, const struct pubkey *remotekey,
const struct pubkey *remote_htlckey, const struct pubkey *remote_htlckey,
const struct pubkey *remote_revocation_key, const struct pubkey *remote_revocation_key,
u64 feerate_per_kw, u32 feerate_per_kw,
const struct htlc **htlc_map) const struct htlc **htlc_map)
{ {
tal_t *tmpctx = tal_tmpctx(NULL); tal_t *tmpctx = tal_tmpctx(NULL);
@ -387,12 +387,12 @@ static u64 calc_fee(const struct bitcoin_tx *tx, u64 input_satoshi)
} }
/* For debugging, we do brute-force increase to find thresholds */ /* For debugging, we do brute-force increase to find thresholds */
static u64 increase(u64 feerate_per_kw) static u32 increase(u32 feerate_per_kw)
{ {
return feerate_per_kw + 1; return feerate_per_kw + 1;
} }
#else #else
static u64 increase(u64 feerate_per_kw) static u64 increase(u32 feerate_per_kw)
{ {
/* BOLT #3: /* BOLT #3:
* *
@ -444,7 +444,8 @@ int main(void)
{ {
tal_t *tmpctx = tal_tmpctx(NULL); tal_t *tmpctx = tal_tmpctx(NULL);
struct sha256_double funding_txid; struct sha256_double funding_txid;
u64 funding_amount_satoshi, dust_limit_satoshi, feerate_per_kw; u64 funding_amount_satoshi, dust_limit_satoshi;
u32 feerate_per_kw;
u16 to_self_delay; u16 to_self_delay;
/* x_ prefix means internal vars we used to derive spec */ /* x_ prefix means internal vars we used to derive spec */
struct privkey local_funding_privkey, x_remote_funding_privkey; struct privkey local_funding_privkey, x_remote_funding_privkey;
@ -713,7 +714,7 @@ int main(void)
"name: simple commitment tx with no HTLCs\n" "name: simple commitment tx with no HTLCs\n"
"to_local_msat: %"PRIu64"\n" "to_local_msat: %"PRIu64"\n"
"to_remote_msat: %"PRIu64"\n" "to_remote_msat: %"PRIu64"\n"
"local_feerate_per_kw: %"PRIu64"\n", "local_feerate_per_kw: %u\n",
to_local_msat, to_remote_msat, feerate_per_kw); to_local_msat, to_remote_msat, feerate_per_kw);
keyset.self_revocation_key = remote_revocation_key; keyset.self_revocation_key = remote_revocation_key;
@ -774,7 +775,7 @@ int main(void)
"name: commitment tx with all 5 htlcs untrimmed (minimum feerate)\n" "name: commitment tx with all 5 htlcs untrimmed (minimum feerate)\n"
"to_local_msat: %"PRIu64"\n" "to_local_msat: %"PRIu64"\n"
"to_remote_msat: %"PRIu64"\n" "to_remote_msat: %"PRIu64"\n"
"local_feerate_per_kw: %"PRIu64"\n", "local_feerate_per_kw: %u\n",
to_local_msat, to_remote_msat, feerate_per_kw); to_local_msat, to_remote_msat, feerate_per_kw);
print_superverbose = true; print_superverbose = true;
@ -846,7 +847,7 @@ int main(void)
tx_must_be_eq(newtx, tx2); tx_must_be_eq(newtx, tx2);
#ifdef DEBUG #ifdef DEBUG
if (feerate_per_kw % 100000 == 0) if (feerate_per_kw % 100000 == 0)
printf("feerate_per_kw = %"PRIu64", fees = %"PRIu64"\n", printf("feerate_per_kw = %u, fees = %"PRIu64"\n",
feerate_per_kw, calc_fee(newtx, funding_amount_satoshi)); feerate_per_kw, calc_fee(newtx, funding_amount_satoshi));
if (tal_count(newtx->output) == tal_count(tx->output)) { if (tal_count(newtx->output) == tal_count(tx->output)) {
tal_free(newtx); tal_free(newtx);
@ -857,7 +858,7 @@ int main(void)
"name: commitment tx with %zu output%s untrimmed (maximum feerate)\n" "name: commitment tx with %zu output%s untrimmed (maximum feerate)\n"
"to_local_msat: %"PRIu64"\n" "to_local_msat: %"PRIu64"\n"
"to_remote_msat: %"PRIu64"\n" "to_remote_msat: %"PRIu64"\n"
"local_feerate_per_kw: %"PRIu64"\n", "local_feerate_per_kw: %u\n",
tal_count(tx->output), tal_count(tx->output),
tal_count(tx->output) > 1 ? "s" : "", tal_count(tx->output) > 1 ? "s" : "",
to_local_msat, to_remote_msat, feerate_per_kw-1); to_local_msat, to_remote_msat, feerate_per_kw-1);
@ -893,7 +894,7 @@ int main(void)
"name: commitment tx with %zu output%s untrimmed (minimum feerate)\n" "name: commitment tx with %zu output%s untrimmed (minimum feerate)\n"
"to_local_msat: %"PRIu64"\n" "to_local_msat: %"PRIu64"\n"
"to_remote_msat: %"PRIu64"\n" "to_remote_msat: %"PRIu64"\n"
"local_feerate_per_kw: %"PRIu64"\n", "local_feerate_per_kw: %u\n",
tal_count(newtx->output), tal_count(newtx->output),
tal_count(newtx->output) > 1 ? "s" : "", tal_count(newtx->output) > 1 ? "s" : "",
to_local_msat, to_remote_msat, feerate_per_kw); to_local_msat, to_remote_msat, feerate_per_kw);
@ -955,7 +956,7 @@ int main(void)
"name: commitment tx with fee greater than funder amount\n" "name: commitment tx with fee greater than funder amount\n"
"to_local_msat: %"PRIu64"\n" "to_local_msat: %"PRIu64"\n"
"to_remote_msat: %"PRIu64"\n" "to_remote_msat: %"PRIu64"\n"
"local_feerate_per_kw: %"PRIu64"\n", "local_feerate_per_kw: %u\n",
to_local_msat, to_remote_msat, feerate_per_kw); to_local_msat, to_remote_msat, feerate_per_kw);
tx = commit_tx(tmpctx, &funding_txid, funding_output_index, tx = commit_tx(tmpctx, &funding_txid, funding_output_index,
funding_amount_satoshi, funding_amount_satoshi,

2
onchaind/onchain.c

@ -31,7 +31,7 @@
static const struct keyset *keyset; static const struct keyset *keyset;
/* The feerate to use when we generate transactions. */ /* The feerate to use when we generate transactions. */
static u64 feerate_per_kw; static u32 feerate_per_kw;
/* The dust limit to use when we generate transactions. */ /* The dust limit to use when we generate transactions. */
static u64 dust_limit_satoshis; static u64 dust_limit_satoshis;

2
onchaind/onchain_wire.csv

@ -10,7 +10,7 @@ onchain_init,,old_remote_per_commitment_point,struct pubkey
onchain_init,,remote_per_commitment_point,struct pubkey onchain_init,,remote_per_commitment_point,struct pubkey
onchain_init,,local_to_self_delay,u32 onchain_init,,local_to_self_delay,u32
onchain_init,,remote_to_self_delay,u32 onchain_init,,remote_to_self_delay,u32
onchain_init,,feerate_per_kw,u64 onchain_init,,feerate_per_kw,u32
onchain_init,,local_dust_limit_satoshi,u64 onchain_init,,local_dust_limit_satoshi,u64
onchain_init,,remote_revocation_basepoint,struct pubkey onchain_init,,remote_revocation_basepoint,struct pubkey
# Gives an easy way to tell if it's our unilateral close or theirs... # Gives an easy way to tell if it's our unilateral close or theirs...

Can't render this file because it has a wrong number of fields in line 2.

2
wallet/wallet.c

@ -438,7 +438,7 @@ static bool wallet_stmt2channel(struct wallet *w, sqlite3_stmt *stmt,
ok &= sqlite3_column_pubkey(stmt, col++, &channel_info->theirbase.delayed_payment); ok &= sqlite3_column_pubkey(stmt, col++, &channel_info->theirbase.delayed_payment);
ok &= sqlite3_column_pubkey(stmt, col++, &channel_info->remote_per_commit); ok &= sqlite3_column_pubkey(stmt, col++, &channel_info->remote_per_commit);
ok &= sqlite3_column_pubkey(stmt, col++, &channel_info->old_remote_per_commit); ok &= sqlite3_column_pubkey(stmt, col++, &channel_info->old_remote_per_commit);
channel_info->feerate_per_kw = sqlite3_column_int64(stmt, col++); channel_info->feerate_per_kw = sqlite3_column_int(stmt, col++);
wallet_channel_config_load(w, remote_config_id, &chan->peer->channel_info->their_config); wallet_channel_config_load(w, remote_config_id, &chan->peer->channel_info->their_config);
} else { } else {
/* No channel_info, skip positions in the result */ /* No channel_info, skip positions in the result */

Loading…
Cancel
Save