From ef4d54df941ead0587edacce437c406c8e209b89 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 21 Nov 2017 13:57:47 +1030 Subject: [PATCH] chaintopology: use satoshi-per-kw everywhere. This means we convert it when retrieving from bitcoind; internally it's always satoshi-per-1000-weight aka millisatoshi-per-weight. Signed-off-by: Rusty Russell --- lightningd/bitcoind.c | 10 +++++----- lightningd/bitcoind.h | 2 +- lightningd/chaintopology.c | 6 +++--- lightningd/chaintopology.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index 49e14e361..3d4a9dd11 100644 --- a/lightningd/bitcoind.c +++ b/lightningd/bitcoind.c @@ -262,18 +262,18 @@ static bool extract_feerate(struct bitcoin_cli *bcli, static void process_estimatefee(struct bitcoin_cli *bcli) { double feerate; - u64 satoshi_per_kb; + u64 satoshi_per_kw; void (*cb)(struct bitcoind *, u64, void *) = bcli->cb; /* FIXME: We could trawl recent blocks for median fee... */ if (!extract_feerate(bcli, bcli->output, bcli->output_bytes, &feerate)) { log_unusual(bcli->bitcoind->log, "Unable to estimate fee"); - satoshi_per_kb = 0; + satoshi_per_kw = 0; } else - /* Rate in satoshi per kb. */ - satoshi_per_kb = feerate * 100000000; + /* Rate in satoshi per kw. */ + satoshi_per_kw = feerate * 100000000 / 4; - cb(bcli->bitcoind, satoshi_per_kb, bcli->cb_arg); + cb(bcli->bitcoind, satoshi_per_kw, bcli->cb_arg); } void bitcoind_estimate_fee_(struct bitcoind *bitcoind, diff --git a/lightningd/bitcoind.h b/lightningd/bitcoind.h index 9157b6aea..f83d2f34a 100644 --- a/lightningd/bitcoind.h +++ b/lightningd/bitcoind.h @@ -57,7 +57,7 @@ void wait_for_bitcoind(struct bitcoind *bitcoind); void bitcoind_estimate_fee_(struct bitcoind *bitcoind, void (*cb)(struct bitcoind *bitcoind, - u64, void *), + u64 satoshi_per_kw, void *), void *arg); #define bitcoind_estimate_fee(bitcoind_, cb, arg) \ diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index aa4a9598c..4624c5b0c 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -291,12 +291,12 @@ static void free_blocks(struct chain_topology *topo, struct block *b) } } -static void update_fee(struct bitcoind *bitcoind, u64 rate, +static void update_fee(struct bitcoind *bitcoind, u64 satoshi_per_kw, struct chain_topology *topo) { log_debug(topo->log, "Feerate %"PRIu64" (was %"PRIu64")", - rate, topo->feerate); - topo->feerate = rate; + satoshi_per_kw, topo->feerate); + topo->feerate = satoshi_per_kw; } /* B is the new chain (linked by ->next); update topology */ diff --git a/lightningd/chaintopology.h b/lightningd/chaintopology.h index 16ebe7f98..04909a6d7 100644 --- a/lightningd/chaintopology.h +++ b/lightningd/chaintopology.h @@ -138,7 +138,7 @@ size_t get_tx_depth(const struct chain_topology *topo, /* Get highest block number. */ u32 get_block_height(const struct chain_topology *topo); -/* Get fee rate. */ +/* Get fee rate in satoshi per kiloweight. */ u64 get_feerate(const struct chain_topology *topo); /* Broadcast a single tx, and rebroadcast as reqd (copies tx).