referrerpolicy=no-referrer-when-downgrade

snowbridge_pallet_ethereum_client/
functions.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
3use crate::config::{
4	EPOCHS_PER_SYNC_COMMITTEE_PERIOD, SLOTS_PER_EPOCH, SYNC_COMMITTEE_BITS_SIZE,
5	SYNC_COMMITTEE_SIZE,
6};
7
8/// Decompress packed bitvector into byte vector according to SSZ deserialization rules. Each byte
9/// in the decompressed vector is either 0 or 1.
10pub fn decompress_sync_committee_bits(
11	input: [u8; SYNC_COMMITTEE_BITS_SIZE],
12) -> [u8; SYNC_COMMITTEE_SIZE] {
13	snowbridge_beacon_primitives::decompress_sync_committee_bits::<
14		SYNC_COMMITTEE_SIZE,
15		SYNC_COMMITTEE_BITS_SIZE,
16	>(input)
17}
18
19/// Compute the sync committee period in which a slot is contained.
20pub fn compute_period(slot: u64) -> u64 {
21	slot / SLOTS_PER_EPOCH as u64 / EPOCHS_PER_SYNC_COMMITTEE_PERIOD as u64
22}
23
24/// Compute epoch in which a slot is contained.
25pub fn compute_epoch(slot: u64, slots_per_epoch: u64) -> u64 {
26	slot / slots_per_epoch
27}
28
29/// Sums the bit vector of sync committee participation.
30pub fn sync_committee_sum(sync_committee_bits: &[u8]) -> u32 {
31	sync_committee_bits.iter().fold(0, |acc: u32, x| acc + *x as u32)
32}