diff --git a/pallets/claims/src/weights.rs b/pallets/claims/src/weights.rs index edcfe88..a1116ba 100644 --- a/pallets/claims/src/weights.rs +++ b/pallets/claims/src/weights.rs @@ -51,33 +51,6 @@ pub trait WeightInfo { fn claim() -> Weight; } -/// Weight for ghost_claims using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - /// Storage: `System::Account` (r:2 w:2) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `GhostClaims::Total` (r:1 w:1) - /// Proof: `GhostClaims::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `CultCollective::Members` (r:2 w:2) - /// Proof: `CultCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) - /// Storage: `CultCollective::MemberCount` (r:6 w:6) - /// Proof: `CultCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) - /// Storage: `CultCollective::IdToIndex` (r:6 w:12) - /// Proof: `CultCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) - /// Storage: `CultCollective::IndexToId` (r:0 w:6) - /// Proof: `CultCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) - fn claim() -> Weight { - // Proof Size summary in bytes: - // Measured: `896` - // Estimated: `16164` - // Minimum execution time: 754_086_000 picoseconds. - Weight::from_parts(756_147_000, 0) - .saturating_add(Weight::from_parts(0, 16164)) - .saturating_add(T::DbWeight::get().reads(17)) - .saturating_add(T::DbWeight::get().writes(29)) - } -} - impl WeightInfo for () { /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) diff --git a/pallets/networks/src/weights.rs b/pallets/networks/src/weights.rs index 135b07d..17ef44d 100644 --- a/pallets/networks/src/weights.rs +++ b/pallets/networks/src/weights.rs @@ -63,166 +63,6 @@ pub trait WeightInfo { fn remove_network() -> Weight; } -/// Weight for ghost_networks using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - /// Storage: `GhostNetworks::Networks` (r:1 w:1) - /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `i` is `[1, 20]`. - /// The range of component `j` is `[1, 150]`. - /// The range of component `k` is `[1, 20]`. - fn register_network(_i: u32, _j: u32, k: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `109` - // Estimated: `3574` - // Minimum execution time: 46_023_000 picoseconds. - Weight::from_parts(97_871_287, 0) - .saturating_add(Weight::from_parts(0, 3574)) - // Standard Error: 94_524 - .saturating_add(Weight::from_parts(940_486, 0).saturating_mul(k.into())) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: `GhostNetworks::Networks` (r:1 w:1) - /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `n` is `[1, 20]`. - fn update_network_name(n: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `302` - // Estimated: `3767` - // Minimum execution time: 49_906_000 picoseconds. - Weight::from_parts(55_537_587, 0) - .saturating_add(Weight::from_parts(0, 3767)) - // Standard Error: 87_704 - .saturating_add(Weight::from_parts(92_366, 0).saturating_mul(n.into())) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: `GhostNetworks::Networks` (r:1 w:1) - /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `n` is `[1, 150]`. - fn update_network_endpoint(n: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `302` - // Estimated: `3767` - // Minimum execution time: 50_556_000 picoseconds. - Weight::from_parts(57_726_674, 0) - .saturating_add(Weight::from_parts(0, 3767)) - // Standard Error: 12_261 - .saturating_add(Weight::from_parts(274, 0).saturating_mul(n.into())) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: `GhostNetworks::Networks` (r:1 w:1) - /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn update_network_finality_delay() -> Weight { - // Proof Size summary in bytes: - // Measured: `302` - // Estimated: `3767` - // Minimum execution time: 49_406_000 picoseconds. - Weight::from_parts(51_256_000, 0) - .saturating_add(Weight::from_parts(0, 3767)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: `GhostNetworks::Networks` (r:1 w:1) - /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn update_network_rate_limit_delay() -> Weight { - // Proof Size summary in bytes: - // Measured: `302` - // Estimated: `3767` - // Minimum execution time: 49_572_000 picoseconds. - Weight::from_parts(52_584_000, 0) - .saturating_add(Weight::from_parts(0, 3767)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: `GhostNetworks::Networks` (r:1 w:1) - /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn update_network_block_distance() -> Weight { - // Proof Size summary in bytes: - // Measured: `302` - // Estimated: `3767` - // Minimum execution time: 48_880_000 picoseconds. - Weight::from_parts(50_596_000, 0) - .saturating_add(Weight::from_parts(0, 3767)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: `GhostNetworks::Networks` (r:1 w:1) - /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn update_network_type() -> Weight { - // Proof Size summary in bytes: - // Measured: `302` - // Estimated: `3767` - // Minimum execution time: 48_282_000 picoseconds. - Weight::from_parts(49_137_000, 0) - .saturating_add(Weight::from_parts(0, 3767)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: `GhostNetworks::Networks` (r:1 w:1) - /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn update_network_gatekeeper() -> Weight { - // Proof Size summary in bytes: - // Measured: `302` - // Estimated: `3767` - // Minimum execution time: 50_853_000 picoseconds. - Weight::from_parts(51_982_000, 0) - .saturating_add(Weight::from_parts(0, 3767)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: `GhostNetworks::Networks` (r:1 w:1) - /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn update_network_topic_name() -> Weight { - // Proof Size summary in bytes: - // Measured: `302` - // Estimated: `3767` - // Minimum execution time: 50_343_000 picoseconds. - Weight::from_parts(52_380_000, 0) - .saturating_add(Weight::from_parts(0, 3767)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: `GhostNetworks::Networks` (r:1 w:1) - /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn update_incoming_network_fee() -> Weight { - // Proof Size summary in bytes: - // Measured: `302` - // Estimated: `3767` - // Minimum execution time: 49_393_000 picoseconds. - Weight::from_parts(80_966_000, 0) - .saturating_add(Weight::from_parts(0, 3767)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: `GhostNetworks::Networks` (r:1 w:1) - /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn update_outgoing_network_fee() -> Weight { - // Proof Size summary in bytes: - // Measured: `302` - // Estimated: `3767` - // Minimum execution time: 49_579_000 picoseconds. - Weight::from_parts(51_126_000, 0) - .saturating_add(Weight::from_parts(0, 3767)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: `GhostNetworks::Networks` (r:1 w:1) - /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn remove_network() -> Weight { - // Proof Size summary in bytes: - // Measured: `302` - // Estimated: `3767` - // Minimum execution time: 44_634_000 picoseconds. - Weight::from_parts(45_815_000, 0) - .saturating_add(Weight::from_parts(0, 3767)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } -} - impl WeightInfo for () { /// Storage: `GhostNetworks::Networks` (r:1 w:1) /// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`) diff --git a/pallets/slow-clap/Cargo.toml b/pallets/slow-clap/Cargo.toml index 5895e0e..c0bdefc 100644 --- a/pallets/slow-clap/Cargo.toml +++ b/pallets/slow-clap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ghost-slow-clap" -version = "0.3.53" +version = "0.3.54" description = "Applause protocol for the EVM bridge" license.workspace = true authors.workspace = true diff --git a/pallets/slow-clap/src/lib.rs b/pallets/slow-clap/src/lib.rs index 4dd4b90..48b61b2 100644 --- a/pallets/slow-clap/src/lib.rs +++ b/pallets/slow-clap/src/lib.rs @@ -23,7 +23,7 @@ use sp_core::H256; use sp_runtime::{ offchain::{ self as rt_offchain, - storage::{MutateStorageError, StorageRetrievalError, StorageValueRef}, + storage::StorageValueRef, storage_lock::{StorageLock, Time}, HttpError, }, @@ -97,8 +97,6 @@ pub struct SessionAuthorityInfo { #[cfg_attr(test, derive(PartialEq))] enum OffchainErr { - FailedSigning, - SubmitTransaction, HttpJsonParsingError, HttpBytesParsingError, HttpRequestError(HttpError), @@ -106,38 +104,65 @@ enum OffchainErr { HttpResponseNotOk(u16), ErrorInEvmResponse, NoStoredNetworks, - NotValidator, + NoEndpointAvailable(NetworkId), StorageRetrievalError(NetworkId), - ConcurrentModificationError(NetworkId), UtxoNotImplemented(NetworkId), UnknownNetworkType(NetworkId), OffchainTimeoutPeriod(NetworkId), - TooManyRequests(NetworkId), } impl core::fmt::Debug for OffchainErr { fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result { match *self { - OffchainErr::FailedSigning => write!(fmt, "Failed to sign clap."), - OffchainErr::SubmitTransaction => write!(fmt, "Failed to submit transaction."), - OffchainErr::HttpJsonParsingError => write!(fmt, "Failed to parse evm response as JSON."), - OffchainErr::HttpBytesParsingError => write!(fmt, "Failed to parse evm response as bytes."), + OffchainErr::HttpJsonParsingError => { + write!(fmt, "Failed to parse evm response as JSON.") + } + OffchainErr::HttpBytesParsingError => { + write!(fmt, "Failed to parse evm response as bytes.") + } OffchainErr::HttpRequestError(http_error) => match http_error { - HttpError::DeadlineReached => write!(fmt, "Requested action couldn't been completed within a deadline."), - HttpError::IoError => write!(fmt, "There was an IO error while processing the request."), - HttpError::Invalid => write!(fmt, "The ID of the request is invalid in this context."), + HttpError::DeadlineReached => write!( + fmt, + "Requested action couldn't been completed within a deadline." + ), + HttpError::IoError => { + write!(fmt, "There was an IO error while processing the request.") + } + HttpError::Invalid => { + write!(fmt, "The ID of the request is invalid in this context.") + } }, - OffchainErr::ConcurrentModificationError(ref network_id) => write!(fmt, "The underlying DB failed to update due to a concurrent modification for network #{:?}.", network_id), - OffchainErr::StorageRetrievalError(ref network_id) => write!(fmt, "Storage value found for network #{:?} but it's undecodable.", network_id), + OffchainErr::StorageRetrievalError(ref network_id) => write!( + fmt, + "Storage value found for network #{:?} but it's undecodable.", + network_id + ), OffchainErr::RequestUncompleted => write!(fmt, "Failed to complete request."), - OffchainErr::HttpResponseNotOk(code) => write!(fmt, "Http response returned code {:?}.", code), + OffchainErr::HttpResponseNotOk(code) => { + write!(fmt, "Http response returned code {:?}.", code) + } OffchainErr::ErrorInEvmResponse => write!(fmt, "Error in evm reponse."), - OffchainErr::NoStoredNetworks => write!(fmt, "No networks stored for the offchain slow claps."), - OffchainErr::NotValidator => write!(fmt, "Not a validator for slow clap, `--validator` flag needed."), - OffchainErr::UtxoNotImplemented(ref network_id) => write!(fmt, "Network #{:?} is marked as UTXO, which is not implemented yet.", network_id), - OffchainErr::UnknownNetworkType(ref network_id) => write!(fmt, "Unknown type for network #{:?}.", network_id), - OffchainErr::OffchainTimeoutPeriod(ref network_id) => write!(fmt, "Offchain request should be in-flight for network #{:?}.", network_id), - OffchainErr::TooManyRequests(ref network_id) => write!(fmt, "Too many requests over RPC endpoint for network #{:?}.", network_id), + OffchainErr::NoStoredNetworks => { + write!(fmt, "No networks stored for the offchain slow claps.") + } + OffchainErr::NoEndpointAvailable(ref network_id) => write!( + fmt, + "No RPC endpoint available for network #{:?}.", + network_id + ), + OffchainErr::UtxoNotImplemented(ref network_id) => write!( + fmt, + "Network #{:?} is marked as UTXO, which is not implemented yet.", + network_id + ), + OffchainErr::UnknownNetworkType(ref network_id) => { + write!(fmt, "Unknown type for network #{:?}.", network_id) + } + OffchainErr::OffchainTimeoutPeriod(ref network_id) => write!( + fmt, + "Offchain request should be in-flight for network #{:?}.", + network_id + ), } } } @@ -359,25 +384,13 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { fn offchain_worker(now: BlockNumberFor) { - match Self::start_slow_clapping(now) { - Ok(iter) => { - for result in iter.into_iter() { - if let Err(e) = result { - log::info!( - target: LOG_TARGET, - "👏 Skipping slow clap at {:?}: {:?}", - now, - e, - ) - } - } - } - Err(e) => log::info!( + if let Err(e) = Self::start_slow_clapping(now) { + log::info!( target: LOG_TARGET, - "👏 Could not start slow clap at {:?}: {:?}", + "👏 Skipping slow clap at {:?}: {:?}", now, e, - ), + ) } } } @@ -680,13 +693,7 @@ impl Pallet { Ok(()) } - fn start_slow_clapping( - block_number: BlockNumberFor, - ) -> OffchainResult>> { - sp_io::offchain::is_validator() - .then(|| ()) - .ok_or(OffchainErr::NotValidator)?; - + fn start_slow_clapping(block_number: BlockNumberFor) -> OffchainResult { let session_index = T::ValidatorSet::session_index(); let networks_len = T::NetworkDataHandler::iter().count(); let network_in_use = T::NetworkDataHandler::iter() @@ -701,7 +708,6 @@ impl Pallet { let network_id_encoded = network_in_use.0.encode(); - let last_timestamp_key = Self::create_storage_key(b"last-timestamp-", &network_id_encoded); let rate_limit_delay_key = Self::create_storage_key(b"rate-limit-", &network_id_encoded); let rate_limit_delay = Self::read_persistent_offchain_storage( &rate_limit_delay_key, @@ -710,51 +716,24 @@ impl Pallet { let network_lock_key = Self::create_storage_key(b"network-lock-", &network_id_encoded); let block_until = - rt_offchain::Duration::from_millis(networks_len as u64 * FETCH_TIMEOUT_PERIOD); + rt_offchain::Duration::from_millis(rate_limit_delay.max(FETCH_TIMEOUT_PERIOD)); let mut network_lock = StorageLock::