network: use interface.bad_header
This commit is contained in:
@@ -820,6 +820,7 @@ class Network(util.DaemonThread):
|
|||||||
next_height = None
|
next_height = None
|
||||||
else:
|
else:
|
||||||
interface.bad = height
|
interface.bad = height
|
||||||
|
interface.bad_header = header
|
||||||
delta = interface.tip - height
|
delta = interface.tip - height
|
||||||
next_height = max(0, interface.tip - 2 * delta)
|
next_height = max(0, interface.tip - 2 * delta)
|
||||||
elif interface.mode == 'binary':
|
elif interface.mode == 'binary':
|
||||||
@@ -828,14 +829,14 @@ class Network(util.DaemonThread):
|
|||||||
interface.blockchain = chain
|
interface.blockchain = chain
|
||||||
else:
|
else:
|
||||||
interface.bad = height
|
interface.bad = height
|
||||||
|
interface.bad_header = header
|
||||||
if interface.bad != interface.good + 1:
|
if interface.bad != interface.good + 1:
|
||||||
next_height = (interface.bad + interface.good) // 2
|
next_height = (interface.bad + interface.good) // 2
|
||||||
else:
|
else:
|
||||||
interface.print_error("can connect at %d"% interface.bad)
|
interface.print_error("can connect at %d"% interface.bad)
|
||||||
branch = self.blockchains.get(interface.bad)
|
branch = self.blockchains.get(interface.bad)
|
||||||
if branch is not None:
|
if branch is not None:
|
||||||
# should check bad_header. test doesnt work if header == good
|
if branch.check_header(interface.bad_header):
|
||||||
if branch.check_header(header):
|
|
||||||
interface.print_error('joining chain', interface.bad)
|
interface.print_error('joining chain', interface.bad)
|
||||||
elif branch.parent.check_header(header):
|
elif branch.parent.check_header(header):
|
||||||
interface.print_error('reorg', interface.bad, interface.tip)
|
interface.print_error('reorg', interface.bad, interface.tip)
|
||||||
@@ -843,19 +844,19 @@ class Network(util.DaemonThread):
|
|||||||
else:
|
else:
|
||||||
# should not happen
|
# should not happen
|
||||||
raise BaseException('error')
|
raise BaseException('error')
|
||||||
# todo: we should check the tip once catch up is nor
|
|
||||||
next_height = None
|
next_height = None
|
||||||
else:
|
else:
|
||||||
if interface.blockchain.height() > interface.good:
|
if interface.blockchain.height() > interface.good:
|
||||||
self.blockchains[interface.bad] = b = interface.blockchain.fork(interface.bad)
|
if not interface.blockchain.check_header(interface.bad_header):
|
||||||
interface.blockchain = b
|
self.blockchains[interface.bad] = b = interface.blockchain.fork(interface.bad)
|
||||||
interface.print_error("new chain", b.filename)
|
interface.blockchain = b
|
||||||
|
interface.print_error("new chain", b.filename)
|
||||||
else:
|
else:
|
||||||
assert interface.blockchain.height() == interface.good
|
assert interface.blockchain.height() == interface.good
|
||||||
|
|
||||||
if interface.blockchain.catch_up is None:
|
if interface.blockchain.catch_up is None:
|
||||||
interface.mode = 'catch_up'
|
interface.mode = 'catch_up'
|
||||||
next_height = interface.bad
|
next_height = interface.blockchain.height() + 1
|
||||||
interface.blockchain.catch_up = interface.server
|
interface.blockchain.catch_up = interface.server
|
||||||
else:
|
else:
|
||||||
interface.print_error('already catching up')
|
interface.print_error('already catching up')
|
||||||
@@ -873,6 +874,7 @@ class Network(util.DaemonThread):
|
|||||||
interface.print_error("cannot connect", height)
|
interface.print_error("cannot connect", height)
|
||||||
interface.mode = 'backward'
|
interface.mode = 'backward'
|
||||||
interface.bad = height
|
interface.bad = height
|
||||||
|
interface.bad_header = header
|
||||||
next_height = height - 1
|
next_height = height - 1
|
||||||
|
|
||||||
if next_height is None:
|
if next_height is None:
|
||||||
@@ -886,6 +888,7 @@ class Network(util.DaemonThread):
|
|||||||
interface.print_error("default: cannot connect %d"% height)
|
interface.print_error("default: cannot connect %d"% height)
|
||||||
interface.mode = 'backward'
|
interface.mode = 'backward'
|
||||||
interface.bad = height
|
interface.bad = height
|
||||||
|
interface.bad_header = header
|
||||||
next_height = height - 1
|
next_height = height - 1
|
||||||
else:
|
else:
|
||||||
interface.print_error("we are ok", height, interface.request)
|
interface.print_error("we are ok", height, interface.request)
|
||||||
@@ -991,6 +994,7 @@ class Network(util.DaemonThread):
|
|||||||
return
|
return
|
||||||
interface.mode = 'backward'
|
interface.mode = 'backward'
|
||||||
interface.bad = height
|
interface.bad = height
|
||||||
|
interface.bad_header = header
|
||||||
self.request_header(interface, height - 1) # should be max(heights)
|
self.request_header(interface, height - 1) # should be max(heights)
|
||||||
|
|
||||||
def blockchain(self):
|
def blockchain(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user