Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lowered max call depth to satisfy mem limits
  • Loading branch information
agryaznov committed Jan 16, 2023
commit 9e387356b273d1efea30a18897c97a90560f7781
15 changes: 5 additions & 10 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,11 @@ pub mod pallet {
}

fn integrity_test() {
// Total runtime memory is expected to have 1Gb upper limit
const MAX_RUNTIME_MEM: u32 = 1024 * 1024 * 1024;
// Total runtime memory is expected to have 128Mb upper limit
const MAX_RUNTIME_MEM: u32 = 1024 * 1024 * 128;
// Memory limits for a single contract:
// Value stack size: 1Mb per contract, default defined in wasmi
const STACK_MAX_SIZE: u32 = 1024 * 1024;
const MAX_STACK_SIZE: u32 = 1024 * 1024;
// Heap limit is normally 16 mempages of 64kb each = 1Mb per contract
let max_heap_size = T::Schedule::get().limits.max_memory_size();
let max_call_depth = T::CallStack::size() as u32;
Expand All @@ -413,15 +413,15 @@ pub mod pallet {
//
// This gives us the following formula:
//
// `(MaxCodeLen * 18 * 4 + STACK_MAX_SIZE + heap_max_size) * stack_height <
// `(MaxCodeLen * 18 * 4 + MAX_STACK_SIZE + max_heap_size) * max_call_depth <
// MAX_RUNTIME_MEM/2`
//
// Hence the upper limit for the `MaxCodeLen` can be defined as follows:
let code_len_limit = MAX_RUNTIME_MEM
.saturating_div(2)
.saturating_div(max_call_depth)
.saturating_sub(max_heap_size)
.saturating_sub(STACK_MAX_SIZE)
.saturating_sub(MAX_STACK_SIZE)
.saturating_div(18 * 4);

assert!(
Expand All @@ -433,11 +433,6 @@ pub mod pallet {
T::MaxCodeLen::get(),
);

println!(
"size of err_msg is {}",
"Debug message too big (size={}) for debug buffer (bound={})".bytes().len()
);

// Debug buffer should at least be large enough to accomodate a simple error message
const MIN_DEBUG_BUF_SIZE: u32 = 256;
assert!(
Expand Down
4 changes: 0 additions & 4 deletions frame/contracts/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ pub struct Limits {
/// The maximum length of a subject in bytes used for PRNG generation.
pub subject_len: u32,

/// The maximum nesting level of the call stack.
pub call_depth: u32,

/// The maximum size of a storage value and event payload in bytes.
pub payload_len: u32,
}
Expand Down Expand Up @@ -526,7 +523,6 @@ impl Default for Limits {
table_size: 4096,
br_table_size: 256,
subject_len: 32,
call_depth: 32,
payload_len: 16 * 1024,
}
}
Expand Down
4 changes: 2 additions & 2 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type CallFilter = TestFilter;
type CallStack = [Frame<Self>; 31];
type CallStack = [Frame<Self>; 6];
type WeightPrice = Self;
type WeightInfo = ();
type ChainExtension =
Expand All @@ -405,7 +405,7 @@ impl Config for Test {
type DepositPerByte = DepositPerByte;
type DepositPerItem = DepositPerItem;
type AddressGenerator = DefaultAddressGenerator;
type MaxCodeLen = ConstU32<{ 128 * 1024 }>;
type MaxCodeLen = ConstU32<{ 123 * 1024 }>;
type MaxStorageKeyLen = ConstU32<128>;
type UnsafeUnstableInterface = UnstableInterface;
type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>;
Expand Down