Browse Source

Qt address list speedup: wallet.is_beyond_limit was slow

hard-fail-on-bad-server-string
SomberNight 5 years ago
parent
commit
1ca6f6f306
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 3
      electrum/gui/qt/address_list.py
  2. 38
      electrum/wallet.py

3
electrum/gui/qt/address_list.py

@ -150,6 +150,7 @@ class AddressList(MyTreeView):
self.refresh_headers()
fx = self.parent.fx
set_address = None
addresses_beyond_gap_limit = self.wallet.get_all_known_addresses_beyond_gap_limit()
for address in addr_list:
num = self.wallet.get_address_history_len(address)
label = self.wallet.labels.get(address, '')
@ -189,7 +190,7 @@ class AddressList(MyTreeView):
# setup column 1
if self.wallet.is_frozen_address(address):
address_item[self.Columns.ADDRESS].setBackground(ColorScheme.BLUE.as_color(True))
if self.wallet.is_beyond_limit(address):
if address in addresses_beyond_gap_limit:
address_item[self.Columns.ADDRESS].setBackground(ColorScheme.RED.as_color(True))
# add item
count = self.model().rowCount()

38
electrum/wallet.py

@ -1866,7 +1866,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
pass
@abstractmethod
def is_beyond_limit(self, address: str) -> bool:
def get_all_known_addresses_beyond_gap_limit(self) -> Set[str]:
pass
@ -1942,8 +1942,8 @@ class Imported_Wallet(Simple_Wallet):
def is_change(self, address):
return False
def is_beyond_limit(self, address):
return False
def get_all_known_addresses_beyond_gap_limit(self) -> Set[str]:
return set()
def get_fingerprint(self):
return ''
@ -2231,21 +2231,23 @@ class Deterministic_Wallet(Abstract_Wallet):
self.synchronize_sequence(False)
self.synchronize_sequence(True)
def is_beyond_limit(self, address):
is_change, i = self.get_address_index(address)
limit = self.gap_limit_for_change if is_change else self.gap_limit
if i < limit:
return False
slice_start = max(0, i - limit)
slice_stop = max(0, i)
if is_change:
prev_addresses = self.get_change_addresses(slice_start=slice_start, slice_stop=slice_stop)
else:
prev_addresses = self.get_receiving_addresses(slice_start=slice_start, slice_stop=slice_stop)
for addr in prev_addresses:
if self.db.get_addr_history(addr):
return False
return True
def get_all_known_addresses_beyond_gap_limit(self):
# note that we don't stop at first large gap
found = set()
def process_addresses(addrs, gap_limit):
rolling_num_unused = 0
for addr in addrs:
if self.db.get_addr_history(addr):
rolling_num_unused = 0
else:
if rolling_num_unused >= gap_limit:
found.add(addr)
rolling_num_unused += 1
process_addresses(self.get_receiving_addresses(), self.gap_limit)
process_addresses(self.get_change_addresses(), self.gap_limit_for_change)
return found
def get_address_index(self, address) -> Optional[Sequence[int]]:
return self.db.get_address_index(address) or self._ephemeral_addr_to_addr_index.get(address)

Loading…
Cancel
Save