From 37169d4ce3880f8ba4253827047cb74794dea8d8 Mon Sep 17 00:00:00 2001 From: Peter White Date: Sat, 2 Mar 2024 14:46:20 -0700 Subject: [PATCH 1/2] feat: add secure weight charging for pop-api extension --- runtime/src/extensions/pop_api_extension.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs index 7e3b77c5..c3f1bf21 100644 --- a/runtime/src/extensions/pop_api_extension.rs +++ b/runtime/src/extensions/pop_api_extension.rs @@ -60,26 +60,24 @@ where { let mut env = env.buf_in_buf_out(); - // charge max weight before reading contract memory - // TODO: causing "1010: block limits exhausted" error - // let weight_limit = env.ext().gas_meter().gas_left(); - // let charged_weight = env.charge_weight(weight_limit)?; - - // TODO: debug_message weight is a good approximation of the additional overhead of going - // from contract layer to substrate layer. - // input length let len = env.in_len(); let call: ::RuntimeCall = env.read_as_unbounded(len)?; + // conservative weight estimate for deserializing the input. The actual weight is less and should utilize a custom benchmark + let base_weight: Weight = T::DbWeight::get().reads(len.into()); + + // weight for dispatching the call + let dispatch_weight = call.get_dispatch_info().weight; + + // charge weight for the cost of the deserialization and the dispatch + let _ = env.charge_weight(base_weight.saturating_add(dispatch_weight))?; + log::debug!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); let sender = env.ext().caller(); let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); - // TODO: uncomment once charged_weight is fixed - // let actual_weight = call.get_dispatch_info().weight; - // env.adjust_weight(charged_weight, actual_weight); let result = call.dispatch(origin); match result { Ok(info) => { From 275f487595779c54b00f977acec000c3e65a6190 Mon Sep 17 00:00:00 2001 From: Peter White Date: Mon, 4 Mar 2024 09:47:34 -0700 Subject: [PATCH 2/2] chore: update zombienet config --- networks/rococo.toml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/networks/rococo.toml b/networks/rococo.toml index 41fd5941..4f581f5e 100644 --- a/networks/rococo.toml +++ b/networks/rococo.toml @@ -4,7 +4,7 @@ node_spawn_timeout = 300 [relaychain] chain = "rococo-local" -default_command = "./bin/polkadot" +default_command = "./cache/polkadot-v1.7.1" [[relaychain.nodes]] name = "alice" @@ -19,4 +19,7 @@ id = 909 default_command = "./target/release/pop-node" [[parachains.collators]] - name = "pop" \ No newline at end of file + name = "pop" + command = "./target/release/pop-node" + port = 9944 + args = ["-lruntime::contracts=debug", "-lpopapi::extension=debug"] \ No newline at end of file