mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 19:51:05 +00:00
contracts: Remove ConfigCache (#8047)
* contracts: Remove ConfigCache * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_contracts --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/contracts/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Fixup test Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
This commit is contained in:
committed by
GitHub
parent
dfefa163f8
commit
1b31f7c5d1
@@ -628,7 +628,7 @@ decl_module! {
|
||||
let origin = ensure_signed(origin)?;
|
||||
let mut gas_meter = GasMeter::new(gas_limit);
|
||||
let result = Self::execute_wasm(origin, &mut gas_meter, |ctx, gas_meter| {
|
||||
let executable = PrefabWasmModule::from_storage(code_hash, &ctx.config.schedule)?;
|
||||
let executable = PrefabWasmModule::from_storage(code_hash, &ctx.schedule)?;
|
||||
let result = ctx.instantiate(endowment, gas_meter, executable, data, &salt)
|
||||
.map(|(_address, output)| output)?;
|
||||
Ok(result)
|
||||
@@ -764,6 +764,17 @@ where
|
||||
.collect();
|
||||
UncheckedFrom::unchecked_from(T::Hashing::hash(&buf))
|
||||
}
|
||||
|
||||
/// Subsistence threshold is the extension of the minimum balance (aka existential deposit)
|
||||
/// by the tombstone deposit, required for leaving a tombstone.
|
||||
///
|
||||
/// Rent or any contract initiated balance transfer mechanism cannot make the balance lower
|
||||
/// than the subsistence threshold in order to guarantee that a tombstone is created.
|
||||
///
|
||||
/// The only way to completely kill a contract without a tombstone is calling `seal_terminate`.
|
||||
pub fn subsistence_threshold() -> BalanceOf<T> {
|
||||
T::Currency::minimum_balance().saturating_add(T::TombstoneDeposit::get())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Module<T>
|
||||
@@ -778,8 +789,8 @@ where
|
||||
&mut GasMeter<T>,
|
||||
) -> ExecResult,
|
||||
) -> ExecResult {
|
||||
let cfg = ConfigCache::preload();
|
||||
let mut ctx = ExecutionContext::top_level(origin, &cfg);
|
||||
let schedule = <Module<T>>::current_schedule();
|
||||
let mut ctx = ExecutionContext::top_level(origin, &schedule);
|
||||
func(&mut ctx, gas_meter)
|
||||
}
|
||||
}
|
||||
@@ -875,49 +886,3 @@ decl_storage! {
|
||||
pub DeletionQueue: Vec<storage::DeletedContract>;
|
||||
}
|
||||
}
|
||||
|
||||
/// In-memory cache of configuration values.
|
||||
///
|
||||
/// We assume that these values can't be changed in the
|
||||
/// course of transaction execution.
|
||||
pub struct ConfigCache<T: Config> {
|
||||
pub schedule: Schedule<T>,
|
||||
pub existential_deposit: BalanceOf<T>,
|
||||
pub tombstone_deposit: BalanceOf<T>,
|
||||
pub max_depth: u32,
|
||||
pub max_value_size: u32,
|
||||
}
|
||||
|
||||
impl<T: Config> ConfigCache<T>
|
||||
where
|
||||
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
|
||||
{
|
||||
fn preload() -> ConfigCache<T> {
|
||||
ConfigCache {
|
||||
schedule: <Module<T>>::current_schedule(),
|
||||
existential_deposit: T::Currency::minimum_balance(),
|
||||
tombstone_deposit: T::TombstoneDeposit::get(),
|
||||
max_depth: T::MaxDepth::get(),
|
||||
max_value_size: T::MaxValueSize::get(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Subsistence threshold is the extension of the minimum balance (aka existential deposit) by the
|
||||
/// tombstone deposit, required for leaving a tombstone.
|
||||
///
|
||||
/// Rent or any contract initiated balance transfer mechanism cannot make the balance lower
|
||||
/// than the subsistence threshold in order to guarantee that a tombstone is created.
|
||||
///
|
||||
/// The only way to completely kill a contract without a tombstone is calling `seal_terminate`.
|
||||
pub fn subsistence_threshold(&self) -> BalanceOf<T> {
|
||||
self.existential_deposit.saturating_add(self.tombstone_deposit)
|
||||
}
|
||||
|
||||
/// The same as `subsistence_threshold` but without the need for a preloaded instance.
|
||||
///
|
||||
/// This is for cases where this value is needed in rent calculation rather than
|
||||
/// during contract execution.
|
||||
pub fn subsistence_threshold_uncached() -> BalanceOf<T> {
|
||||
T::Currency::minimum_balance().saturating_add(T::TombstoneDeposit::get())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user