Browse Source

verifier: if we fail to verify SPV proof, disconnect from server

3.3.3.1
SomberNight 7 years ago
parent
commit
c49e563881
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 11
      electrum/verifier.py

11
electrum/verifier.py

@ -24,12 +24,11 @@
import asyncio import asyncio
from typing import Sequence, Optional from typing import Sequence, Optional
from aiorpcx import TaskGroup from .util import ThreadJob, bh2u, VerifiedTxInfo
from .util import ThreadJob, bh2u, VerifiedTxInfo, aiosafe
from .bitcoin import Hash, hash_decode, hash_encode from .bitcoin import Hash, hash_decode, hash_encode
from .transaction import Transaction from .transaction import Transaction
from .blockchain import hash_header from .blockchain import hash_header
from .interface import GracefulDisconnect
class MerkleVerificationFailure(Exception): pass class MerkleVerificationFailure(Exception): pass
@ -94,14 +93,10 @@ class SPV(ThreadJob):
verify_tx_is_in_block(tx_hash, merkle_branch, pos, header, tx_height) verify_tx_is_in_block(tx_hash, merkle_branch, pos, header, tx_height)
except MerkleVerificationFailure as e: except MerkleVerificationFailure as e:
self.print_error(str(e)) self.print_error(str(e))
# FIXME: we should make a fresh connection to a server raise GracefulDisconnect(e)
# to recover from this, as this TX will now never verify
return
# we passed all the tests # we passed all the tests
self.merkle_roots[tx_hash] = header.get('merkle_root') self.merkle_roots[tx_hash] = header.get('merkle_root')
try: try:
# note: we could pop in the beginning, but then we would request
# this proof again in case of verification failure from the same server
self.requested_merkle.remove(tx_hash) self.requested_merkle.remove(tx_hash)
except KeyError: pass except KeyError: pass
self.print_error("verified %s" % tx_hash) self.print_error("verified %s" % tx_hash)

Loading…
Cancel
Save