Rename pallet trait Trait to Config (#7599)

* rename Trait to Config

* add test asserting using Trait is still valid.

* fix ui tests
This commit is contained in:
Guillaume Thiolliere
2020-11-30 15:34:54 +01:00
committed by GitHub
parent dd3c84c362
commit 1cbfc9257f
200 changed files with 1767 additions and 1607 deletions
@@ -24,7 +24,7 @@
//! we define this simple definition of a contract that can be passed to `create_code` that
//! compiles it down into a `WasmModule` that can be used as a contract's code.
use crate::Trait;
use crate::Config;
use crate::Module as Contracts;
use parity_wasm::elements::{Instruction, Instructions, FuncBody, ValueType, BlockType};
@@ -87,9 +87,9 @@ pub struct ImportedMemory {
}
impl ImportedMemory {
pub fn max<T: Trait>() -> Self
pub fn max<T: Config>() -> Self
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
let pages = max_pages::<T>();
@@ -105,15 +105,15 @@ pub struct ImportedFunction {
/// A wasm module ready to be put on chain with `put_code`.
#[derive(Clone)]
pub struct WasmModule<T:Trait> {
pub struct WasmModule<T:Config> {
pub code: Vec<u8>,
pub hash: <T::Hashing as Hash>::Output,
memory: Option<ImportedMemory>,
}
impl<T: Trait> From<ModuleDefinition> for WasmModule<T>
impl<T: Config> From<ModuleDefinition> for WasmModule<T>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
fn from(def: ModuleDefinition) -> Self {
@@ -225,9 +225,9 @@ where
}
}
impl<T: Trait> WasmModule<T>
impl<T: Config> WasmModule<T>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
/// Creates a wasm module with an empty `call` and `deploy` function and nothing else.
@@ -483,9 +483,9 @@ pub mod body {
}
/// The maximum amount of pages any contract is allowed to have according to the current `Schedule`.
pub fn max_pages<T: Trait>() -> u32
pub fn max_pages<T: Config>() -> u32
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
Contracts::<T>::current_schedule().limits.memory_pages
@@ -50,7 +50,7 @@ const API_BENCHMARK_BATCHES: u32 = 20;
const INSTR_BENCHMARK_BATCHES: u32 = 1;
/// An instantiated and deployed contract.
struct Contract<T: Trait> {
struct Contract<T: Config> {
caller: T::AccountId,
account_id: T::AccountId,
addr: <T::Lookup as StaticLookup>::Source,
@@ -72,14 +72,14 @@ impl Endow {
/// The maximum amount of balance a caller can transfer without being brought below
/// the existential deposit. This assumes that every caller is funded with the amount
/// returned by `caller_funding`.
fn max<T:Trait>() -> BalanceOf<T> {
fn max<T:Config>() -> BalanceOf<T> {
caller_funding::<T>().saturating_sub(T::Currency::minimum_balance())
}
}
impl<T: Trait> Contract<T>
impl<T: Config> Contract<T>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
/// Create new contract and use a default account id as instantiator.
@@ -115,7 +115,7 @@ where
// storage_size cannot be zero because otherwise a contract that is just above
// the subsistence threshold does not pay rent given a large enough subsistence
// threshold. But we need rent payments to occur in order to benchmark for worst cases.
let storage_size = Config::<T>::subsistence_threshold_uncached()
let storage_size = ConfigCache::<T>::subsistence_threshold_uncached()
.checked_div(&T::RentDepositOffset::get())
.unwrap_or_else(Zero::zero);
@@ -212,16 +212,16 @@ where
/// A `Contract` that was evicted after accumulating some storage.
///
/// This is used to benchmark contract resurrection.
struct Tombstone<T: Trait> {
struct Tombstone<T: Config> {
/// The contract that was evicted.
contract: Contract<T>,
/// The storage the contract held when it was avicted.
storage: Vec<(StorageKey, Vec<u8>)>,
}
impl<T: Trait> Tombstone<T>
impl<T: Config> Tombstone<T>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
/// Create and evict a new contract with the supplied storage item count and size each.
@@ -243,7 +243,7 @@ where
}
/// Generate `stor_num` storage items. Each has the size `stor_size`.
fn create_storage<T: Trait>(
fn create_storage<T: Config>(
stor_num: u32,
stor_size: u32
) -> Result<Vec<(StorageKey, Vec<u8>)>, &'static str> {
@@ -257,7 +257,7 @@ fn create_storage<T: Trait>(
}
/// The funding that each account that either calls or instantiates contracts is funded with.
fn caller_funding<T: Trait>() -> BalanceOf<T> {
fn caller_funding<T: Config>() -> BalanceOf<T> {
BalanceOf::<T>::max_value() / 2u32.into()
}
@@ -299,7 +299,7 @@ benchmarks! {
let s in 0 .. code::max_pages::<T>() * 64;
let data = vec![42u8; (n * 1024) as usize];
let salt = vec![42u8; (s * 1024) as usize];
let endowment = Config::<T>::subsistence_threshold_uncached();
let endowment = ConfigCache::<T>::subsistence_threshold_uncached();
let caller = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, caller_funding::<T>());
let WasmModule { code, hash, .. } = WasmModule::<T>::dummy_with_mem();
@@ -374,7 +374,7 @@ benchmarks! {
// the caller should get the reward for being a good snitch
assert_eq!(
T::Currency::free_balance(&instance.caller),
caller_funding::<T>() - instance.endowment + <T as Trait>::SurchargeReward::get(),
caller_funding::<T>() - instance.endowment + <T as Config>::SurchargeReward::get(),
);
}
@@ -1127,7 +1127,7 @@ benchmarks! {
.collect::<Vec<_>>();
let account_len = accounts.get(0).map(|i| i.encode().len()).unwrap_or(0);
let account_bytes = accounts.iter().flat_map(|x| x.encode()).collect();
let value = Config::<T>::subsistence_threshold_uncached();
let value = ConfigCache::<T>::subsistence_threshold_uncached();
assert!(value > 0u32.into());
let value_bytes = value.encode();
let value_len = value_bytes.len();
@@ -1334,7 +1334,7 @@ benchmarks! {
let hash_len = hashes.get(0).map(|x| x.encode().len()).unwrap_or(0);
let hashes_bytes = hashes.iter().flat_map(|x| x.encode()).collect::<Vec<_>>();
let hashes_len = hashes_bytes.len();
let value = Config::<T>::subsistence_threshold_uncached();
let value = ConfigCache::<T>::subsistence_threshold_uncached();
assert!(value > 0u32.into());
let value_bytes = value.encode();
let value_len = value_bytes.len();
@@ -1454,7 +1454,7 @@ benchmarks! {
let input_len = inputs.get(0).map(|x| x.len()).unwrap_or(0);
let input_bytes = inputs.iter().cloned().flatten().collect::<Vec<_>>();
let inputs_len = input_bytes.len();
let value = Config::<T>::subsistence_threshold_uncached();
let value = ConfigCache::<T>::subsistence_threshold_uncached();
assert!(value > 0u32.into());
let value_bytes = value.encode();
let value_len = value_bytes.len();
@@ -20,7 +20,7 @@
///! environment that provides the seal interface as imported functions.
use super::{
Trait,
Config,
code::WasmModule,
};
use sp_core::crypto::UncheckedFrom;
@@ -39,9 +39,9 @@ impl Sandbox {
}
}
impl<T: Trait> From<&WasmModule<T>> for Sandbox
impl<T: Config> From<&WasmModule<T>> for Sandbox
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
/// Creates an instance from the supplied module and supplies as much memory
+39 -39
View File
@@ -15,7 +15,7 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use crate::{
CodeHash, Config, Event, RawEvent, Trait, Module as Contracts,
CodeHash, ConfigCache, Event, RawEvent, Config, Module as Contracts,
TrieId, BalanceOf, ContractInfo, gas::GasMeter, rent::Rent, storage::{self, Storage},
Error, ContractInfoOf
};
@@ -30,14 +30,14 @@ use frame_support::{
};
use pallet_contracts_primitives::{ErrorOrigin, ExecError, ExecReturnValue, ExecResult, ReturnFlags};
pub type AccountIdOf<T> = <T as frame_system::Trait>::AccountId;
pub type MomentOf<T> = <<T as Trait>::Time as Time>::Moment;
pub type SeedOf<T> = <T as frame_system::Trait>::Hash;
pub type BlockNumberOf<T> = <T as frame_system::Trait>::BlockNumber;
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type MomentOf<T> = <<T as Config>::Time as Time>::Moment;
pub type SeedOf<T> = <T as frame_system::Config>::Hash;
pub type BlockNumberOf<T> = <T as frame_system::Config>::BlockNumber;
pub type StorageKey = [u8; 32];
/// A type that represents a topic of an event. At the moment a hash is used.
pub type TopicOf<T> = <T as frame_system::Trait>::Hash;
pub type TopicOf<T> = <T as frame_system::Config>::Hash;
/// Describes whether we deal with a contract or a plain account.
pub enum TransactorKind {
@@ -54,7 +54,7 @@ pub enum TransactorKind {
/// This interface is specialized to an account of the executing code, so all
/// operations are implicitly performed on that account.
pub trait Ext {
type T: Trait;
type T: Config;
/// Returns the storage entry of the executing account by the given `key`.
///
@@ -171,7 +171,7 @@ pub trait Ext {
/// Loader is a companion of the `Vm` trait. It loads an appropriate abstract
/// executable to be executed by an accompanying `Vm` implementation.
pub trait Loader<T: Trait> {
pub trait Loader<T: Config> {
type Executable;
/// Load the initializer portion of the code specified by the `code_hash`. This
@@ -190,7 +190,7 @@ pub trait Loader<T: Trait> {
///
/// Execution of code can end by either implicit termination (that is, reached the end of
/// executable), explicit termination via returning a buffer or termination due to a trap.
pub trait Vm<T: Trait> {
pub trait Vm<T: Config> {
type Executable;
fn execute<E: Ext<T = T>>(
@@ -202,12 +202,12 @@ pub trait Vm<T: Trait> {
) -> ExecResult;
}
pub struct ExecutionContext<'a, T: Trait + 'a, V, L> {
pub struct ExecutionContext<'a, T: Config + 'a, V, L> {
pub caller: Option<&'a ExecutionContext<'a, T, V, L>>,
pub self_account: T::AccountId,
pub self_trie_id: Option<TrieId>,
pub depth: usize,
pub config: &'a Config<T>,
pub config: &'a ConfigCache<T>,
pub vm: &'a V,
pub loader: &'a L,
pub timestamp: MomentOf<T>,
@@ -216,7 +216,7 @@ pub struct ExecutionContext<'a, T: Trait + 'a, V, L> {
impl<'a, T, E, V, L> ExecutionContext<'a, T, V, L>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
L: Loader<T, Executable = E>,
V: Vm<T, Executable = E>,
@@ -225,7 +225,7 @@ where
///
/// The specified `origin` address will be used as `sender` for. The `origin` must be a regular
/// account (not a contract).
pub fn top_level(origin: T::AccountId, cfg: &'a Config<T>, vm: &'a V, loader: &'a L) -> Self {
pub fn top_level(origin: T::AccountId, cfg: &'a ConfigCache<T>, vm: &'a V, loader: &'a L) -> Self {
ExecutionContext {
caller: None,
self_trie_id: None,
@@ -437,7 +437,7 @@ enum TransferCause {
/// is specified as `Terminate`. Otherwise, any transfer that would bring the sender below the
/// subsistence threshold (for contracts) or the existential deposit (for plain accounts)
/// results in an error.
fn transfer<'a, T: Trait, V: Vm<T>, L: Loader<T>>(
fn transfer<'a, T: Config, V: Vm<T>, L: Loader<T>>(
cause: TransferCause,
origin: TransactorKind,
transactor: &T::AccountId,
@@ -483,7 +483,7 @@ where
/// implies that the control won't be returned to the contract anymore, but there is still some code
/// on the path of the return from that call context. Therefore, care must be taken in these
/// situations.
struct CallContext<'a, 'b: 'a, T: Trait + 'b, V: Vm<T> + 'b, L: Loader<T>> {
struct CallContext<'a, 'b: 'a, T: Config + 'b, V: Vm<T> + 'b, L: Loader<T>> {
ctx: &'a mut ExecutionContext<'b, T, V, L>,
caller: T::AccountId,
value_transferred: BalanceOf<T>,
@@ -493,7 +493,7 @@ struct CallContext<'a, 'b: 'a, T: Trait + 'b, V: Vm<T> + 'b, L: Loader<T>> {
impl<'a, 'b: 'a, T, E, V, L> Ext for CallContext<'a, 'b, T, V, L>
where
T: Trait + 'b,
T: Config + 'b,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
V: Vm<T, Executable = E>,
L: Loader<T, Executable = E>,
@@ -693,13 +693,13 @@ where
}
}
fn deposit_event<T: Trait>(
fn deposit_event<T: Config>(
topics: Vec<T::Hash>,
event: Event<T>,
) {
<frame_system::Module<T>>::deposit_event_indexed(
&*topics,
<T as Trait>::Event::from(event).into(),
<T as Config>::Event::from(event).into(),
)
}
@@ -716,7 +716,7 @@ mod tests {
};
use crate::{
gas::GasMeter, tests::{ExtBuilder, Test, MetaEvent},
exec::ExecReturnValue, CodeHash, Config,
exec::ExecReturnValue, CodeHash, ConfigCache,
gas::Gas,
storage::Storage,
tests::{ALICE, BOB, CHARLIE},
@@ -769,7 +769,7 @@ mod tests {
fn insert(&mut self, f: impl Fn(MockCtx) -> ExecResult + 'a) -> CodeHash<Test> {
// Generate code hashes as monotonically increasing values.
let code_hash = <Test as frame_system::Trait>::Hash::from_low_u64_be(self.counter);
let code_hash = <Test as frame_system::Config>::Hash::from_low_u64_be(self.counter);
self.counter += 1;
self.map.insert(code_hash, MockExecutable::new(f));
@@ -843,7 +843,7 @@ mod tests {
});
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
place_contract(&BOB, exec_ch);
@@ -867,7 +867,7 @@ mod tests {
let loader = MockLoader::empty();
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(origin.clone(), &cfg, &vm, &loader);
set_balance(&origin, 100);
set_balance(&dest, 0);
@@ -900,7 +900,7 @@ mod tests {
);
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(origin.clone(), &cfg, &vm, &loader);
place_contract(&BOB, return_ch);
set_balance(&origin, 100);
@@ -930,7 +930,7 @@ mod tests {
let loader = MockLoader::empty();
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(origin.clone(), &cfg, &vm, &loader);
set_balance(&origin, 0);
@@ -966,7 +966,7 @@ mod tests {
);
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(origin, &cfg, &vm, &loader);
place_contract(&BOB, return_ch);
@@ -997,7 +997,7 @@ mod tests {
);
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(origin, &cfg, &vm, &loader);
place_contract(&BOB, return_ch);
@@ -1025,7 +1025,7 @@ mod tests {
// This one tests passing the input data into a contract via call.
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
place_contract(&BOB, input_data_ch);
@@ -1050,7 +1050,7 @@ mod tests {
// This one tests passing the input data into a contract via instantiate.
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 100);
@@ -1097,7 +1097,7 @@ mod tests {
});
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&BOB, 1);
place_contract(&BOB, recurse_ch);
@@ -1142,7 +1142,7 @@ mod tests {
});
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(origin.clone(), &cfg, &vm, &loader);
place_contract(&dest, bob_ch);
@@ -1184,7 +1184,7 @@ mod tests {
});
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
place_contract(&BOB, bob_ch);
place_contract(&CHARLIE, charlie_ch);
@@ -1208,7 +1208,7 @@ mod tests {
let dummy_ch = loader.insert(|_| exec_success());
ExtBuilder::default().existential_deposit(15).build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
assert_matches!(
@@ -1234,7 +1234,7 @@ mod tests {
);
ExtBuilder::default().existential_deposit(15).build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 1000);
@@ -1268,7 +1268,7 @@ mod tests {
);
ExtBuilder::default().existential_deposit(15).build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 1000);
@@ -1303,7 +1303,7 @@ mod tests {
// Instantiate a contract and save it's address in `instantiated_contract_address`.
let (address, output) = ctx.ext.instantiate(
&dummy_ch,
Config::<Test>::subsistence_threshold_uncached(),
ConfigCache::<Test>::subsistence_threshold_uncached(),
ctx.gas_meter,
vec![],
&[48, 49, 50],
@@ -1315,7 +1315,7 @@ mod tests {
});
ExtBuilder::default().existential_deposit(15).build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 1000);
set_balance(&BOB, 100);
@@ -1368,7 +1368,7 @@ mod tests {
});
ExtBuilder::default().existential_deposit(15).build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 1000);
set_balance(&BOB, 100);
@@ -1400,7 +1400,7 @@ mod tests {
.existential_deposit(15)
.build()
.execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 1000);
@@ -1434,7 +1434,7 @@ mod tests {
});
ExtBuilder::default().build().execute_with(|| {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let mut ctx = ExecutionContext::top_level(ALICE, &cfg, &vm, &loader);
set_balance(&ALICE, 100);
+4 -4
View File
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use crate::Trait;
use crate::Config;
use sp_std::marker::PhantomData;
use sp_runtime::traits::Zero;
use frame_support::dispatch::{
@@ -60,7 +60,7 @@ impl<T: Any + Debug + PartialEq + Eq> TestAuxiliaries for T {}
/// Implementing type is expected to be super lightweight hence `Copy` (`Clone` is added
/// for consistency). If inlined there should be no observable difference compared
/// to a hand-written code.
pub trait Token<T: Trait>: Copy + Clone + TestAuxiliaries {
pub trait Token<T: Config>: Copy + Clone + TestAuxiliaries {
/// Metadata type, which the token can require for calculating the amount
/// of gas to charge. Can be a some configuration type or
/// just the `()`.
@@ -84,7 +84,7 @@ pub struct ErasedToken {
pub token: Box<dyn Any>,
}
pub struct GasMeter<T: Trait> {
pub struct GasMeter<T: Config> {
gas_limit: Gas,
/// Amount of gas left from initial gas limit. Can reach zero.
gas_left: Gas,
@@ -92,7 +92,7 @@ pub struct GasMeter<T: Trait> {
#[cfg(test)]
tokens: Vec<ErasedToken>,
}
impl<T: Trait> GasMeter<T> {
impl<T: Config> GasMeter<T> {
pub fn new(gas_limit: Gas) -> Self {
GasMeter {
gas_limit,
+23 -23
View File
@@ -18,7 +18,7 @@
//!
//! The Contract module provides functionality for the runtime to deploy and execute WebAssembly smart-contracts.
//!
//! - [`contract::Trait`](./trait.Trait.html)
//! - [`contract::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//!
//! ## Overview
@@ -126,18 +126,18 @@ use pallet_contracts_primitives::{
};
use frame_support::weights::Weight;
pub type CodeHash<T> = <T as frame_system::Trait>::Hash;
pub type CodeHash<T> = <T as frame_system::Config>::Hash;
pub type TrieId = Vec<u8>;
/// Information for managing an account and its sub trie abstraction.
/// This is the required info to cache for an account
#[derive(Encode, Decode, RuntimeDebug)]
pub enum ContractInfo<T: Trait> {
pub enum ContractInfo<T: Config> {
Alive(AliveContractInfo<T>),
Tombstone(TombstoneContractInfo<T>),
}
impl<T: Trait> ContractInfo<T> {
impl<T: Config> ContractInfo<T> {
/// If contract is alive then return some alive info
pub fn get_alive(self) -> Option<AliveContractInfo<T>> {
if let ContractInfo::Alive(alive) = self {
@@ -190,7 +190,7 @@ impl<T: Trait> ContractInfo<T> {
}
pub type AliveContractInfo<T> =
RawAliveContractInfo<CodeHash<T>, BalanceOf<T>, <T as frame_system::Trait>::BlockNumber>;
RawAliveContractInfo<CodeHash<T>, BalanceOf<T>, <T as frame_system::Config>::BlockNumber>;
/// Information for managing an account and its sub trie abstraction.
/// This is the required info to cache for an account.
@@ -230,7 +230,7 @@ pub(crate) fn child_trie_info(trie_id: &[u8]) -> ChildInfo {
}
pub type TombstoneContractInfo<T> =
RawTombstoneContractInfo<<T as frame_system::Trait>::Hash, <T as frame_system::Trait>::Hashing>;
RawTombstoneContractInfo<<T as frame_system::Config>::Hash, <T as frame_system::Config>::Hashing>;
#[derive(Encode, Decode, PartialEq, Eq, RuntimeDebug)]
pub struct RawTombstoneContractInfo<H, Hasher>(H, PhantomData<Hasher>);
@@ -250,18 +250,18 @@ where
}
}
impl<T: Trait> From<AliveContractInfo<T>> for ContractInfo<T> {
impl<T: Config> From<AliveContractInfo<T>> for ContractInfo<T> {
fn from(alive_info: AliveContractInfo<T>) -> Self {
Self::Alive(alive_info)
}
}
pub type BalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type NegativeImbalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
type Time: Time;
type Randomness: Randomness<Self::Hash>;
@@ -269,7 +269,7 @@ pub trait Trait: frame_system::Trait {
type Currency: Currency<Self::AccountId>;
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// Handler for rent payments.
type RentPayment: OnUnbalanced<NegativeImbalanceOf<Self>>;
@@ -323,7 +323,7 @@ pub trait Trait: frame_system::Trait {
decl_error! {
/// Error for the contracts module.
pub enum Error for Module<T: Trait>
pub enum Error for Module<T: Config>
where
T::AccountId: UncheckedFrom<T::Hash>,
T::AccountId: AsRef<[u8]>,
@@ -383,7 +383,7 @@ decl_error! {
decl_module! {
/// Contracts module.
pub struct Module<T: Trait> for enum Call
pub struct Module<T: Config> for enum Call
where
origin: T::Origin,
T::AccountId: UncheckedFrom<T::Hash>,
@@ -564,7 +564,7 @@ decl_module! {
}
/// Public APIs provided by the contracts module.
impl<T: Trait> Module<T>
impl<T: Config> Module<T>
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
@@ -638,7 +638,7 @@ where
}
}
impl<T: Trait> Module<T>
impl<T: Config> Module<T>
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>,
{
@@ -647,7 +647,7 @@ where
gas_meter: &mut GasMeter<T>,
func: impl FnOnce(&mut ExecutionContext<T, WasmVm<T>, WasmLoader<T>>, &mut GasMeter<T>) -> ExecResult,
) -> ExecResult {
let cfg = Config::preload();
let cfg = ConfigCache::preload();
let vm = WasmVm::new(&cfg.schedule);
let loader = WasmLoader::new(&cfg.schedule);
let mut ctx = ExecutionContext::top_level(origin, &cfg, &vm, &loader);
@@ -659,8 +659,8 @@ decl_event! {
pub enum Event<T>
where
Balance = BalanceOf<T>,
<T as frame_system::Trait>::AccountId,
<T as frame_system::Trait>::Hash
<T as frame_system::Config>::AccountId,
<T as frame_system::Config>::Hash
{
/// Contract deployed by address at the specified address. \[owner, contract\]
Instantiated(AccountId, AccountId),
@@ -699,7 +699,7 @@ decl_event! {
}
decl_storage! {
trait Store for Module<T: Trait> as Contracts
trait Store for Module<T: Config> as Contracts
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
@@ -722,7 +722,7 @@ decl_storage! {
///
/// We assume that these values can't be changed in the
/// course of transaction execution.
pub struct Config<T: Trait> {
pub struct ConfigCache<T: Config> {
pub schedule: Schedule<T>,
pub existential_deposit: BalanceOf<T>,
pub tombstone_deposit: BalanceOf<T>,
@@ -730,12 +730,12 @@ pub struct Config<T: Trait> {
pub max_value_size: u32,
}
impl<T: Trait> Config<T>
impl<T: Config> ConfigCache<T>
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
fn preload() -> Config<T> {
Config {
fn preload() -> ConfigCache<T> {
ConfigCache {
schedule: <Module<T>>::current_schedule(),
existential_deposit: T::Currency::minimum_balance(),
tombstone_deposit: T::TombstoneDeposit::get(),
+6 -6
View File
@@ -18,7 +18,7 @@
use crate::{
AliveContractInfo, BalanceOf, ContractInfo, ContractInfoOf, Module, RawEvent,
TombstoneContractInfo, Trait, CodeHash, Config, Error,
TombstoneContractInfo, Config, CodeHash, ConfigCache, Error,
};
use sp_std::prelude::*;
use sp_io::hashing::blake2_256;
@@ -36,11 +36,11 @@ use sp_runtime::{
///
/// This amount respects the contract's rent allowance and the subsistence deposit.
/// Because of that, charging the amount cannot remove the contract.
struct OutstandingAmount<T: Trait> {
struct OutstandingAmount<T: Config> {
amount: BalanceOf<T>,
}
impl<T: Trait> OutstandingAmount<T> {
impl<T: Config> OutstandingAmount<T> {
/// Create the new outstanding amount.
///
/// The amount should be always withdrawable and it should not kill the account.
@@ -67,7 +67,7 @@ impl<T: Trait> OutstandingAmount<T> {
}
}
enum Verdict<T: Trait> {
enum Verdict<T: Config> {
/// The contract is exempted from paying rent.
///
/// For example, it already paid its rent in the current block, or it has enough deposit for not
@@ -90,7 +90,7 @@ pub struct Rent<T>(sp_std::marker::PhantomData<T>);
impl<T> Rent<T>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
/// Returns a fee charged per block from the contract.
@@ -129,7 +129,7 @@ where
free_balance: &BalanceOf<T>,
contract: &AliveContractInfo<T>,
) -> Option<BalanceOf<T>> {
let subsistence_threshold = Config::<T>::subsistence_threshold_uncached();
let subsistence_threshold = ConfigCache::<T>::subsistence_threshold_uncached();
// Reserved balance contributes towards the subsistence threshold to stay consistent
// with the existential deposit where the reserved balance is also counted.
if *total_balance < subsistence_threshold {
+10 -10
View File
@@ -17,7 +17,7 @@
//! This module contains the cost schedule and supporting code that constructs a
//! sane default schedule from a `WeightInfo` implementation.
use crate::{Trait, weights::WeightInfo};
use crate::{Config, weights::WeightInfo};
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
@@ -42,7 +42,7 @@ pub const INSTR_BENCHMARK_BATCH_SIZE: u32 = 1_000;
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "std", serde(bound(serialize = "", deserialize = "")))]
#[derive(Clone, Encode, Decode, PartialEq, Eq, ScheduleDebug)]
pub struct Schedule<T: Trait> {
pub struct Schedule<T: Config> {
/// Version of the schedule.
pub version: u32,
@@ -131,7 +131,7 @@ pub struct Limits {
/// and dropping return values in order to maintain a valid module.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, Encode, Decode, PartialEq, Eq, WeightDebug)]
pub struct InstructionWeights<T: Trait> {
pub struct InstructionWeights<T: Config> {
pub i64const: u32,
pub i64load: u32,
pub i64store: u32,
@@ -190,7 +190,7 @@ pub struct InstructionWeights<T: Trait> {
/// Describes the weight for each imported function that a contract is allowed to call.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, Encode, Decode, PartialEq, Eq, WeightDebug)]
pub struct HostFnWeights<T: Trait> {
pub struct HostFnWeights<T: Config> {
/// Weight of calling `seal_caller`.
pub caller: Weight,
@@ -410,7 +410,7 @@ macro_rules! cost_byte_batched {
}
}
impl<T: Trait> Default for Schedule<T> {
impl<T: Config> Default for Schedule<T> {
fn default() -> Self {
Self {
version: 0,
@@ -440,7 +440,7 @@ impl Default for Limits {
}
}
impl<T: Trait> Default for InstructionWeights<T> {
impl<T: Config> Default for InstructionWeights<T> {
fn default() -> Self {
let max_pages = Limits::default().memory_pages;
Self {
@@ -500,7 +500,7 @@ impl<T: Trait> Default for InstructionWeights<T> {
}
}
impl<T: Trait> Default for HostFnWeights<T> {
impl<T: Config> Default for HostFnWeights<T> {
fn default() -> Self {
Self {
caller: cost_batched!(seal_caller),
@@ -554,12 +554,12 @@ impl<T: Trait> Default for HostFnWeights<T> {
}
}
struct ScheduleRules<'a, T: Trait> {
struct ScheduleRules<'a, T: Config> {
schedule: &'a Schedule<T>,
params: Vec<u32>,
}
impl<T: Trait> Schedule<T> {
impl<T: Config> Schedule<T> {
pub fn rules(&self, module: &elements::Module) -> impl rules::Rules + '_ {
ScheduleRules {
schedule: &self,
@@ -576,7 +576,7 @@ impl<T: Trait> Schedule<T> {
}
}
impl<'a, T: Trait> rules::Rules for ScheduleRules<'a, T> {
impl<'a, T: Config> rules::Rules for ScheduleRules<'a, T> {
fn instruction_cost(&self, instruction: &elements::Instruction) -> Option<u32> {
use parity_wasm::elements::Instruction::*;
let w = &self.schedule.instruction_weights;
+2 -2
View File
@@ -18,7 +18,7 @@
use crate::{
exec::{AccountIdOf, StorageKey},
AliveContractInfo, BalanceOf, CodeHash, ContractInfo, ContractInfoOf, Trait, TrieId,
AliveContractInfo, BalanceOf, CodeHash, ContractInfo, ContractInfoOf, Config, TrieId,
AccountCounter,
};
use sp_std::prelude::*;
@@ -37,7 +37,7 @@ pub struct Storage<T>(PhantomData<T>);
impl<T> Storage<T>
where
T: Trait,
T: Config,
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
/// Reads a storage kv pair of a contract.
+25 -25
View File
@@ -16,8 +16,8 @@
use crate::{
BalanceOf, ContractInfo, ContractInfoOf, GenesisConfig, Module,
RawAliveContractInfo, RawEvent, Trait, Schedule, gas::Gas,
Error, Config, RuntimeReturnCode, storage::Storage,
RawAliveContractInfo, RawEvent, Config, Schedule, gas::Gas,
Error, ConfigCache, RuntimeReturnCode, storage::Storage,
exec::AccountIdOf,
};
use assert_matches::assert_matches;
@@ -110,7 +110,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -137,7 +137,7 @@ impl frame_system::Trait for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type Event = MetaEvent;
@@ -149,7 +149,7 @@ impl pallet_balances::Trait for Test {
parameter_types! {
pub const MinimumPeriod: u64 = 1;
}
impl pallet_timestamp::Trait for Test {
impl pallet_timestamp::Config for Test {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
@@ -176,7 +176,7 @@ impl Convert<Weight, BalanceOf<Self>> for Test {
}
}
impl Trait for Test {
impl Config for Test {
type Time = Timestamp;
type Randomness = Randomness;
type Currency = Balances;
@@ -251,7 +251,7 @@ fn compile_module<T>(
fixture_name: &str,
) -> wat::Result<(Vec<u8>, <T::Hashing as Hash>::Output)>
where
T: frame_system::Trait,
T: frame_system::Config,
{
let fixture_path = ["fixtures/", fixture_name, ".wat"].concat();
let wasm_binary = wat::parse_file(fixture_path)?;
@@ -367,7 +367,7 @@ fn instantiate_and_call_and_deposit_event() {
.build()
.execute_with(|| {
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
let subsistence = super::Config::<Test>::subsistence_threshold_uncached();
let subsistence = super::ConfigCache::<Test>::subsistence_threshold_uncached();
assert_ok!(Contracts::put_code(Origin::signed(ALICE), wasm));
@@ -472,7 +472,7 @@ fn deposit_event_max_value_limit() {
addr.clone(),
0,
GAS_LIMIT * 2, // we are copying a huge buffer,
<Test as Trait>::MaxValueSize::get().encode(),
<Test as Config>::MaxValueSize::get().encode(),
));
// Call contract with too large a storage value.
@@ -482,7 +482,7 @@ fn deposit_event_max_value_limit() {
addr,
0,
GAS_LIMIT,
(<Test as Trait>::MaxValueSize::get() + 1).encode(),
(<Test as Config>::MaxValueSize::get() + 1).encode(),
),
Error::<Test>::ValueTooLarge,
);
@@ -591,7 +591,7 @@ fn storage_size() {
30_000,
GAS_LIMIT,
code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(1_000u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -725,7 +725,7 @@ fn deduct_blocks() {
Origin::signed(ALICE),
30_000,
GAS_LIMIT, code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(1_000u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -830,7 +830,7 @@ fn claim_surcharge(blocks: u64, trigger_call: impl Fn(AccountIdOf<Test>) -> bool
Origin::signed(ALICE),
100,
GAS_LIMIT, code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(1_000u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -869,7 +869,7 @@ fn removals(trigger_call: impl Fn(AccountIdOf<Test>) -> bool) {
Origin::signed(ALICE),
100,
GAS_LIMIT, code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(1_000u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -911,7 +911,7 @@ fn removals(trigger_call: impl Fn(AccountIdOf<Test>) -> bool) {
1_000,
GAS_LIMIT,
code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(100u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(100u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -960,14 +960,14 @@ fn removals(trigger_call: impl Fn(AccountIdOf<Test>) -> bool) {
// Create
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
let subsistence_threshold =
Balances::minimum_balance() + <Test as Trait>::TombstoneDeposit::get();
Balances::minimum_balance() + <Test as Config>::TombstoneDeposit::get();
assert_ok!(Contracts::put_code(Origin::signed(ALICE), wasm.clone()));
assert_ok!(Contracts::instantiate(
Origin::signed(ALICE),
50 + subsistence_threshold,
GAS_LIMIT,
code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(1_000u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -1039,7 +1039,7 @@ fn call_removed_contract() {
Origin::signed(ALICE),
100,
GAS_LIMIT, code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(1_000u32).encode(), // rent allowance
<Test as pallet_balances::Config>::Balance::from(1_000u32).encode(), // rent allowance
vec![],
));
let addr = Contracts::contract_address(&ALICE, &code_hash, &[]);
@@ -1177,7 +1177,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
30_000,
GAS_LIMIT,
set_rent_code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(0u32).encode(),
<Test as pallet_balances::Config>::Balance::from(0u32).encode(),
vec![],
));
let addr_bob = Contracts::contract_address(&ALICE, &set_rent_code_hash, &[]);
@@ -1227,7 +1227,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
30_000,
GAS_LIMIT,
restoration_code_hash.into(),
<Test as pallet_balances::Trait>::Balance::from(0u32).encode(),
<Test as pallet_balances::Config>::Balance::from(0u32).encode(),
vec![],
));
let addr_django = Contracts::contract_address(&CHARLIE, &restoration_code_hash, &[]);
@@ -1384,7 +1384,7 @@ fn storage_max_value_limit() {
addr.clone(),
0,
GAS_LIMIT * 2, // we are copying a huge buffer
<Test as Trait>::MaxValueSize::get().encode(),
<Test as Config>::MaxValueSize::get().encode(),
));
// Call contract with too large a storage value.
@@ -1394,7 +1394,7 @@ fn storage_max_value_limit() {
addr,
0,
GAS_LIMIT,
(<Test as Trait>::MaxValueSize::get() + 1).encode(),
(<Test as Config>::MaxValueSize::get() + 1).encode(),
),
Error::<Test>::ValueTooLarge,
);
@@ -1709,7 +1709,7 @@ fn crypto_hashes() {
fn transfer_return_code() {
let (wasm, code_hash) = compile_module::<Test>("transfer_return_code").unwrap();
ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
let subsistence = Config::<Test>::subsistence_threshold_uncached();
let subsistence = ConfigCache::<Test>::subsistence_threshold_uncached();
let _ = Balances::deposit_creating(&ALICE, 10 * subsistence);
assert_ok!(Contracts::put_code(Origin::signed(ALICE), wasm));
@@ -1756,7 +1756,7 @@ fn call_return_code() {
let (caller_code, caller_hash) = compile_module::<Test>("call_return_code").unwrap();
let (callee_code, callee_hash) = compile_module::<Test>("ok_trap_revert").unwrap();
ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
let subsistence = Config::<Test>::subsistence_threshold_uncached();
let subsistence = ConfigCache::<Test>::subsistence_threshold_uncached();
let _ = Balances::deposit_creating(&ALICE, 10 * subsistence);
let _ = Balances::deposit_creating(&CHARLIE, 10 * subsistence);
assert_ok!(Contracts::put_code(Origin::signed(ALICE), caller_code));
@@ -1849,7 +1849,7 @@ fn instantiate_return_code() {
let (caller_code, caller_hash) = compile_module::<Test>("instantiate_return_code").unwrap();
let (callee_code, callee_hash) = compile_module::<Test>("ok_trap_revert").unwrap();
ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
let subsistence = Config::<Test>::subsistence_threshold_uncached();
let subsistence = ConfigCache::<Test>::subsistence_threshold_uncached();
let _ = Balances::deposit_creating(&ALICE, 10 * subsistence);
let _ = Balances::deposit_creating(&CHARLIE, 10 * subsistence);
assert_ok!(Contracts::put_code(Origin::signed(ALICE), caller_code));
@@ -27,7 +27,7 @@
//! Thus, before executing a contract it should be reinstrument with new schedule.
use crate::wasm::{prepare, runtime::Env, PrefabWasmModule};
use crate::{CodeHash, CodeStorage, PristineCode, Schedule, Trait};
use crate::{CodeHash, CodeStorage, PristineCode, Schedule, Config};
use sp_std::prelude::*;
use sp_runtime::traits::Hash;
use sp_core::crypto::UncheckedFrom;
@@ -37,7 +37,7 @@ use frame_support::StorageMap;
/// as a result of this function.
///
/// This function instruments the given code and caches it in the storage.
pub fn save<T: Trait>(
pub fn save<T: Config>(
original_code: Vec<u8>,
schedule: &Schedule<T>,
) -> Result<CodeHash<T>, &'static str> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
@@ -55,7 +55,7 @@ pub fn save<T: Trait>(
/// This version neither checks nor instruments the passed in code. This is useful
/// when code needs to be benchmarked without the injected instrumentation.
#[cfg(feature = "runtime-benchmarks")]
pub fn save_raw<T: Trait>(
pub fn save_raw<T: Config>(
original_code: Vec<u8>,
schedule: &Schedule<T>,
) -> Result<CodeHash<T>, &'static str> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
@@ -73,7 +73,7 @@ pub fn save_raw<T: Trait>(
/// If the module was instrumented with a lower version of schedule than
/// the current one given as an argument, then this function will perform
/// re-instrumentation and update the cache in the storage.
pub fn load<T: Trait>(
pub fn load<T: Config>(
code_hash: &CodeHash<T>,
schedule: &Schedule<T>,
) -> Result<PrefabWasmModule, &'static str> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
@@ -129,8 +129,8 @@ macro_rules! define_func {
args: &[sp_sandbox::Value],
) -> Result<sp_sandbox::ReturnValue, sp_sandbox::HostError>
where
<E::T as frame_system::Trait>::AccountId:
sp_core::crypto::UncheckedFrom<<E::T as frame_system::Trait>::Hash> +
<E::T as frame_system::Config>::AccountId:
sp_core::crypto::UncheckedFrom<<E::T as frame_system::Config>::Hash> +
AsRef<[u8]>
{
#[allow(unused)]
@@ -190,8 +190,8 @@ macro_rules! define_env {
impl<E: Ext> $crate::wasm::env_def::FunctionImplProvider<E> for $init_name
where
<E::T as frame_system::Trait>::AccountId:
sp_core::crypto::UncheckedFrom<<E::T as frame_system::Trait>::Hash> +
<E::T as frame_system::Config>::AccountId:
sp_core::crypto::UncheckedFrom<<E::T as frame_system::Config>::Hash> +
AsRef<[u8]>
{
fn impls<F: FnMut(&[u8], $crate::wasm::env_def::HostFunc<E>)>(f: &mut F) {
+9 -9
View File
@@ -17,7 +17,7 @@
//! This module provides a means for executing contracts
//! represented in wasm.
use crate::{CodeHash, Schedule, Trait};
use crate::{CodeHash, Schedule, Config};
use crate::wasm::env_def::FunctionImplProvider;
use crate::exec::Ext;
use crate::gas::GasMeter;
@@ -68,17 +68,17 @@ pub struct WasmExecutable {
}
/// Loader which fetches `WasmExecutable` from the code cache.
pub struct WasmLoader<'a, T: Trait> {
pub struct WasmLoader<'a, T: Config> {
schedule: &'a Schedule<T>,
}
impl<'a, T: Trait> WasmLoader<'a, T> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
impl<'a, T: Config> WasmLoader<'a, T> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
pub fn new(schedule: &'a Schedule<T>) -> Self {
WasmLoader { schedule }
}
}
impl<'a, T: Trait> crate::exec::Loader<T> for WasmLoader<'a, T>
impl<'a, T: Config> crate::exec::Loader<T> for WasmLoader<'a, T>
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
@@ -101,17 +101,17 @@ where
}
/// Implementation of `Vm` that takes `WasmExecutable` and executes it.
pub struct WasmVm<'a, T: Trait> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
pub struct WasmVm<'a, T: Config> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
schedule: &'a Schedule<T>,
}
impl<'a, T: Trait> WasmVm<'a, T> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
impl<'a, T: Config> WasmVm<'a, T> where T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> {
pub fn new(schedule: &'a Schedule<T>) -> Self {
WasmVm { schedule }
}
}
impl<'a, T: Trait> crate::exec::Vm<T> for WasmVm<'a, T>
impl<'a, T: Config> crate::exec::Vm<T> for WasmVm<'a, T>
where
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]>
{
@@ -462,8 +462,8 @@ mod tests {
gas_meter: &mut GasMeter<E::T>,
) -> ExecResult
where
<E::T as frame_system::Trait>::AccountId:
UncheckedFrom<<E::T as frame_system::Trait>::Hash> + AsRef<[u8]>
<E::T as frame_system::Config>::AccountId:
UncheckedFrom<<E::T as frame_system::Config>::Hash> + AsRef<[u8]>
{
use crate::exec::Vm;
@@ -20,7 +20,7 @@
use crate::wasm::env_def::ImportSatisfyCheck;
use crate::wasm::PrefabWasmModule;
use crate::{Schedule, Trait};
use crate::{Schedule, Config};
use parity_wasm::elements::{self, Internal, External, MemoryType, Type, ValueType};
use pwasm_utils;
@@ -34,13 +34,13 @@ pub const IMPORT_MODULE_FN: &str = "seal0";
/// compiler toolchains might not support specifying other modules than "env" for memory imports.
pub const IMPORT_MODULE_MEMORY: &str = "env";
struct ContractModule<'a, T: Trait> {
struct ContractModule<'a, T: Config> {
/// A deserialized module. The module is valid (this is Guaranteed by `new` method).
module: elements::Module,
schedule: &'a Schedule<T>,
}
impl<'a, T: Trait> ContractModule<'a, T> {
impl<'a, T: Config> ContractModule<'a, T> {
/// Creates a new instance of `ContractModule`.
///
/// Returns `Err` if the `original_code` couldn't be decoded or
@@ -369,7 +369,7 @@ impl<'a, T: Trait> ContractModule<'a, T> {
}
}
fn get_memory_limits<T: Trait>(module: Option<&MemoryType>, schedule: &Schedule<T>)
fn get_memory_limits<T: Config>(module: Option<&MemoryType>, schedule: &Schedule<T>)
-> Result<(u32, u32), &'static str>
{
if let Some(memory_type) = module {
@@ -410,7 +410,7 @@ fn get_memory_limits<T: Trait>(module: Option<&MemoryType>, schedule: &Schedule<
/// - all imported functions from the external environment matches defined by `env` module,
///
/// The preprocessing includes injecting code for gas metering and metering the height of stack.
pub fn prepare_contract<C: ImportSatisfyCheck, T: Trait>(
pub fn prepare_contract<C: ImportSatisfyCheck, T: Config>(
original_code: &[u8],
schedule: &Schedule<T>,
) -> Result<PrefabWasmModule, &'static str> {
@@ -452,7 +452,7 @@ pub fn prepare_contract<C: ImportSatisfyCheck, T: Trait>(
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking {
use super::{
Trait, ContractModule, PrefabWasmModule, ImportSatisfyCheck, Schedule, get_memory_limits
Config, ContractModule, PrefabWasmModule, ImportSatisfyCheck, Schedule, get_memory_limits
};
use parity_wasm::elements::FunctionType;
@@ -463,7 +463,7 @@ pub mod benchmarking {
}
/// Prepare function that neither checks nor instruments the passed in code.
pub fn prepare_contract<T: Trait>(original_code: &[u8], schedule: &Schedule<T>)
pub fn prepare_contract<T: Config>(original_code: &[u8], schedule: &Schedule<T>)
-> Result<PrefabWasmModule, &'static str>
{
let contract_module = ContractModule::new(original_code, schedule)?;
@@ -17,7 +17,7 @@
//! Environment definition of the wasm smart-contract runtime.
use crate::{
HostFnWeights, Schedule, Trait, CodeHash, BalanceOf, Error,
HostFnWeights, Schedule, Config, CodeHash, BalanceOf, Error,
exec::{Ext, StorageKey, TopicOf},
gas::{Gas, GasMeter, Token, GasMeterResult},
wasm::env_def::ConvertibleToWasm,
@@ -193,7 +193,7 @@ pub enum RuntimeToken {
HashBlake128(u32),
}
impl<T: Trait> Token<T> for RuntimeToken
impl<T: Config> Token<T> for RuntimeToken
where
T::AccountId: UncheckedFrom<T::Hash>, T::AccountId: AsRef<[u8]>
{
@@ -291,8 +291,8 @@ pub struct Runtime<'a, E: Ext + 'a> {
impl<'a, E> Runtime<'a, E>
where
E: Ext + 'a,
<E::T as frame_system::Trait>::AccountId:
UncheckedFrom<<E::T as frame_system::Trait>::Hash> + AsRef<[u8]>
<E::T as frame_system::Config>::AccountId:
UncheckedFrom<<E::T as frame_system::Config>::Hash> + AsRef<[u8]>
{
pub fn new(
ext: &'a mut E,
@@ -709,7 +709,7 @@ define_env!(Env, <E: Ext>,
value_len: u32
) -> ReturnCode => {
ctx.charge_gas(RuntimeToken::Transfer)?;
let callee: <<E as Ext>::T as frame_system::Trait>::AccountId =
let callee: <<E as Ext>::T as frame_system::Config>::AccountId =
ctx.read_sandbox_memory_as(account_ptr, account_len)?;
let value: BalanceOf<<E as Ext>::T> =
ctx.read_sandbox_memory_as(value_ptr, value_len)?;
@@ -762,7 +762,7 @@ define_env!(Env, <E: Ext>,
output_len_ptr: u32
) -> ReturnCode => {
ctx.charge_gas(RuntimeToken::CallBase(input_data_len))?;
let callee: <<E as Ext>::T as frame_system::Trait>::AccountId =
let callee: <<E as Ext>::T as frame_system::Config>::AccountId =
ctx.read_sandbox_memory_as(callee_ptr, callee_len)?;
let value: BalanceOf<<E as Ext>::T> = ctx.read_sandbox_memory_as(value_ptr, value_len)?;
let input_data = ctx.read_sandbox_memory(input_data_ptr, input_data_len)?;
@@ -922,7 +922,7 @@ define_env!(Env, <E: Ext>,
beneficiary_len: u32
) => {
ctx.charge_gas(RuntimeToken::Terminate)?;
let beneficiary: <<E as Ext>::T as frame_system::Trait>::AccountId =
let beneficiary: <<E as Ext>::T as frame_system::Config>::AccountId =
ctx.read_sandbox_memory_as(beneficiary_ptr, beneficiary_len)?;
if let Ok(_) = ctx.ext.terminate(&beneficiary).map_err(|e| ctx.store_err(e)) {
@@ -1169,7 +1169,7 @@ define_env!(Env, <E: Ext>,
delta_count: u32
) => {
ctx.charge_gas(RuntimeToken::RestoreTo(delta_count))?;
let dest: <<E as Ext>::T as frame_system::Trait>::AccountId =
let dest: <<E as Ext>::T as frame_system::Config>::AccountId =
ctx.read_sandbox_memory_as(dest_ptr, dest_len)?;
let code_hash: CodeHash<<E as Ext>::T> =
ctx.read_sandbox_memory_as(code_hash_ptr, code_hash_len)?;
+1 -1
View File
@@ -144,7 +144,7 @@ pub trait WeightInfo {
/// Weights for pallet_contracts using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn update_schedule() -> Weight {
(35_214_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))