Skip to content

Allow for constructing light client data across fork boundaries #7502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions beacon_node/beacon_chain/src/light_client_server_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,12 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {

let fork_name = chain_spec.fork_name_at_epoch(epoch.into());

let light_client_update =
LightClientUpdate::from_ssz_bytes(&light_client_update_bytes, &fork_name)
.map_err(store::errors::Error::SszDecodeError)?;
let light_client_update = LightClientUpdate::from_ssz_bytes_by_fork_and_spec(
&light_client_update_bytes,
fork_name,
chain_spec,
)
.map_err(store::errors::Error::SszDecodeError)?;

light_client_updates.push(light_client_update);
}
Expand Down
10 changes: 5 additions & 5 deletions beacon_node/beacon_chain/tests/store_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ async fn light_client_bootstrap_test() {
.unwrap();

let bootstrap_slot = match lc_bootstrap {
LightClientBootstrap::Altair(lc_bootstrap) => lc_bootstrap.header.beacon.slot,
LightClientBootstrap::Capella(lc_bootstrap) => lc_bootstrap.header.beacon.slot,
LightClientBootstrap::Deneb(lc_bootstrap) => lc_bootstrap.header.beacon.slot,
LightClientBootstrap::Electra(lc_bootstrap) => lc_bootstrap.header.beacon.slot,
LightClientBootstrap::Fulu(lc_bootstrap) => lc_bootstrap.header.beacon.slot,
LightClientBootstrap::Altair(lc_bootstrap) => lc_bootstrap.header.beacon().slot,
LightClientBootstrap::Capella(lc_bootstrap) => lc_bootstrap.header.beacon().slot,
LightClientBootstrap::Deneb(lc_bootstrap) => lc_bootstrap.header.beacon().slot,
LightClientBootstrap::Electra(lc_bootstrap) => lc_bootstrap.header.beacon().slot,
LightClientBootstrap::Fulu(lc_bootstrap) => lc_bootstrap.header.beacon().slot,
};

assert_eq!(
Expand Down
21 changes: 14 additions & 7 deletions beacon_node/lighthouse_network/src/rpc/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::sync::Arc;
use tokio_util::codec::{Decoder, Encoder};
use types::{
BlobSidecar, ChainSpec, DataColumnSidecar, DataColumnsByRootIdentifier, EthSpec, ForkContext,
ForkName, Hash256, LightClientBootstrap, LightClientFinalityUpdate,
ForkName, ForkVersionDecode, Hash256, LightClientBootstrap, LightClientFinalityUpdate,
LightClientOptimisticUpdate, LightClientUpdate, RuntimeVariableList, SignedBeaconBlock,
SignedBeaconBlockAltair, SignedBeaconBlockBase, SignedBeaconBlockBellatrix,
SignedBeaconBlockCapella, SignedBeaconBlockDeneb, SignedBeaconBlockElectra,
Expand Down Expand Up @@ -282,7 +282,12 @@ impl<E: EthSpec> SSZSnappyOutboundCodec<E> {
// Safe to `take` from `self.fork_name` as we have all the bytes we need to
// decode an ssz object at this point.
let fork_name = self.fork_name.take();
handle_rpc_response(self.protocol.versioned_protocol, &decoded_buffer, fork_name)
handle_rpc_response(
self.protocol.versioned_protocol,
&decoded_buffer,
fork_name,
&self.fork_context.spec,
)
}
Err(e) => handle_error(e, reader.get_ref().get_ref().position(), max_compressed_len),
}
Expand Down Expand Up @@ -664,6 +669,7 @@ fn handle_rpc_response<E: EthSpec>(
versioned_protocol: SupportedProtocol,
decoded_buffer: &[u8],
fork_name: Option<ForkName>,
spec: &ChainSpec,
) -> Result<Option<RpcSuccessResponse<E>>, RPCError> {
match versioned_protocol {
SupportedProtocol::StatusV1 => Ok(Some(RpcSuccessResponse::Status(
Expand Down Expand Up @@ -773,7 +779,7 @@ fn handle_rpc_response<E: EthSpec>(
)))),
SupportedProtocol::LightClientBootstrapV1 => match fork_name {
Some(fork_name) => Ok(Some(RpcSuccessResponse::LightClientBootstrap(Arc::new(
LightClientBootstrap::from_ssz_bytes(decoded_buffer, fork_name)?,
LightClientBootstrap::from_ssz_bytes_by_fork(decoded_buffer, fork_name)?,
)))),
None => Err(RPCError::ErrorResponse(
RpcErrorResponse::InvalidRequest,
Expand All @@ -785,7 +791,7 @@ fn handle_rpc_response<E: EthSpec>(
},
SupportedProtocol::LightClientOptimisticUpdateV1 => match fork_name {
Some(fork_name) => Ok(Some(RpcSuccessResponse::LightClientOptimisticUpdate(
Arc::new(LightClientOptimisticUpdate::from_ssz_bytes(
Arc::new(LightClientOptimisticUpdate::from_ssz_bytes_by_fork(
decoded_buffer,
fork_name,
)?),
Expand All @@ -800,7 +806,7 @@ fn handle_rpc_response<E: EthSpec>(
},
SupportedProtocol::LightClientFinalityUpdateV1 => match fork_name {
Some(fork_name) => Ok(Some(RpcSuccessResponse::LightClientFinalityUpdate(
Arc::new(LightClientFinalityUpdate::from_ssz_bytes(
Arc::new(LightClientFinalityUpdate::from_ssz_bytes_by_fork(
decoded_buffer,
fork_name,
)?),
Expand All @@ -815,9 +821,10 @@ fn handle_rpc_response<E: EthSpec>(
},
SupportedProtocol::LightClientUpdatesByRangeV1 => match fork_name {
Some(fork_name) => Ok(Some(RpcSuccessResponse::LightClientUpdatesByRange(
Arc::new(LightClientUpdate::from_ssz_bytes(
Arc::new(LightClientUpdate::from_ssz_bytes_by_fork_and_spec(
decoded_buffer,
&fork_name,
fork_name,
spec,
)?),
))),
None => Err(RPCError::ErrorResponse(
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/lighthouse_network/src/types/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::sync::Arc;
use types::{
Attestation, AttestationBase, AttesterSlashing, AttesterSlashingBase, AttesterSlashingElectra,
BlobSidecar, DataColumnSidecar, DataColumnSubnetId, EthSpec, ForkContext, ForkName,
LightClientFinalityUpdate, LightClientOptimisticUpdate, ProposerSlashing,
ForkVersionDecode, LightClientFinalityUpdate, LightClientOptimisticUpdate, ProposerSlashing,
SignedAggregateAndProof, SignedAggregateAndProofBase, SignedAggregateAndProofElectra,
SignedBeaconBlock, SignedBeaconBlockAltair, SignedBeaconBlockBase, SignedBeaconBlockBellatrix,
SignedBeaconBlockCapella, SignedBeaconBlockDeneb, SignedBeaconBlockElectra,
Expand Down Expand Up @@ -370,7 +370,7 @@ impl<E: EthSpec> PubsubMessage<E> {
GossipKind::LightClientFinalityUpdate => {
let light_client_finality_update = match fork_context.from_context_bytes(gossip_topic.fork_digest) {
Some(&fork_name) => {
LightClientFinalityUpdate::from_ssz_bytes(data, fork_name)
LightClientFinalityUpdate::from_ssz_bytes_by_fork(data, fork_name)
.map_err(|e| format!("{:?}", e))?
},
None => return Err(format!(
Expand All @@ -385,7 +385,7 @@ impl<E: EthSpec> PubsubMessage<E> {
GossipKind::LightClientOptimisticUpdate => {
let light_client_optimistic_update = match fork_context.from_context_bytes(gossip_topic.fork_digest) {
Some(&fork_name) => {
LightClientOptimisticUpdate::from_ssz_bytes(data, fork_name)
LightClientOptimisticUpdate::from_ssz_bytes_by_fork(data, fork_name)
.map_err(|e| format!("{:?}", e))?
},
None => return Err(format!(
Expand Down
14 changes: 10 additions & 4 deletions beacon_node/store/src/hot_cold_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,11 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>

let fork_name = self.spec.fork_name_at_epoch(epoch.into());

let light_client_update =
LightClientUpdate::from_ssz_bytes(&light_client_update_bytes, &fork_name)?;
let light_client_update = LightClientUpdate::from_ssz_bytes_by_fork_and_spec(
&light_client_update_bytes,
fork_name,
&self.spec,
)?;

return Ok(Some(light_client_update));
}
Expand All @@ -782,8 +785,11 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>

let fork_name = self.spec.fork_name_at_epoch(epoch.into());

let light_client_update =
LightClientUpdate::from_ssz_bytes(&light_client_update_bytes, &fork_name)?;
let light_client_update = LightClientUpdate::from_ssz_bytes_by_fork_and_spec(
&light_client_update_bytes,
fork_name,
&self.spec,
)?;

light_client_updates.push(light_client_update);

Expand Down
Loading
Loading