Skip to content
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

Revert "Revert to use BoundedVec for SyncCommitteePrepared" #819

Merged
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/parachain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ jobs:
command: tarpaulin
args: >-
--manifest-path parachain/Cargo.toml
--verbose
--release
--verbose
--workspace
--features runtime-benchmarks
--avoid-cfg-tarpaulin
Expand Down
2 changes: 1 addition & 1 deletion cumulus
Submodule cumulus updated 1 files
+2 −2 Cargo.lock
4 changes: 2 additions & 2 deletions parachain/Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -30,7 +31,7 @@ benchmarks! {

let initial_sync_data = initial_sync();

EthereumBeaconClient::<T>::initial_sync(initial_sync_data.clone())?;
EthereumBeaconClient::<T>::initial_sync(&initial_sync_data)?;

let finalized_header_update = finalized_header_update();

Expand Down Expand Up @@ -59,7 +60,7 @@ benchmarks! {

let initial_sync_data = initial_sync();

EthereumBeaconClient::<T>::initial_sync(initial_sync_data.clone())?;
EthereumBeaconClient::<T>::initial_sync(&initial_sync_data)?;

let header_update = header_update();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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};

pub fn initialize_sync_committee<T: Config>() -> Result<SyncCommitteeUpdate, &'static str> {
let initial_sync_data = initial_sync();

EthereumBeaconClient::<T>::initial_sync(initial_sync_data.clone())?;
EthereumBeaconClient::<T>::initial_sync(&initial_sync_data)?;

let sync_committee_update = sync_committee_update();

Expand All @@ -31,7 +31,7 @@ pub fn initialize_sync_committee<T: Config>() -> Result<SyncCommitteeUpdate, &'s

pub fn sync_committee<T: Config>(
update: &SyncCommitteeUpdate,
) -> Result<SyncCommitteePrepared, &'static str> {
) -> Result<SyncCommitteePrepared<SYNC_COMMITTEE_SIZE>, &'static str> {
let current_period =
EthereumBeaconClient::<T>::compute_current_sync_period(update.attested_header.slot);
let sync_committee = SyncCommittees::<T>::get(current_period).ok_or("no sync committee")?;
Expand Down
12 changes: 5 additions & 7 deletions parachain/pallets/ethereum-beacon-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod tests;
#[cfg(test)]
#[cfg(not(feature = "minimal"))]
mod tests_mainnet;

#[cfg(test)]
#[cfg(feature = "minimal")]
mod tests_minimal;
Expand Down Expand Up @@ -54,8 +55,7 @@ pub type SyncCommitteeUpdate =
pub type FinalizedHeaderUpdate =
primitives::FinalizedHeaderUpdate<SYNC_COMMITTEE_SIZE, SYNC_COMMITTEE_BITS_SIZE>;
pub type SyncCommittee = primitives::SyncCommittee<SYNC_COMMITTEE_SIZE>;
pub type SyncCommitteePrepared =
primitives::SyncCommitteePrepared<ConstU32<{ SYNC_COMMITTEE_SIZE as u32 }>>;
pub type SyncCommitteePrepared = primitives::SyncCommitteePrepared<SYNC_COMMITTEE_SIZE>;

