commit 37143fd628bff1beafa1894bf643115b6966a7fb
parent ba2211f52e6cfafaac468e9635210a5eb2a96f5c
Author: ThomasV <thomasv@electrum.org>
Date: Fri, 14 Jul 2017 06:20:05 +0200
fix blockchain offset
Diffstat:
2 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/lib/blockchain.py b/lib/blockchain.py
@@ -147,7 +147,7 @@ class Blockchain(util.PrintError):
def save_header(self, header):
height = header.get('block_height')
if not self.is_saved:
- assert height == self.checkpoint + len(self.headers) + 1
+ assert height == self.checkpoint + len(self.headers)
self.headers.append(header)
if len(self.headers) > 10:
self.fork_and_save()
diff --git a/lib/network.py b/lib/network.py
@@ -840,7 +840,7 @@ class Network(util.DaemonThread):
self.connection_down(interface.server)
interface.request = None
return
- can_connect = self.can_connect(header)
+ can_connect = interface.blockchain.can_connect(header)
if interface.mode == 'backward':
if can_connect:
interface.good = height
@@ -863,23 +863,21 @@ class Network(util.DaemonThread):
if interface.bad != interface.good + 1:
next_height = (interface.bad + interface.good) // 2
else:
- delta1 = interface.blockchain.height() - interface.good
- delta2 = interface.tip - interface.good
- interface.print_error("chain split detected at %d"%interface.good, delta1, delta2)
- interface.blockchain = Blockchain(self.config, False, interface.bad)
+ interface.print_error("can connect at %d"% interface.good)
+ interface.blockchain = Blockchain(self.config, interface.blockchain.filename, interface.good)
interface.blockchain.catch_up = interface.server
- self.blockchains[interface.bad] = interface.blockchain
- interface.print_error("catching up")
+ self.blockchains[interface.good] = interface.blockchain
+ interface.print_error("catching up with new chain")
interface.mode = 'catch_up'
next_height = interface.good
elif interface.mode == 'catch_up':
if can_connect:
interface.blockchain.save_header(header)
- self.notify('updated')
next_height = height + 1 if height < interface.tip else None
else:
# go back
+ interface.print_error("cannot connect", height)
interface.mode = 'backward'
interface.bad = height
next_height = height - 1
@@ -890,6 +888,7 @@ class Network(util.DaemonThread):
interface.mode = 'default'
interface.print_error('catch up done', interface.blockchain.height())
interface.blockchain.catch_up = None
+ self.notify('updated')
elif interface.mode == 'default':
assert not can_connect