mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
plugins/bcli: fake minimum fee if we're in regtest mode.
Saves a great deal of confusion for regtest users. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Changed: JSON-RPC: If bitcoind won't give a fee estimate in regtest, use minimum.
This commit is contained in:
parent
c78e2cc024
commit
4848c0022f
@ -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);
|
||||
}
|
||||
|
@ -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', {
|
||||
|
@ -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}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user