XMR compat: skip unnecessary wallet open with tracking wallet refresh

This commit is contained in:
The MMGen Project 2026-11-16 10:45:27 +00:00
commit 91d94a383a
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
6 changed files with 56 additions and 18 deletions

View file

@ -252,7 +252,8 @@ class Signable:
self.parent.xmr_cur_wallet_idx = new_idx
return Config({
'_clone': self.parent.xmrwallet_cfg,
'no_restart_wallet_daemon': old_idx == new_idx})
'no_restart_wallet_daemon': old_idx is not None,
'cur_wallet': new_idx if new_idx == old_idx else None})
def print_summary(self, signables):
info_func = 'get_info' if self.cfg.full_summary else 'get_info_oneline'

View file

@ -1 +1 @@
17.1.0dev0
17.1.0dev1

View file

@ -13,6 +13,7 @@ proto.xmr.tw.view: Monero protocol base class for tracking wallet view classes
import asyncio
from collections import namedtuple
from ....cfg import Config
from ....obj import ImmutableAttr, Int
from ....util import msg, ymsg, suf, cached_property
from ....color import red, green
@ -64,22 +65,24 @@ class MoneroTwView:
if refresh:
from ....exception import SocketError
cfg = Config({'_clone': self.cfg, 'cur_wallet': self.cur_wallet})
op = xmrwallet_op('dump_data_refresh', cfg, None, None, compat_call=True)
try:
op = xmrwallet_op('dump_data_refresh', self.cfg, None, None, compat_call=True)
dump_data = await op.main()
except SocketError as e:
ymsg(f'Refresh failed: {e}')
await asyncio.sleep(1.5)
return None
else:
op = xmrwallet_op('dump_data', self.cfg, None, None, compat_call=True)
await op.restart_wallet_daemon()
dump_data = await op.main()
await op.restart_wallet_daemon()
dump_data = await op.main()
if dump_data:
self.sid = SeedID(sid=dump_data[0]['seed_id'])
self.blockcount = Int(dump_data[0]['blockcount'])
self.timestamp = dump_data[0]['timestamp']
self.cur_wallet = dump_data[-1]['wallet_num']
self.al_id = self.sid + ':M'
self.total = self.unlocked_total = self.proto.coin_amt('0')

View file

