diff --git a/jmclient/jmclient/blockchaininterface.py b/jmclient/jmclient/blockchaininterface.py index 2cb16f9f9..e36a66456 100644 --- a/jmclient/jmclient/blockchaininterface.py +++ b/jmclient/jmclient/blockchaininterface.py @@ -70,14 +70,14 @@ def _estimate_fee_basic(self, conf_target: int) -> Optional[int]: or None in case of error. """ - def _fee_per_kb_has_been_manually_set(self, N: int) -> bool: - """If the 'block' target is higher than 1000, interpret it + def _fee_per_kb_has_been_manually_set(self, tx_fees: int) -> bool: + """If the block target (tx_fees) is higher than 1000, interpret it as manually set fee sats/kvB. """ - return N > 1000 + return tx_fees > 1000 - def estimate_fee_per_kb(self, N: int) -> int: - """ The argument N may be either a number of blocks target, + def estimate_fee_per_kb(self, tx_fees: int) -> int: + """ The argument tx_fees may be either a number of blocks target, for estimation of feerate by Core, or a number of satoshis per kilo-vbyte (see `_fee_per_kb_has_been_manually_set` for how this is distinguished). @@ -101,8 +101,8 @@ def estimate_fee_per_kb(self, N: int) -> int: mempoolminfee_in_sat_randomized = random.uniform( mempoolminfee_in_sat, mempoolminfee_in_sat * float(1 + tx_fees_factor)) - if self._fee_per_kb_has_been_manually_set(N): - N_res = random.uniform(N, N * float(1 - tx_fees_factor)) + if self._fee_per_kb_has_been_manually_set(tx_fees): + N_res = random.uniform(tx_fees, tx_fees * float(1 - tx_fees_factor)) if N_res < mempoolminfee_in_sat: msg = "Using this mempool min fee as tx feerate" if tx_fees_factor != 0: @@ -117,7 +117,7 @@ def estimate_fee_per_kb(self, N: int) -> int: log.info(msg + ": " + btc.fee_per_kb_to_str(N_res) + ".") return int(N_res) - retval = self._estimate_fee_basic(N) + retval = self._estimate_fee_basic(tx_fees) if retval is None: log.warn("Falling back to default: " + btc.fee_per_kb_to_str(fallback_fee) + ".") @@ -134,7 +134,7 @@ def estimate_fee_per_kb(self, N: int) -> int: mempoolminfee_in_sat_randomized) + ".") return int(mempoolminfee_in_sat_randomized) else: - msg = "Using bitcoin network feerate for " + str(N) + \ + msg = "Using bitcoin network feerate for " + str(tx_fees) + \ " block confirmation target" if tx_fees_factor != 0: msg = msg + " (randomized for privacy)" @@ -466,13 +466,13 @@ def _get_mempool_min_fee(self) -> Optional[int]: return None return btc.btc_to_sat(rpc_result['mempoolminfee']) - def _estimate_fee_basic(self, N: int) -> Optional[int]: + def _estimate_fee_basic(self, tx_fees: int) -> Optional[int]: # Special bitcoin core case: sometimes the highest priority # cannot be estimated in that case the 2nd highest priority # should be used instead of falling back to hardcoded values - tries = 2 if N == 1 else 1 + tries = 2 if tx_fees == 1 else 1 for i in range(tries): - rpc_result = self._rpc('estimatesmartfee', [N + i]) + rpc_result = self._rpc('estimatesmartfee', [tx_fees + i]) if not rpc_result: # in case of connection error: return None @@ -681,9 +681,9 @@ def __init__(self, jsonRpc, wallet_name): self.shutdown_signal = False self.destn_addr = self._rpc("getnewaddress", []) - def estimate_fee_per_kb(self, N: int) -> int: + def estimate_fee_per_kb(self, tx_fees: int) -> int: if not self.absurd_fees: - return super().estimate_fee_per_kb(N) + return super().estimate_fee_per_kb(tx_fees) else: return jm_single().config.getint("POLICY", "absurd_fee_per_kb") + 100 diff --git a/jmclient/test/commontest.py b/jmclient/test/commontest.py index 2827264f5..530bc8ea5 100644 --- a/jmclient/test/commontest.py +++ b/jmclient/test/commontest.py @@ -135,7 +135,7 @@ def query_utxo_set(self, txouts, includeconfs=False): result.append(result_dict) return result - def estimate_fee_per_kb(self, N: int) -> int: + def estimate_fee_per_kb(self, tx_fees: int) -> int: return 30000