Support LightClientFinalityUpdate and LightClientOptimisticUpdate rpcs (#3849)

* add light client optimistic and finality update rpc

* Arc the updates in the response

* add conditional advertisement for both LightClientOptimisticUpdate and LightClientFinalityUpdate

* alter display for inboundrequest light client optimistic and finality updates

* remove LightClientOptimistic/FinalityReuest struct and some minor fixes

* rebase

* failing rpc_test for LightClientBootstrap and beginning of MockLib2pLightClient

* minor change

* added MockRPCHandler by importing everything except OutboundRequest. Need to implement the ConnectionHandler trait now should be copy pastable

* almost there but ran into issue where needed to implement BaseOutboundRequest.

* failing but running with a light client service of sorts

* small test change

* changed Protocol::LightClientBootstrap response limit

* deleted some stuff from ConnectionHandler Implementation for the mock light client if you need to make something with multiple requests work maybe check here

* deleted purging expired inbound/outbound streams code

* deleted drive inbound streams that need to be processed

* removed unused imports

* made things private again

* deleted inject_fully_negotiated_inbound

* made more things private again

* more

* turned the logger off in the test

* added failing test for new rpc

* add rate limit for new rpcs

* change InboundUpgrade function to use new rpcs. fmt. add test for LightClientFinalityUpdate

* rebasing fix

* add LightClientUpdate to handle_rpc functions

* added context bytes

* fmt

* use correct unsed_tcp4_port function

* fix for recent config changes and adding context_bytes for the light client protocols

* fix clippy complaint

* Merge branch 'unstable' into lc-reqresp

# Conflicts:
#	beacon_node/beacon_processor/src/lib.rs
#	beacon_node/lighthouse_network/src/peer_manager/mod.rs
#	beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs
#	beacon_node/lighthouse_network/src/rpc/config.rs
#	beacon_node/lighthouse_network/src/rpc/methods.rs
#	beacon_node/lighthouse_network/src/rpc/mod.rs
#	beacon_node/lighthouse_network/src/rpc/outbound.rs
#	beacon_node/lighthouse_network/src/rpc/protocol.rs
#	beacon_node/lighthouse_network/src/rpc/rate_limiter.rs
#	beacon_node/lighthouse_network/src/rpc/self_limiter.rs
#	beacon_node/lighthouse_network/src/service/api_types.rs
#	beacon_node/lighthouse_network/tests/common/mod.rs
#	beacon_node/lighthouse_network/tests/rpc_tests.rs
#	beacon_node/network/src/network_beacon_processor/rpc_methods.rs
#	beacon_node/network/src/router.rs

* Error handling updates and various cleanups.

* Moar minor clean ups.

* Do not ban peer for rate limiting light client requests

* Merge branch 'unstable' into lc-reqresp. Also removed the mock light client tests to make it compile (See #4940).

# Conflicts:
#	beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs
#	beacon_node/lighthouse_network/src/rpc/methods.rs
#	beacon_node/lighthouse_network/src/rpc/mod.rs
#	beacon_node/lighthouse_network/src/rpc/protocol.rs
#	beacon_node/lighthouse_network/src/service/api_types.rs
#	beacon_node/lighthouse_network/tests/common/mod.rs
#	beacon_node/network/src/network_beacon_processor/rpc_methods.rs
#	beacon_node/network/src/router.rs
#	consensus/types/src/light_client_bootstrap.rs
#	consensus/types/src/light_client_finality_update.rs
#	consensus/types/src/light_client_optimistic_update.rs

* Remove unnecessary changes

* Add missing light client queue handling.

* Merge branch 'unstable' into lc-reqresp

* Merge branch 'unstable' into lc-reqresp

# Conflicts:
#	beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs
#	beacon_node/lighthouse_network/src/service/api_types.rs
#	consensus/types/src/light_client_finality_update.rs
#	consensus/types/src/light_client_optimistic_update.rs

* Add context bytes for light client RPC responses.

* Add RPC limits for light client object.

* Fix lint

* Fix incorrect light client max size computation.

* Merge branch 'unstable' into lc-reqresp

# Conflicts:
#	beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs
#	beacon_node/lighthouse_network/src/rpc/protocol.rs
#	beacon_node/lighthouse_network/src/service/api_types.rs

* Remove unwanted local changes.

* Merge branch 'unstable' into lc-reqresp

* Replace `unimplemented` electra code path with deneb values.
This commit is contained in:
GeemoCandama
2024-04-09 16:23:39 +09:00
committed by GitHub
parent 1b88d29807
commit 32be063f0f
19 changed files with 612 additions and 70 deletions

View File

@@ -1,7 +1,10 @@
use std::sync::Arc;
use libp2p::swarm::ConnectionId;
use types::{BlobSidecar, EthSpec, LightClientBootstrap, SignedBeaconBlock};
use types::{
BlobSidecar, EthSpec, LightClientBootstrap, LightClientFinalityUpdate,
LightClientOptimisticUpdate, SignedBeaconBlock,
};
use crate::rpc::methods::{BlobsByRangeRequest, BlobsByRootRequest};
use crate::rpc::{
@@ -40,6 +43,10 @@ pub enum Request {
BlocksByRoot(BlocksByRootRequest),
// light client bootstrap request
LightClientBootstrap(LightClientBootstrapRequest),
// light client optimistic update request
LightClientOptimisticUpdate,
// light client finality update request
LightClientFinalityUpdate,
/// A request blobs root request.
BlobsByRoot(BlobsByRootRequest),
}
@@ -64,7 +71,9 @@ impl<E: EthSpec> std::convert::From<Request> for OutboundRequest<E> {
}),
),
},
Request::LightClientBootstrap(_) => {
Request::LightClientBootstrap(_)
| Request::LightClientOptimisticUpdate
| Request::LightClientFinalityUpdate => {
unreachable!("Lighthouse never makes an outbound light client request")
}
Request::BlobsByRange(r) => OutboundRequest::BlobsByRange(r),
@@ -94,6 +103,10 @@ pub enum Response<E: EthSpec> {
BlobsByRoot(Option<Arc<BlobSidecar<E>>>),
/// A response to a LightClientUpdate request.
LightClientBootstrap(Arc<LightClientBootstrap<E>>),
/// A response to a LightClientOptimisticUpdate request.
LightClientOptimisticUpdate(Arc<LightClientOptimisticUpdate<E>>),
/// A response to a LightClientFinalityUpdate request.
LightClientFinalityUpdate(Arc<LightClientFinalityUpdate<E>>),
}
impl<E: EthSpec> std::convert::From<Response<E>> for RPCCodedResponse<E> {
@@ -119,6 +132,12 @@ impl<E: EthSpec> std::convert::From<Response<E>> for RPCCodedResponse<E> {
Response::LightClientBootstrap(b) => {
RPCCodedResponse::Success(RPCResponse::LightClientBootstrap(b))
}
Response::LightClientOptimisticUpdate(o) => {
RPCCodedResponse::Success(RPCResponse::LightClientOptimisticUpdate(o))
}
Response::LightClientFinalityUpdate(f) => {
RPCCodedResponse::Success(RPCResponse::LightClientFinalityUpdate(f))
}
}
}
}

