Skip to content

Commit e59ea13

Browse files
authored
Merge of #6634
2 parents 6ab6eae + cdf3643 commit e59ea13

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

beacon_node/lighthouse_network/src/rpc/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ impl<Id: ReqId, E: EthSpec> RPC<Id, E> {
232232
}
233233
}
234234
} else {
235-
ToSwarm::NotifyHandler {
236-
peer_id,
237-
handler: NotifyHandler::Any,
238-
event: RPCSend::Request(request_id, req),
239-
}
235+
RPCSend::Request(request_id, req)
240236
};
241237

242-
self.events.push(event);
238+
self.events.push(BehaviourAction::NotifyHandler {
239+
peer_id,
240+
handler: NotifyHandler::Any,
241+
event,
242+
});
243243
}
244244

245245
/// Lighthouse wishes to disconnect from this peer by sending a Goodbye message. This

beacon_node/lighthouse_network/src/rpc/self_limiter.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(crate) struct SelfRateLimiter<Id: ReqId, E: EthSpec> {
3535
/// Rate limiter for our own requests.
3636
limiter: RateLimiter,
3737
/// Requests that are ready to be sent.
38-
ready_requests: SmallVec<[BehaviourAction<Id, E>; 3]>,
38+
ready_requests: SmallVec<[(PeerId, RPCSend<Id, E>); 3]>,
3939
/// Slog logger.
4040
log: Logger,
4141
}
@@ -76,7 +76,7 @@ impl<Id: ReqId, E: EthSpec> SelfRateLimiter<Id, E> {
7676
peer_id: PeerId,
7777
request_id: Id,
7878
req: RequestType<E>,
79-
) -> Result<BehaviourAction<Id, E>, Error> {
79+
) -> Result<RPCSend<Id, E>, Error> {
8080
let protocol = req.versioned_protocol().protocol();
8181
// First check that there are not already other requests waiting to be sent.
8282
if let Some(queued_requests) = self.delayed_requests.get_mut(&(peer_id, protocol)) {
@@ -108,13 +108,9 @@ impl<Id: ReqId, E: EthSpec> SelfRateLimiter<Id, E> {
108108
request_id: Id,
109109
req: RequestType<E>,
110110
log: &Logger,
111-
) -> Result<BehaviourAction<Id, E>, (QueuedRequest<Id, E>, Duration)> {
111+
) -> Result<RPCSend<Id, E>, (QueuedRequest<Id, E>, Duration)> {
112112
match limiter.allows(&peer_id, &req) {
113-
Ok(()) => Ok(BehaviourAction::NotifyHandler {
114-
peer_id,
115-
handler: NotifyHandler::Any,
116-
event: RPCSend::Request(request_id, req),
117-
}),
113+
Ok(()) => Ok(RPCSend::Request(request_id, req)),
118114
Err(e) => {
119115
let protocol = req.versioned_protocol();
120116
match e {
@@ -126,11 +122,7 @@ impl<Id: ReqId, E: EthSpec> SelfRateLimiter<Id, E> {
126122
"Self rate limiting error for a batch that will never fit. Sending request anyway. Check configuration parameters.";
127123
"protocol" => %req.versioned_protocol().protocol()
128124
);
129-
Ok(BehaviourAction::NotifyHandler {
130-
peer_id,
131-
handler: NotifyHandler::Any,
132-
event: RPCSend::Request(request_id, req),
133-
})
125+
Ok(RPCSend::Request(request_id, req))
134126
}
135127
RateLimitedErr::TooSoon(wait_time) => {
136128
debug!(log, "Self rate limiting"; "protocol" => %protocol.protocol(), "wait_time_ms" => wait_time.as_millis(), "peer_id" => %peer_id);
@@ -156,7 +148,7 @@ impl<Id: ReqId, E: EthSpec> SelfRateLimiter<Id, E> {
156148
// If one fails just wait for the next window that allows sending requests.
157149
return;
158150
}
159-
Ok(event) => self.ready_requests.push(event),
151+
Ok(event) => self.ready_requests.push((peer_id, event)),
160152
}
161153
}
162154
if queued_requests.is_empty() {
@@ -203,8 +195,12 @@ impl<Id: ReqId, E: EthSpec> SelfRateLimiter<Id, E> {
203195
let _ = self.limiter.poll_unpin(cx);
204196

205197
// Finally return any queued events.
206-
if !self.ready_requests.is_empty() {
207-
return Poll::Ready(self.ready_requests.remove(0));
198+
if let Some((peer_id, event)) = self.ready_requests.pop() {
199+
return Poll::Ready(BehaviourAction::NotifyHandler {
200+
peer_id,
201+
handler: NotifyHandler::Any,
202+
event,
203+
});
208204
}
209205

210206
Poll::Pending

0 commit comments

Comments
 (0)