Merge pull request #74 from nahuhh/monero_speed
Some checks are pending
lint / build (3.12) (push) Waiting to run

ux: XMR optimizations
This commit is contained in:
tecnovert 2024-11-25 21:22:11 +00:00 committed by GitHub
commit 1b36154142
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 26 deletions

View file

@ -994,18 +994,6 @@ class BasicSwap(BaseApp):
except Exception as e: except Exception as e:
self.log.error("Sanity checks failed: %s", str(e)) self.log.error("Sanity checks failed: %s", str(e))
elif c == Coins.XMR:
try:
ci.ensureWalletExists()
except Exception as e: # noqa: F841
self.log.warning("Can't open XMR wallet, could be locked.")
continue
elif c == Coins.WOW:
try:
ci.ensureWalletExists()
except Exception as e: # noqa: F841
self.log.warning("Can't open WOW wallet, could be locked.")
continue
elif c == Coins.LTC: elif c == Coins.LTC:
ci_mweb = self.ci(Coins.LTC_MWEB) ci_mweb = self.ci(Coins.LTC_MWEB)
is_encrypted, _ = self.getLockedState() is_encrypted, _ = self.getLockedState()

View file

@ -135,6 +135,7 @@ class XMRInterface(CoinInterface):
self._rpctimeout = coin_settings.get("rpctimeout", 60) self._rpctimeout = coin_settings.get("rpctimeout", 60)
self._walletrpctimeout = coin_settings.get("walletrpctimeout", 120) self._walletrpctimeout = coin_settings.get("walletrpctimeout", 120)
# walletrpctimeoutlong likely unneeded
self._walletrpctimeoutlong = coin_settings.get("walletrpctimeoutlong", 600) self._walletrpctimeoutlong = coin_settings.get("walletrpctimeoutlong", 600)
self.rpc = make_xmr_rpc_func( self.rpc = make_xmr_rpc_func(
@ -182,11 +183,23 @@ class XMRInterface(CoinInterface):
params["password"] = self._wallet_password params["password"] = self._wallet_password
try: try:
# Can't reopen the same wallet in windows, !is_keys_file_locked() self.rpc_wallet("open_wallet", params)
self.rpc_wallet("close_wallet") # TODO Remove `refresh` after upstream fix to refresh on open_wallet
self.rpc_wallet("refresh")
except Exception: except Exception:
self._log.debug(f"Failed to open {self.coin_name()} wallet")
try:
# TODO Remove `store` after upstream fix to autosave on close_wallet
self.rpc_wallet("store")
self.rpc_wallet("close_wallet")
self._log.debug(f"Attempt to save and close {self.coin_name()} wallet")
except Exception as e:
self._log.debug(f"{self.coin_name()}: {e}")
pass pass
self.rpc_wallet("open_wallet", params) self.rpc_wallet("open_wallet", params)
# TODO Remove `refresh` after upstream fix to refresh on open_wallet
self.rpc_wallet("refresh")
self._log.debug(f"Reattempt to open {self.coin_name()} wallet")
def initialiseWallet( def initialiseWallet(
self, key_view: bytes, key_spend: bytes, restore_height=None self, key_view: bytes, key_spend: bytes, restore_height=None
@ -272,7 +285,6 @@ class XMRInterface(CoinInterface):
raise e raise e
rv = {} rv = {}
self.rpc_wallet("refresh")
balance_info = self.rpc_wallet("get_balance") balance_info = self.rpc_wallet("get_balance")
rv["balance"] = self.format_amount(balance_info["unlocked_balance"]) rv["balance"] = self.format_amount(balance_info["unlocked_balance"])
@ -373,7 +385,6 @@ class XMRInterface(CoinInterface):
) -> bytes: ) -> bytes:
with self._mx_wallet: with self._mx_wallet:
self.openWallet(self._wallet_filename) self.openWallet(self._wallet_filename)
self.rpc_wallet("refresh")
Kbv = self.getPubkey(kbv) Kbv = self.getPubkey(kbv)
shared_addr = xmr_util.encode_address(Kbv, Kbs, self._addr_prefix) shared_addr = xmr_util.encode_address(Kbv, Kbs, self._addr_prefix)
@ -413,8 +424,6 @@ class XMRInterface(CoinInterface):
self.createWallet(params) self.createWallet(params)
self.openWallet(address_b58) self.openWallet(address_b58)
self.rpc_wallet("refresh", timeout=self._walletrpctimeoutlong)
""" """
# Debug # Debug
try: try:
@ -466,7 +475,6 @@ class XMRInterface(CoinInterface):
def findTxnByHash(self, txid): def findTxnByHash(self, txid):
with self._mx_wallet: with self._mx_wallet:
self.openWallet(self._wallet_filename) self.openWallet(self._wallet_filename)
self.rpc_wallet("refresh", timeout=self._walletrpctimeoutlong)
try: try:
current_height = self.rpc2("get_height", timeout=self._rpctimeout)[ current_height = self.rpc2("get_height", timeout=self._rpctimeout)[
@ -535,7 +543,6 @@ class XMRInterface(CoinInterface):
self.createWallet(params) self.createWallet(params)
self.openWallet(wallet_filename) self.openWallet(wallet_filename)
self.rpc_wallet("refresh")
rv = self.rpc_wallet("get_balance") rv = self.rpc_wallet("get_balance")
if rv["balance"] < cb_swap_value: if rv["balance"] < cb_swap_value:
self._log.warning("Balance is too low, checking for existing spend.") self._log.warning("Balance is too low, checking for existing spend.")
@ -590,7 +597,6 @@ class XMRInterface(CoinInterface):
) -> str: ) -> str:
with self._mx_wallet: with self._mx_wallet:
self.openWallet(self._wallet_filename) self.openWallet(self._wallet_filename)
self.rpc_wallet("refresh")
if sweepall: if sweepall:
balance = self.rpc_wallet("get_balance") balance = self.rpc_wallet("get_balance")
@ -670,8 +676,6 @@ class XMRInterface(CoinInterface):
self.createWallet(params) self.createWallet(params)
self.openWallet(address_b58) self.openWallet(address_b58)
self.rpc_wallet("refresh")
rv = self.rpc_wallet( rv = self.rpc_wallet(
"get_transfers", "get_transfers",
{"in": True, "out": True, "pending": True, "failed": True}, {"in": True, "out": True, "pending": True, "failed": True},
@ -685,7 +689,6 @@ class XMRInterface(CoinInterface):
with self._mx_wallet: with self._mx_wallet:
self.openWallet(self._wallet_filename) self.openWallet(self._wallet_filename)
self.rpc_wallet("refresh")
balance_info = self.rpc_wallet("get_balance") balance_info = self.rpc_wallet("get_balance")
return balance_info["unlocked_balance"] return balance_info["unlocked_balance"]