From 88c94c4acd254b4607f9c4abf6bd87a144a6a443 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Mon, 11 Apr 2022 00:11:51 +0200 Subject: [PATCH] Set default anon tx ring size to 12 and add setting. --- basicswap/basicswap.py | 14 ++++++++++++++ basicswap/http_server.py | 7 ++++++- basicswap/interface_btc.py | 2 +- basicswap/interface_part.py | 11 ++++++++--- basicswap/templates/settings.html | 3 +++ tests/basicswap/test_xmr.py | 3 ++- 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 892831d..ed0ede8 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -390,6 +390,7 @@ class BasicSwap(BaseApp): } if coin == Coins.PART: + self.coin_clients[coin]['anon_tx_ring_size'] = chain_client_settings.get('anon_tx_ring_size', 12) self.coin_clients[Coins.PART_ANON] = self.coin_clients[coin] self.coin_clients[Coins.PART_BLIND] = self.coin_clients[coin] @@ -5094,6 +5095,19 @@ class BasicSwap(BaseApp): self.ci(coin).setConfTarget(new_conf_target) break + if 'anon_tx_ring_size' in data: + new_anon_tx_ring_size = data['anon_tx_ring_size'] + ensure(new_anon_tx_ring_size >= 3 and new_anon_tx_ring_size < 33, 'Invalid anon_tx_ring_size') + + if settings_cc.get('anon_tx_ring_size', 12) != new_anon_tx_ring_size: + settings_changed = True + settings_cc['anon_tx_ring_size'] = new_anon_tx_ring_size + for coin, cc in self.coin_clients.items(): + if cc['name'] == coin_name: + cc['anon_tx_ring_size'] = new_anon_tx_ring_size + self.ci(coin).setAnonTxRingSize(new_anon_tx_ring_size) + break + if settings_changed: settings_path = os.path.join(self.data_dir, cfg.CONFIG_FILENAME) shutil.copyfile(settings_path, settings_path + '.last') diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 7ddbd7a..9ddcbf7 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -575,6 +575,8 @@ class HttpHandler(BaseHTTPRequestHandler): data['automatically_select_daemon'] = True if get_data_entry(form_data, 'autosetdaemon_' + name) == 'true' else False else: data['conf_target'] = int(get_data_entry(form_data, 'conf_target_' + name)) + if name == 'particl': + data['anon_tx_ring_size'] = int(get_data_entry(form_data, 'rct_ring_size_' + name)) settings_changed, suggest_reboot = swap_client.editSettings(name, data) if settings_changed is True: @@ -609,7 +611,10 @@ class HttpHandler(BaseHTTPRequestHandler): chains_formatted[-1]['autosetdaemon'] = c.get('automatically_select_daemon', False) else: chains_formatted[-1]['conf_target'] = c.get('conf_target', 2) - if name != 'particl': + + if name == 'particl': + chains_formatted[-1]['anon_tx_ring_size'] = c.get('anon_tx_ring_size', 12) + else: if c.get('connection_type', 'Unknown') == 'none': if 'connection_type_prev' in c: chains_formatted[-1]['can_reenable'] = True diff --git a/basicswap/interface_btc.py b/basicswap/interface_btc.py index 1c25e0f..4f26f54 100644 --- a/basicswap/interface_btc.py +++ b/basicswap/interface_btc.py @@ -208,7 +208,7 @@ class BTCInterface(CoinInterface): rpc_conn.close() def setConfTarget(self, new_conf_target): - assert(new_conf_target >= 1 and new_conf_target < 33), 'Invalid conf_target value' + ensure(new_conf_target >= 1 and new_conf_target < 33, 'Invalid conf_target value') self._conf_target = new_conf_target def testDaemonRPC(self): diff --git a/basicswap/interface_part.py b/basicswap/interface_part.py index 9ceff79..0a863a7 100644 --- a/basicswap/interface_part.py +++ b/basicswap/interface_part.py @@ -65,9 +65,13 @@ class PARTInterface(BTCInterface): def txoType(): return CTxOutPart - def setDefaults(self) -> None: - super().setDefaults() - self._anon_tx_ring_size = 8 # TODO: Make option + def __init__(self, coin_settings, network, swap_client=None): + super().__init__(coin_settings, network, swap_client) + self.setAnonTxRingSize(int(coin_settings.get('anon_tx_ring_size', 12))) + + def setAnonTxRingSize(self, value): + ensure(value >= 3 and value < 33, 'Invalid anon_tx_ring_size value') + self._anon_tx_ring_size = value def knownWalletSeed(self): # TODO: Double check @@ -708,6 +712,7 @@ class PARTInterfaceAnon(PARTInterface): utxo = autxos[0] utxo_sats = make_int(utxo['amount']) + if spend_actual_balance and utxo_sats != cb_swap_value: self._log.warning('Spending actual balance {}, not swap value {}.'.format(utxo_sats, cb_swap_value)) cb_swap_value = utxo_sats diff --git a/basicswap/templates/settings.html b/basicswap/templates/settings.html index 32744d8..ecfe964 100644 --- a/basicswap/templates/settings.html +++ b/basicswap/templates/settings.html @@ -59,6 +59,9 @@ node.xmr.to:18081
{% else %} Blocks Confirmed Target {% endif %} +{% if c.name == 'particl' %} +Anon Tx Ring Size +{% endif %} {% if c.can_disable == true %} diff --git a/tests/basicswap/test_xmr.py b/tests/basicswap/test_xmr.py index 08a8159..4e16429 100644 --- a/tests/basicswap/test_xmr.py +++ b/tests/basicswap/test_xmr.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 tecnovert +# Copyright (c) 2020-2022 tecnovert # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php. @@ -168,6 +168,7 @@ def prepare_swapclient_dir(datadir, node_id, network_key, network_pubkey, with_l 'datadir': os.path.join(datadir, 'part_' + str(node_id)), 'bindir': cfg.PARTICL_BINDIR, 'blocks_confirmed': 2, # Faster testing + 'anon_tx_ring_size': 5, # Faster testing }, 'bitcoin': { 'connection_type': 'rpc',