Browse Source

improve blockchain search

2.9.x
ThomasV 8 years ago
parent
commit
3d4c64f9e0
  1. 56
      lib/network.py

56
lib/network.py

@ -839,24 +839,28 @@ class Network(util.DaemonThread):
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.good) interface.print_error("can connect at %d"% interface.bad)
b = self.blockchains.get(interface.good) b = self.blockchains.get(interface.bad)
# if there is a reorg we connect to the parent if b is not None:
if b is not None and interface.good == b.checkpoint: if b.check_header(header):
interface.print_error('reorg', interface.good, interface.tip) interface.print_error('joining chain', interface.bad)
interface.blockchain = b.parent
interface.mode = 'default'
next_height = interface.tip
else:
if b is None:
b = interface.blockchain.fork(interface.bad)
self.blockchains[interface.bad] = b
interface.print_error("catching up on new blockchain", b.filename)
if b.catch_up is None:
b.catch_up = interface.server
interface.blockchain = b interface.blockchain = b
interface.mode = 'catch_up' elif b.parent.check_header(header):
next_height = interface.bad interface.print_error('reorg', interface.bad, interface.tip)
interface.blockchain = b.parent
else:
# should not happen
raise BaseException('error')
# todo: we should check the tip once catch up is nor
next_height = None
else:
b = interface.blockchain.fork(interface.bad)
self.blockchains[interface.bad] = b
interface.print_error("new chain", b.filename)
b.catch_up = interface.server
interface.blockchain = b
interface.mode = 'catch_up'
next_height = interface.bad
# todo: garbage collect blockchain objects # todo: garbage collect blockchain objects
self.notify('updated') self.notify('updated')
@ -874,18 +878,19 @@ class Network(util.DaemonThread):
if next_height is None: if next_height is None:
# exit catch_up state # exit catch_up state
interface.request = None
interface.mode = 'default'
interface.print_error('catch up done', interface.blockchain.height()) interface.print_error('catch up done', interface.blockchain.height())
interface.blockchain.catch_up = None interface.blockchain.catch_up = None
self.notify('updated') self.notify('updated')
elif interface.mode == 'default': elif interface.mode == 'default':
assert not can_connect if not ok:
interface.print_error("cannot connect %d"% height) interface.print_error("default: cannot connect %d"% height)
interface.mode = 'backward' interface.mode = 'backward'
interface.bad = height interface.bad = height
next_height = height - 1 next_height = height - 1
else:
interface.print_error("we are ok", height, interface.request)
next_height = None
else: else:
raise BaseException(interface.mode) raise BaseException(interface.mode)
# If not finished, get the next header # If not finished, get the next header
@ -894,6 +899,9 @@ class Network(util.DaemonThread):
self.request_chunk(interface, next_height // 2016) self.request_chunk(interface, next_height // 2016)
else: else:
self.request_header(interface, next_height) self.request_header(interface, next_height)
else:
interface.mode = 'default'
interface.request = None
# refresh network dialog # refresh network dialog
self.notify('interfaces') self.notify('interfaces')

Loading…
Cancel
Save