Skip to content

Commit

Permalink
Rename fee function params from N to tx_fees
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapsk committed Jul 26, 2023
1 parent 895587a commit 936695a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions jmclient/jmclient/blockchaininterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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:
Expand All @@ -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) + ".")
Expand All @@ -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)"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jmclient/test/commontest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 936695a

Please sign in to comment.