Qt address list speedup: wallet.is_beyond_limit was slow

This commit is contained in:
SomberNight 2020-02-29 07:28:13 +01:00
parent a0b096dcb2
commit 1ca6f6f306
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9
2 changed files with 22 additions and 19 deletions

View file

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

View file

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