fn decompress_sync_committee_bits(
input: [u8; SYNC_COMMITTEE_BITS_SIZE],
Expand Down Expand Up @@ -201,7 +201,7 @@ pub mod pallet {
);

if let Some(initial_sync) = self.initial_sync.clone() {
Pallet::<T>::initial_sync(initial_sync).unwrap();
Pallet::<T>::initial_sync(&initial_sync).unwrap();
}
}
}
Expand Down Expand Up @@ -910,9 +910,7 @@ pub mod pallet {
pub(super) fn sync_committee_for_period(
period: u64,
) -> Result<SyncCommitteePrepared, DispatchError> {
let pub_keys =
<SyncCommittees<T>>::get(period).ok_or(Error::<T>::SyncCommitteeMissing)?;
Ok(pub_keys)
<SyncCommittees<T>>::get(period).ok_or(Error::<T>::SyncCommitteeMissing.into())
}

pub(super) fn compute_fork_version(epoch: u64) -> ForkVersion {
Expand All @@ -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.",
Expand Down
9 changes: 4 additions & 5 deletions parachain/pallets/ethereum-beacon-client/src/tests_mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn it_syncs_from_an_initial_checkpoint() {
let initial_sync = get_initial_sync::<SYNC_COMMITTEE_SIZE>();

new_tester::<mock_mainnet::Test>().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();

Expand Down Expand Up @@ -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::<SYNC_COMMITTEE_SIZE, SYNC_COMMITTEE_BITS_SIZE>();
let current_sync_committee =
get_initial_sync::<{ SYNC_COMMITTEE_SIZE }>().current_sync_committee;
let current_sync_committee = get_initial_sync::<SYNC_COMMITTEE_SIZE>().current_sync_committee;

let current_period = mock_mainnet::EthereumBeaconClient::compute_current_sync_period(
update.attested_header.slot,
Expand All @@ -117,7 +116,7 @@ fn it_errors_when_weak_subjectivity_period_exceeded_for_a_finalized_header_updat
import_time,
beacon_slot: slot - 1,
});
ValidatorsRoot::<mock_mainnet::Test>::set(get_validators_root::<{ SYNC_COMMITTEE_SIZE }>());
ValidatorsRoot::<mock_mainnet::Test>::set(get_validators_root::<SYNC_COMMITTEE_SIZE>());

assert_err!(
mock_mainnet::EthereumBeaconClient::import_finalized_header(
Expand Down Expand Up @@ -147,7 +146,7 @@ fn it_processes_a_header_update() {
current_period,
&current_sync_committee,
));
ValidatorsRoot::<mock_mainnet::Test>::set(get_validators_root::<{ SYNC_COMMITTEE_SIZE }>());
ValidatorsRoot::<mock_mainnet::Test>::set(get_validators_root::<SYNC_COMMITTEE_SIZE>());
LatestFinalizedHeaderState::<mock_mainnet::Test>::set(FinalizedHeaderState {
beacon_block_root: finalized_block_root,
beacon_slot: finalized_slot,
Expand Down
3 changes: 2 additions & 1 deletion parachain/primitives/beacon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
24 changes: 12 additions & 12 deletions parachain/primitives/beacon/src/types.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -180,23 +180,23 @@ impl<const COMMITTEE_SIZE: usize> SyncCommittee<COMMITTEE_SIZE> {

/// 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<MaxCommitteeSize: Get<u32>> {
pub pubkeys: BoundedVec<PublicKeyPrepared, MaxCommitteeSize>,
pub struct SyncCommitteePrepared<const COMMITTEE_SIZE: usize> {
pub pubkeys: [PublicKeyPrepared; COMMITTEE_SIZE],
pub aggregate_pubkey: PublicKeyPrepared,
}

impl<const COMMITTEE_SIZE: usize, MaxCommitteeSize: Get<u32>>
TryFrom<&SyncCommittee<COMMITTEE_SIZE>> for SyncCommitteePrepared<MaxCommitteeSize>
impl<const COMMITTEE_SIZE: usize> TryFrom<&SyncCommittee<COMMITTEE_SIZE>>
for SyncCommitteePrepared<COMMITTEE_SIZE>
{
type Error = BlsError;

fn try_from(sync_committee: &SyncCommittee<COMMITTEE_SIZE>) -> Result<Self, Self::Error> {
let g1_pubkeys = prepare_g1_pubkeys(&sync_committee.pubkeys.to_vec())?;
let pubkeys = BoundedVec::<PublicKeyPrepared, MaxCommitteeSize>::try_from(g1_pubkeys)
.map_err(|_| BlsError::InvalidPublicKey)?;
let aggregate_pubkey = prepare_milagro_pubkey(&sync_committee.aggregate_pubkey)?;
Ok(SyncCommitteePrepared::<MaxCommitteeSize> { pubkeys, aggregate_pubkey })
let g1_pubkeys = prepare_g1_pubkeys(&sync_committee.pubkeys)?;

Ok(SyncCommitteePrepared::<COMMITTEE_SIZE> {
pubkeys: g1_pubkeys.try_into().expect("checked statically; qed"),
aggregate_pubkey: prepare_milagro_pubkey(&sync_committee.aggregate_pubkey)?,
})
}
}

Expand Down