From 4618741c88c6acca09852db60495fee449853bc8 Mon Sep 17 00:00:00 2001 From: Andrey Orlov Date: Wed, 2 Feb 2022 18:55:29 +0400 Subject: [PATCH 1/2] Add MaxEncodedLen implementations in pallets --- frame/composable-traits/src/bonded_finance.rs | 6 +++--- frame/composable-traits/src/governance.rs | 4 ++-- frame/composable-traits/src/time.rs | 6 +++--- frame/composable-traits/src/vault.rs | 2 +- frame/composable-traits/src/vesting.rs | 2 +- frame/crowdloan-rewards/src/lib.rs | 2 +- frame/crowdloan-rewards/src/models.rs | 6 +++--- frame/lending/src/lib.rs | 2 +- frame/liquidations/src/lib.rs | 2 +- frame/mosaic/src/lib.rs | 4 ++-- frame/mosaic/src/relayer.rs | 6 +++--- frame/vault/src/capabilities.rs | 2 +- frame/vault/src/models.rs | 2 +- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/frame/composable-traits/src/bonded_finance.rs b/frame/composable-traits/src/bonded_finance.rs index 96995dd5e0f..9e6bd544665 100644 --- a/frame/composable-traits/src/bonded_finance.rs +++ b/frame/composable-traits/src/bonded_finance.rs @@ -26,7 +26,7 @@ pub trait BondedFinance { } /// The Bond duration. -#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Encode, Decode, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] pub enum BondDuration { /// Finite duration, liquidity is returned after a number of `blocks`. Finite { return_in: BlockNumber }, @@ -35,7 +35,7 @@ pub enum BondDuration { } /// The Bond offer. -#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Encode, Decode, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] pub struct BondOffer { /// The account that will receive the locked assets. pub beneficiary: AccountId, @@ -53,7 +53,7 @@ pub struct BondOffer { } /// The Bond reward. Asset and rules reward will be given. -#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Encode, Decode, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)] pub struct BondOfferReward { /// The actual reward asset. pub asset: AssetId, diff --git a/frame/composable-traits/src/governance.rs b/frame/composable-traits/src/governance.rs index 4ff38375443..912d8afcc9c 100644 --- a/frame/composable-traits/src/governance.rs +++ b/frame/composable-traits/src/governance.rs @@ -1,12 +1,12 @@ use frame_support::{ - codec::{Decode, Encode}, + codec::{Decode, Encode, MaxEncodedLen}, RuntimeDebug, }; use frame_system::RawOrigin; use scale_info::TypeInfo; /// Like `RawOrigin`, but always signed. -#[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode, TypeInfo)] +#[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo)] pub enum SignedRawOrigin { /// The system itself ordained this dispatch to happen: this is the highest privilege level. Root, diff --git a/frame/composable-traits/src/time.rs b/frame/composable-traits/src/time.rs index a8648be8496..0d2f4313ffb 100644 --- a/frame/composable-traits/src/time.rs +++ b/frame/composable-traits/src/time.rs @@ -16,7 +16,7 @@ pub const ONE_HOUR: DurationSeconds = 60 * 60; /// accounts to length of year) pub const SECONDS_PER_YEAR_NAIVE: DurationSeconds = 365 * 24 * ONE_HOUR; -#[derive(Decode, Encode, Clone, TypeInfo, Debug, PartialEq)] +#[derive(Decode, Encode, Clone, Debug, PartialEq, TypeInfo)] pub enum TimeReleaseFunction { LinearDecrease(LinearDecrease), StairstepExponentialDecrease(StairstepExponentialDecrease), @@ -28,13 +28,13 @@ impl Default for TimeReleaseFunction { } } -#[derive(Default, Decode, Encode, Clone, TypeInfo, Debug, PartialEq)] +#[derive(Default, Decode, Encode, Clone, Debug, PartialEq, TypeInfo)] pub struct LinearDecrease { /// Seconds after start when the amount reaches zero pub total: DurationSeconds, } -#[derive(Default, Decode, Encode, Clone, TypeInfo, Debug, PartialEq)] +#[derive(Default, Decode, Encode, Clone, Debug, PartialEq, TypeInfo)] pub struct StairstepExponentialDecrease { // Length of time between drops pub step: DurationSeconds, diff --git a/frame/composable-traits/src/vault.rs b/frame/composable-traits/src/vault.rs index 91a9f6d6b05..605d2cf965b 100644 --- a/frame/composable-traits/src/vault.rs +++ b/frame/composable-traits/src/vault.rs @@ -25,7 +25,7 @@ pub enum FundsAvailability { MustLiquidate, } -#[derive(Copy, Clone, Encode, Decode, Debug, PartialEq, TypeInfo)] +#[derive(Copy, Clone, Encode, Decode, Debug, PartialEq, MaxEncodedLen, TypeInfo)] pub enum Deposit { /// Indicates that the vault has deposited an amount large enough to forever be exempt from /// rent payments. diff --git a/frame/composable-traits/src/vesting.rs b/frame/composable-traits/src/vesting.rs index b68a178d01e..b525bfd14bd 100644 --- a/frame/composable-traits/src/vesting.rs +++ b/frame/composable-traits/src/vesting.rs @@ -24,7 +24,7 @@ pub trait VestedTransfer { /// /// Benefits would be granted gradually, `per_period` amount every `period` /// of blocks after `start`. -#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)] pub struct VestingSchedule { /// Vesting starting block pub start: BlockNumber, diff --git a/frame/crowdloan-rewards/src/lib.rs b/frame/crowdloan-rewards/src/lib.rs index 2cb481053ce..245dfaf9f22 100644 --- a/frame/crowdloan-rewards/src/lib.rs +++ b/frame/crowdloan-rewards/src/lib.rs @@ -81,7 +81,7 @@ pub mod pallet { use super::models::{EcdsaSignature, EthereumAddress, Proof, RemoteAccount}; - #[derive(Encode, Decode, PartialEq, Copy, Clone, TypeInfo)] + #[derive(Encode, Decode, PartialEq, Copy, Clone, MaxEncodedLen, TypeInfo)] pub struct Reward { pub(crate) total: Balance, pub(crate) claimed: Balance, diff --git a/frame/crowdloan-rewards/src/models.rs b/frame/crowdloan-rewards/src/models.rs index 157b15b7a16..627bffa8852 100644 --- a/frame/crowdloan-rewards/src/models.rs +++ b/frame/crowdloan-rewards/src/models.rs @@ -1,4 +1,4 @@ -use codec::{Decode, Encode}; +use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_runtime::{MultiSignature, RuntimeDebug}; @@ -8,14 +8,14 @@ pub enum Proof { Ethereum(EcdsaSignature), } -#[derive(Hash, Clone, PartialEq, Eq, RuntimeDebug, Encode, Decode, TypeInfo)] +#[derive(Hash, Clone, PartialEq, Eq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo)] #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] pub enum RemoteAccount { RelayChain(AccountId), Ethereum(EthereumAddress), } -#[derive(Hash, Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)] +#[derive(Hash, Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, MaxEncodedLen, TypeInfo)] pub struct EthereumAddress(pub [u8; 20]); #[cfg(feature = "std")] diff --git a/frame/lending/src/lib.rs b/frame/lending/src/lib.rs index 5d8efda1f23..961dd36bf23 100644 --- a/frame/lending/src/lib.rs +++ b/frame/lending/src/lib.rs @@ -103,7 +103,7 @@ pub mod pallet { ::LiquidationStrategyId, >; - #[derive(Default, Debug, Copy, Clone, Encode, Decode, PartialEq, TypeInfo)] + #[derive(Default, Debug, Copy, Clone, Encode, Decode, PartialEq, MaxEncodedLen, TypeInfo)] #[repr(transparent)] pub struct MarketIndex(u32); diff --git a/frame/liquidations/src/lib.rs b/frame/liquidations/src/lib.rs index d5dd25d043c..36e2579730f 100644 --- a/frame/liquidations/src/lib.rs +++ b/frame/liquidations/src/lib.rs @@ -155,7 +155,7 @@ pub mod pallet { } } - #[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq)] + #[derive(Clone, Debug, PartialEq, Encode, Decode, TypeInfo)] pub enum LiquidationStrategyConfiguration { DutchAuction(TimeReleaseFunction), UniswapV2 { slippage: Perquintill }, diff --git a/frame/mosaic/src/lib.rs b/frame/mosaic/src/lib.rs index e46c110d2d7..b232a9bb022 100644 --- a/frame/mosaic/src/lib.rs +++ b/frame/mosaic/src/lib.rs @@ -85,7 +85,7 @@ pub mod pallet { Outgoing, } - #[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq)] + #[derive(Clone, Debug, Encode, Decode, MaxEncodedLen, TypeInfo, PartialEq)] pub struct AssetInfo { pub last_mint_block: BlockNumber, pub budget: Balance, @@ -93,7 +93,7 @@ pub mod pallet { pub penalty_decayer: Decayer, } - #[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq)] + #[derive(Clone, Debug, Encode, Decode, MaxEncodedLen, TypeInfo, PartialEq)] pub struct NetworkInfo { pub enabled: bool, pub max_transfer_size: Balance, diff --git a/frame/mosaic/src/relayer.rs b/frame/mosaic/src/relayer.rs index 54620e8c908..5c1d7d9beb6 100644 --- a/frame/mosaic/src/relayer.rs +++ b/frame/mosaic/src/relayer.rs @@ -2,7 +2,7 @@ use frame_support::pallet_prelude::*; /// A wrapper around the `Relayer` configuration which forces the user to respect the TTL and update /// the relayer `AccountId` if mandated. -#[derive(Decode, Encode, TypeInfo)] +#[derive(Decode, Encode, MaxEncodedLen, TypeInfo)] pub struct StaleRelayer { relayer: RelayerConfig, } @@ -22,7 +22,7 @@ impl StaleRelayer { } /// Configuration for the relayer account. -#[derive(PartialEq, Eq, Debug, Decode, Encode, TypeInfo)] +#[derive(PartialEq, Eq, Debug, Decode, Encode, MaxEncodedLen, TypeInfo)] pub struct RelayerConfig { /// Current AccountId used by the relayer. current: AccountId, @@ -45,7 +45,7 @@ impl From> } /// Next relayer configuration to be used. -#[derive(PartialEq, Eq, Debug, Decode, Encode, TypeInfo)] +#[derive(PartialEq, Eq, Debug, Decode, Encode, MaxEncodedLen, TypeInfo)] pub struct Next { ttl: BlockNumber, account: AccountId, diff --git a/frame/vault/src/capabilities.rs b/frame/vault/src/capabilities.rs index 0615d328862..fc9ae1481da 100644 --- a/frame/vault/src/capabilities.rs +++ b/frame/vault/src/capabilities.rs @@ -5,7 +5,7 @@ use scale_info::TypeInfo; bitflags! { /// Capabilities (or more accurately, `incapabilities`) restrict functionality of specific vault /// instances. - #[derive(Encode, Decode, TypeInfo)] + #[derive(Encode, Decode, MaxEncodedLen, TypeInfo)] pub struct Capabilities: u32 { /// Tomb-stoning a vault is schedules it for deletion. const TOMBSTONED = 0b000000001; diff --git a/frame/vault/src/models.rs b/frame/vault/src/models.rs index 462456b9d55..d2fca912903 100644 --- a/frame/vault/src/models.rs +++ b/frame/vault/src/models.rs @@ -4,7 +4,7 @@ use frame_support::pallet_prelude::*; use scale_info::TypeInfo; use sp_runtime::Perquintill; -#[derive(Copy, Clone, Encode, Decode, Default, Debug, PartialEq, TypeInfo)] +#[derive(Copy, Clone, Encode, Decode, Default, Debug, PartialEq, MaxEncodedLen, TypeInfo)] pub struct VaultInfo { pub asset_id: CurrencyId, pub lp_token_id: CurrencyId, From 0d5f2f899726b6af1f3cac2305b49b663fe56e09 Mon Sep 17 00:00:00 2001 From: Andrey Orlov Date: Wed, 2 Feb 2022 19:09:38 +0400 Subject: [PATCH 2/2] Formatting --- frame/crowdloan-rewards/src/models.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frame/crowdloan-rewards/src/models.rs b/frame/crowdloan-rewards/src/models.rs index 627bffa8852..f357d4ab22a 100644 --- a/frame/crowdloan-rewards/src/models.rs +++ b/frame/crowdloan-rewards/src/models.rs @@ -15,7 +15,9 @@ pub enum RemoteAccount { Ethereum(EthereumAddress), } -#[derive(Hash, Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, MaxEncodedLen, TypeInfo)] +#[derive( + Hash, Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, MaxEncodedLen, TypeInfo, +)] pub struct EthereumAddress(pub [u8; 20]); #[cfg(feature = "std")]