From 0c0a2d292c312162a338c7c698e6972a85c70c0f Mon Sep 17 00:00:00 2001 From: Sasha Gryaznov Date: Mon, 29 May 2023 16:25:05 +0300 Subject: [PATCH] Customize schedule with runtime memory limit suitable for development node (#187) In recent PR https://github.com/paritytech/substrate-contracts-node/pull/182#issuecomment-1536514910, the CI step of running `cargo test` was commented out as a dirty workaround for the pallet contracts integrity test failure. The test checks that the pallet configuration is memory safe. So to make the test pass, we enlarge the runtime memory limit in the Schedule. We do this because this development node [allows](https://github.com/paritytech/substrate-contracts-node/blob/8d13ddef3f5c728d1661e79c511a28cef206b298/runtime/src/lib.rs#L367) larger contract size than it is normally allowed in a production running node. This should be fine for the development node where possible security implications could be neglected for the sake of development convenience. **However, please DO NOT do this to your production node config, unless you are sure that the limit you're setting is the real memory limit of your runtime**. --- .gitlab-ci.yml | 2 +- runtime/src/lib.rs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f33b8f4..65a1ba9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -76,7 +76,7 @@ build-linux: <<: *build-refs script: - time cargo build --release - # - time cargo test --release --all + - time cargo test --release --all - mkdir -p ./artifacts/substrate-contracts-node-linux/ - cp target/release/substrate-contracts-node ./artifacts/substrate-contracts-node-linux/substrate-contracts-node diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 21427f5..81ef5d4 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -134,6 +134,16 @@ const fn deposit(items: u32, bytes: u32) -> Balance { (items as Balance * UNIT + (bytes as Balance) * (5 * MILLIUNIT / 100)) / 10 } +fn schedule() -> pallet_contracts::Schedule { + pallet_contracts::Schedule { + limits: pallet_contracts::Limits { + runtime_memory: 1024 * 1024 * 1024, + ..Default::default() + }, + ..Default::default() + } +} + impl pallet_insecure_randomness_collective_flip::Config for Runtime {} parameter_types! { @@ -315,7 +325,7 @@ impl pallet_assets::Config for Runtime { parameter_types! { pub const DepositPerItem: Balance = deposit(1, 0); pub const DepositPerByte: Balance = deposit(0, 1); - pub Schedule: pallet_contracts::Schedule = Default::default(); + pub Schedule: pallet_contracts::Schedule = schedule::(); pub const DefaultDepositLimit: Balance = deposit(1024, 1024 * 1024); } @@ -350,7 +360,7 @@ impl pallet_contracts::Config for Runtime { type CallFilter = AllowBalancesCall; type DepositPerItem = DepositPerItem; type DepositPerByte = DepositPerByte; - type CallStack = [pallet_contracts::Frame; 31]; + type CallStack = [pallet_contracts::Frame; 23]; type WeightPrice = pallet_transaction_payment::Pallet; type WeightInfo = pallet_contracts::weights::SubstrateWeight; type ChainExtension = pallet_assets_chain_extension::substrate::AssetsExtension;