mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-21 08:31:52 +03:00
Fix UI refreshes. (#6639)
* Add event for new peak. * Refresh connections for farmer and wallet. * Display syncing x/x instead of x/0. * Refresh UI connections tasks. * Preventive catch exception inside new_peak related to UI tasks. * Add back black line. * Try to optimize refreshes. * Limit refreshes. * Try 1s sleep. * Typo in the comment. * Try 1.5s
This commit is contained in:
parent
2e9182aa86
commit
2335beff15
@ -105,6 +105,7 @@ class Farmer:
|
||||
|
||||
async def on_connect(self, peer: WSChiaConnection):
|
||||
# Sends a handshake to the harvester
|
||||
self.state_changed("add_connection", {})
|
||||
handshake = harvester_protocol.HarvesterHandshake(
|
||||
self.get_public_keys(),
|
||||
self.pool_public_keys,
|
||||
|
@ -80,6 +80,7 @@ class FullNode:
|
||||
timelord_lock: asyncio.Lock
|
||||
initialized: bool
|
||||
weight_proof_handler: Optional[WeightProofHandler]
|
||||
_ui_tasks: Set[asyncio.Task]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -100,6 +101,7 @@ class FullNode:
|
||||
self.sync_store = None
|
||||
self.signage_point_times = [time.time() for _ in range(self.constants.NUM_SPS_SUB_SLOT)]
|
||||
self.full_node_store = FullNodeStore(self.constants)
|
||||
self._ui_tasks = set()
|
||||
|
||||
if name:
|
||||
self.log = logging.getLogger(name)
|
||||
@ -333,6 +335,11 @@ class FullNode:
|
||||
self.sync_store.backtrack_syncing[peer.peer_node_id] -= 1
|
||||
return found_fork_point
|
||||
|
||||
async def _refresh_ui_connections(self, sleep_before: float = 0):
|
||||
if sleep_before > 0:
|
||||
await asyncio.sleep(sleep_before)
|
||||
self._state_changed("peer_changed_peak")
|
||||
|
||||
async def new_peak(self, request: full_node_protocol.NewPeak, peer: ws.WSChiaConnection):
|
||||
"""
|
||||
We have received a notification of a new peak from a peer. This happens either when we have just connected,
|
||||
@ -344,6 +351,17 @@ class FullNode:
|
||||
|
||||
"""
|
||||
|
||||
try:
|
||||
seen_header_hash = self.sync_store.seen_header_hash(request.header_hash)
|
||||
# Updates heights in the UI. Sleeps 1.5s before, so other peers have time to update their peaks as well.
|
||||
# Limit to 3 refreshes.
|
||||
if not seen_header_hash and len(self._ui_tasks) < 3:
|
||||
self._ui_tasks.add(asyncio.create_task(self._refresh_ui_connections(1.5)))
|
||||
# Prune completed connect tasks
|
||||
self._ui_tasks = set(filter(lambda t: not t.done(), self._ui_tasks))
|
||||
except Exception as e:
|
||||
self.log.warning(f"Exception UI refresh task: {e}")
|
||||
|
||||
# Store this peak/peer combination in case we want to sync to it, and to keep track of peers
|
||||
self.sync_store.peer_has_block(request.header_hash, peer.peer_node_id, request.weight, request.height, True)
|
||||
|
||||
|
@ -59,6 +59,9 @@ class SyncStore:
|
||||
def get_long_sync(self) -> bool:
|
||||
return self.long_sync
|
||||
|
||||
def seen_header_hash(self, header_hash: bytes32) -> bool:
|
||||
return header_hash in self.peak_to_peer
|
||||
|
||||
def peer_has_block(self, header_hash: bytes32, peer_id: bytes32, weight: uint128, height: uint32, new_peak: bool):
|
||||
"""
|
||||
Adds a record that a certain peer has a block.
|
||||
|
@ -105,6 +105,10 @@ class FullNodeRpcApi:
|
||||
assert sync_tip_height is not None
|
||||
if peak is not None:
|
||||
sync_progress_height: uint32 = peak.height
|
||||
# Don't display we're syncing towards 0, instead show 'Syncing height/height'
|
||||
# until sync_store retrieves the correct number.
|
||||
if sync_tip_height == uint32(0):
|
||||
sync_tip_height = peak.height
|
||||
else:
|
||||
sync_progress_height = uint32(0)
|
||||
else:
|
||||
|
@ -49,7 +49,7 @@ class RpcServer:
|
||||
payloads: List[Dict] = await self.rpc_api._state_changed(*args)
|
||||
|
||||
change = args[0]
|
||||
if change == "add_connection" or change == "close_connection":
|
||||
if change == "add_connection" or change == "close_connection" or change == "peer_changed_peak":
|
||||
data = await self.get_connections({})
|
||||
if data is not None:
|
||||
|
||||
|
@ -338,6 +338,7 @@ class WalletNode:
|
||||
if self.wallet_state_manager is None or self.backup_initialized is False:
|
||||
return None
|
||||
messages_peer_ids = await self._messages_to_resend()
|
||||
self.wallet_state_manager.state_changed("add_connection")
|
||||
for msg, peer_ids in messages_peer_ids:
|
||||
if peer.peer_node_id in peer_ids:
|
||||
continue
|
||||
@ -350,6 +351,8 @@ class WalletNode:
|
||||
while not self._shut_down and tries < 5:
|
||||
if self.has_full_node():
|
||||
await self.wallet_peers.ensure_is_closed()
|
||||
if self.wallet_state_manager is not None:
|
||||
self.wallet_state_manager.state_changed("add_connection")
|
||||
break
|
||||
tries += 1
|
||||
await asyncio.sleep(self.config["peer_connect_interval"])
|
||||
|
Loading…
Reference in New Issue
Block a user