From 8fb3c4810f31cb8465aeaeec2c505f4f17df6acd Mon Sep 17 00:00:00 2001 From: Valentyn Faychuk Date: Sun, 22 Dec 2024 23:03:20 +0200 Subject: [PATCH] info forwarding optimisation Signed-off-by: Valentyn Faychuk --- mint_sol/src/main.rs | 2 ++ src/datastore.rs | 6 ++++-- src/grpc/client.rs | 3 ++- src/grpc/server.rs | 4 ++-- src/main.rs | 1 + 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mint_sol/src/main.rs b/mint_sol/src/main.rs index 9f86767..7633dfc 100644 --- a/mint_sol/src/main.rs +++ b/mint_sol/src/main.rs @@ -14,6 +14,8 @@ fn main() { } fn send_sol(receiver: &str) { + // If this account uses all SOL, feel free to top up at 4qhFFULVHMpemFKGhpLfsVv126uruJgCxg2idLxedoa3 + // https://solana.com/es/developers/guides/getstarted/solana-token-airdrop-and-faucets#2-web-faucet let private_key_with_sol: [u8; 64] = [ 39, 134, 81, 114, 233, 110, 215, 232, 203, 125, 133, 232, 212, 223, 75, 196, 115, 246, 42, 121, 212, 231, 156, 82, 191, 86, 7, 217, 17, 241, 98, 12, 57, 12, 114, 15, 167, 208, 130, diff --git a/src/datastore.rs b/src/datastore.rs index a080673..5e5c93d 100644 --- a/src/datastore.rs +++ b/src/datastore.rs @@ -187,8 +187,10 @@ impl State { my_info.clone() } - /// This returns true if NodeInfo got modified. + /// This returns true if the update should be further forwarded + /// For example, we never forward our own updates that came back pub fn process_node_update(&self, (ip, node_info): (String, NodeInfo)) -> bool { + let is_update_mine = ip == self.my_ip; let is_update_new = self .nodes .get(&ip) @@ -199,7 +201,7 @@ impl State { node_info.log(&ip); self.nodes.insert(ip, node_info); } - is_update_new + is_update_new && !is_update_mine } pub fn get_node_list(&self) -> Vec<(String, NodeInfo)> { diff --git a/src/grpc/client.rs b/src/grpc/client.rs index 31a4355..0b7d79c 100644 --- a/src/grpc/client.rs +++ b/src/grpc/client.rs @@ -36,6 +36,7 @@ impl ConnManager { pub async fn start(self) { loop { if let Some(ip) = self.state.get_random_disconnected_node() { + println!("Found random disconnected node {ip}"); self.connect_wrapper(ip.clone()).await; } sleep(Duration::from_secs(3)).await; @@ -107,7 +108,7 @@ impl ConnManager { if self.state.process_node_update(update.clone().into()) && self.tx.send(update.clone()).is_err() { - println!("tokio broadcast receivers had an issue consuming the channel"); + println!("Tokio broadcast receivers had an issue consuming the channel"); }; } diff --git a/src/grpc/server.rs b/src/grpc/server.rs index a11b13e..b3d5e11 100644 --- a/src/grpc/server.rs +++ b/src/grpc/server.rs @@ -153,10 +153,10 @@ impl Update for MyServer { match msg { Ok(update) => { if update.ip != remote_ip { - println!("node {remote_ip} is forwarding us the update for {}", update.ip); + println!("Node {remote_ip} is forwarding us the update for {}", update.ip); } if state.process_node_update(update.clone().into()) && tx.send(update.clone()).is_err() { - println!("tokio broadcast receivers had an issue consuming the channel"); + println!("Tokio broadcast receivers had an issue consuming the channel"); }; } Err(e) => { diff --git a/src/main.rs b/src/main.rs index 2a08c28..4278009 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,6 +48,7 @@ async fn resolve_my_ip() -> Result { pub async fn heartbeat_cron(my_ip: String, state: Arc, tx: Sender) { loop { sleep(Duration::from_secs(60)).await; + println!("Heartbeat..."); let _ = tx.send((my_ip.clone(), state.get_my_info()).into()); state.remove_inactive_nodes(); }