From 3742d7562761541e2fa22ef7816f65d2ada4acb1 Mon Sep 17 00:00:00 2001 From: pgherveou Date: Fri, 4 Aug 2023 15:51:27 +0200 Subject: [PATCH 1/3] Contracts: expose charge_storage to chain_extension --- frame/contracts/src/exec.rs | 11 +++++++++-- frame/contracts/src/wasm/mod.rs | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index 6203b31f67a5b..b3d506bd4c560 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -17,7 +17,7 @@ use crate::{ gas::GasMeter, - storage::{self, DepositAccount, WriteOutcome}, + storage::{self, meter::Diff, DepositAccount, WriteOutcome}, BalanceOf, CodeHash, CodeInfo, CodeInfoOf, Config, ContractInfo, ContractInfoOf, DebugBufferVec, Determinism, Error, Event, Nonce, Origin, Pallet as Contracts, Schedule, System, WasmBlob, LOG_TARGET, @@ -266,12 +266,15 @@ pub trait Ext: sealing::Sealed { /// Get a reference to the schedule used by the current call. fn schedule(&self) -> &Schedule; - /// Get an immutable reference to the nested gas meter. + /// Gean immutable reference to the nested gas meter. fn gas_meter(&self) -> &GasMeter; /// Get a mutable reference to the nested gas meter. fn gas_meter_mut(&mut self) -> &mut GasMeter; + /// Charges `diff` from the meter. + fn charge_storage(&mut self, diff: &Diff); + /// Append a string to the debug buffer. /// /// It is added as-is without any additional new line. @@ -1429,6 +1432,10 @@ where &mut self.top_frame_mut().nested_gas } + fn charge_storage(&mut self, diff: &Diff) { + self.top_frame_mut().nested_storage.charge(diff) + } + fn append_debug_buffer(&mut self, msg: &str) -> bool { if let Some(buffer) = &mut self.debug_message { buffer diff --git a/frame/contracts/src/wasm/mod.rs b/frame/contracts/src/wasm/mod.rs index 551bfba3fbe6f..291f39f7fa797 100644 --- a/frame/contracts/src/wasm/mod.rs +++ b/frame/contracts/src/wasm/mod.rs @@ -701,6 +701,7 @@ mod tests { fn gas_meter_mut(&mut self) -> &mut GasMeter { &mut self.gas_meter } + fn charge_storage(&mut self, _diff: &crate::storage::meter::Diff) {} fn append_debug_buffer(&mut self, msg: &str) -> bool { self.debug_buffer.extend(msg.as_bytes()); true From 67e82add8e520606596a36b46f2749a6f6ae1490 Mon Sep 17 00:00:00 2001 From: pgherveou Date: Fri, 4 Aug 2023 15:52:59 +0200 Subject: [PATCH 2/3] fix typo --- frame/contracts/src/exec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index b3d506bd4c560..a0c3050e34353 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -266,7 +266,7 @@ pub trait Ext: sealing::Sealed { /// Get a reference to the schedule used by the current call. fn schedule(&self) -> &Schedule; - /// Gean immutable reference to the nested gas meter. + /// Get an immutable reference to the nested gas meter. fn gas_meter(&self) -> &GasMeter; /// Get a mutable reference to the nested gas meter. From 090ea08da61213f2d5545b21d45b9d2291c9551c Mon Sep 17 00:00:00 2001 From: pgherveou Date: Sat, 5 Aug 2023 17:31:31 +0200 Subject: [PATCH 3/3] export Diff --- frame/contracts/src/chain_extension.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/contracts/src/chain_extension.rs b/frame/contracts/src/chain_extension.rs index 6d1f3df90f23e..664504d207f3a 100644 --- a/frame/contracts/src/chain_extension.rs +++ b/frame/contracts/src/chain_extension.rs @@ -79,7 +79,7 @@ use frame_support::weights::Weight; use sp_runtime::DispatchError; use sp_std::{marker::PhantomData, vec::Vec}; -pub use crate::{exec::Ext, gas::ChargedAmount, Config}; +pub use crate::{exec::Ext, gas::ChargedAmount, storage::meter::Diff, Config}; pub use frame_system::Config as SysConfig; pub use pallet_contracts_primitives::ReturnFlags;