Browse Source

wallet: fix maturity off-by-one

based on Electron-Cash/Electron-Cash@c70957eb131ccb780726c8d01bcbb914df5b9644
dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
SomberNight 6 years ago
parent
commit
abde8ff169
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 9
      electrum/address_synchronizer.py

9
electrum/address_synchronizer.py

@ -551,7 +551,7 @@ class AddressSynchronizer(Logger):
txs.add(tx_hash) txs.add(tx_hash)
return txs return txs
def get_local_height(self): def get_local_height(self) -> int:
""" return last known height if we are offline """ """ return last known height if we are offline """
cached_local_height = getattr(self.threadlocal_cache, 'local_height', None) cached_local_height = getattr(self.threadlocal_cache, 'local_height', None)
if cached_local_height is not None: if cached_local_height is not None:
@ -742,11 +742,11 @@ class AddressSynchronizer(Logger):
assert isinstance(excluded_coins, set), f"excluded_coins should be set, not {type(excluded_coins)}" assert isinstance(excluded_coins, set), f"excluded_coins should be set, not {type(excluded_coins)}"
received, sent = self.get_addr_io(address) received, sent = self.get_addr_io(address)
c = u = x = 0 c = u = x = 0
local_height = self.get_local_height() mempool_height = self.get_local_height() + 1 # height of next block
for txo, (tx_height, v, is_cb) in received.items(): for txo, (tx_height, v, is_cb) in received.items():
if txo in excluded_coins: if txo in excluded_coins:
continue continue
if is_cb and tx_height + COINBASE_MATURITY > local_height: if is_cb and tx_height + COINBASE_MATURITY > mempool_height:
x += v x += v
elif tx_height > 0: elif tx_height > 0:
c += v c += v
@ -774,6 +774,7 @@ class AddressSynchronizer(Logger):
domain = set(domain) domain = set(domain)
if excluded_addresses: if excluded_addresses:
domain = set(domain) - set(excluded_addresses) domain = set(domain) - set(excluded_addresses)
mempool_height = self.get_local_height() + 1 # height of next block
for addr in domain: for addr in domain:
utxos = self.get_addr_utxo(addr) utxos = self.get_addr_utxo(addr)
for x in utxos.values(): for x in utxos.values():
@ -781,7 +782,7 @@ class AddressSynchronizer(Logger):
continue continue
if nonlocal_only and x['height'] == TX_HEIGHT_LOCAL: if nonlocal_only and x['height'] == TX_HEIGHT_LOCAL:
continue continue
if mature_only and x['coinbase'] and x['height'] + COINBASE_MATURITY > self.get_local_height(): if mature_only and x['coinbase'] and x['height'] + COINBASE_MATURITY > mempool_height:
continue continue
coins.append(x) coins.append(x)
continue continue

Loading…
Cancel
Save