Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Nov 1, 2024
1 parent d993fc8 commit fd18f8d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/fiber/graph_syncer.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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,
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit fd18f8d

Please sign in to comment.