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>
This commit is contained in:
Christian Decker 2018-10-22 21:36:08 +02:00 committed by Rusty Russell
parent 40943c9867
commit 46b2e7502c
2 changed files with 16 additions and 0 deletions

View file

@ -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]

View file

@ -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', {