View File

@@ -1170,6 +1170,14 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
Request::LightClientBootstrap(_) => {
metrics::inc_counter_vec(&metrics::TOTAL_RPC_REQUESTS, &["light_client_bootstrap"])
}
Request::LightClientOptimisticUpdate => metrics::inc_counter_vec(
&metrics::TOTAL_RPC_REQUESTS,
&["light_client_optimistic_update"],
),
Request::LightClientFinalityUpdate => metrics::inc_counter_vec(
&metrics::TOTAL_RPC_REQUESTS,
&["light_client_finality_update"],
),
Request::BlocksByRange { .. } => {
metrics::inc_counter_vec(&metrics::TOTAL_RPC_REQUESTS, &["blocks_by_range"])
}
@@ -1508,6 +1516,22 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
);
Some(event)
}
InboundRequest::LightClientOptimisticUpdate => {
let event = self.build_request(
peer_request_id,
peer_id,
Request::LightClientOptimisticUpdate,
);
Some(event)
}
InboundRequest::LightClientFinalityUpdate => {
let event = self.build_request(
peer_request_id,
peer_id,
Request::LightClientFinalityUpdate,
);
Some(event)
}
}
}
HandlerEvent::Ok(RPCReceived::Response(id, resp)) => {
@@ -1545,6 +1569,16 @@ impl<AppReqId: ReqId, E: EthSpec> Network<AppReqId, E> {
RPCResponse::LightClientBootstrap(bootstrap) => {
self.build_response(id, peer_id, Response::LightClientBootstrap(bootstrap))
}
RPCResponse::LightClientOptimisticUpdate(update) => self.build_response(
id,
peer_id,
Response::LightClientOptimisticUpdate(update),
),
RPCResponse::LightClientFinalityUpdate(update) => self.build_response(
id,
peer_id,
Response::LightClientFinalityUpdate(update),
),
}
}
HandlerEvent::Ok(RPCReceived::EndOfStream(id, termination)) => {