referrerpolicy=no-referrer-when-downgrade

snowbridge_pallet_ethereum_client/benchmarking/
util.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
3use crate::{
4	decompress_sync_committee_bits, Config, CurrentSyncCommittee, Pallet as EthereumBeaconClient,
5	Update, ValidatorsRoot, Vec,
6};
7use snowbridge_beacon_primitives::PublicKeyPrepared;
8use sp_core::H256;
9
10pub fn participant_pubkeys<T: Config>(
11	update: &Update,
12) -> Result<Vec<PublicKeyPrepared>, &'static str> {
13	let sync_committee_bits =
14		decompress_sync_committee_bits(update.sync_aggregate.sync_committee_bits);
15	let current_sync_committee = <CurrentSyncCommittee<T>>::get();
16	let pubkeys = EthereumBeaconClient::<T>::find_pubkeys(
17		&sync_committee_bits,
18		(*current_sync_committee.pubkeys).as_ref(),
19		true,
20	);
21	Ok(pubkeys)
22}
23
24pub fn absent_pubkeys<T: Config>(update: &Update) -> Result<Vec<PublicKeyPrepared>, &'static str> {
25	let sync_committee_bits =
26		decompress_sync_committee_bits(update.sync_aggregate.sync_committee_bits);
27	let current_sync_committee = <CurrentSyncCommittee<T>>::get();
28	let pubkeys = EthereumBeaconClient::<T>::find_pubkeys(
29		&sync_committee_bits,
30		(*current_sync_committee.pubkeys).as_ref(),
31		false,
32	);
33	Ok(pubkeys)
34}
35
36pub fn signing_root<T: Config>(update: &Update) -> Result<H256, &'static str> {
37	let validators_root = <ValidatorsRoot<T>>::get();
38	let signing_root = EthereumBeaconClient::<T>::signing_root(
39		&update.attested_header,
40		validators_root,
41		update.signature_slot,
42	)?;
43	Ok(signing_root)
44}