make initialise authorities infallable and fix benchmarking

Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
Uncle Stinky 2026-02-24 22:02:26 +03:00
parent 6a5029017c
commit 93387218ec
Signed by: st1nky
GPG Key ID: 016064BD97603B40
4 changed files with 38 additions and 26 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "ghost-slow-clap" name = "ghost-slow-clap"
version = "0.4.23" version = "0.4.24"
description = "Applause protocol for the EVM bridge" description = "Applause protocol for the EVM bridge"
license.workspace = true license.workspace = true
authors.workspace = true authors.workspace = true

View File

@ -90,11 +90,7 @@ benchmarks! {
session_index, session_index,
authority_index, authority_index,
network_id, network_id,
commitment: CommitmentDetails {
last_stored_block: 69, last_stored_block: 69,
commits: 420,
last_updated: 1337,
}
}; };
let authority_id = authorities let authority_id = authorities
@ -102,20 +98,21 @@ benchmarks! {
.expect("first authority should exist"); .expect("first authority should exist");
let signature = authority_id.sign(&block_commitment.encode()) let signature = authority_id.sign(&block_commitment.encode())
.ok_or("couldn't make signature")?; .ok_or("couldn't make signature")?;
}: _(RawOrigin::None, block_commitment, signature) }: _(RawOrigin::None, block_commitment, signature)
verify { verify {
let current_block_number = <Pallet<T> as BlockNumberProvider>::current_block_number();
let stored_commitment = BlockCommitments::<T>::get(&network_id) let stored_commitment = BlockCommitments::<T>::get(&network_id)
.get(&authority_index) .get(&authority_index)
.cloned() .cloned()
.unwrap_or_default(); .unwrap_or_default();
assert_eq!(stored_commitment.last_stored_block, 69); assert_eq!(stored_commitment.last_stored_block, 69);
assert_eq!(stored_commitment.commits, 1); assert_eq!(stored_commitment.commits, 1);
assert_eq!(stored_commitment.last_updated, 1337); assert_eq!(stored_commitment.last_updated, current_block_number);
} }
try_offend_validators { try_offend_validators {
let n in 4 .. T::MaxAuthorities::get(); let n in 4 .. T::MaxAuthorities::get();
let d in 0 .. T::MaxAuthorities::get().saturating_div(3);
let session_index = T::ValidatorSet::session_index(); let session_index = T::ValidatorSet::session_index();
let mut validators_vec = Vec::new(); let mut validators_vec = Vec::new();
@ -131,7 +128,7 @@ benchmarks! {
let offence_type = OffenceType::CommitmentOffence; let offence_type = OffenceType::CommitmentOffence;
let disabled_bitmap = BitMap::new(T::MaxAuthorities::get()); let disabled_bitmap = BitMap::new(T::MaxAuthorities::get());
let mut offence_bitmap = BitMap::new(T::MaxAuthorities::get()); let mut offence_bitmap = BitMap::new(T::MaxAuthorities::get());
for i in 0 .. (n / 3) { for i in 0..d {
offence_bitmap.set(i); offence_bitmap.set(i);
} }
}: { }: {

View File

@ -2,10 +2,13 @@ use sp_runtime::{traits::UniqueSaturatedInto, SaturatedConversion, Saturating};
use sp_staking::SessionIndex; use sp_staking::SessionIndex;
use crate::{ use crate::{
AuthIndex, BLOCK_COMMITMENT_DELAY, BalanceOf, BlockCommitment, BlockCommitments, BlockNumberFor, Call, Clap, Config, Decode, Deserialize, Encode, ExternalBlockNumber, H256, LOG_TARGET, NetworkIdOf, RuntimeAppPublic, RuntimeDebug, SubmitTransaction, Vec, deserialisations::{ deserialisations::{
de_string_to_bytes, de_string_to_h256, de_string_to_block_number, de_string_to_block_number_pure, de_string_to_block_number, de_string_to_block_number_pure, de_string_to_bytes,
de_string_to_vec_of_bytes, de_string_to_h256, de_string_to_vec_of_bytes,
} },
AuthIndex, BalanceOf, BlockCommitment, BlockCommitments, BlockNumberFor, Call, Clap, Config,
Decode, Deserialize, Encode, ExternalBlockNumber, NetworkIdOf, RuntimeAppPublic, RuntimeDebug,
SubmitTransaction, Vec, BLOCK_COMMITMENT_DELAY, H256, LOG_TARGET,
}; };
const NUMBER_OF_TOPICS: usize = 3; const NUMBER_OF_TOPICS: usize = 3;

View File

@ -140,7 +140,11 @@ pub struct ApplauseDetail<NetworkId, Balance> {
} }
impl<NetworkId, Balance: Default> ApplauseDetail<NetworkId, Balance> { impl<NetworkId, Balance: Default> ApplauseDetail<NetworkId, Balance> {
pub fn new(network_id: NetworkId, block_number: ExternalBlockNumber, max_authorities: usize) -> Self { pub fn new(
network_id: NetworkId,
block_number: ExternalBlockNumber,
max_authorities: usize,
) -> Self {
ApplauseDetail { ApplauseDetail {
network_id, network_id,
block_number, block_number,
@ -171,7 +175,11 @@ enum OffchainErr<NetworkId> {
DifferentEvmResponseTypes, DifferentEvmResponseTypes,
MissingBlockNumber(u32, u32), MissingBlockNumber(u32, u32),
ContradictoryTransactionLogs(u32, u32), ContradictoryTransactionLogs(u32, u32),
ContradictoryBlockMedian(ExternalBlockNumber, ExternalBlockNumber, ExternalBlockNumber), ContradictoryBlockMedian(
ExternalBlockNumber,
ExternalBlockNumber,
ExternalBlockNumber,
),
UnparsableRequestBody(Vec<u8>), UnparsableRequestBody(Vec<u8>),
NoEndpointAvailable(NetworkId), NoEndpointAvailable(NetworkId),
StorageRetrievalError(NetworkId), StorageRetrievalError(NetworkId),
@ -503,9 +511,8 @@ pub mod pallet {
if let Some((network_id, network_data)) = if let Some((network_id, network_data)) =
T::NetworkDataHandler::network_for_block(converted_block) T::NetworkDataHandler::network_for_block(converted_block)
{ {
weight = weight.saturating_add(T::DbWeight::get().reads_writes(3, 1)); weight.saturating_accrue(T::DbWeight::get().reads_writes(3, 1));
// TODO: put wrapper function with precalculated weight here
let session_index = T::ValidatorSet::session_index(); let session_index = T::ValidatorSet::session_index();
let block_commitments = BlockCommitments::<T>::get(&network_id); let block_commitments = BlockCommitments::<T>::get(&network_id);
let validators = Validators::<T>::get(&session_index); let validators = Validators::<T>::get(&session_index);
@ -568,7 +575,7 @@ pub mod pallet {
network_id, network_id,
}); });
weight = weight.saturating_add(extra_weight); weight.saturating_accrue(extra_weight);
} }
weight weight
@ -938,7 +945,8 @@ impl<T: Config> Pallet<T> {
return Err(OffchainErr::NoEndpointAvailable(network_id)); return Err(OffchainErr::NoEndpointAvailable(network_id));
} }
let (from_block, to_block): (ExternalBlockNumber, ExternalBlockNumber) = StorageValueRef::persistent(&block_number_key) let (from_block, to_block): (ExternalBlockNumber, ExternalBlockNumber) =
StorageValueRef::persistent(&block_number_key)
.get() .get()
.map_err(|_| OffchainErr::StorageRetrievalError(network_id))? .map_err(|_| OffchainErr::StorageRetrievalError(network_id))?
.unwrap_or_default(); .unwrap_or_default();
@ -1304,12 +1312,16 @@ impl<T: Config> Pallet<T> {
); );
let authorities_len = authorities.len(); let authorities_len = authorities.len();
let bounded_authorities = WeakBoundedVec::<_, T::MaxAuthorities>::try_from(authorities) let bounded_authorities = WeakBoundedVec::<_, T::MaxAuthorities>::force_from(
.expect("more than the maximum number of authorities"); authorities,
Some("slow claps reached maximum number of authorities"),
);
let validators = T::ValidatorSet::validators(); let validators = T::ValidatorSet::validators();
let bounded_validators = WeakBoundedVec::<_, T::MaxAuthorities>::try_from(validators) let bounded_validators = WeakBoundedVec::<_, T::MaxAuthorities>::force_from(
.expect("more than the maximum number of validators"); validators,
Some("slow claps reached maximum number of validators"),
);
if let Some(target_session_index) = session_index.checked_sub(T::HistoryDepth::get()) { if let Some(target_session_index) = session_index.checked_sub(T::HistoryDepth::get()) {
Self::clear_history(&target_session_index); Self::clear_history(&target_session_index);