@@ -11,8 +11,7 @@ use crate::peer_manager::{MIN_OUTBOUND_ONLY_FACTOR, PEER_EXCESS_FACTOR, PRIORITY
1111use crate :: rpc:: methods:: MetadataRequest ;
1212use crate :: rpc:: {
1313 GoodbyeReason , HandlerErr , InboundRequestId , NetworkParams , Protocol , RPCError , RPCMessage ,
14- RPCReceived , RequestType , ResponseTermination , RpcErrorResponse , RpcResponse ,
15- RpcSuccessResponse , RPC ,
14+ RPCReceived , RequestType , ResponseTermination , RpcResponse , RpcSuccessResponse , RPC ,
1615} ;
1716use crate :: types:: {
1817 all_topics_at_fork, core_topics_to_subscribe, is_fork_non_core_topic, subnet_from_topic_hash,
@@ -39,7 +38,7 @@ use std::path::PathBuf;
3938use std:: pin:: Pin ;
4039use std:: sync:: Arc ;
4140use std:: time:: Duration ;
42- use tracing:: { debug, info, instrument, trace, warn} ;
41+ use tracing:: { debug, error , info, instrument, trace, warn} ;
4342use types:: {
4443 consts:: altair:: SYNC_COMMITTEE_SUBNET_COUNT , EnrForkId , EthSpec , ForkContext , Slot , SubnetId ,
4544} ;
@@ -1146,35 +1145,22 @@ impl<E: EthSpec> Network<E> {
11461145 name = "libp2p" ,
11471146 skip_all
11481147 ) ]
1149- pub fn send_response (
1148+ pub fn send_response < T : Into < RpcResponse < E > > > (
11501149 & mut self ,
11511150 peer_id : PeerId ,
11521151 inbound_request_id : InboundRequestId ,
1153- response : Response < E > ,
1152+ response : T ,
11541153 ) {
1155- self . eth2_rpc_mut ( )
1156- . send_response ( peer_id, inbound_request_id, response. into ( ) )
1157- }
1158-
1159- /// Inform the peer that their request produced an error.
1160- #[ instrument( parent = None ,
1161- level = "trace" ,
1162- fields( service = "libp2p" ) ,
1163- name = "libp2p" ,
1164- skip_all
1165- ) ]
1166- pub fn send_error_response (
1167- & mut self ,
1168- peer_id : PeerId ,
1169- inbound_request_id : InboundRequestId ,
1170- error : RpcErrorResponse ,
1171- reason : String ,
1172- ) {
1173- self . eth2_rpc_mut ( ) . send_response (
1174- peer_id,
1175- inbound_request_id,
1176- RpcResponse :: Error ( error, reason. into ( ) ) ,
1177- )
1154+ if let Err ( response) =
1155+ self . eth2_rpc_mut ( )
1156+ . send_response ( peer_id, inbound_request_id, response. into ( ) )
1157+ {
1158+ if self . network_globals . peers . read ( ) . is_connected ( & peer_id) {
1159+ error ! ( %peer_id, ?inbound_request_id, %response,
1160+ "Request not found in RPC active requests while peer is still connected"
1161+ ) ;
1162+ }
1163+ }
11781164 }
11791165
11801166 /* Peer management functions */
@@ -1460,19 +1446,6 @@ impl<E: EthSpec> Network<E> {
14601446 name = "libp2p" ,
14611447 skip_all
14621448 ) ]
1463- fn send_meta_data_response (
1464- & mut self ,
1465- _req : MetadataRequest < E > ,
1466- inbound_request_id : InboundRequestId ,
1467- peer_id : PeerId ,
1468- ) {
1469- let metadata = self . network_globals . local_metadata . read ( ) . clone ( ) ;
1470- // The encoder is responsible for sending the negotiated version of the metadata
1471- let event = RpcResponse :: Success ( RpcSuccessResponse :: MetaData ( Arc :: new ( metadata) ) ) ;
1472- self . eth2_rpc_mut ( )
1473- . send_response ( peer_id, inbound_request_id, event) ;
1474- }
1475-
14761449 // RPC Propagation methods
14771450 /// Queues the response to be sent upwards as long at it was requested outside the Behaviour.
14781451 #[ must_use = "return the response" ]
@@ -1760,9 +1733,13 @@ impl<E: EthSpec> Network<E> {
17601733 self . peer_manager_mut ( ) . ping_request ( & peer_id, ping. data ) ;
17611734 None
17621735 }
1763- RequestType :: MetaData ( req ) => {
1736+ RequestType :: MetaData ( _req ) => {
17641737 // send the requested meta-data
1765- self . send_meta_data_response ( req, inbound_request_id, peer_id) ;
1738+ let metadata = self . network_globals . local_metadata . read ( ) . clone ( ) ;
1739+ // The encoder is responsible for sending the negotiated version of the metadata
1740+ let response =
1741+ RpcResponse :: Success ( RpcSuccessResponse :: MetaData ( Arc :: new ( metadata) ) ) ;
1742+ self . send_response ( peer_id, inbound_request_id, response) ;
17661743 None
17671744 }
17681745 RequestType :: Goodbye ( reason) => {
0 commit comments