From 0be5a4fca73a17dae681898e7d087fd54d468072 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Fri, 1 Dec 2023 19:16:28 +0200 Subject: [PATCH] Add min_relay_fee option. --- basicswap/basicswap.py | 8 ++------ basicswap/interface/btc.py | 31 ++++++++++++++++++++++--------- basicswap/interface/nav.py | 14 -------------- bin/basicswap_prepare.py | 1 + 4 files changed, 25 insertions(+), 29 deletions(-) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 4bb17db..9bdc021 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -472,6 +472,8 @@ class BasicSwap(BaseApp): if coin == Coins.FIRO: self.coin_clients[coin]['use_csv'] = False + if 'min_relay_fee' not in self.coin_clients[coin]: + self.coin_clients[coin]['min_relay_fee'] = 0.00001 if coin == Coins.PART: self.coin_clients[coin]['anon_tx_ring_size'] = chain_client_settings.get('anon_tx_ring_size', 12) @@ -1792,12 +1794,6 @@ class BasicSwap(BaseApp): return self.callcoinrpc(coin_type, 'getnetworkinfo')['relayfee'] def getFeeRateForCoin(self, coin_type, conf_target: int = 2): - chain_client_settings = self.getChainClientSettings(coin_type) - override_feerate = chain_client_settings.get('override_feerate', None) - if override_feerate: - self.log.debug('Fee rate override used for %s: %f', Coins(coin_type).name, override_feerate) - return override_feerate, 'override_feerate' - return self.ci(coin_type).get_fee_rate(conf_target) def estimateWithdrawFee(self, coin_type, fee_rate): diff --git a/basicswap/interface/btc.py b/basicswap/interface/btc.py index bd04a95..aa8d76e 100644 --- a/basicswap/interface/btc.py +++ b/basicswap/interface/btc.py @@ -358,18 +358,31 @@ class BTCInterface(CoinInterface): if self.sc._restrict_unknown_seed_wallets: ensure(addr_info['hdseedid'] == self._expect_seedid_hex, 'unexpected seedid') - def get_fee_rate(self, conf_target: int = 2): - try: - fee_rate = self.rpc_callback('estimatesmartfee', [conf_target])['feerate'] - assert (fee_rate > 0.0), 'Non positive feerate' - return fee_rate, 'estimatesmartfee' - except Exception: + def get_fee_rate(self, conf_target: int = 2) -> (float, str): + chain_client_settings = self._sc.getChainClientSettings(self.coin_type()) + override_feerate = chain_client_settings.get('override_feerate', None) + if override_feerate: + self._log.debug('Fee rate override used for %s: %f', self.coin_name(), override_feerate) + return override_feerate, 'override_feerate' + + min_relay_fee = chain_client_settings.get('min_relay_fee', None) + def try_get_fee_rate(self, conf_target): try: - fee_rate = self.rpc_callback('getwalletinfo')['paytxfee'] + fee_rate = self.rpc_callback('estimatesmartfee', [conf_target])['feerate'] assert (fee_rate > 0.0), 'Non positive feerate' - return fee_rate, 'paytxfee' + return fee_rate, 'estimatesmartfee' except Exception: - return self.rpc_callback('getnetworkinfo')['relayfee'], 'relayfee' + try: + fee_rate = self.rpc_callback('getwalletinfo')['paytxfee'] + assert (fee_rate > 0.0), 'Non positive feerate' + return fee_rate, 'paytxfee' + except Exception: + return self.rpc_callback('getnetworkinfo')['relayfee'], 'relayfee' + + fee_rate, rate_src = try_get_fee_rate(self, conf_target) + if min_relay_fee and min_relay_fee > fee_rate: + return min_relay_fee, 'min_relay_fee' + return fee_rate, rate_src def isSegwitAddress(self, address: str) -> bool: return address.startswith(self.chainparams_network()['hrp'] + '1') diff --git a/basicswap/interface/nav.py b/basicswap/interface/nav.py index 72c13e2..d2481a8 100644 --- a/basicswap/interface/nav.py +++ b/basicswap/interface/nav.py @@ -727,17 +727,3 @@ class NAVInterface(BTCInterface): i2h(tx.sha256), tx_fee_rate, vsize, pay_fee) return tx.serialize() - - def get_fee_rate(self, conf_target: int = 2): - - try: - fee_rate = self.rpc_callback('estimatesmartfee', [conf_target])['feerate'] - assert (fee_rate > 0.0), 'Non positive feerate' - return fee_rate, 'estimatesmartfee' - except Exception: - try: - fee_rate = self.rpc_callback('getwalletinfo')['paytxfee'] - assert (fee_rate > 0.0), 'Non positive feerate' - return fee_rate, 'paytxfee' - except Exception: - return self.rpc_callback('getnetworkinfo')['relayfee'], 'relayfee' diff --git a/bin/basicswap_prepare.py b/bin/basicswap_prepare.py index 4897da1..a89da5a 100755 --- a/bin/basicswap_prepare.py +++ b/bin/basicswap_prepare.py @@ -1590,6 +1590,7 @@ def main(): 'blocks_confirmed': 1, 'conf_target': 2, 'core_version_group': 14, + 'min_relay_fee': 0.00001, 'chain_lookups': 'local', }, 'navcoin': {