From 3d8836c1e5037abe477fb735ce6ac73f2bd11971 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 22 Aug 2018 10:58:49 +0930 Subject: [PATCH] bitcoind: don't use double in extracting feerate. It introduces imprecision (took 1 satoshi off results in the coming tests), and we have a helper for this already. Signed-off-by: Rusty Russell --- lightningd/bitcoind.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index 95a6e3b9d..6595dcdf1 100644 --- a/lightningd/bitcoind.c +++ b/lightningd/bitcoind.c @@ -280,7 +280,7 @@ start_bitcoin_cli(struct bitcoind *bitcoind, static bool extract_feerate(struct bitcoin_cli *bcli, const char *output, size_t output_bytes, - double *feerate) + u64 *feerate) { const jsmntok_t *tokens, *feeratetok; bool valid; @@ -303,7 +303,7 @@ static bool extract_feerate(struct bitcoin_cli *bcli, if (!feeratetok) return false; - return json_to_double(output, feeratetok, feerate); + return json_tok_bitcoin_amount(output, feeratetok, feerate); } struct estimatefee { @@ -322,7 +322,7 @@ static void do_one_estimatefee(struct bitcoind *bitcoind, static bool process_estimatefee(struct bitcoin_cli *bcli) { - double feerate; + u64 feerate; struct estimatefee *efee = bcli->cb_arg; /* FIXME: We could trawl recent blocks for median fee... */ @@ -332,7 +332,7 @@ static bool process_estimatefee(struct bitcoin_cli *bcli) efee->satoshi_per_kw[efee->i] = 0; } else /* Rate in satoshi per kw. */ - efee->satoshi_per_kw[efee->i] = feerate * 100000000 / 4; + efee->satoshi_per_kw[efee->i] = feerate / 4; efee->i++; if (efee->i == tal_count(efee->satoshi_per_kw)) {