Browse Source

Remove old reorg forcing code

master
Neil Booth 8 years ago
parent
commit
1b589d3d1f
  1. 19
      server/block_processor.py

19
server/block_processor.py

@ -358,10 +358,7 @@ class BlockProcessor(LoggedClass):
self.clean_db() self.clean_db()
def coros(self, force_backup=False): def coros(self):
if force_backup:
return [self.force_chain_reorg(True), self.prefetcher.start()]
else:
return [self.start(), self.prefetcher.start()] return [self.start(), self.prefetcher.start()]
async def start(self): async def start(self):
@ -406,19 +403,13 @@ class BlockProcessor(LoggedClass):
await self.on_update(self.height, self.touched) await self.on_update(self.height, self.touched)
self.touched = set() self.touched = set()
async def force_chain_reorg(self, to_genesis): async def handle_chain_reorg(self):
try:
await self.handle_chain_reorg(to_genesis)
finally:
self.flush(True)
async def handle_chain_reorg(self, to_genesis=False):
# First get all state on disk # First get all state on disk
self.logger.info('chain reorg detected') self.logger.info('chain reorg detected')
self.flush(True) self.flush(True)
self.logger.info('finding common height...') self.logger.info('finding common height...')
hashes = await self.reorg_hashes(to_genesis) hashes = await self.reorg_hashes()
# Reverse and convert to hex strings. # Reverse and convert to hex strings.
hashes = [hash_to_str(hash) for hash in reversed(hashes)] hashes = [hash_to_str(hash) for hash in reversed(hashes)]
for hex_hashes in chunks(hashes, 50): for hex_hashes in chunks(hashes, 50):
@ -429,7 +420,7 @@ class BlockProcessor(LoggedClass):
await self.prefetcher.clear(self.height) await self.prefetcher.clear(self.height)
self.logger.info('prefetcher reset') self.logger.info('prefetcher reset')
async def reorg_hashes(self, to_genesis): async def reorg_hashes(self):
'''Return the list of hashes to back up beacuse of a reorg. '''Return the list of hashes to back up beacuse of a reorg.
The hashes are returned in order of increasing height.''' The hashes are returned in order of increasing height.'''
@ -447,7 +438,7 @@ class BlockProcessor(LoggedClass):
hex_hashes = [hash_to_str(hash) for hash in hashes] hex_hashes = [hash_to_str(hash) for hash in hashes]
d_hex_hashes = await self.daemon.block_hex_hashes(start, count) d_hex_hashes = await self.daemon.block_hex_hashes(start, count)
n = match_pos(hex_hashes, d_hex_hashes) n = match_pos(hex_hashes, d_hex_hashes)
if n >= 0 and not to_genesis: if n >= 0:
start += n + 1 start += n + 1
break break
count = min(count * 2, start) count = min(count * 2, start)

Loading…
Cancel
Save