From 3d0f2d6fd72a54b4f6191f3bccde6ded6aaa68cc Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Tue, 11 Oct 2022 13:53:22 +0200 Subject: [PATCH] fix: randomize fallback transaction fee also, use tx_fees_factor for randomized max mempoolminfee and make sure that tx_fees_factor is equal or greater than zero. Co-authored-by: Kristaps Kaupe --- jmclient/jmclient/blockchaininterface.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/jmclient/jmclient/blockchaininterface.py b/jmclient/jmclient/blockchaininterface.py index c506459..3efd79a 100644 --- a/jmclient/jmclient/blockchaininterface.py +++ b/jmclient/jmclient/blockchaininterface.py @@ -462,12 +462,13 @@ class BitcoinCoreInterface(BlockchainInterface): if not rpc_result: # in case of connection error: return None + + tx_fees_factor = abs(jm_single().config.getfloat('POLICY', 'tx_fees_factor')) + mempoolminfee_in_sat = btc.btc_to_sat(rpc_result['mempoolminfee']) mempoolminfee_in_sat_randomized = random.uniform( - mempoolminfee_in_sat, mempoolminfee_in_sat * float(1.2)) + mempoolminfee_in_sat, mempoolminfee_in_sat * float(1 + tx_fees_factor)) - tx_fees_factor = float(jm_single().config.get('POLICY', - 'tx_fees_factor')) if super().fee_per_kb_has_been_manually_set(N): N_res = random.uniform(N * float(1 - tx_fees_factor), N * float(1 + tx_fees_factor)) @@ -504,10 +505,12 @@ class BitcoinCoreInterface(BlockchainInterface): estimate_in_sat * float(1 + tx_fees_factor)) break else: # cannot get a valid estimate after `tries` tries: - retval = 10000 + fallback_fee = 10000 + retval = random.uniform(fallback_fee * float(1 - tx_fees_factor), + fallback_fee * float(1 + tx_fees_factor)) log.warn("Could not source a fee estimate from Core, " + "falling back to default: " + - btc.fee_per_kb_to_str(retval) + ".") + btc.fee_per_kb_to_str(fallback_fee) + ".") if retval < mempoolminfee_in_sat: log.info("Using this mempool min fee as tx feerate: " +