Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,6 @@ parameter_types! {
pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * DAYS);
pub const SurchargeReward: Balance = 150 * MILLICENTS;
pub const SignedClaimHandicap: u32 = 2;
pub const MaxDepth: u32 = 32;
pub const MaxValueSize: u32 = 16 * 1024;
// The lazy deletion runs inside on_initialize.
pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO *
Expand All @@ -809,7 +808,7 @@ impl pallet_contracts::Config for Runtime {
type DepositPerStorageItem = DepositPerStorageItem;
type RentFraction = RentFraction;
type SurchargeReward = SurchargeReward;
type MaxDepth = MaxDepth;
type CallStack = [pallet_contracts::Frame<Self>; 31];
type MaxValueSize = MaxValueSize;
type WeightPrice = pallet_transaction_payment::Module<Self>;
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
Expand Down
1 change: 1 addition & 0 deletions frame/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ log = { version = "0.4", default-features = false }
parity-wasm = { version = "0.42", default-features = false }
pwasm-utils = { version = "0.17", default-features = false }
serde = { version = "1", optional = true, features = ["derive"] }
smallvec = { version = "1", default-features = false, features = ["const_generics"] }
wasmi-validation = { version = "0.4", default-features = false }

# Only used in benchmarking to generate random contract code
Expand Down
28 changes: 16 additions & 12 deletions frame/contracts/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,17 @@ where

/// Store the supplied storage items into this contracts storage.
fn store(&self, items: &Vec<(StorageKey, Vec<u8>)>) -> Result<(), &'static str> {
let info = self.alive_info()?;
let mut info = self.alive_info()?;
for item in items {
Storage::<T>::write(
&self.account_id,
&info.trie_id,
<System<T>>::block_number(),
&mut info,
&item.0,
Some(item.1.clone()),
)
.map_err(|_| "Failed to write storage to restoration dest")?;
}
<ContractInfoOf<T>>::insert(&self.account_id, ContractInfo::Alive(info.clone()));
Ok(())
}

Expand Down Expand Up @@ -1148,16 +1149,17 @@ benchmarks! {
.. Default::default()
});
let instance = Contract::<T>::new(code, vec![], Endow::Max)?;
let trie_id = instance.alive_info()?.trie_id;
let mut info = instance.alive_info()?;
for key in keys {
Storage::<T>::write(
&instance.account_id,
&trie_id,
<System<T>>::block_number(),
&mut info,
key.as_slice().try_into().map_err(|e| "Key has wrong length")?,
Some(vec![42; T::MaxValueSize::get() as usize])
)
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, ContractInfo::Alive(info.clone()));
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::max_value(), vec![])

Expand Down Expand Up @@ -1193,16 +1195,17 @@ benchmarks! {
.. Default::default()
});
let instance = Contract::<T>::new(code, vec![], Endow::Max)?;
let trie_id = instance.alive_info()?.trie_id;
let mut info = instance.alive_info()?;
for key in keys {
Storage::<T>::write(
&instance.account_id,
&trie_id,
<System<T>>::block_number(),
&mut info,
key.as_slice().try_into().map_err(|e| "Key has wrong length")?,
Some(vec![])
)
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, ContractInfo::Alive(info.clone()));
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::max_value(), vec![])

Expand Down Expand Up @@ -1238,14 +1241,15 @@ benchmarks! {
.. Default::default()
});
let instance = Contract::<T>::new(code, vec![], Endow::Max)?;
let trie_id = instance.alive_info()?.trie_id;
let mut info = instance.alive_info()?;
Storage::<T>::write(
&instance.account_id,
&trie_id,
<System<T>>::block_number(),
&mut info,
key.as_slice().try_into().map_err(|e| "Key has wrong length")?,
Some(vec![42u8; (n * 1024) as usize])
)
.map_err(|_| "Failed to write to storage during setup.")?;
<ContractInfoOf<T>>::insert(&instance.account_id, ContractInfo::Alive(info.clone()));
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::max_value(), vec![])

Expand Down
6 changes: 3 additions & 3 deletions frame/contracts/src/chain_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

use crate::{
Error,
wasm::{Runtime, RuntimeToken},
wasm::{Runtime, RuntimeCosts},
};
use codec::Decode;
use frame_support::weights::Weight;
Expand Down Expand Up @@ -171,7 +171,7 @@ where
///
/// Weight is synonymous with gas in substrate.
pub fn charge_weight(&mut self, amount: Weight) -> Result<()> {
self.inner.runtime.charge_gas(RuntimeToken::ChainExtension(amount)).map(|_| ())
self.inner.runtime.charge_gas(RuntimeCosts::ChainExtension(amount)).map(|_| ())
}

/// Grants access to the execution environment of the current contract call.
Expand Down Expand Up @@ -349,7 +349,7 @@ where
buffer,
allow_skip,
|len| {
weight_per_byte.map(|w| RuntimeToken::ChainExtension(w.saturating_mul(len.into())))
weight_per_byte.map(|w| RuntimeCosts::ChainExtension(w.saturating_mul(len.into())))
},
)
}
Expand Down
Loading