mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-22 00:52:32 +03:00
c4c14939a5
* 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
27 lines
1.2 KiB
Python
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
|