mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-08-24 10:05:29 -05:00
* Enable PEP604 Ruff rules * Fix harcoded signature in test * Hack CLVMStreamable test with note to fast follow
34 lines
1.4 KiB
Python
34 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Awaitable, Callable
|
|
|
|
from chia_rs.sized_ints import uint32
|
|
|
|
from chia.consensus.blockchain_interface import BlockchainInterface
|
|
from chia.server.ws_connection import WSChiaConnection
|
|
|
|
|
|
async def check_fork_next_block(
|
|
blockchain: BlockchainInterface,
|
|
fork_point_height: uint32,
|
|
peers_with_peak: list[WSChiaConnection],
|
|
check_block_future: Callable[[WSChiaConnection, uint32, BlockchainInterface], Awaitable[bool]],
|
|
) -> uint32:
|
|
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.copy():
|
|
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
|