From 46b2e7502c8172fe54049f3377072265c292a6e7 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 22 Oct 2018 21:36:08 +0200 Subject: [PATCH] bitcoin: If we fail to estimate the fee in testnet use the minfee When developing in regtest or testnet it is really inconvenient to have to fake traffic and generate blocks just to get estimatesmartfee to return a valid estimate. This just sets the minfee if bitcoind doesn't return a valid estimate. Reported-by: Rene Pickhardt <@renepickhardt> Signed-off-by: Christian Decker <@cdecker> --- lightningd/bitcoind.c | 15 +++++++++++++++ tests/test_misc.py | 1 + 2 files changed, 16 insertions(+) diff --git a/lightningd/bitcoind.c b/lightningd/bitcoind.c index e3c44a393..55b261d2d 100644 --- a/lightningd/bitcoind.c +++ b/lightningd/bitcoind.c @@ -1,6 +1,7 @@ /* Code for talking to bitcoind. We use bitcoin-cli. */ #include "bitcoin/base58.h" #include "bitcoin/block.h" +#include "bitcoin/feerate.h" #include "bitcoin/shadouble.h" #include "bitcoind.h" #include "lightningd.h" @@ -352,7 +353,21 @@ static bool process_estimatefee(struct bitcoin_cli *bcli) if (!extract_feerate(bcli, bcli->output, bcli->output_bytes, &feerate)) { log_unusual(bcli->bitcoind->log, "Unable to estimate %s/%u fee", efee->estmode[efee->i], efee->blocks[efee->i]); + +#if DEVELOPER + /* This is needed to test for failed feerate estimates + * in DEVELOPER mode */ efee->satoshi_per_kw[efee->i] = 0; +#else + /* If we are in testnet mode we want to allow payments + * with the minimal fee even if the estimate didn't + * work out. This is less disruptive than erring out + * all the time. */ + if (get_chainparams(bcli->bitcoind->ld)->testnet) + efee->satoshi_per_kw[efee->i] = FEERATE_FLOOR; + else + efee->satoshi_per_kw[efee->i] = 0; +#endif } else /* Rate in satoshi per kw. */ efee->satoshi_per_kw[efee->i] diff --git a/tests/test_misc.py b/tests/test_misc.py index 02b64fded..f9f2bd65a 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -864,6 +864,7 @@ def test_ipv4_and_ipv6(node_factory): assert int(bind[0]['port']) == port +@unittest.skipIf(not DEVELOPER, "Without DEVELOPER=1 we snap to FEERATE_FLOOR on testnets") def test_feerates(node_factory): l1 = node_factory.get_node(options={'log-level': 'io'}, start=False) l1.daemon.rpcproxy.mock_rpc('estimatesmartfee', {