From 6e8adab8bba00f539355219bde0155e02868838c Mon Sep 17 00:00:00 2001 From: David Salami Date: Tue, 26 Sep 2023 11:25:49 +0100 Subject: [PATCH] support base payload and enable testnet and mainnet feature flags --- .../consensus/sync-committee/Cargo.toml | 3 +- .../sync-committee/src/beacon_client.rs | 40 ++++++++++--------- .../consensus/sync-committee/src/types.rs | 2 +- parachain/node/Cargo.toml | 2 + parachain/runtime/Cargo.toml | 3 ++ scripts/docker/Dockerfile | 2 +- 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/parachain/modules/consensus/sync-committee/Cargo.toml b/parachain/modules/consensus/sync-committee/Cargo.toml index 16b15265f..f4a5c05a7 100644 --- a/parachain/modules/consensus/sync-committee/Cargo.toml +++ b/parachain/modules/consensus/sync-committee/Cargo.toml @@ -60,4 +60,5 @@ std = [ "pallet-ismp/std", ] -testnet = [] +testnet = ["sync-committee-verifier/testnet", "sync-committee-primitives/testnet"] +mainnet = ["sync-committee-verifier/mainnet", "sync-committee-primitives/mainnet"] diff --git a/parachain/modules/consensus/sync-committee/src/beacon_client.rs b/parachain/modules/consensus/sync-committee/src/beacon_client.rs index 731e2fd84..7920c6168 100644 --- a/parachain/modules/consensus/sync-committee/src/beacon_client.rs +++ b/parachain/modules/consensus/sync-committee/src/beacon_client.rs @@ -43,7 +43,7 @@ impl ConsensusClient trusted_consensus_state: Vec, consensus_proof: Vec, ) -> Result<(Vec, VerifiedCommitments), Error> { - let BeaconClientUpdate { optimism_payload, consensus_update, arbitrum_payload } = + let BeaconClientUpdate { mut op_stack_payload, consensus_update, arbitrum_payload } = BeaconClientUpdate::decode(&mut &consensus_proof[..]).map_err(|_| { Error::ImplementationSpecific("Cannot decode beacon client update".to_string()) })?; @@ -81,27 +81,29 @@ impl ConsensusClient state_machine_map .insert(StateMachine::Ethereum(Ethereum::ExecutionLayer), state_commitment_vec); - if let Some(optimism_payload) = optimism_payload { - let state = verify_optimism_payload::( - optimism_payload, - &state_root[..], - *consensus_state - .l2_oracle_address - .get(&StateMachine::Ethereum(Ethereum::Optimism)) - .ok_or_else(|| { - Error::ImplementationSpecific( - "Optimism l2 oracle address was not set".into(), - ) + + let op_stack = + [StateMachine::Ethereum(Ethereum::Base), StateMachine::Ethereum(Ethereum::Optimism)]; + + for state_machine_id in op_stack { + if let Some(payload) = op_stack_payload.remove(&state_machine_id) { + let state = verify_optimism_payload::( + payload, + &state_root[..], + *consensus_state.l2_oracle_address.get(&state_machine_id).ok_or_else(|| { + Error::ImplementationSpecific("l2 oracle address was not set".into()) })?, - )?; + )?; - let optimism_state_commitment_height = - StateCommitmentHeight { commitment: state.commitment, height: state.height.height }; + let state_commitment_height = StateCommitmentHeight { + commitment: state.commitment, + height: state.height.height, + }; - let mut state_commitment_vec: Vec = Vec::new(); - state_commitment_vec.push(optimism_state_commitment_height); - state_machine_map - .insert(StateMachine::Ethereum(Ethereum::Optimism), state_commitment_vec); + let mut state_commitment_vec: Vec = Vec::new(); + state_commitment_vec.push(state_commitment_height); + state_machine_map.insert(state_machine_id, state_commitment_vec); + } } if let Some(arbitrum_payload) = arbitrum_payload { diff --git a/parachain/modules/consensus/sync-committee/src/types.rs b/parachain/modules/consensus/sync-committee/src/types.rs index 42f1ff63d..775b168bd 100644 --- a/parachain/modules/consensus/sync-committee/src/types.rs +++ b/parachain/modules/consensus/sync-committee/src/types.rs @@ -32,7 +32,7 @@ pub struct ConsensusState { #[derive(Encode, Decode)] pub struct BeaconClientUpdate { pub consensus_update: LightClientUpdate, - pub optimism_payload: Option, + pub op_stack_payload: BTreeMap, pub arbitrum_payload: Option, } diff --git a/parachain/node/Cargo.toml b/parachain/node/Cargo.toml index 061769eac..9b55c9022 100644 --- a/parachain/node/Cargo.toml +++ b/parachain/node/Cargo.toml @@ -94,3 +94,5 @@ try-runtime = [ "try-runtime-cli/try-runtime", "hyperbridge-runtime/try-runtime" ] +testnet = ["hyperbridge-runtime/testnet"] +mainnet = ["hyperbridge-runtime/mainnet"] diff --git a/parachain/runtime/Cargo.toml b/parachain/runtime/Cargo.toml index 6d9eef5dc..1026aab4e 100644 --- a/parachain/runtime/Cargo.toml +++ b/parachain/runtime/Cargo.toml @@ -169,3 +169,6 @@ try-runtime = [ "pallet-xcm/try-runtime", "parachain-info/try-runtime", ] + +testnet = ["ismp-sync-committee/testnet"] +mainnet = ["ismp-sync-committee/mainnet"] diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile index b577583b9..016ea16e2 100644 --- a/scripts/docker/Dockerfile +++ b/scripts/docker/Dockerfile @@ -2,6 +2,6 @@ FROM paritytech/ci-linux:production COPY ./ ./ -RUN RUSTFLAGS="-C link-args=-Wl,--allow-multiple-definition" cargo build --release -p hyperbridge +RUN RUSTFLAGS="-C link-args=-Wl,--allow-multiple-definition" cargo build --release -p hyperbridge --features testnet ENTRYPOINT ["./target/release/hyperbridge"]