Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Contracts: expose charge_storage to chain_extension (#14712)
Browse files Browse the repository at this point in the history
* Contracts: expose charge_storage to chain_extension

* fix typo

* export Diff
  • Loading branch information
pgherveou authored Aug 17, 2023
1 parent ecd503d commit 0cdf702
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion frame/contracts/src/chain_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 8 additions & 1 deletion frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::unsafe_debug::ExecutionObserver;
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,
Expand Down Expand Up @@ -274,6 +274,9 @@ pub trait Ext: sealing::Sealed {
/// Get a mutable reference to the nested gas meter.
fn gas_meter_mut(&mut self) -> &mut GasMeter<Self::T>;

/// 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.
Expand Down Expand Up @@ -1451,6 +1454,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
Expand Down
1 change: 1 addition & 0 deletions frame/contracts/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ mod tests {
fn gas_meter_mut(&mut self) -> &mut GasMeter<Self::T> {
&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
Expand Down

0 comments on commit 0cdf702

Please sign in to comment.