|
@ -225,21 +225,23 @@ class BlockProcessor(server.db.DB): |
|
|
self.open_dbs() |
|
|
self.open_dbs() |
|
|
self.caught_up_event.set() |
|
|
self.caught_up_event.set() |
|
|
|
|
|
|
|
|
async def check_and_advance_blocks(self, blocks, first): |
|
|
async def check_and_advance_blocks(self, raw_blocks, first): |
|
|
'''Process the list of blocks passed. Detects and handles reorgs.''' |
|
|
'''Process the list of raw blocks passed. Detects and handles |
|
|
self.prefetcher.processing_blocks(blocks) |
|
|
reorgs. |
|
|
|
|
|
''' |
|
|
|
|
|
self.prefetcher.processing_blocks(raw_blocks) |
|
|
if first != self.height + 1: |
|
|
if first != self.height + 1: |
|
|
# If we prefetched two sets of blocks and the first caused |
|
|
# If we prefetched two sets of blocks and the first caused |
|
|
# a reorg this will happen when we try to process the |
|
|
# a reorg this will happen when we try to process the |
|
|
# second. It should be very rare. |
|
|
# second. It should be very rare. |
|
|
self.logger.warning('ignoring {:,d} blocks starting height {:,d}, ' |
|
|
self.logger.warning('ignoring {:,d} blocks starting height {:,d}, ' |
|
|
'expected {:,d}' |
|
|
'expected {:,d}'.format(len(raw_blocks), first, |
|
|
.format(len(blocks), first, self.height + 1)) |
|
|
self.height + 1)) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
blocks = [self.coin.block_full(block, first + n) |
|
|
blocks = [self.coin.block(raw_block, first + n) |
|
|
for n, block in enumerate(blocks)] |
|
|
for n, raw_block in enumerate(raw_blocks)] |
|
|
headers = [b.header for b in blocks] |
|
|
headers = [block.header for block in blocks] |
|
|
hprevs = [self.coin.header_prevhash(h) for h in headers] |
|
|
hprevs = [self.coin.header_prevhash(h) for h in headers] |
|
|
chain = [self.tip] + [self.coin.header_hash(h) for h in headers[:-1]] |
|
|
chain = [self.tip] + [self.coin.header_hash(h) for h in headers[:-1]] |
|
|
|
|
|
|
|
@ -562,26 +564,26 @@ class BlockProcessor(server.db.DB): |
|
|
|
|
|
|
|
|
return undo_info |
|
|
return undo_info |
|
|
|
|
|
|
|
|
def backup_blocks(self, blocks): |
|
|
def backup_blocks(self, raw_blocks): |
|
|
'''Backup the blocks and flush. |
|
|
'''Backup the raw blocks and flush. |
|
|
|
|
|
|
|
|
The blocks should be in order of decreasing height, starting at. |
|
|
The blocks should be in order of decreasing height, starting at. |
|
|
self.height. A flush is performed once the blocks are backed up. |
|
|
self.height. A flush is performed once the blocks are backed up. |
|
|
''' |
|
|
''' |
|
|
self.assert_flushed() |
|
|
self.assert_flushed() |
|
|
assert self.height >= len(blocks) |
|
|
assert self.height >= len(raw_blocks) |
|
|
|
|
|
|
|
|
coin = self.coin |
|
|
coin = self.coin |
|
|
for block in blocks: |
|
|
for raw_block in raw_blocks: |
|
|
# Check and update self.tip |
|
|
# Check and update self.tip |
|
|
block_full = coin.block_full(block, self.height) |
|
|
block = coin.block(raw_block, self.height) |
|
|
header_hash = coin.header_hash(block_full.header) |
|
|
header_hash = coin.header_hash(block.header) |
|
|
if header_hash != self.tip: |
|
|
if header_hash != self.tip: |
|
|
raise ChainError('backup block {} not tip {} at height {:,d}' |
|
|
raise ChainError('backup block {} not tip {} at height {:,d}' |
|
|
.format(hash_to_str(header_hash), |
|
|
.format(hash_to_str(header_hash), |
|
|
hash_to_str(self.tip), self.height)) |
|
|
hash_to_str(self.tip), self.height)) |
|
|
self.tip = coin.header_prevhash(block_full.header) |
|
|
self.tip = coin.header_prevhash(block.header) |
|
|
self.backup_txs(block_full.transactions) |
|
|
self.backup_txs(block.transactions) |
|
|
self.height -= 1 |
|
|
self.height -= 1 |
|
|
self.tx_counts.pop() |
|
|
self.tx_counts.pop() |
|
|
|
|
|
|
|
|