|
|
|
@ -412,19 +412,24 @@ class BitcoinCoreInterface(BlockchainInterface): |
|
|
|
how this is distinguished). |
|
|
|
how this is distinguished). |
|
|
|
In the latter case, it is prevented from falling below the |
|
|
|
In the latter case, it is prevented from falling below the |
|
|
|
minimum allowed feerate for relay on the Bitcoin network. |
|
|
|
minimum allowed feerate for relay on the Bitcoin network. |
|
|
|
|
|
|
|
In case of failure to connect, None is returned. |
|
|
|
|
|
|
|
In case of failure to source a specific minimum fee relay rate |
|
|
|
|
|
|
|
(which is used to sanity check user's chosen fee rate), 1000 |
|
|
|
|
|
|
|
is used. |
|
|
|
|
|
|
|
In case of failure to source a feerate estimate for targeted |
|
|
|
|
|
|
|
number of blocks, a default of 10000 is returned. |
|
|
|
""" |
|
|
|
""" |
|
|
|
if super().fee_per_kb_has_been_manually_set(N): |
|
|
|
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 relay fee as floor to avoid relay |
|
|
|
# problems |
|
|
|
# problems |
|
|
|
btc_relayfee = -1 |
|
|
|
|
|
|
|
rpc_result = self._rpc('getnetworkinfo', None) |
|
|
|
rpc_result = self._rpc('getnetworkinfo', None) |
|
|
|
btc_relayfee = rpc_result.get('relayfee', btc_relayfee) |
|
|
|
if not rpc_result: |
|
|
|
if btc_relayfee > 0: |
|
|
|
# in case of connection error: |
|
|
|
relayfee_in_sat = int(Decimal(1e8) * Decimal(btc_relayfee)) |
|
|
|
return None |
|
|
|
else: # cannot get valid relayfee: fall back to 1000 sat/kbyte |
|
|
|
btc_relayfee = rpc_result.get('relayfee', 1000) |
|
|
|
relayfee_in_sat = 1000 |
|
|
|
relayfee_in_sat = int(Decimal(1e8) * Decimal(btc_relayfee)) |
|
|
|
log.debug("Using this min relay fee as tx feerate per kB floor: " + |
|
|
|
log.debug("Using this min relay fee as tx feerate floor: " + |
|
|
|
btc.fee_per_kb_to_str(1000)) |
|
|
|
btc.fee_per_kb_to_str(relayfee_in_sat)) |
|
|
|
return int(max(relayfee_in_sat, random.uniform(N * float(0.8), |
|
|
|
return int(max(relayfee_in_sat, random.uniform(N * float(0.8), |
|
|
|
N * float(1.2)))) |
|
|
|
N * float(1.2)))) |
|
|
|
|
|
|
|
|
|
|
|
@ -433,19 +438,25 @@ class BitcoinCoreInterface(BlockchainInterface): |
|
|
|
# should be used instead of falling back to hardcoded values |
|
|
|
# should be used instead of falling back to hardcoded values |
|
|
|
tries = 2 if N == 1 else 1 |
|
|
|
tries = 2 if N == 1 else 1 |
|
|
|
|
|
|
|
|
|
|
|
estimate = -1 |
|
|
|
|
|
|
|
retval = -1 |
|
|
|
|
|
|
|
for i in range(tries): |
|
|
|
for i in range(tries): |
|
|
|
rpc_result = self._rpc('estimatesmartfee', [N + i]) |
|
|
|
rpc_result = self._rpc('estimatesmartfee', [N + i]) |
|
|
|
estimate = rpc_result.get('feerate', estimate) |
|
|
|
if not rpc_result: |
|
|
|
if estimate > 0: |
|
|
|
# in case of connection error: |
|
|
|
|
|
|
|
return None |
|
|
|
|
|
|
|
estimate = rpc_result.get('feerate') |
|
|
|
|
|
|
|
# `estimatesmartfee` will currently return in the format |
|
|
|
|
|
|
|
# `{'errors': ['Insufficient data or no feerate found'], 'blocks': N}` |
|
|
|
|
|
|
|
# if it is not able to make an estimate. We insist that |
|
|
|
|
|
|
|
# the 'feerate' key is found and contains a positive value: |
|
|
|
|
|
|
|
if estimate and estimate > 0: |
|
|
|
|
|
|
|
retval = int(Decimal(1e8) * Decimal(estimate)) |
|
|
|
break |
|
|
|
break |
|
|
|
else: # estimate <= 0 |
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
if retval == -1: |
|
|
|
log.info("Using bitcoin network feerate: " +\ |
|
|
|
retval = int(Decimal(1e8) * Decimal(estimate)) |
|
|
|
|
|
|
|
log.info("Using bitcoin network feerate (per kB in sats): " +\ |
|
|
|
|
|
|
|
btc.fee_per_kb_to_str(retval)) |
|
|
|
btc.fee_per_kb_to_str(retval)) |
|
|
|
return retval |
|
|
|
return retval |
|
|
|
|
|
|
|
|
|
|
|
|