diff --git a/.github/workflows/parachain.yml b/.github/workflows/parachain.yml index 70fe5b9bc8..89723d2765 100644 --- a/.github/workflows/parachain.yml +++ b/.github/workflows/parachain.yml @@ -99,7 +99,8 @@ jobs: command: tarpaulin args: >- --manifest-path parachain/Cargo.toml - --verbose + --release + --verbose --workspace --features runtime-benchmarks --avoid-cfg-tarpaulin diff --git a/cumulus b/cumulus index 262f554226..d45182d8fc 160000 --- a/cumulus +++ b/cumulus @@ -1 +1 @@ -Subproject commit 262f554226f9b6efa8f1ecb4770625d35ccb85c0 +Subproject commit d45182d8fcb681899bf30b0c89a9a5d1caa3d6d9 diff --git a/parachain/Cargo.lock b/parachain/Cargo.lock index 2c29f7289a..1d50fc99de 100644 --- a/parachain/Cargo.lock +++ b/parachain/Cargo.lock @@ -71,7 +71,7 @@ dependencies = [ [[package]] name = "amcl" version = "0.3.0" -source = "git+https://github.com/snowfork/milagro_bls?rev=b95ca5be05e3c6e5b865b7e1f4a768dfa97f27f8#b95ca5be05e3c6e5b865b7e1f4a768dfa97f27f8" +source = "git+https://github.com/snowfork/milagro_bls?rev=a6d66e4eb89015e352fb1c9f7b661ecdbb5b2176#a6d66e4eb89015e352fb1c9f7b661ecdbb5b2176" dependencies = [ "parity-scale-codec", "scale-info", @@ -2242,7 +2242,7 @@ dependencies = [ [[package]] name = "milagro_bls" version = "1.5.0" -source = "git+https://github.com/snowfork/milagro_bls?rev=b95ca5be05e3c6e5b865b7e1f4a768dfa97f27f8#b95ca5be05e3c6e5b865b7e1f4a768dfa97f27f8" +source = "git+https://github.com/snowfork/milagro_bls?rev=a6d66e4eb89015e352fb1c9f7b661ecdbb5b2176#a6d66e4eb89015e352fb1c9f7b661ecdbb5b2176" dependencies = [ "amcl", "hex", diff --git a/parachain/pallets/ethereum-beacon-client/src/benchmarking/mod.rs b/parachain/pallets/ethereum-beacon-client/src/benchmarking/mod.rs index 10fb3790cf..caeaa8f9b5 100644 --- a/parachain/pallets/ethereum-beacon-client/src/benchmarking/mod.rs +++ b/parachain/pallets/ethereum-beacon-client/src/benchmarking/mod.rs @@ -7,6 +7,7 @@ use frame_system::RawOrigin; // For benchmark focus on main spec only mod data_mainnet; use data_mainnet::*; + mod util; use primitives::{ fast_aggregate_verify, fast_aggregate_verify_legacy, prepare_aggregate_pubkey, @@ -30,7 +31,7 @@ benchmarks! { let initial_sync_data = initial_sync(); - EthereumBeaconClient::::initial_sync(initial_sync_data.clone())?; + EthereumBeaconClient::::initial_sync(&initial_sync_data)?; let finalized_header_update = finalized_header_update(); @@ -59,7 +60,7 @@ benchmarks! { let initial_sync_data = initial_sync(); - EthereumBeaconClient::::initial_sync(initial_sync_data.clone())?; + EthereumBeaconClient::::initial_sync(&initial_sync_data)?; let header_update = header_update(); diff --git a/parachain/pallets/ethereum-beacon-client/src/benchmarking/util.rs b/parachain/pallets/ethereum-beacon-client/src/benchmarking/util.rs index 30d85a9683..1e044540e6 100644 --- a/parachain/pallets/ethereum-beacon-client/src/benchmarking/util.rs +++ b/parachain/pallets/ethereum-beacon-client/src/benchmarking/util.rs @@ -1,9 +1,9 @@ use crate::{ decompress_sync_committee_bits, Config, LatestSyncCommitteePeriod, - Pallet as EthereumBeaconClient, SyncCommitteePrepared, SyncCommitteeUpdate, SyncCommittees, - ValidatorsRoot, Vec, + Pallet as EthereumBeaconClient, SyncCommitteeUpdate, SyncCommittees, ValidatorsRoot, Vec, + SYNC_COMMITTEE_SIZE, }; -use primitives::PublicKeyPrepared; +use primitives::{PublicKeyPrepared, SyncCommitteePrepared}; use sp_core::H256; use super::{initial_sync, sync_committee_update}; @@ -11,7 +11,7 @@ use super::{initial_sync, sync_committee_update}; pub fn initialize_sync_committee() -> Result { let initial_sync_data = initial_sync(); - EthereumBeaconClient::::initial_sync(initial_sync_data.clone())?; + EthereumBeaconClient::::initial_sync(&initial_sync_data)?; let sync_committee_update = sync_committee_update(); @@ -31,7 +31,7 @@ pub fn initialize_sync_committee() -> Result( update: &SyncCommitteeUpdate, -) -> Result { +) -> Result, &'static str> { let current_period = EthereumBeaconClient::::compute_current_sync_period(update.attested_header.slot); let sync_committee = SyncCommittees::::get(current_period).ok_or("no sync committee")?; diff --git a/parachain/pallets/ethereum-beacon-client/src/lib.rs b/parachain/pallets/ethereum-beacon-client/src/lib.rs index 89fa8f1296..2274bc85d4 100644 --- a/parachain/pallets/ethereum-beacon-client/src/lib.rs +++ b/parachain/pallets/ethereum-beacon-client/src/lib.rs @@ -11,6 +11,7 @@ mod tests; #[cfg(test)] #[cfg(not(feature = "minimal"))] mod tests_mainnet; + #[cfg(test)] #[cfg(feature = "minimal")] mod tests_minimal; @@ -54,8 +55,7 @@ pub type SyncCommitteeUpdate = pub type FinalizedHeaderUpdate = primitives::FinalizedHeaderUpdate; pub type SyncCommittee = primitives::SyncCommittee; -pub type SyncCommitteePrepared = - primitives::SyncCommitteePrepared>; +pub type SyncCommitteePrepared = primitives::SyncCommitteePrepared; fn decompress_sync_committee_bits( input: [u8; SYNC_COMMITTEE_BITS_SIZE], @@ -201,7 +201,7 @@ pub mod pallet { ); if let Some(initial_sync) = self.initial_sync.clone() { - Pallet::::initial_sync(initial_sync).unwrap(); + Pallet::::initial_sync(&initial_sync).unwrap(); } } } @@ -910,9 +910,7 @@ pub mod pallet { pub(super) fn sync_committee_for_period( period: u64, ) -> Result { - let pub_keys = - >::get(period).ok_or(Error::::SyncCommitteeMissing)?; - Ok(pub_keys) + >::get(period).ok_or(Error::::SyncCommitteeMissing.into()) } pub(super) fn compute_fork_version(epoch: u64) -> ForkVersion { @@ -931,7 +929,7 @@ pub mod pallet { fork_versions.genesis.version } - pub(super) fn initial_sync(update: InitialUpdate) -> Result<(), &'static str> { + pub(super) fn initial_sync(update: &InitialUpdate) -> Result<(), &'static str> { log::info!( target: "ethereum-beacon-client", "💫 Received initial sync, starting processing.", diff --git a/parachain/pallets/ethereum-beacon-client/src/tests_mainnet.rs b/parachain/pallets/ethereum-beacon-client/src/tests_mainnet.rs index 51c7d159b3..71d7ed6469 100644 --- a/parachain/pallets/ethereum-beacon-client/src/tests_mainnet.rs +++ b/parachain/pallets/ethereum-beacon-client/src/tests_mainnet.rs @@ -18,7 +18,7 @@ fn it_syncs_from_an_initial_checkpoint() { let initial_sync = get_initial_sync::(); new_tester::().execute_with(|| { - assert_ok!(mock_mainnet::EthereumBeaconClient::initial_sync(initial_sync.clone())); + assert_ok!(mock_mainnet::EthereumBeaconClient::initial_sync(&initial_sync)); let block_root: H256 = initial_sync.header.hash_tree_root().unwrap(); @@ -95,8 +95,7 @@ fn it_processes_a_finalized_header_update() { #[test] fn it_errors_when_weak_subjectivity_period_exceeded_for_a_finalized_header_update() { let update = get_finalized_header_update::(); - let current_sync_committee = - get_initial_sync::<{ SYNC_COMMITTEE_SIZE }>().current_sync_committee; + let current_sync_committee = get_initial_sync::().current_sync_committee; let current_period = mock_mainnet::EthereumBeaconClient::compute_current_sync_period( update.attested_header.slot, @@ -117,7 +116,7 @@ fn it_errors_when_weak_subjectivity_period_exceeded_for_a_finalized_header_updat import_time, beacon_slot: slot - 1, }); - ValidatorsRoot::::set(get_validators_root::<{ SYNC_COMMITTEE_SIZE }>()); + ValidatorsRoot::::set(get_validators_root::()); assert_err!( mock_mainnet::EthereumBeaconClient::import_finalized_header( @@ -147,7 +146,7 @@ fn it_processes_a_header_update() { current_period, ¤t_sync_committee, )); - ValidatorsRoot::::set(get_validators_root::<{ SYNC_COMMITTEE_SIZE }>()); + ValidatorsRoot::::set(get_validators_root::()); LatestFinalizedHeaderState::::set(FinalizedHeaderState { beacon_block_root: finalized_block_root, beacon_slot: finalized_slot, diff --git a/parachain/primitives/beacon/Cargo.toml b/parachain/primitives/beacon/Cargo.toml index 2645bc808c..be85bcb477 100644 --- a/parachain/primitives/beacon/Cargo.toml +++ b/parachain/primitives/beacon/Cargo.toml @@ -26,7 +26,8 @@ byte-slice-cast = { version = "1.2.1", default-features = false } snowbridge-ethereum = { path = "../../primitives/ethereum", default-features = false } static_assertions = { version = "1.1.0" } -milagro_bls = { git = "https://github.com/snowfork/milagro_bls", default-features = false, rev="b95ca5be05e3c6e5b865b7e1f4a768dfa97f27f8"} +# milagro_bls = { path = "../../../../milagro_bls", default-features = false } +milagro_bls = { git = "https://github.com/snowfork/milagro_bls", default-features = false, rev="a6d66e4eb89015e352fb1c9f7b661ecdbb5b2176"} [dev-dependencies] hex-literal = { version = "0.4.1" } diff --git a/parachain/primitives/beacon/src/types.rs b/parachain/primitives/beacon/src/types.rs index 8b734e3e75..14594994d3 100644 --- a/parachain/primitives/beacon/src/types.rs +++ b/parachain/primitives/beacon/src/types.rs @@ -1,8 +1,8 @@ use codec::{Decode, Encode, MaxEncodedLen}; -use frame_support::{traits::Get, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound}; +use frame_support::{CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound}; use scale_info::TypeInfo; use sp_core::{H160, H256, U256}; -use sp_runtime::{BoundedVec, RuntimeDebug}; +use sp_runtime::RuntimeDebug; use sp_std::prelude::*; use crate::config::{PUBKEY_SIZE, SIGNATURE_SIZE}; @@ -180,23 +180,23 @@ impl SyncCommittee { /// Prepared G1 public key of sync committee as it is stored in the runtime storage. #[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, MaxEncodedLen)] -#[scale_info(skip_type_params(MaxCommitteeSize))] -pub struct SyncCommitteePrepared> { - pub pubkeys: BoundedVec, +pub struct SyncCommitteePrepared { + pub pubkeys: [PublicKeyPrepared; COMMITTEE_SIZE], pub aggregate_pubkey: PublicKeyPrepared, } -impl> - TryFrom<&SyncCommittee> for SyncCommitteePrepared +impl TryFrom<&SyncCommittee> + for SyncCommitteePrepared { type Error = BlsError; fn try_from(sync_committee: &SyncCommittee) -> Result { - let g1_pubkeys = prepare_g1_pubkeys(&sync_committee.pubkeys.to_vec())?; - let pubkeys = BoundedVec::::try_from(g1_pubkeys) - .map_err(|_| BlsError::InvalidPublicKey)?; - let aggregate_pubkey = prepare_milagro_pubkey(&sync_committee.aggregate_pubkey)?; - Ok(SyncCommitteePrepared:: { pubkeys, aggregate_pubkey }) + let g1_pubkeys = prepare_g1_pubkeys(&sync_committee.pubkeys)?; + + Ok(SyncCommitteePrepared:: { + pubkeys: g1_pubkeys.try_into().expect("checked statically; qed"), + aggregate_pubkey: prepare_milagro_pubkey(&sync_committee.aggregate_pubkey)?, + }) } }