From fd18f8daa2d8578d7bc0acfe13e7caa891ba2350 Mon Sep 17 00:00:00 2001 From: YI Date: Thu, 31 Oct 2024 14:54:50 +0800 Subject: [PATCH] stash --- src/fiber/graph_syncer.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/fiber/graph_syncer.rs b/src/fiber/graph_syncer.rs index 96932f71..01cea392 100644 --- a/src/fiber/graph_syncer.rs +++ b/src/fiber/graph_syncer.rs @@ -1,7 +1,7 @@ //! This is the main module for the graph syncer. It is responsible for //! syncing the graph with one specific peer. -use ractor::{async_trait as rasync_trait, call, Actor, ActorProcessingErr, ActorRef}; +use ractor::{async_trait as rasync_trait, call, Actor, ActorCell, ActorProcessingErr, ActorRef}; use tentacle::secio::PeerId; use tracing::{debug, error}; @@ -72,7 +72,8 @@ impl GraphSyncer { } impl GraphSyncer { - fn tell_network_we_want_to_exit(&self, status: GraphSyncerExitStatus) { + fn exit_with_status(&self, actor: ActorCell, status: GraphSyncerExitStatus) { + actor.stop(Some(format!("Actively exiting with status {:?}", status))); let peer_id = self.peer_id.clone(); self.network .send_message(NetworkActorMessage::new_event( @@ -119,7 +120,7 @@ impl Actor for GraphSyncer { debug!("Graph syncer handling message {:?}", &message); match message { GraphSyncerMessage::PeerDisConnected => { - self.tell_network_we_want_to_exit(GraphSyncerExitStatus::Failed); + self.exit_with_status(myself.get_cell(), GraphSyncerExitStatus::Failed); } GraphSyncerMessage::GetChannels(starting_height) => { if starting_height > self.ending_height { @@ -153,7 +154,7 @@ impl Actor for GraphSyncer { } Err(e) => { error!("Failed to get channels from peer: {:?}", e); - self.tell_network_we_want_to_exit(GraphSyncerExitStatus::Failed); + self.exit_with_status(myself.get_cell(), GraphSyncerExitStatus::Failed); } } } @@ -174,7 +175,10 @@ impl Actor for GraphSyncer { debug!("Get broadcast messages from peer successfully."); if next_time > self.ending_time { debug!("Graph syncer finished syncing with peer."); - self.tell_network_we_want_to_exit(GraphSyncerExitStatus::Succeeded); + self.exit_with_status( + myself.get_cell(), + GraphSyncerExitStatus::Succeeded, + ); } else { myself.send_message(GraphSyncerMessage::GetBroadcastMessages( next_time, @@ -183,7 +187,7 @@ impl Actor for GraphSyncer { } Err(e) => { error!("Failed to get broadcast messages from peer: {:?}", e); - self.tell_network_we_want_to_exit(GraphSyncerExitStatus::Failed); + self.exit_with_status(myself.get_cell(), GraphSyncerExitStatus::Failed); } } }