electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 819044221b5e8090d36de5c5f9d5245f49c2988e
parent 78e9152723ad3c4f35f6e82f8be045be35a2afa4
Author: SomberNight <somber.night@protonmail.com>
Date:   Thu, 13 Sep 2018 19:00:21 +0200

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.

Diffstat:
Melectrum/verifier.py | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/electrum/verifier.py b/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: