Browse Source

fix blockchain offset

2.9.x
ThomasV 8 years ago
parent
commit
37143fd628
  1. 2
      lib/blockchain.py
  2. 15
      lib/network.py

2
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()

15
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

Loading…
Cancel
Save