|
@ -206,10 +206,10 @@ class Network(util.DaemonThread): |
|
|
util.DaemonThread.__init__(self) |
|
|
util.DaemonThread.__init__(self) |
|
|
self.config = SimpleConfig(config) if type(config) == type({}) else config |
|
|
self.config = SimpleConfig(config) if type(config) == type({}) else config |
|
|
self.num_server = 10 if not self.config.get('oneserver') else 0 |
|
|
self.num_server = 10 if not self.config.get('oneserver') else 0 |
|
|
self.blockchains = { 0:Blockchain(self.config, 'blockchain_headers', None) } |
|
|
self.blockchains = { 0:Blockchain(self.config, 'blockchain_headers') } |
|
|
for x in os.listdir(self.config.path): |
|
|
for x in os.listdir(self.config.path): |
|
|
if x.startswith('blockchain_fork_'): |
|
|
if x.startswith('blockchain_fork_'): |
|
|
b = Blockchain(self.config, x, None) |
|
|
b = Blockchain(self.config, x) |
|
|
self.blockchains[b.checkpoint] = b |
|
|
self.blockchains[b.checkpoint] = b |
|
|
self.print_error("blockchains", self.blockchains.keys()) |
|
|
self.print_error("blockchains", self.blockchains.keys()) |
|
|
self.blockchain_index = config.get('blockchain_index', 0) |
|
|
self.blockchain_index = config.get('blockchain_index', 0) |
|
@ -864,12 +864,17 @@ class Network(util.DaemonThread): |
|
|
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.good) |
|
|
interface.blockchain = Blockchain(self.config, interface.blockchain.filename, interface.good) |
|
|
b = self.blockchains.get(interface.good) |
|
|
interface.blockchain.catch_up = interface.server |
|
|
if b is None: |
|
|
self.blockchains[interface.good] = interface.blockchain |
|
|
b = interface.blockchain.fork(interface.good) |
|
|
interface.print_error("catching up with new chain") |
|
|
b.catch_up = interface.server |
|
|
|
|
|
interface.print_error("catching up with new chain") |
|
|
|
|
|
self.blockchains[interface.good] = b |
|
|
interface.mode = 'catch_up' |
|
|
interface.mode = 'catch_up' |
|
|
next_height = interface.good |
|
|
next_height = interface.good |
|
|
|
|
|
interface.blockchain = b |
|
|
|
|
|
# todo: garbage collect blockchain objects |
|
|
|
|
|
self.notify('updated') |
|
|
|
|
|
|
|
|
elif interface.mode == 'catch_up': |
|
|
elif interface.mode == 'catch_up': |
|
|
if can_connect: |
|
|
if can_connect: |
|
@ -906,6 +911,8 @@ 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) |
|
|
|
|
|
# refresh network dialog |
|
|
|
|
|
self.notify('interfaces') |
|
|
|
|
|
|
|
|
def maintain_requests(self): |
|
|
def maintain_requests(self): |
|
|
for interface in self.interfaces.values(): |
|
|
for interface in self.interfaces.values(): |
|
|