make initialise authorities infallable and fix benchmarking
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
6a5029017c
commit
93387218ec
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ghost-slow-clap"
|
||||
version = "0.4.23"
|
||||
version = "0.4.24"
|
||||
description = "Applause protocol for the EVM bridge"
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
|
||||
@ -90,11 +90,7 @@ benchmarks! {
|
||||
session_index,
|
||||
authority_index,
|
||||
network_id,
|
||||
commitment: CommitmentDetails {
|
||||
last_stored_block: 69,
|
||||
commits: 420,
|
||||
last_updated: 1337,
|
||||
}
|
||||
};
|
||||
|
||||
let authority_id = authorities
|
||||
@ -102,20 +98,21 @@ benchmarks! {
|
||||
.expect("first authority should exist");
|
||||
let signature = authority_id.sign(&block_commitment.encode())
|
||||
.ok_or("couldn't make signature")?;
|
||||
|
||||
}: _(RawOrigin::None, block_commitment, signature)
|
||||
verify {
|
||||
let current_block_number = <Pallet<T> as BlockNumberProvider>::current_block_number();
|
||||
let stored_commitment = BlockCommitments::<T>::get(&network_id)
|
||||
.get(&authority_index)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
assert_eq!(stored_commitment.last_stored_block, 69);
|
||||
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 {
|
||||
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 mut validators_vec = Vec::new();
|
||||
@ -131,7 +128,7 @@ benchmarks! {
|
||||
let offence_type = OffenceType::CommitmentOffence;
|
||||
let disabled_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);
|
||||
}
|
||||
}: {
|
||||
|
||||
@ -2,10 +2,13 @@ use sp_runtime::{traits::UniqueSaturatedInto, SaturatedConversion, Saturating};
|
||||
use sp_staking::SessionIndex;
|
||||
|
||||
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::{
|
||||
de_string_to_bytes, de_string_to_h256, de_string_to_block_number, de_string_to_block_number_pure,
|
||||
de_string_to_vec_of_bytes,
|
||||
}
|
||||
deserialisations::{
|
||||
de_string_to_block_number, de_string_to_block_number_pure, de_string_to_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;
|
||||
|
||||
@ -140,7 +140,11 @@ pub struct 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 {
|
||||
network_id,
|
||||
block_number,
|
||||
@ -171,7 +175,11 @@ enum OffchainErr<NetworkId> {
|
||||
DifferentEvmResponseTypes,
|
||||
MissingBlockNumber(u32, u32),
|
||||
ContradictoryTransactionLogs(u32, u32),
|
||||
ContradictoryBlockMedian(ExternalBlockNumber, ExternalBlockNumber, ExternalBlockNumber),
|
||||
ContradictoryBlockMedian(
|
||||
ExternalBlockNumber,
|
||||
ExternalBlockNumber,
|
||||
ExternalBlockNumber,
|
||||
),
|
||||
UnparsableRequestBody(Vec<u8>),
|
||||
NoEndpointAvailable(NetworkId),
|
||||
StorageRetrievalError(NetworkId),
|
||||
@ -503,9 +511,8 @@ pub mod pallet {
|
||||
if let Some((network_id, network_data)) =
|
||||
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 block_commitments = BlockCommitments::<T>::get(&network_id);
|
||||
let validators = Validators::<T>::get(&session_index);
|
||||
@ -568,7 +575,7 @@ pub mod pallet {
|
||||
network_id,
|
||||
});
|
||||
|
||||
weight = weight.saturating_add(extra_weight);
|
||||
weight.saturating_accrue(extra_weight);
|
||||
}
|
||||
|
||||
weight
|
||||
@ -938,7 +945,8 @@ impl<T: Config> Pallet<T> {
|
||||
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()
|
||||
.map_err(|_| OffchainErr::StorageRetrievalError(network_id))?
|
||||
.unwrap_or_default();
|
||||
@ -1304,12 +1312,16 @@ impl<T: Config> Pallet<T> {
|
||||
);
|
||||
|
||||
let authorities_len = authorities.len();
|
||||
let bounded_authorities = WeakBoundedVec::<_, T::MaxAuthorities>::try_from(authorities)
|
||||
.expect("more than the maximum number of authorities");
|
||||
let bounded_authorities = WeakBoundedVec::<_, T::MaxAuthorities>::force_from(
|
||||
authorities,
|
||||
Some("slow claps reached maximum number of authorities"),
|
||||
);
|
||||
|
||||
let validators = T::ValidatorSet::validators();
|
||||
let bounded_validators = WeakBoundedVec::<_, T::MaxAuthorities>::try_from(validators)
|
||||
.expect("more than the maximum number of validators");
|
||||
let bounded_validators = WeakBoundedVec::<_, T::MaxAuthorities>::force_from(
|
||||
validators,
|
||||
Some("slow claps reached maximum number of validators"),
|
||||
);
|
||||
|
||||
if let Some(target_session_index) = session_index.checked_sub(T::HistoryDepth::get()) {
|
||||
Self::clear_history(&target_session_index);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user