Browse Source

Use mempoolminfee instead of minrelaytxfee as tx feerate floor

master
Kristaps Kaupe 5 years ago
parent
commit
7bfc758110
No known key found for this signature in database
GPG Key ID: 33E472FE870C7E5D
  1. 51
      jmclient/jmclient/blockchaininterface.py

51
jmclient/jmclient/blockchaininterface.py

@ -412,8 +412,8 @@ class BitcoinCoreInterface(BlockchainInterface):
for estimation of feerate by Core, or a number of satoshis for estimation of feerate by Core, or a number of satoshis
per kilo-vbyte (see `fee_per_kb_has_been_manually_set` for per kilo-vbyte (see `fee_per_kb_has_been_manually_set` for
how this is distinguished). how this is distinguished).
In the latter case, it is prevented from falling below the In both cases it is prevented from falling below the current
minimum allowed feerate for relay on the Bitcoin network. minimum feerate for tx to be accepted into node's mempool.
In case of failure to connect, None is returned. In case of failure to connect, None is returned.
In case of failure to source a specific minimum fee relay rate In case of failure to source a specific minimum fee relay rate
(which is used to sanity check user's chosen fee rate), 1000 (which is used to sanity check user's chosen fee rate), 1000
@ -421,19 +421,27 @@ class BitcoinCoreInterface(BlockchainInterface):
In case of failure to source a feerate estimate for targeted In case of failure to source a feerate estimate for targeted
number of blocks, a default of 10000 is returned. number of blocks, a default of 10000 is returned.
""" """
if super().fee_per_kb_has_been_manually_set(N):
# use the local bitcoin core relay fee as floor to avoid relay # use the local bitcoin core minimum mempool fee as floor to avoid
# problems # relay problems
rpc_result = self._rpc('getnetworkinfo', None) rpc_result = self._rpc('getmempoolinfo', None)
if not rpc_result: if not rpc_result:
# in case of connection error: # in case of connection error:
return None return None
btc_relayfee = rpc_result.get('relayfee', 1000) mempoolminfee_in_sat = btc.btc_to_sat(rpc_result['mempoolminfee'])
relayfee_in_sat = int(Decimal(1e8) * Decimal(btc_relayfee)) mempoolminfee_in_sat_randomized = random.uniform(
log.debug("Using this min relay fee as tx feerate floor: " + mempoolminfee_in_sat, mempoolminfee_in_sat * float(1.2))
btc.fee_per_kb_to_str(relayfee_in_sat))
return int(max(relayfee_in_sat, random.uniform(N * float(0.8), if super().fee_per_kb_has_been_manually_set(N):
N * float(1.2)))) N_res = random.uniform(N * float(0.8), N * float(1.2))
if N_res < mempoolminfee_in_sat:
log.info("Using this mempool min fee as tx feerate: " +
btc.fee_per_kb_to_str(mempoolminfee_in_sat) + ".")
return int(mempoolminfee_in_sat_randomized)
else:
log.info("Using this manually set tx feerate (randomized " +
"for privacy): " + btc.fee_per_kb_to_str(N_res) + ".")
return int(N_res)
# Special bitcoin core case: sometimes the highest priority # Special bitcoin core case: sometimes the highest priority
# cannot be estimated in that case the 2nd highest priority # cannot be estimated in that case the 2nd highest priority
@ -451,16 +459,25 @@ class BitcoinCoreInterface(BlockchainInterface):
# if it is not able to make an estimate. We insist that # if it is not able to make an estimate. We insist that
# the 'feerate' key is found and contains a positive value: # the 'feerate' key is found and contains a positive value:
if estimate and estimate > 0: if estimate and estimate > 0:
retval = int(Decimal(1e8) * Decimal(estimate)) estimate_in_sat = btc.btc_to_sat(estimate)
retval = random.uniform(estimate_in_sat * float(0.8),
estimate_in_sat * float(1.2))
break break
else: # cannot get a valid estimate after `tries` tries: else: # cannot get a valid estimate after `tries` tries:
log.warn("Could not source a fee estimate from Core, " +
"falling back to default.")
retval = 10000 retval = 10000
log.warn("Could not source a fee estimate from Core, " +
"falling back to default: " +
btc.fee_per_kb_to_str(retval) + ".")
log.info("Using bitcoin network feerate: " +\ if retval < mempoolminfee_in_sat:
log.info("Using this mempool min fee as tx feerate: " +
btc.fee_per_kb_to_str(mempoolminfee_in_sat) + ".")
return int(mempoolminfee_in_sat_randomized)
else:
log.info("Using bitcoin network feerate for " + str(N) +
" block confirmation target (randomized for privacy): " +
btc.fee_per_kb_to_str(retval)) btc.fee_per_kb_to_str(retval))
return retval return int(retval)
def get_current_block_height(self): def get_current_block_height(self):
try: try:

Loading…
Cancel
Save