mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +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:
@@ -56,8 +56,8 @@ pub fn process_registry_updates<E: EthSpec>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn process_registry_updates_slow<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
pub fn process_registry_updates_slow<E: EthSpec>(
|
||||
state: &mut BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), Error> {
|
||||
process_epoch_single_pass(
|
||||
|
||||
@@ -47,8 +47,8 @@ pub fn process_slashings<E: EthSpec>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn process_slashings_slow<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
pub fn process_slashings_slow<E: EthSpec>(
|
||||
state: &mut BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), Error> {
|
||||
process_epoch_single_pass(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{test_utils::TestRandom, *};
|
||||
use derivative::Derivative;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz::Decode;
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use test_random_derive::TestRandom;
|
||||
use tree_hash::TreeHash;
|
||||
@@ -109,6 +109,23 @@ impl<E: EthSpec> ExecutionPayloadHeader<E> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
pub fn ssz_max_var_len_for_fork(fork_name: ForkName) -> usize {
|
||||
// Matching here in case variable fields are added in future forks.
|
||||
// TODO(electra): review electra changes
|
||||
match fork_name {
|
||||
ForkName::Base
|
||||
| ForkName::Altair
|
||||
| ForkName::Merge
|
||||
| ForkName::Capella
|
||||
| ForkName::Deneb
|
||||
| ForkName::Electra => {
|
||||
// Max size of variable length `extra_data` field
|
||||
E::max_extra_data_bytes() * <u8 as Encode>::ssz_fixed_len()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E: EthSpec> ExecutionPayloadHeaderRef<'a, E> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::{BeaconState, EthSpec, FixedVector, Hash256, SyncCommittee};
|
||||
use super::{BeaconState, EthSpec, FixedVector, Hash256, LightClientHeader, SyncCommittee};
|
||||
use crate::{
|
||||
light_client_update::*, test_utils::TestRandom, ChainSpec, ForkName, ForkVersionDeserialize,
|
||||
LightClientHeaderAltair, LightClientHeaderCapella, LightClientHeaderDeneb, SignedBeaconBlock,
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
use derivative::Derivative;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serde_json::Value;
|
||||
use ssz::Decode;
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::sync::Arc;
|
||||
use superstruct::superstruct;
|
||||
@@ -59,6 +59,17 @@ pub struct LightClientBootstrap<E: EthSpec> {
|
||||
}
|
||||
|
||||
impl<E: EthSpec> LightClientBootstrap<E> {
|
||||
pub fn map_with_fork_name<F, R>(&self, func: F) -> R
|
||||
where
|
||||
F: Fn(ForkName) -> R,
|
||||
{
|
||||
match self {
|
||||
Self::Altair(_) => func(ForkName::Altair),
|
||||
Self::Capella(_) => func(ForkName::Capella),
|
||||
Self::Deneb(_) => func(ForkName::Deneb),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_slot<'a>(&'a self) -> Slot {
|
||||
map_light_client_bootstrap_ref!(&'a _, self.to_ref(), |inner, cons| {
|
||||
cons(inner);
|
||||
@@ -85,6 +96,22 @@ impl<E: EthSpec> LightClientBootstrap<E> {
|
||||
Ok(bootstrap)
|
||||
}
|
||||
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
pub fn ssz_max_len_for_fork(fork_name: ForkName) -> usize {
|
||||
// TODO(electra): review electra changes
|
||||
match fork_name {
|
||||
ForkName::Base => 0,
|
||||
ForkName::Altair
|
||||
| ForkName::Merge
|
||||
| ForkName::Capella
|
||||
| ForkName::Deneb
|
||||
| ForkName::Electra => {
|
||||
<LightClientBootstrapAltair<E> as Encode>::ssz_fixed_len()
|
||||
+ LightClientHeader::<E>::ssz_max_var_len_for_fork(fork_name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_beacon_state(
|
||||
beacon_state: &mut BeaconState<E>,
|
||||
block: &SignedBeaconBlock<E>,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::{EthSpec, FixedVector, Hash256, Slot, SyncAggregate};
|
||||
use super::{EthSpec, FixedVector, Hash256, LightClientHeader, Slot, SyncAggregate};
|
||||
use crate::ChainSpec;
|
||||
use crate::{
|
||||
light_client_update::*, test_utils::TestRandom, ForkName, ForkVersionDeserialize,
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
use derivative::Derivative;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serde_json::Value;
|
||||
use ssz::Decode;
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_derive::Decode;
|
||||
use ssz_derive::Encode;
|
||||
use superstruct::superstruct;
|
||||
@@ -59,9 +59,9 @@ pub struct LightClientFinalityUpdate<E: EthSpec> {
|
||||
pub finalized_header: LightClientHeaderDeneb<E>,
|
||||
/// Merkle proof attesting finalized header.
|
||||
pub finality_branch: FixedVector<Hash256, FinalizedRootProofLen>,
|
||||
/// current sync aggreggate
|
||||
/// current sync aggregate
|
||||
pub sync_aggregate: SyncAggregate<E>,
|
||||
/// Slot of the sync aggregated singature
|
||||
/// Slot of the sync aggregated signature
|
||||
pub signature_slot: Slot,
|
||||
}
|
||||
|
||||
@@ -126,6 +126,17 @@ impl<E: EthSpec> LightClientFinalityUpdate<E> {
|
||||
Ok(finality_update)
|
||||
}
|
||||
|
||||
pub fn map_with_fork_name<F, R>(&self, func: F) -> R
|
||||
where
|
||||
F: Fn(ForkName) -> R,
|
||||
{
|
||||
match self {
|
||||
Self::Altair(_) => func(ForkName::Altair),
|
||||
Self::Capella(_) => func(ForkName::Capella),
|
||||
Self::Deneb(_) => func(ForkName::Deneb),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_attested_header_slot<'a>(&'a self) -> Slot {
|
||||
map_light_client_finality_update_ref!(&'a _, self.to_ref(), |inner, cons| {
|
||||
cons(inner);
|
||||
@@ -153,6 +164,22 @@ impl<E: EthSpec> LightClientFinalityUpdate<E> {
|
||||
|
||||
Ok(finality_update)
|
||||
}
|
||||
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
pub fn ssz_max_len_for_fork(fork_name: ForkName) -> usize {
|
||||
// TODO(electra): review electra changes
|
||||
match fork_name {
|
||||
ForkName::Base => 0,
|
||||
ForkName::Altair
|
||||
| ForkName::Merge
|
||||
| ForkName::Capella
|
||||
| ForkName::Deneb
|
||||
| ForkName::Electra => {
|
||||
<LightClientFinalityUpdateAltair<E> as Encode>::ssz_fixed_len()
|
||||
+ 2 * LightClientHeader::<E>::ssz_max_var_len_for_fork(fork_name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> ForkVersionDeserialize for LightClientFinalityUpdate<E> {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::BeaconBlockHeader;
|
||||
use crate::ChainSpec;
|
||||
use crate::ForkName;
|
||||
use crate::ForkVersionDeserialize;
|
||||
@@ -7,6 +6,7 @@ use crate::{
|
||||
test_utils::TestRandom, EthSpec, ExecutionPayloadHeaderCapella, ExecutionPayloadHeaderDeneb,
|
||||
FixedVector, Hash256, SignedBeaconBlock,
|
||||
};
|
||||
use crate::{BeaconBlockHeader, ExecutionPayloadHeader};
|
||||
use derivative::Derivative;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz::Decode;
|
||||
@@ -116,6 +116,15 @@ impl<E: EthSpec> LightClientHeader<E> {
|
||||
) -> Result<Self, ssz::DecodeError> {
|
||||
Self::from_ssz_bytes(bytes, fork_name)
|
||||
}
|
||||
|
||||
pub fn ssz_max_var_len_for_fork(fork_name: ForkName) -> usize {
|
||||
match fork_name {
|
||||
ForkName::Base | ForkName::Altair | ForkName::Merge => 0,
|
||||
ForkName::Capella | ForkName::Deneb | ForkName::Electra => {
|
||||
ExecutionPayloadHeader::<E>::ssz_max_var_len_for_fork(fork_name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> LightClientHeaderAltair<E> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::{EthSpec, ForkName, ForkVersionDeserialize, Slot, SyncAggregate};
|
||||
use super::{EthSpec, ForkName, ForkVersionDeserialize, LightClientHeader, Slot, SyncAggregate};
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::{
|
||||
light_client_update::*, ChainSpec, LightClientHeaderAltair, LightClientHeaderCapella,
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
use derivative::Derivative;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serde_json::Value;
|
||||
use ssz::Decode;
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_derive::Decode;
|
||||
use ssz_derive::Encode;
|
||||
use superstruct::superstruct;
|
||||
@@ -53,9 +53,9 @@ pub struct LightClientOptimisticUpdate<E: EthSpec> {
|
||||
pub attested_header: LightClientHeaderCapella<E>,
|
||||
#[superstruct(only(Deneb), partial_getter(rename = "attested_header_deneb"))]
|
||||
pub attested_header: LightClientHeaderDeneb<E>,
|
||||
/// current sync aggreggate
|
||||
/// current sync aggregate
|
||||
pub sync_aggregate: SyncAggregate<E>,
|
||||
/// Slot of the sync aggregated singature
|
||||
/// Slot of the sync aggregated signature
|
||||
pub signature_slot: Slot,
|
||||
}
|
||||
|
||||
@@ -97,6 +97,17 @@ impl<E: EthSpec> LightClientOptimisticUpdate<E> {
|
||||
Ok(optimistic_update)
|
||||
}
|
||||
|
||||
pub fn map_with_fork_name<F, R>(&self, func: F) -> R
|
||||
where
|
||||
F: Fn(ForkName) -> R,
|
||||
{
|
||||
match self {
|
||||
Self::Altair(_) => func(ForkName::Altair),
|
||||
Self::Capella(_) => func(ForkName::Capella),
|
||||
Self::Deneb(_) => func(ForkName::Deneb),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_slot<'a>(&'a self) -> Slot {
|
||||
map_light_client_optimistic_update_ref!(&'a _, self.to_ref(), |inner, cons| {
|
||||
cons(inner);
|
||||
@@ -138,6 +149,22 @@ impl<E: EthSpec> LightClientOptimisticUpdate<E> {
|
||||
|
||||
Ok(optimistic_update)
|
||||
}
|
||||
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
pub fn ssz_max_len_for_fork(fork_name: ForkName) -> usize {
|
||||
// TODO(electra): review electra changes
|
||||
match fork_name {
|
||||
ForkName::Base => 0,
|
||||
ForkName::Altair
|
||||
| ForkName::Merge
|
||||
| ForkName::Capella
|
||||
| ForkName::Deneb
|
||||
| ForkName::Electra => {
|
||||
<LightClientOptimisticUpdateAltair<E> as Encode>::ssz_fixed_len()
|
||||
+ LightClientHeader::<E>::ssz_max_var_len_for_fork(fork_name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> ForkVersionDeserialize for LightClientOptimisticUpdate<E> {
|
||||
|
||||
Reference in New Issue
Block a user