Browse Source

Merge JoinMarket-Org/joinmarket-clientserver#1378: fix: randomize fallback transaction fee

3d0f2d6fd7 fix: randomize fallback transaction fee (theborakompanioni)

Pull request description:

  Resolves #1363

  Before this PR, if no fee estimate could be sourced, the fallback fee was always 10_000 sats/kilo-vbyte:
  ```
  Before:
  2022-10-11 05:45:19,429 [DEBUG]  rpc: getmempoolinfo None
  2022-10-11 05:45:19,432 [DEBUG]  rpc: estimatesmartfee [3]
  2022-10-11 05:45:19,438 [WARNING]  Could not source a fee estimate from Core, falling back to default: 10000 sat/vkB (10.0 sat/vB).
  2022-10-11 05:45:19,439 [INFO]  Using bitcoin network feerate for 3 block confirmation target (randomized for privacy): 10000 sat/vkB (10.0 sat/vB)
  2022-10-11 05:45:19,444 [DEBUG]  rpc: getmempoolinfo None
  2022-10-11 05:45:19,446 [DEBUG]  rpc: estimatesmartfee [3]
  2022-10-11 05:45:19,452 [WARNING]  Could not source a fee estimate from Core, falling back to default: 10000 sat/vkB (10.0 sat/vB).
  2022-10-11 05:45:19,453 [INFO]  Using bitcoin network feerate for 3 block confirmation target (randomized for privacy): 10000 sat/vkB (10.0 sat/vB)
  2022-10-11 05:45:19,488 [INFO]  Using a fee of: 0.00001420 BTC (1420 sat).
  ```

  After this PR, the fallback fee will take into account the value of `tx_fees_factor` to randomize the value (if `tx_fees_factor` is greater than zero):
  ```
  2022-10-11 05:51:00,112 [DEBUG]  rpc: getmempoolinfo None
  2022-10-11 05:51:00,114 [DEBUG]  rpc: estimatesmartfee [3]
  2022-10-11 05:51:00,119 [WARNING]  Could not source a fee estimate from Core, falling back to default: 10000 sat/vkB (10.0 sat/vB).
  2022-10-11 05:51:00,120 [INFO]  Using bitcoin network feerate for 3 block confirmation target (randomized for privacy): 9962 sat/vkB (9.9 sat/vB)
  2022-10-11 05:51:00,123 [DEBUG]  rpc: getmempoolinfo None
  2022-10-11 05:51:00,126 [DEBUG]  rpc: estimatesmartfee [3]
  2022-10-11 05:51:00,133 [WARNING]  Could not source a fee estimate from Core, falling back to default: 10000 sat/vkB (10.0 sat/vB).
  2022-10-11 05:51:00,134 [INFO]  Using bitcoin network feerate for 3 block confirmation target (randomized for privacy): 10898 sat/vkB (10.8 sat/vB)
  2022-10-11 05:51:00,156 [INFO]  Using a fee of: 0.00001547 BTC (1547 sat).
  ```

  Additionally, `fx_fees_factor` will be used to calculate `mempoolminfee_in_sat_randomized` instead of using a hardcoded max value of `1.2` (20%). If this is not wanted or you think this is a mistake, the second commit can be reverted in order to only apply the behaviour described above.

ACKs for top commit:
  kristapsk:
    ACK 3d0f2d6fd7

Tree-SHA512: d950532e0abe9558b067b2b764f0c43b8a20f27c7c2223600ee461174124a21ec05c2d304ace2006d461d0ff0ae504ba246676a509240eea6d86fe975898a2f7
master
Kristaps Kaupe 3 years ago
parent
commit
5740c3bec8
No known key found for this signature in database
GPG Key ID: 33E472FE870C7E5D
  1. 13
      jmclient/jmclient/blockchaininterface.py

13
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: " +

Loading…
Cancel
Save