Skip to content

Commit

Permalink
Customize schedule with runtime memory limit suitable for development…
Browse files Browse the repository at this point in the history
… node (paritytech#187)

In recent PR
paritytech#182 (comment),
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**.
  • Loading branch information
agryaznov authored and hummusonrails committed Jun 5, 2023
1 parent c3e250f commit 0c0a2d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 12 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: pallet_contracts::Config>() -> pallet_contracts::Schedule<T> {
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! {
Expand Down Expand Up @@ -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<Runtime> = Default::default();
pub Schedule: pallet_contracts::Schedule<Runtime> = schedule::<Runtime>();
pub const DefaultDepositLimit: Balance = deposit(1024, 1024 * 1024);
}

Expand Down Expand Up @@ -350,7 +360,7 @@ impl pallet_contracts::Config for Runtime {
type CallFilter = AllowBalancesCall;
type DepositPerItem = DepositPerItem;
type DepositPerByte = DepositPerByte;
type CallStack = [pallet_contracts::Frame<Self>; 31];
type CallStack = [pallet_contracts::Frame<Self>; 23];
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
type ChainExtension = pallet_assets_chain_extension::substrate::AssetsExtension;
Expand Down

0 comments on commit 0c0a2d2

Please sign in to comment.