diff --git a/crates/light-client-verifier/src/consensus.rs b/crates/light-client-verifier/src/consensus.rs index 49d4b05..55f1204 100644 --- a/crates/light-client-verifier/src/consensus.rs +++ b/crates/light-client-verifier/src/consensus.rs @@ -2,7 +2,7 @@ use crate::context::{ChainConsensusVerificationContext, ConsensusVerificationCon use crate::errors::Error; use crate::internal_prelude::*; use crate::misbehaviour::Misbehaviour; -use crate::state::LightClientStoreReader; +use crate::state::{get_sync_committee_at_period, LightClientStoreReader}; use crate::updates::{ConsensusUpdate, ExecutionUpdate, LightClientBootstrap}; use core::marker::PhantomData; use ethereum_consensus::beacon::{BeaconBlockHeader, Root, DOMAIN_SYNC_COMMITTEE}; @@ -163,7 +163,7 @@ impl Result, Error> { let update_signature_period = compute_sync_committee_period_at_slot(ctx, update.signature_slot()); - if let Some(committee) = store.get_sync_committee(ctx, update_signature_period) { + if let Some(committee) = get_sync_committee_at_period(ctx, store, update_signature_period) { Ok(committee) } else { Err(Error::UnexpectedSingaturePeriod( @@ -331,7 +331,9 @@ pub fn validate_light_client_update< ctx, consensus_update.attested_beacon_header().slot, ); - if let Some(committee) = store.get_sync_committee(ctx, update_attested_period + 1) { + if let Some(committee) = + get_sync_committee_at_period(ctx, store, update_attested_period + 1) + { if committee != *update_next_sync_committee { return Err(Error::InconsistentNextSyncCommittee( committee.aggregate_pubkey.clone(), diff --git a/crates/light-client-verifier/src/state.rs b/crates/light-client-verifier/src/state.rs index e097104..fbea558 100644 --- a/crates/light-client-verifier/src/state.rs +++ b/crates/light-client-verifier/src/state.rs @@ -4,6 +4,7 @@ use ethereum_consensus::{ sync_protocol::{SyncCommittee, SyncCommitteePeriod}, }; +/// A trait for reading the light client store pub trait LightClientStoreReader { /// Returns the current sync committee period fn current_period(&self, ctx: &CC) -> SyncCommitteePeriod; @@ -14,23 +15,6 @@ pub trait LightClientStoreReader { /// Returns the next sync committee corresponding to the `current_period() + 1` if available fn next_sync_committee(&self) -> Option>; - /// Returns the sync committee corresponding to the given signature period if available - fn get_sync_committee( - &self, - ctx: &CC, - signature_period: SyncCommitteePeriod, - ) -> Option> { - let current_period = self.current_period(ctx); - let next_period = current_period + 1; - if signature_period == current_period { - self.current_sync_committee() - } else if signature_period == next_period { - self.next_sync_committee() - } else { - None - } - } - /// Returns a error indicating whether the update is relevant to this store. /// /// This method should be used to determine whether the update should be applied to the store. @@ -40,3 +24,24 @@ pub trait LightClientStoreReader { update: &C, ) -> Result<(), Error>; } + +/// Returns the sync committee corresponding to the given signature period if available +pub fn get_sync_committee_at_period< + CC: ChainContext, + const SYNC_COMMITTEE_SIZE: usize, + ST: LightClientStoreReader, +>( + ctx: &CC, + store: &ST, + signature_period: SyncCommitteePeriod, +) -> Option> { + let current_period = store.current_period(ctx); + let next_period = current_period + 1; + if signature_period == current_period { + store.current_sync_committee() + } else if signature_period == next_period { + store.next_sync_committee() + } else { + None + } +}