Browse Source

verifier: need to wait for reorg

fixes race between verifier and block header download.
scenario: client starts, connects to server. while client was offline,
there was a reorg. txn A was not mined in the old chain, but is mined
after reorg. client subscribes to addresses and starts downloading headers,
concurrently. server tells client txn A is mined at height H >= reorg height.
client sees it has block header at height H, asks for SPV proof for txn A.
but the header the client has is still the old one, the verifier was faster
than the block header download (race...). client receives proof. proof is
incorrect for old header. client disconnects.
3.3.3.1
SomberNight 6 years ago
parent
commit
819044221b
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 4
      electrum/verifier.py

4
electrum/verifier.py

@ -90,7 +90,9 @@ class SPV(ThreadJob):
tx_height = merkle.get('block_height')
pos = merkle.get('pos')
merkle_branch = merkle.get('merkle')
header = self.network.blockchain().read_header(tx_height)
# we need to wait if header sync/reorg is still ongoing, hence lock:
async with self.network.bhi_lock:
header = self.network.blockchain().read_header(tx_height)
try:
verify_tx_is_in_block(tx_hash, merkle_branch, pos, header, tx_height)
except MerkleVerificationFailure as e:

Loading…
Cancel
Save