diff --git a/cumulus/polkadot-parachains/canvas-kusama/src/contracts.rs b/cumulus/polkadot-parachains/canvas-kusama/src/contracts.rs new file mode 100644 index 0000000000..5f43383555 --- /dev/null +++ b/cumulus/polkadot-parachains/canvas-kusama/src/contracts.rs @@ -0,0 +1,54 @@ +use crate::{ + constants::currency::deposit, Balance, Balances, Call, Event, RandomnessCollectiveFlip, + Runtime, RuntimeBlockWeights, Timestamp, +}; +use frame_support::{parameter_types, traits::Nothing, weights::Weight}; +use pallet_contracts::{ + weights::{SubstrateWeight, WeightInfo}, + Config, DefaultAddressGenerator, Frame, Schedule, +}; +pub use parachains_common::AVERAGE_ON_INITIALIZE_RATIO; + +// Prints debug output of the `contracts` pallet to stdout if the node is +// started with `-lruntime::contracts=debug`. +pub const CONTRACTS_DEBUG_OUTPUT: bool = true; + +parameter_types! { + pub const DepositPerItem: Balance = deposit(1, 0); + pub const DepositPerByte: Balance = deposit(0, 1); + // The lazy deletion runs inside on_initialize. + pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO * + RuntimeBlockWeights::get().max_block; + // The weight needed for decoding the queue should be less or equal than a fifth + // of the overall weight dedicated to the lazy deletion. + pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / ( + ::WeightInfo::on_initialize_per_queue_item(1) - + ::WeightInfo::on_initialize_per_queue_item(0) + )) / 5) as u32; + pub MySchedule: Schedule = Default::default(); +} + +impl Config for Runtime { + type Time = Timestamp; + type Randomness = RandomnessCollectiveFlip; + type Currency = Balances; + type Event = Event; + type Call = Call; + /// The safest default is to allow no calls at all. + /// + /// Runtimes should whitelist dispatchables that are allowed to be called from contracts + /// and make sure they are stable. Dispatchables exposed to contracts are not allowed to + /// change because that would break already deployed contracts. The `Call` structure itself + /// is not allowed to change the indices of existing pallets, too. + type CallFilter = Nothing; + type DepositPerItem = DepositPerItem; + type DepositPerByte = DepositPerByte; + type WeightPrice = pallet_transaction_payment::Pallet; + type WeightInfo = SubstrateWeight; + type ChainExtension = (); + type DeletionQueueDepth = DeletionQueueDepth; + type DeletionWeightLimit = DeletionWeightLimit; + type Schedule = MySchedule; + type CallStack = [Frame; 31]; + type AddressGenerator = DefaultAddressGenerator; +} diff --git a/cumulus/polkadot-parachains/canvas-kusama/src/lib.rs b/cumulus/polkadot-parachains/canvas-kusama/src/lib.rs index deb6f3576b..e8a3b946fc 100644 --- a/cumulus/polkadot-parachains/canvas-kusama/src/lib.rs +++ b/cumulus/polkadot-parachains/canvas-kusama/src/lib.rs @@ -22,6 +22,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod constants; +mod contracts; mod xcm_config; use sp_api::impl_runtime_apis; @@ -41,10 +42,10 @@ use sp_version::RuntimeVersion; use constants::{currency::*, fee::WeightToFee}; use frame_support::{ construct_runtime, parameter_types, - traits::{Everything, Nothing}, + traits::{ConstU128, ConstU16, ConstU32, ConstU64, ConstU8, Everything}, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight}, - DispatchClass, Weight, + DispatchClass, }, PalletId, }; @@ -60,8 +61,10 @@ use xcm_config::CollatorSelectionUpdateOrigin; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; +#[cfg(feature = "try-runtime")] +use frame_support::weights::Weight; + // Polkadot imports -use pallet_contracts::weights::WeightInfo; use polkadot_runtime_common::{BlockHashCount, RocksDbWeight, SlowAdjustingFeeUpdate}; /// The address format for describing accounts. @@ -96,10 +99,6 @@ pub type Executive = frame_executive::Executive< AllPalletsWithSystem, >; -// Prints debug output of the `contracts` pallet to stdout if the node is -// started with `-lruntime::contracts=debug`. -pub const CONTRACTS_DEBUG_OUTPUT: bool = true; - impl_opaque_keys! { pub struct SessionKeys { pub aura: Aura, @@ -146,7 +145,6 @@ parameter_types! { }) .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) .build_or_panic(); - pub const SS58Prefix: u8 = 42; } // Configure FRAME pallets to include in runtime. @@ -172,67 +170,48 @@ impl frame_system::Config for Runtime { type OnKilledAccount = (); type AccountData = pallet_balances::AccountData; type SystemWeightInfo = frame_system::weights::SubstrateWeight; - type SS58Prefix = SS58Prefix; + type SS58Prefix = ConstU16<42>; type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -parameter_types! { - pub const MinimumPeriod: u64 = SLOT_DURATION / 2; + type MaxConsumers = ConstU32<16>; } impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; type OnTimestampSet = (); - type MinimumPeriod = MinimumPeriod; + type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>; type WeightInfo = pallet_timestamp::weights::SubstrateWeight; } -parameter_types! { - pub const UncleGenerations: u32 = 0; -} - impl pallet_authorship::Config for Runtime { type FindAuthor = pallet_session::FindAccountFromAuthorIndex; - type UncleGenerations = UncleGenerations; + type UncleGenerations = ConstU32<0>; type FilterUncle = (); type EventHandler = (CollatorSelection,); } -parameter_types! { - pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; - pub const MaxLocks: u32 = 50; - pub const MaxReserves: u32 = 50; -} - impl pallet_balances::Config for Runtime { - type MaxLocks = MaxLocks; + type MaxLocks = ConstU32<50>; /// The type for recording an account's balance. type Balance = Balance; /// The ubiquitous event type. type Event = Event; type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; + type ExistentialDeposit = ConstU128; type AccountStore = System; type WeightInfo = pallet_balances::weights::SubstrateWeight; - type MaxReserves = MaxReserves; + type MaxReserves = ConstU32<50>; type ReserveIdentifier = [u8; 8]; } -parameter_types! { - /// Relay Chain `TransactionByteFee` / 10 - pub const TransactionByteFee: Balance = 1 * MILLICENTS; - pub const OperationalFeeMultiplier: u8 = 5; -} - impl pallet_transaction_payment::Config for Runtime { type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter>; - type TransactionByteFee = TransactionByteFee; + /// Relay Chain `TransactionByteFee` / 10 + type TransactionByteFee = ConstU128; type WeightToFee = WeightToFee; type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; - type OperationalFeeMultiplier = OperationalFeeMultiplier; + type OperationalFeeMultiplier = ConstU8<5>; } parameter_types! { @@ -240,7 +219,6 @@ parameter_types! { pub const DepositBase: Balance = deposit(1, 88); // Additional storage item size of 32 bytes. pub const DepositFactor: Balance = deposit(0, 32); - pub const MaxSignatories: u16 = 100; } impl pallet_multisig::Config for Runtime { @@ -249,7 +227,7 @@ impl pallet_multisig::Config for Runtime { type Currency = Balances; type DepositBase = DepositBase; type DepositFactor = DepositFactor; - type MaxSignatories = MaxSignatories; + type MaxSignatories = ConstU16<100>; type WeightInfo = pallet_multisig::weights::SubstrateWeight; } @@ -260,60 +238,15 @@ impl pallet_utility::Config for Runtime { type WeightInfo = pallet_utility::weights::SubstrateWeight; } -parameter_types! { - pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4; - pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4; -} - impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; type OnSystemEvent = (); type SelfParaId = parachain_info::Pallet; type DmpMessageHandler = DmpQueue; - type ReservedDmpWeight = ReservedDmpWeight; + type ReservedDmpWeight = ConstU64<{ MAXIMUM_BLOCK_WEIGHT / 4 }>; type OutboundXcmpMessageSource = XcmpQueue; type XcmpMessageHandler = XcmpQueue; - type ReservedXcmpWeight = ReservedXcmpWeight; -} - -parameter_types! { - pub const DepositPerItem: Balance = deposit(1, 0); - pub const DepositPerByte: Balance = deposit(0, 1); - // The lazy deletion runs inside on_initialize. - pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO * - RuntimeBlockWeights::get().max_block; - // The weight needed for decoding the queue should be less or equal than a fifth - // of the overall weight dedicated to the lazy deletion. - pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / ( - ::WeightInfo::on_initialize_per_queue_item(1) - - ::WeightInfo::on_initialize_per_queue_item(0) - )) / 5) as u32; - pub Schedule: pallet_contracts::Schedule = Default::default(); -} - -impl pallet_contracts::Config for Runtime { - type Time = Timestamp; - type Randomness = RandomnessCollectiveFlip; - type Currency = Balances; - type Event = Event; - type Call = Call; - /// The safest default is to allow no calls at all. - /// - /// Runtimes should whitelist dispatchables that are allowed to be called from contracts - /// and make sure they are stable. Dispatchables exposed to contracts are not allowed to - /// change because that would break already deployed contracts. The `Call` structure itself - /// is not allowed to change the indices of existing pallets, too. - type CallFilter = Nothing; - type DepositPerItem = DepositPerItem; - type DepositPerByte = DepositPerByte; - type WeightPrice = pallet_transaction_payment::Pallet; - type WeightInfo = pallet_contracts::weights::SubstrateWeight; - type ChainExtension = (); - type DeletionQueueDepth = DeletionQueueDepth; - type DeletionWeightLimit = DeletionWeightLimit; - type Schedule = Schedule; - type CallStack = [pallet_contracts::Frame; 31]; - type AddressGenerator = pallet_contracts::DefaultAddressGenerator; + type ReservedXcmpWeight = ConstU64<{ MAXIMUM_BLOCK_WEIGHT / 4 }>; } impl pallet_randomness_collective_flip::Config for Runtime {} @@ -325,7 +258,6 @@ impl cumulus_pallet_aura_ext::Config for Runtime {} parameter_types! { pub const Period: u32 = 6 * HOURS; pub const Offset: u32 = 0; - pub const MaxAuthorities: u32 = 100_000; } impl pallet_session::Config for Runtime { @@ -345,15 +277,11 @@ impl pallet_session::Config for Runtime { impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; type DisabledValidators = (); - type MaxAuthorities = MaxAuthorities; + type MaxAuthorities = ConstU32<100_000>; } parameter_types! { pub const PotId: PalletId = PalletId(*b"PotStake"); - pub const MaxCandidates: u32 = 1000; - pub const MinCandidates: u32 = 5; - pub const SessionLength: BlockNumber = 6 * HOURS; - pub const MaxInvulnerables: u32 = 100; } impl pallet_collator_selection::Config for Runtime { @@ -361,9 +289,9 @@ impl pallet_collator_selection::Config for Runtime { type Currency = Balances; type UpdateOrigin = CollatorSelectionUpdateOrigin; type PotId = PotId; - type MaxCandidates = MaxCandidates; - type MinCandidates = MinCandidates; - type MaxInvulnerables = MaxInvulnerables; + type MaxCandidates = ConstU32<1000>; + type MinCandidates = ConstU32<5>; + type MaxInvulnerables = ConstU32<100>; // should be a multiple of session or things will get inconsistent type KickThreshold = Period; type ValidatorId = ::AccountId; @@ -558,7 +486,15 @@ impl pallet_contracts_rpc_runtime_api::ContractsApi, input_data: Vec, ) -> pallet_contracts_primitives::ContractExecResult { - Contracts::bare_call(origin, dest, value, gas_limit, storage_deposit_limit, input_data, CONTRACTS_DEBUG_OUTPUT) + Contracts::bare_call( + origin, + dest, + value, + gas_limit, + storage_deposit_limit, + input_data, + contracts::CONTRACTS_DEBUG_OUTPUT, + ) } fn instantiate( @@ -569,17 +505,24 @@ impl pallet_contracts_rpc_runtime_api::ContractsApi, data: Vec, salt: Vec, - ) -> pallet_contracts_primitives::ContractInstantiateResult - { - Contracts::bare_instantiate(origin, value, gas_limit, storage_deposit_limit, code, data, salt, CONTRACTS_DEBUG_OUTPUT) + ) -> pallet_contracts_primitives::ContractInstantiateResult { + Contracts::bare_instantiate( + origin, + value, + gas_limit, + storage_deposit_limit, + code, + data, + salt, + contracts::CONTRACTS_DEBUG_OUTPUT, + ) } fn upload_code( origin: AccountId, code: Vec, storage_deposit_limit: Option, - ) -> pallet_contracts_primitives::CodeUploadResult - { + ) -> pallet_contracts_primitives::CodeUploadResult { Contracts::bare_upload_code(origin, code, storage_deposit_limit) }