chia-blockchain/chia/util/check_fork_next_block.py
Almog De Paz c4c14939a5
Sync faster (#7665)
* better concurrency for sync_from_fork_point

* dedup code in wallet

* revert

* lint

* lint

* logs

* lint

* lint

* error handling, async bug fix

* lint

* break fetch if bath failed coroutine

* remove outdated comment

* consolidate duplicate code

* consolidate duplicate code

* notify wallet after each batch

* typo

* add try/catch/finally

* typing, check stale peer

* comment on worker shutdown
2021-08-18 18:26:38 -07:00

27 lines
1.2 KiB
Python

from typing import List, Callable
from chia.consensus.blockchain_interface import BlockchainInterface
from chia.util.ints import uint32
async def check_fork_next_block(
blockchain: BlockchainInterface, fork_point_height: uint32, peers_with_peak: List, check_block_future: Callable
):
our_peak_height = blockchain.get_peak_height()
ses_heigths = blockchain.get_ses_heights()
if len(ses_heigths) > 2 and our_peak_height is not None:
ses_heigths.sort()
max_fork_ses_height = ses_heigths[-3]
potential_peek = uint32(our_peak_height + 1)
# This is the fork point in SES in the case where no fork was detected
if blockchain.get_peak_height() is not None and fork_point_height == max_fork_ses_height:
for peer in peers_with_peak:
if peer.closed:
peers_with_peak.remove(peer)
continue
# Grab a block at peak + 1 and check if fork point is actually our current height
if await check_block_future(peer, potential_peek, blockchain):
fork_point_height = our_peak_height
break
return fork_point_height