From cdf36430abf8dab6f381c129ce637193e56f8be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Fri, 29 Nov 2024 14:34:49 +0000 Subject: [PATCH] use RpcSend instead of BehaviourAction on Rpc::self_limiter::ready_requests --- beacon_node/lighthouse_network/src/rpc/mod.rs | 12 ++++---- .../src/rpc/self_limiter.rs | 28 ++++++++----------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/beacon_node/lighthouse_network/src/rpc/mod.rs b/beacon_node/lighthouse_network/src/rpc/mod.rs index 7d091da7660..f8acfbc5769 100644 --- a/beacon_node/lighthouse_network/src/rpc/mod.rs +++ b/beacon_node/lighthouse_network/src/rpc/mod.rs @@ -231,14 +231,14 @@ impl RPC { } } } else { - ToSwarm::NotifyHandler { - peer_id, - handler: NotifyHandler::Any, - event: RPCSend::Request(request_id, req), - } + RPCSend::Request(request_id, req) }; - self.events.push(event); + self.events.push(BehaviourAction::NotifyHandler { + peer_id, + handler: NotifyHandler::Any, + event, + }); } /// Lighthouse wishes to disconnect from this peer by sending a Goodbye message. This diff --git a/beacon_node/lighthouse_network/src/rpc/self_limiter.rs b/beacon_node/lighthouse_network/src/rpc/self_limiter.rs index e968ad11e3d..1831db4bc70 100644 --- a/beacon_node/lighthouse_network/src/rpc/self_limiter.rs +++ b/beacon_node/lighthouse_network/src/rpc/self_limiter.rs @@ -34,7 +34,7 @@ pub(crate) struct SelfRateLimiter { /// Rate limiter for our own requests. limiter: RateLimiter, /// Requests that are ready to be sent. - ready_requests: SmallVec<[BehaviourAction; 3]>, + ready_requests: SmallVec<[(PeerId, RPCSend); 3]>, /// Slog logger. log: Logger, } @@ -71,7 +71,7 @@ impl SelfRateLimiter { peer_id: PeerId, request_id: Id, req: RequestType, - ) -> Result, Error> { + ) -> Result, Error> { let protocol = req.versioned_protocol().protocol(); // First check that there are not already other requests waiting to be sent. if let Some(queued_requests) = self.delayed_requests.get_mut(&(peer_id, protocol)) { @@ -103,13 +103,9 @@ impl SelfRateLimiter { request_id: Id, req: RequestType, log: &Logger, - ) -> Result, (QueuedRequest, Duration)> { + ) -> Result, (QueuedRequest, Duration)> { match limiter.allows(&peer_id, &req) { - Ok(()) => Ok(BehaviourAction::NotifyHandler { - peer_id, - handler: NotifyHandler::Any, - event: RPCSend::Request(request_id, req), - }), + Ok(()) => Ok(RPCSend::Request(request_id, req)), Err(e) => { let protocol = req.versioned_protocol(); match e { @@ -121,11 +117,7 @@ impl SelfRateLimiter { "Self rate limiting error for a batch that will never fit. Sending request anyway. Check configuration parameters."; "protocol" => %req.versioned_protocol().protocol() ); - Ok(BehaviourAction::NotifyHandler { - peer_id, - handler: NotifyHandler::Any, - event: RPCSend::Request(request_id, req), - }) + Ok(RPCSend::Request(request_id, req)) } RateLimitedErr::TooSoon(wait_time) => { debug!(log, "Self rate limiting"; "protocol" => %protocol.protocol(), "wait_time_ms" => wait_time.as_millis(), "peer_id" => %peer_id); @@ -151,7 +143,7 @@ impl SelfRateLimiter { // If one fails just wait for the next window that allows sending requests. return; } - Ok(event) => self.ready_requests.push(event), + Ok(event) => self.ready_requests.push((peer_id, event)), } } if queued_requests.is_empty() { @@ -198,8 +190,12 @@ impl SelfRateLimiter { let _ = self.limiter.poll_unpin(cx); // Finally return any queued events. - if !self.ready_requests.is_empty() { - return Poll::Ready(self.ready_requests.remove(0)); + if let Some((peer_id, event)) = self.ready_requests.pop() { + return Poll::Ready(BehaviourAction::NotifyHandler { + peer_id, + handler: NotifyHandler::Any, + event, + }); } Poll::Pending