contracts: Move Schedule from Storage to Config (#8773)

* Move `Schedule` from Storage to Config

* Updated CHANGELOG

* Fix nits from review

* Fix migration

* Print the debug buffer as tracing message

* Use `debug` instead of `trace` and update README

* Add additional assert to test

* Rename `schedule_version` to `instruction_weights_version`

* Fixed typo

* Added more comments to wat fixtures

* Add clarification for the `debug_message` field
This commit is contained in:
Alexander Theißen
2021-05-13 21:56:11 +02:00
committed by GitHub
parent 3c0270fe57
commit 1ac95b6ba6
23 changed files with 1465 additions and 1056 deletions
+2 -40
View File
@@ -343,12 +343,6 @@ impl<'a, T: Config> ContractModule<'a, T> {
.get(*type_idx as usize)
.ok_or_else(|| "validation: import entry points to a non-existent type")?;
// We disallow importing `seal_println` unless debug features are enabled,
// which should only be allowed on a dev chain
if !self.schedule.enable_println && import.field().as_bytes() == b"seal_println" {
return Err("module imports `seal_println` but debug features disabled");
}
if !T::ChainExtension::enabled() &&
import.field().as_bytes() == b"seal_call_chain_extension"
{
@@ -439,7 +433,7 @@ fn do_preparation<C: ImportSatisfyCheck, T: Config>(
schedule,
)?;
Ok(PrefabWasmModule {
schedule_version: schedule.version,
instruction_weights_version: schedule.instruction_weights.version,
initial,
maximum,
_reserved: None,
@@ -505,7 +499,7 @@ pub mod benchmarking {
let contract_module = ContractModule::new(&original_code, schedule)?;
let memory_limits = get_memory_limits(contract_module.scan_imports::<()>(&[])?, schedule)?;
Ok(PrefabWasmModule {
schedule_version: schedule.version,
instruction_weights_version: schedule.instruction_weights.version,
initial: memory_limits.0,
maximum: memory_limits.1,
_reserved: None,
@@ -547,8 +541,6 @@ mod tests {
// new version of nop with other data type for argumebt
[seal1] nop(_ctx, _unused: i32) => { unreachable!(); },
[seal0] seal_println(_ctx, _ptr: u32, _len: u32) => { unreachable!(); },
);
}
@@ -938,36 +930,6 @@ mod tests {
"#,
Err("module imports a non-existent function")
);
prepare_test!(seal_println_debug_disabled,
r#"
(module
(import "seal0" "seal_println" (func $seal_println (param i32 i32)))
(func (export "call"))
(func (export "deploy"))
)
"#,
Err("module imports `seal_println` but debug features disabled")
);
#[test]
fn seal_println_debug_enabled() {
let wasm = wat::parse_str(
r#"
(module
(import "seal0" "seal_println" (func $seal_println (param i32 i32)))
(func (export "call"))
(func (export "deploy"))
)
"#
).unwrap();
let mut schedule = Schedule::default();
schedule.enable_println = true;
let r = do_preparation::<env::Test, crate::tests::Test>(wasm, &schedule);
assert_matches::assert_matches!(r, Ok(_));
}
}
mod entrypoints {