Skip to content

Commit

Permalink
Revert to use BoundedVec for SyncCommitteePrepared
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed May 3, 2023
1 parent b63b1ac commit 22274fa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/parachain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ jobs:
command: tarpaulin
args: >-
--manifest-path parachain/Cargo.toml
--release
--verbose
--verbose
--workspace
--features runtime-benchmarks
--avoid-cfg-tarpaulin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
decompress_sync_committee_bits, Config, LatestSyncCommitteePeriod,
Pallet as EthereumBeaconClient, SyncCommitteeUpdate, SyncCommittees, ValidatorsRoot, Vec,
SYNC_COMMITTEE_SIZE,
Pallet as EthereumBeaconClient, SyncCommitteePrepared, SyncCommitteeUpdate, SyncCommittees,
ValidatorsRoot, Vec,
};
use primitives::{PublicKeyPrepared, SyncCommitteePrepared};
use primitives::PublicKeyPrepared;
use sp_core::H256;

use super::{initial_sync, sync_committee_update};
Expand Down Expand Up @@ -31,7 +31,7 @@ pub fn initialize_sync_committee<T: Config>() -> Result<SyncCommitteeUpdate, &'s

pub fn sync_committee<T: Config>(
update: &SyncCommitteeUpdate,
) -> Result<SyncCommitteePrepared<SYNC_COMMITTEE_SIZE>, &'static str> {
) -> Result<SyncCommitteePrepared, &'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
3 changes: 2 additions & 1 deletion parachain/pallets/ethereum-beacon-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ 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<SYNC_COMMITTEE_SIZE>;
pub type SyncCommitteePrepared =
primitives::SyncCommitteePrepared<ConstU32<{ SYNC_COMMITTEE_SIZE as u32 }>>;

fn decompress_sync_committee_bits(
input: [u8; SYNC_COMMITTEE_BITS_SIZE],
Expand Down
25 changes: 10 additions & 15 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::{CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound};
use frame_support::{traits::Get, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound};
use scale_info::TypeInfo;
use sp_core::{H160, H256, U256};
use sp_runtime::RuntimeDebug;
use sp_runtime::{BoundedVec, RuntimeDebug};
use sp_std::prelude::*;

use crate::config::{PUBKEY_SIZE, SIGNATURE_SIZE};
Expand Down Expand Up @@ -180,28 +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)]
pub struct SyncCommitteePrepared<const COMMITTEE_SIZE: usize> {
pub pubkeys: [PublicKeyPrepared; COMMITTEE_SIZE],
#[scale_info(skip_type_params(MaxCommitteeSize))]
pub struct SyncCommitteePrepared<MaxCommitteeSize: Get<u32>> {
pub pubkeys: BoundedVec<PublicKeyPrepared, MaxCommitteeSize>,
pub aggregate_pubkey: PublicKeyPrepared,
}

impl<const COMMITTEE_SIZE: usize> TryFrom<&SyncCommittee<COMMITTEE_SIZE>>
for SyncCommitteePrepared<COMMITTEE_SIZE>
impl<const COMMITTEE_SIZE: usize, MaxCommitteeSize: Get<u32>>
TryFrom<&SyncCommittee<COMMITTEE_SIZE>> for SyncCommitteePrepared<MaxCommitteeSize>
{
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: [PublicKeyPrepared; COMMITTEE_SIZE] =
g1_pubkeys.try_into().unwrap_or_else(|v: Vec<PublicKeyPrepared>| {
panic!(
"Expected Vec length of pubkeys as {} but actually it was {}",
COMMITTEE_SIZE,
v.len()
)
});
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::<COMMITTEE_SIZE> { pubkeys, aggregate_pubkey })
Ok(SyncCommitteePrepared::<MaxCommitteeSize> { pubkeys, aggregate_pubkey })
}
}

Expand Down

0 comments on commit 22274fa

Please sign in to comment.