From 734052595951aba24a6b0d78d1580f0335f997a2 Mon Sep 17 00:00:00 2001 From: renancloudwalk <53792026+renancloudwalk@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:35:35 -0300 Subject: [PATCH] chore: add periodic peer discovery (#978) --- src/eth/consensus/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/eth/consensus/mod.rs b/src/eth/consensus/mod.rs index 8393a312b..2b1795f5d 100644 --- a/src/eth/consensus/mod.rs +++ b/src/eth/consensus/mod.rs @@ -125,6 +125,7 @@ impl Consensus { let consensus = Arc::new(consensus); let _ = Self::discover_peers(Arc::clone(&consensus)).await; //TODO refactor this method to also receive addresses from the environment + Self::initialize_periodic_peer_discovery(Arc::clone(&consensus)); Self::initialize_append_entries_channel(Arc::clone(&consensus), Arc::clone(&receiver)); Self::initialize_server(Arc::clone(&consensus)); @@ -153,6 +154,17 @@ impl Consensus { }) } + fn initialize_periodic_peer_discovery(consensus: Arc) { + named_spawn("consensus::peer_discovery", async move { + let mut interval = tokio::time::interval(Duration::from_secs(30)); + loop { + interval.tick().await; + tracing::info!("Starting periodic peer discovery..."); + Self::discover_peers(Arc::clone(&consensus)).await; + } + }); + } + fn initialize_append_entries_channel(consensus: Arc, receiver: Arc>>) { named_spawn("consensus::sender", async move { let peers = consensus.peers.read().await;