mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 12:11:59 +00:00
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:
@@ -605,6 +605,37 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Create a new work event to process a `LightClientOptimisticUpdate` request from the RPC network.
|
||||
pub fn send_light_client_optimistic_update_request(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
) -> Result<(), Error<T::EthSpec>> {
|
||||
let processor = self.clone();
|
||||
let process_fn =
|
||||
move || processor.handle_light_client_optimistic_update(peer_id, request_id);
|
||||
|
||||
self.try_send(BeaconWorkEvent {
|
||||
drop_during_sync: true,
|
||||
work: Work::LightClientOptimisticUpdateRequest(Box::new(process_fn)),
|
||||
})
|
||||
}
|
||||
|
||||
/// Create a new work event to process a `LightClientFinalityUpdate` request from the RPC network.
|
||||
pub fn send_light_client_finality_update_request(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
) -> Result<(), Error<T::EthSpec>> {
|
||||
let processor = self.clone();
|
||||
let process_fn = move || processor.handle_light_client_finality_update(peer_id, request_id);
|
||||
|
||||
self.try_send(BeaconWorkEvent {
|
||||
drop_during_sync: true,
|
||||
work: Work::LightClientFinalityUpdateRequest(Box::new(process_fn)),
|
||||
})
|
||||
}
|
||||
|
||||
/// Send a message to `sync_tx`.
|
||||
///
|
||||
/// Creates a log if there is an internal error.
|
||||
|
||||
@@ -293,7 +293,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle a `BlocksByRoot` request from the peer.
|
||||
/// Handle a `LightClientBootstrap` request from the peer.
|
||||
pub fn handle_light_client_bootstrap(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
@@ -329,6 +329,60 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
|
||||
};
|
||||
}
|
||||
|
||||
/// Handle a `LightClientOptimisticUpdate` request from the peer.
|
||||
pub fn handle_light_client_optimistic_update(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
) {
|
||||
let Some(light_client_optimistic_update) = self
|
||||
.chain
|
||||
.light_client_server_cache
|
||||
.get_latest_optimistic_update()
|
||||
else {
|
||||
self.send_error_response(
|
||||
peer_id,
|
||||
RPCResponseErrorCode::ResourceUnavailable,
|
||||
"Latest optimistic update not available".into(),
|
||||
request_id,
|
||||
);
|
||||
return;
|
||||
};
|
||||
|
||||
self.send_response(
|
||||
peer_id,
|
||||
Response::LightClientOptimisticUpdate(Arc::new(light_client_optimistic_update)),
|
||||
request_id,
|
||||
)
|
||||
}
|
||||
|
||||
/// Handle a `LightClientFinalityUpdate` request from the peer.
|
||||
pub fn handle_light_client_finality_update(
|
||||
self: &Arc<Self>,
|
||||
peer_id: PeerId,
|
||||
request_id: PeerRequestId,
|
||||
) {
|
||||
let Some(light_client_finality_update) = self
|
||||
.chain
|
||||
.light_client_server_cache
|
||||
.get_latest_finality_update()
|
||||
else {
|
||||
self.send_error_response(
|
||||
peer_id,
|
||||
RPCResponseErrorCode::ResourceUnavailable,
|
||||
"Latest finality update not available".into(),
|
||||
request_id,
|
||||
);
|
||||
return;
|
||||
};
|
||||
|
||||
self.send_response(
|
||||
peer_id,
|
||||
Response::LightClientFinalityUpdate(Arc::new(light_client_finality_update)),
|
||||
request_id,
|
||||
)
|
||||
}
|
||||
|
||||
/// Handle a `BlocksByRange` request from the peer.
|
||||
pub fn handle_blocks_by_range_request(
|
||||
self: Arc<Self>,
|
||||
|
||||
@@ -220,6 +220,14 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
self.network_beacon_processor
|
||||
.send_light_client_bootstrap_request(peer_id, request_id, request),
|
||||
),
|
||||
Request::LightClientOptimisticUpdate => self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
.send_light_client_optimistic_update_request(peer_id, request_id),
|
||||
),
|
||||
Request::LightClientFinalityUpdate => self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
.send_light_client_finality_update_request(peer_id, request_id),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +258,10 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
Response::BlobsByRoot(blob) => {
|
||||
self.on_blobs_by_root_response(peer_id, request_id, blob);
|
||||
}
|
||||
Response::LightClientBootstrap(_) => unreachable!(),
|
||||
// Light client responses should not be received
|
||||
Response::LightClientBootstrap(_)
|
||||
| Response::LightClientOptimisticUpdate(_)
|
||||
| Response::LightClientFinalityUpdate(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user