fix #3955: fix interference between verifier and catch_up
This commit is contained in:
parent
1f1844ac13
commit
0928ac961a
|
@ -181,7 +181,8 @@ class Blockchain(util.PrintError):
|
|||
if d < 0:
|
||||
chunk = chunk[-d:]
|
||||
d = 0
|
||||
self.write(chunk, d, index > len(self.checkpoints))
|
||||
truncate = index >= len(self.checkpoints)
|
||||
self.write(chunk, d, truncate)
|
||||
self.swap_with_parent()
|
||||
|
||||
def swap_with_parent(self):
|
||||
|
@ -338,7 +339,7 @@ class Blockchain(util.PrintError):
|
|||
self.save_chunk(idx, data)
|
||||
return True
|
||||
except BaseException as e:
|
||||
self.print_error('verify_chunk failed', str(e))
|
||||
self.print_error('verify_chunk %d failed'%idx, str(e))
|
||||
return False
|
||||
|
||||
def get_checkpoints(self):
|
||||
|
|
|
@ -777,6 +777,7 @@ class Network(util.DaemonThread):
|
|||
error = response.get('error')
|
||||
result = response.get('result')
|
||||
params = response.get('params')
|
||||
blockchain = interface.blockchain
|
||||
if result is None or params is None or error is not None:
|
||||
interface.print_error(error or 'bad response')
|
||||
return
|
||||
|
@ -785,17 +786,17 @@ class Network(util.DaemonThread):
|
|||
if index not in self.requested_chunks:
|
||||
return
|
||||
self.requested_chunks.remove(index)
|
||||
connect = interface.blockchain.connect_chunk(index, result)
|
||||
connect = blockchain.connect_chunk(index, result)
|
||||
if not connect:
|
||||
self.connection_down(interface.server)
|
||||
return
|
||||
# If not finished, get the next chunk
|
||||
if interface.blockchain.height() < interface.tip:
|
||||
if index >= len(blockchain.checkpoints) and blockchain.height() < interface.tip:
|
||||
self.request_chunk(interface, index+1)
|
||||
else:
|
||||
interface.mode = 'default'
|
||||
interface.print_error('catch up done', interface.blockchain.height())
|
||||
interface.blockchain.catch_up = None
|
||||
interface.print_error('catch up done', blockchain.height())
|
||||
blockchain.catch_up = None
|
||||
self.notify('updated')
|
||||
|
||||
def request_header(self, interface, height):
|
||||
|
|
|
@ -36,15 +36,19 @@ class SPV(ThreadJob):
|
|||
self.merkle_roots = {}
|
||||
|
||||
def run(self):
|
||||
if not self.network.interface:
|
||||
return
|
||||
lh = self.network.get_local_height()
|
||||
unverified = self.wallet.get_unverified_txs()
|
||||
blockchain = self.network.blockchain()
|
||||
for tx_hash, tx_height in unverified.items():
|
||||
# do not request merkle branch before headers are available
|
||||
if (tx_height > 0) and (tx_height <= lh):
|
||||
header = self.network.blockchain().read_header(tx_height)
|
||||
if header is None and self.network.interface:
|
||||
header = blockchain.read_header(tx_height)
|
||||
if header is None:
|
||||
index = tx_height // 2016
|
||||
self.network.request_chunk(self.network.interface, index)
|
||||
if index < len(blockchain.checkpoints):
|
||||
self.network.request_chunk(self.network.interface, index)
|
||||
else:
|
||||
if tx_hash not in self.merkle_roots:
|
||||
request = ('blockchain.transaction.get_merkle',
|
||||
|
|
Loading…
Reference in New Issue