Skip to content

Commit

Permalink
Merge #1636: Allow absurd fee override when setting tx fee manually
Browse files Browse the repository at this point in the history
196a097 Allow absurd fee override when setting tx fee manually (Kristaps Kaupe)

Pull request description:

  When user manually specifies `--txfee` with `sendpayment.py`, he likely knows what he is doing. So allow there fees above `absurd_fee_per_kb` setting. But still ask for user confirmation as he could possible made a mistake, for example, added some extra zeros to the value.

Top commit has no ACKs.

Tree-SHA512: 2155c38a483fd6392153bf42b2ea87cb9395f0da289cc2743602493df9e924a1d621688704a46d179e3e574ce41e82ced26b62331157ac2c3d1481931a334ace
  • Loading branch information
kristapsk committed Jan 22, 2024
2 parents 69ffa9c + 196a097 commit 8319870
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 21 additions & 0 deletions scripts/sendpayment.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,27 @@ def main():

# If tx_fees are set manually by CLI argument, override joinmarket.cfg:
if int(options.txfee) > 0:
if jm_single().bc_interface.fee_per_kb_has_been_manually_set(
options.txfee):
absurd_fee = jm_single().config.getint("POLICY",
"absurd_fee_per_kb")
tx_fees_factor = jm_single().config.getfloat("POLICY",
"tx_fees_factor")
max_potential_txfee = int(max(options.txfee,
options.txfee * float(1 + tx_fees_factor)))
if max_potential_txfee > absurd_fee:
jmprint(
"WARNING: Manually specified Bitcoin transaction fee "
f"{btc.fee_per_kb_to_str(options.txfee)} can be "
"randomized up to "
f"{btc.fee_per_kb_to_str(max_potential_txfee)}, "
"above absurd value "
f"{btc.fee_per_kb_to_str(absurd_fee)}.",
"warning")
if input("Still continue? (y/n):")[0] != "y":
sys.exit("Aborted by user.")
jm_single().config.set("POLICY", "absurd_fee_per_kb",
str(max_potential_txfee))
jm_single().config.set("POLICY", "tx_fees", str(options.txfee))

maxcjfee = (1, float('inf'))
Expand Down
6 changes: 3 additions & 3 deletions src/jmclient/blockchaininterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def get_unspent_indices(self, transaction: btc.CTransaction) -> List[int]:
# and return the indices of the others:
return [i for i, val in enumerate(res) if val]

def _fee_per_kb_has_been_manually_set(self, tx_fees: int) -> bool:
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.
"""
Expand All @@ -242,7 +242,7 @@ def _fee_per_kb_has_been_manually_set(self, tx_fees: int) -> bool:
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
per kilo-vbyte (see `fee_per_kb_has_been_manually_set` for
how this is distinguished).
In both cases it is prevented from falling below the current
minimum feerate for tx to be accepted into node's mempool.
Expand All @@ -264,7 +264,7 @@ def estimate_fee_per_kb(self, tx_fees: 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(tx_fees):
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"
Expand Down

0 comments on commit 8319870

Please sign in to comment.