diff --git a/plugins/bcli.c b/plugins/bcli.c index 193767e6a..5aa6d07d1 100644 --- a/plugins/bcli.c +++ b/plugins/bcli.c @@ -69,6 +69,14 @@ struct bitcoind { /* Percent of CONSERVATIVE/2 feerate we'll use for commitment txs. */ u64 commit_fee_percent; + + /* Whether we fake fees (regtest) */ + bool fake_fees; + +#if DEVELOPER + /* Override in case we're developer mode for testing*/ + bool no_fake_fees; +#endif }; static struct bitcoind *bitcoind; @@ -431,6 +439,11 @@ estimatefees_parse_feerate(struct bitcoin_cli *bcli, u64 *feerate) /* Paranoia: if it had a feerate, but was malformed: */ if (json_get_member(bcli->output, tokens, "feerate")) return command_err_bcli_badjson(bcli, "cannot scan"); + /* Regtest fee estimation is generally awful: Fake it at min. */ + if (bitcoind->fake_fees) { + *feerate = 1000; + return NULL; + } /* We return null if estimation failed, and bitcoin-cli will * exit with 0 but no feerate field on failure. */ return estimatefees_null_response(bcli); @@ -874,6 +887,11 @@ static const char *init(struct plugin *p, const char *buffer UNUSED, const jsmntok_t *config UNUSED) { wait_and_check_bitcoind(p); + + /* Usually we fake up fees in regtest */ + if (streq(chainparams->network_name, "regtest")) + bitcoind->fake_fees = IFDEV(!bitcoind->no_fake_fees, true); + plugin_log(p, LOG_INFORM, "bitcoin-cli initialized and connected to bitcoind."); @@ -938,6 +956,9 @@ static struct bitcoind *new_bitcoind(const tal_t *ctx) bitcoind->rpcport = NULL; bitcoind->max_fee_multiplier = 10; bitcoind->commit_fee_percent = 100; +#if DEVELOPER + bitcoind->no_fake_fees = false; +#endif return bitcoind; } @@ -994,6 +1015,10 @@ int main(int argc, char *argv[]) " closed more often due to fee fluctuations," " large values may result in large fees.", u32_option, &bitcoind->max_fee_multiplier), + plugin_option("dev-no-fake-fees", + "bool", + "Suppress fee faking for regtest", + bool_option, &bitcoind->no_fake_fees), #endif /* DEVELOPER */ NULL); } diff --git a/tests/test_connection.py b/tests/test_connection.py index fd94b1e01..5f44d5644 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -2282,7 +2282,7 @@ def test_fundee_forget_funding_tx_unconfirmed(node_factory, bitcoind): @unittest.skipIf(not DEVELOPER, "needs dev_fail") def test_no_fee_estimate(node_factory, bitcoind, executor): - l1 = node_factory.get_node(start=False) + l1 = node_factory.get_node(start=False, options={'dev-no-fake-fees': True}) # Fail any fee estimation requests until we allow them further down l1.daemon.rpcproxy.mock_rpc('estimatesmartfee', { diff --git a/tests/test_misc.py b/tests/test_misc.py index 1c35ff829..ee2d6415f 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -1438,7 +1438,8 @@ def test_ipv4_and_ipv6(node_factory): "FEERATE_FLOOR on testnets, and we test the new API." ) def test_feerates(node_factory): - l1 = node_factory.get_node(options={'log-level': 'io'}, start=False) + l1 = node_factory.get_node(options={'log-level': 'io', + 'dev-no-fake-fees': True}, start=False) l1.daemon.rpcproxy.mock_rpc('estimatesmartfee', { 'error': {"errors": ["Insufficient data or no feerate found"], "blocks": 0} })