diff --git a/pallets/slow-clap/Cargo.toml b/pallets/slow-clap/Cargo.toml index 95849ce..034bbca 100644 --- a/pallets/slow-clap/Cargo.toml +++ b/pallets/slow-clap/Cargo.toml @@ -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 diff --git a/pallets/slow-clap/src/benchmarking.rs b/pallets/slow-clap/src/benchmarking.rs index 10ec813..1341c29 100644 --- a/pallets/slow-clap/src/benchmarking.rs +++ b/pallets/slow-clap/src/benchmarking.rs @@ -90,11 +90,7 @@ benchmarks! { session_index, authority_index, network_id, - commitment: CommitmentDetails { - last_stored_block: 69, - commits: 420, - last_updated: 1337, - } + last_stored_block: 69, }; 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 = as BlockNumberProvider>::current_block_number(); let stored_commitment = BlockCommitments::::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); } }: { diff --git a/pallets/slow-clap/src/evm_types.rs b/pallets/slow-clap/src/evm_types.rs index 7450132..e6c437f 100644 --- a/pallets/slow-clap/src/evm_types.rs +++ b/pallets/slow-clap/src/evm_types.rs @@ -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; diff --git a/pallets/slow-clap/src/lib.rs b/pallets/slow-clap/src/lib.rs index 275c3a0..7e27021 100644 --- a/pallets/slow-clap/src/lib.rs +++ b/pallets/slow-clap/src/lib.rs @@ -140,7 +140,11 @@ pub struct ApplauseDetail { } impl ApplauseDetail { - 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 { DifferentEvmResponseTypes, MissingBlockNumber(u32, u32), ContradictoryTransactionLogs(u32, u32), - ContradictoryBlockMedian(ExternalBlockNumber, ExternalBlockNumber, ExternalBlockNumber), + ContradictoryBlockMedian( + ExternalBlockNumber, + ExternalBlockNumber, + ExternalBlockNumber, + ), UnparsableRequestBody(Vec), 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::::get(&network_id); let validators = Validators::::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,10 +945,11 @@ impl Pallet { return Err(OffchainErr::NoEndpointAvailable(network_id)); } - let (from_block, to_block): (ExternalBlockNumber, ExternalBlockNumber) = StorageValueRef::persistent(&block_number_key) - .get() - .map_err(|_| OffchainErr::StorageRetrievalError(network_id))? - .unwrap_or_default(); + let (from_block, to_block): (ExternalBlockNumber, ExternalBlockNumber) = + StorageValueRef::persistent(&block_number_key) + .get() + .map_err(|_| OffchainErr::StorageRetrievalError(network_id))? + .unwrap_or_default(); match network_data.network_type { NetworkType::Evm => { @@ -1304,12 +1312,16 @@ impl Pallet { ); 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);