Skip to content

Commit

Permalink
bump sync-committee-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege committed Sep 7, 2023
1 parent ffa4307 commit 979ceef
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 61 deletions.
189 changes: 153 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 11 additions & 13 deletions parachain/modules/consensus/sync-committee/src/beacon_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ use crate::{
prelude::*,
utils::{get_value_from_proof, get_values_from_proof},
};
use sync_committee_verifier::BlsVerify;

pub const BEACON_CONSENSUS_ID: ConsensusClientId = *b"BEAC";

#[derive(Default, Clone)]
pub struct SyncCommitteeConsensusClient<H: IsmpHost, V: BlsVerify>(core::marker::PhantomData<H>, V);
pub struct SyncCommitteeConsensusClient<H: IsmpHost>(core::marker::PhantomData<H>);

impl<H: IsmpHost + Send + Sync + Default + 'static, V: BlsVerify> ConsensusClient
for SyncCommitteeConsensusClient<H, V>
impl<H: IsmpHost + Send + Sync + Default + 'static> ConsensusClient
for SyncCommitteeConsensusClient<H>
{
fn verify_consensus(
&self,
Expand Down Expand Up @@ -66,12 +65,11 @@ impl<H: IsmpHost + Send + Sync + Default + 'static, V: BlsVerify> ConsensusClien
))
})?;

let new_light_client_state =
sync_committee_verifier::verify_sync_committee_attestation::<V>(
no_codec_light_client_state,
no_codec_light_client_update,
)
.map_err(|_| Error::ConsensusProofVerificationFailed { id: BEACON_CONSENSUS_ID })?;
let new_light_client_state = sync_committee_verifier::verify_sync_committee_attestation(
no_codec_light_client_state,
no_codec_light_client_update,
)
.map_err(|_| Error::ConsensusProofVerificationFailed { id: BEACON_CONSENSUS_ID })?;

let mut state_machine_map: BTreeMap<StateMachine, Vec<StateCommitmentHeight>> =
BTreeMap::new();
Expand All @@ -82,7 +80,7 @@ impl<H: IsmpHost + Send + Sync + Default + 'static, V: BlsVerify> ConsensusClien
BEACON_CONSENSUS_ID,
consensus_update.execution_payload.block_number,
consensus_update.execution_payload.timestamp,
&state_root,
&state_root[..],
)?;

let ethereum_state_commitment_height = StateCommitmentHeight {
Expand All @@ -98,7 +96,7 @@ impl<H: IsmpHost + Send + Sync + Default + 'static, V: BlsVerify> ConsensusClien
if let Some(optimism_payload) = optimism_payload {
let state = verify_optimism_payload::<H>(
optimism_payload,
&state_root,
&state_root[..],
consensus_state.l2_oracle_address,
)?;

Expand All @@ -114,7 +112,7 @@ impl<H: IsmpHost + Send + Sync + Default + 'static, V: BlsVerify> ConsensusClien
if let Some(arbitrum_payload) = arbitrum_payload {
let state = verify_arbitrum_payload::<H>(
arbitrum_payload,
&state_root,
&state_root[..],
consensus_state.rollup_core_address,
)?;

Expand Down
2 changes: 2 additions & 0 deletions parachain/modules/consensus/sync-committee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ pub mod presets;
mod tests;
pub mod types;
pub mod utils;

pub use beacon_client::*;
2 changes: 1 addition & 1 deletion parachain/modules/consensus/sync-committee/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ethabi::ethereum_types::{H160, H256};
use hash256_std_hasher::Hash256StdHasher;
use hash_db::Hasher;
use ismp::host::{IsmpHost, StateMachine};
use sync_committee_primitives::derived_types::{LightClientState, LightClientUpdate};
use sync_committee_primitives::types::{LightClientState, LightClientUpdate};

pub struct KeccakHasher<H: IsmpHost>(core::marker::PhantomData<H>);

Expand Down
19 changes: 8 additions & 11 deletions parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,21 +495,18 @@ pub struct ConsensusProvider;

impl ConsensusClientProvider for ConsensusProvider {
fn consensus_client(id: ConsensusClientId) -> Result<Box<dyn ConsensusClient>, Error> {
let client = match id {
match id {
ismp_parachain::consensus::PARACHAIN_CONSENSUS_ID => {
let parachain = ParachainConsensusClient::<Runtime, IsmpParachain>::default();
Box::new(parachain)
Ok(Box::new(parachain))
},
ismp_sync_committee::BEACON_CONSENSUS_ID => {
let sync_committee =
ismp_sync_committee::SyncCommitteeConsensusClient::<Host<Runtime>>::default();
Ok(Box::new(sync_committee))
},
// ismp_sync_committee::BEACON_CONSENSUS_ID => {
// use ismp_sync_committee::{SignatureVerifier, SyncCommitteeConsensusClient};
// let sync_committee =
// SyncCommitteeConsensusClient::<Host<Runtime>, SignatureVerifier>::default();
// Box::new(sync_committee)
// },
_ => Err(Error::ImplementationSpecific("Unknown consensus client".into()))?,
};

Ok(client)
}
}
}

Expand Down

0 comments on commit 979ceef

Please sign in to comment.