Skip to content
Merged
Changes from all commits
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
chore: set a runtime CALL_ENUM_MAX_SIZE
  • Loading branch information
dandanlen committed May 23, 2022
commit d0f382e5e7d44fae4db4d3534b795d4f8077db94
32 changes: 32 additions & 0 deletions state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,3 +777,35 @@ impl_runtime_apis! {
}
}
}

#[cfg(test)]
mod test {
use super::*;

const CALL_ENUM_MAX_SIZE: usize = 320;

// Introduced from polkdadot
#[test]
fn call_size() {
assert!(
core::mem::size_of::<Call>() <= CALL_ENUM_MAX_SIZE,
r"
Polkadot suggests a 230 byte limit for the size of the Call type. We use {} but this runtime's call size
is {}. If this test fails then you have just added a call variant that exceed the limit.

Congratulations!

Maybe consider boxing some calls to reduce their size. Otherwise, increasing the CALL_ENUM_MAX_SIZE is
acceptable (within reason). The issue is that the enum always uses max(enum_size) of memory, even if your
are using a smaller variant. Note this is irrelevant from a SCALE-encoding POV, it only affects the size of
the enum on the stack.
Context:
- https://github.com/paritytech/substrate/pull/9418
- https://rust-lang.github.io/rust-clippy/master/#large_enum_variant
- https://fasterthanli.me/articles/peeking-inside-a-rust-enum
",
CALL_ENUM_MAX_SIZE,
core::mem::size_of::<Call>(),
);
}
}