@ -10,7 +10,7 @@
xmrwallet.ops.dump: Monero wallet ops for the MMGen Suite
"""
from ...util import msg, Msg
from ...util import msg, Msg, gmsg
from ..file.outputs import MoneroWalletDumpFile
@ -31,9 +31,9 @@ class OpDump(OpWallet):
return True
class OpDumpDataCommon(OpWallet):
wallet_offline = True
return_data = True
wallet_desc = 'source'
skip_refresh = True
async def process_wallet(self, d, h, last):
@ -64,7 +64,12 @@ class OpDumpData(OpDumpDataCommon):
stem = 'load'
class OpDumpDataRefresh(OpDumpData):
wallet_offline = False
async def process_wallet(self, d, h, last):
self.wd.test_monerod_port() # raises SocketError on fail, handled by caller
gmsg(' Refreshing wallet')
self.c.call('refresh')
return await super().process_wallet(d, h, last)
class OpDumpJson(OpDumpDataCommon):
stem = 'dump'

View file

@ -40,6 +40,7 @@ class OpWallet(OpBase):
disable_authentication = False
main_starts_daemon = False
main_opens_wallet = True
skip_refresh = False
def __init__(self, cfg, uarg_tuple):
@ -73,7 +74,7 @@ class OpWallet(OpBase):
disable_authentication = self.disable_authentication,
offline = self.wallet_offline,
trust_monerod = self.trust_monerod,
test_monerod = not self.wallet_offline)
test_monerod = not (self.wallet_offline or self.skip_refresh))
if self.is_create and self.cfg.compat:
self.wd.wallet_dir.mkdir(parents=True, exist_ok=True)
@ -108,7 +109,8 @@ class OpWallet(OpBase):
self.to_process
and self.start_daemon
and not self.cfg.no_start_wallet_daemon
and not (self.cfg.no_restart_wallet_daemon and self.wd.state == 'ready'))
and not (self.cfg.no_restart_wallet_daemon and self.wd.state == 'ready')
and not self.cfg.cur_wallet)
if self.need_daemon_start and not self.main_starts_daemon:
asyncio.run(self.restart_wallet_daemon())
@ -194,6 +196,9 @@ class OpWallet(OpBase):
async def main(self):
def do_open_wallet(h):
h.open_wallet(desc=self.wallet_desc, refresh=not (self.wallet_offline or self.skip_refresh))
if self.need_daemon_start and self.main_starts_daemon:
await self.restart_wallet_daemon()
@ -204,8 +209,16 @@ class OpWallet(OpBase):
c = self.add_wallet_desc,
d = suf(self.to_process)))
if self.cfg.cur_wallet:
addr_data = (
[a for a in self.addr_data if a.idx == self.cfg.cur_wallet]
+ [a for a in self.addr_data if a.idx != self.cfg.cur_wallet])
assert addr_data[0].idx == self.cfg.cur_wallet, 'wallet index mismatch'
else:
addr_data = self.addr_data
data = []
for n, d in enumerate(self.addr_data): # [d.idx, d.sec, d.addr, d.wallet_passwd, d.viewkey]
for n, d in enumerate(addr_data): # [d.idx, d.sec, d.addr, d.wallet_passwd, d.viewkey]
fn = self.get_wallet_fn(d)
if self.is_create and self.stat_wallet(fn):
continue
@ -216,8 +229,13 @@ class OpWallet(OpBase):
d = fn.name))
h = MoneroWalletRPC(self, d)
if self.main_opens_wallet:
h.open_wallet(self.wallet_desc, refresh=not self.wallet_offline)
if self.cfg.cur_wallet:
if n:
do_open_wallet(h)
else:
gmsg('\n Using already opened wallet')
elif self.main_opens_wallet:
do_open_wallet(h)
data.append(await self.process_wallet(d, h, last=(n == len(self.addr_data) - 1)))

View file

@ -11,7 +11,7 @@
test.cmdtest_d.xmr_autosign: xmr autosigning tests for the cmdtest.py test suite
"""
import os, re, asyncio, json
import os, re, asyncio, json, time
from mmgen.util import suf
from mmgen.color import blue, cyan, brown
@ -603,6 +603,7 @@ class CmdTestXMRCompat(CmdTestXMRAutosign):
('user_twview_chk5', 'viewing user’s tracking wallets (check balances)'),
('wait_loop_kill', 'stopping autosign wait loop'),
('stop_daemons', 'stopping all wallet and coin daemons'),
('user_listaddresses_refresh_fail', 'failed wallet refresh'),
('user_newacct1', 'adding account to user’s tracking wallet (dfl label)'),
('user_newacct2', 'adding account to user’s tracking wallet (no timestr)'),
('user_newacct3', 'adding account to user’s tracking wallet'),
@ -796,6 +797,8 @@ class CmdTestXMRCompat(CmdTestXMRAutosign):
menu = '',
interactive = True,
pexpect_interact = False,
refresh_loop = False,
refresh_fail = False,
expect_str = '',
expect_arr = []):
@ -812,7 +815,6 @@ class CmdTestXMRCompat(CmdTestXMRAutosign):
al = AddrIdxList(fmt_str=self.users[self.user].kal_range)
for n in range(len(al)):
t.expect('Loading')
t.expect('Opening')
if pexpect_interact:
t.p.interact() # pexpect interact() is currently broken
self.remove_device_online()
@ -831,13 +833,20 @@ class CmdTestXMRCompat(CmdTestXMRAutosign):
if have_lbl:
t.expect(': ', lbl_text + '\n') # add label
t.expect('(y/N): ', ('y' if add_timestr else 'n')) # add timestr
if refresh_loop:
while True:
t.expect(menu_prompt, 'R')
time.sleep(1)
if have_new_addr:
t.expect('(y/N): ', 'y')
for ch in menu:
t.expect(menu_prompt, ch)
if ch == 'R':
if refresh_fail:
t.expect('Refresh failed')
break
for n in range(len(al)):
for s in ('Loading', 'Opening', 'Refreshing'):
for s in ('Loading', 'Refreshing'):
t.expect(s)
if expect_str:
t.expect(expect_str, regex=True)
@ -945,7 +954,6 @@ class CmdTestXMRCompat(CmdTestXMRAutosign):
al = AddrIdxList(fmt_str=self.users[self.user].kal_range)
for n in range(len(al)):
t.expect('Loading')
t.expect('Opening')
if sweep_type:
t.expect(self.menu_prompt, menu)
for ch in sweep_menu:
@ -969,6 +977,9 @@ class CmdTestXMRCompat(CmdTestXMRAutosign):
self.remove_device_online()
return t
def user_listaddresses_refresh_fail(self):
return self._user_twops('listaddresses', menu='R', refresh_fail=True)
class CmdTestXMRAutosignDev(CmdTestXMRAutosign):
"""
Monero autosigning operations (non-compat mode, for development)