mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 04:48:21 +00:00
Errors for all RPC Requests (#5867)
* Return and error if peer has disconnected * Report errors for rate limited requests * Code improvement * Bump rust version to 1.78 * Downgrade to 1.77 * Update beacon_node/lighthouse_network/src/service/mod.rs Co-authored-by: João Oliveira <hello@jxs.pt> * fix fmt * Merge branch 'unstable' of https://github.com/sigp/lighthouse into rpc-peer-disconnect-error * update lockfile
This commit is contained in:
@@ -240,7 +240,7 @@ impl futures::stream::Stream for GossipCache {
|
||||
|
||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||
match self.expirations.poll_expired(cx) {
|
||||
Poll::Ready(Some(Ok(expired))) => {
|
||||
Poll::Ready(Some(expired)) => {
|
||||
let expected_key = expired.key();
|
||||
let (topic, data) = expired.into_inner();
|
||||
match self.topic_msgs.get_mut(&topic) {
|
||||
@@ -259,7 +259,6 @@ impl futures::stream::Stream for GossipCache {
|
||||
}
|
||||
Poll::Ready(Some(Ok(topic)))
|
||||
}
|
||||
Poll::Ready(Some(Err(x))) => Poll::Ready(Some(Err(x.to_string()))),
|
||||
Poll::Ready(None) => Poll::Ready(None),
|
||||
Poll::Pending => Poll::Pending,
|
||||
}
|
||||
|
||||
@@ -917,12 +917,23 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
|
||||
/* Eth2 RPC behaviour functions */
|
||||
|
||||
/// Send a request to a peer over RPC.
|
||||
pub fn send_request(&mut self, peer_id: PeerId, request_id: AppReqId, request: Request) {
|
||||
pub fn send_request(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
request_id: AppReqId,
|
||||
request: Request,
|
||||
) -> Result<(), (AppReqId, RPCError)> {
|
||||
// Check if the peer is connected before sending an RPC request
|
||||
if !self.swarm.is_connected(&peer_id) {
|
||||
return Err((request_id, RPCError::Disconnected));
|
||||
}
|
||||
|
||||
self.eth2_rpc_mut().send_request(
|
||||
peer_id,
|
||||
RequestId::Application(request_id),
|
||||
request.into(),
|
||||
)
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Send a successful response to a peer over RPC.
|
||||
|
||||
Reference in New Issue
Block a user