Raise on chain reorgs
In 0.06 advance_block() returned None instead of True. Cleaner to throw.
This commit is contained in:
parent
0ccea80fc3
commit
aa6e4ad922
@ -138,8 +138,14 @@ class Prefetcher(LoggedClass):
|
|||||||
|
|
||||||
return blocks, size
|
return blocks, size
|
||||||
|
|
||||||
|
|
||||||
class MissingUTXOError(Exception):
|
class MissingUTXOError(Exception):
|
||||||
pass
|
'''Raised if a mempool tx input UTXO couldn't be found.'''
|
||||||
|
|
||||||
|
|
||||||
|
class ChainReorg(Exception):
|
||||||
|
'''Raised on a blockchain reorganisation.'''
|
||||||
|
|
||||||
|
|
||||||
class MemPool(LoggedClass):
|
class MemPool(LoggedClass):
|
||||||
'''Representation of the daemon's mempool.
|
'''Representation of the daemon's mempool.
|
||||||
@ -374,14 +380,14 @@ class BlockProcessor(LoggedClass):
|
|||||||
'''
|
'''
|
||||||
blocks, mempool_hashes = await self.prefetcher.get_blocks()
|
blocks, mempool_hashes = await self.prefetcher.get_blocks()
|
||||||
caught_up = mempool_hashes is not None
|
caught_up = mempool_hashes is not None
|
||||||
for block in blocks:
|
try:
|
||||||
if self.advance_block(block, caught_up):
|
for block in blocks:
|
||||||
await self.handle_chain_reorg()
|
self.advance_block(block, caught_up)
|
||||||
return
|
await asyncio.sleep(0) # Yield
|
||||||
await asyncio.sleep(0) # Yield
|
if caught_up:
|
||||||
|
await self.caught_up(mempool_hashes)
|
||||||
if caught_up:
|
except ChainReorg:
|
||||||
await self.caught_up(mempool_hashes)
|
await self.handle_chain_reorg()
|
||||||
|
|
||||||
async def caught_up(self, mempool_hashes):
|
async def caught_up(self, mempool_hashes):
|
||||||
'''Called after each deamon poll if caught up.'''
|
'''Called after each deamon poll if caught up.'''
|
||||||
@ -711,7 +717,7 @@ class BlockProcessor(LoggedClass):
|
|||||||
header, tx_hashes, txs = self.coin.read_block(block)
|
header, tx_hashes, txs = self.coin.read_block(block)
|
||||||
prev_hash, header_hash = self.coin.header_hashes(header)
|
prev_hash, header_hash = self.coin.header_hashes(header)
|
||||||
if prev_hash != self.tip:
|
if prev_hash != self.tip:
|
||||||
return None
|
raise ChainReorg
|
||||||
|
|
||||||
touched = set()
|
touched = set()
|
||||||
self.fs_cache.advance_block(header, tx_hashes, txs)
|
self.fs_cache.advance_block(header, tx_hashes, txs)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user