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 2 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: 0 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ parameter_types! {
impl pallet_contracts::Trait for Runtime {
type Time = Timestamp;
type Randomness = RandomnessCollectiveFlip;
type Call = Call;
type Event = Event;
type DetermineContractAddress = pallet_contracts::SimpleAddressDeterminer<Runtime>;
type TrieIdGenerator = pallet_contracts::TrieIdFromParentCounter<Runtime>;
Expand Down
14 changes: 0 additions & 14 deletions frame/contracts/fixtures/dispatch_call.wat

This file was deleted.

15 changes: 0 additions & 15 deletions frame/contracts/fixtures/dispatch_call_then_trap.wat

This file was deleted.

74 changes: 0 additions & 74 deletions frame/contracts/fixtures/get_runtime_storage.wat

This file was deleted.

4 changes: 2 additions & 2 deletions frame/contracts/fixtures/restoration.wat
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@

;; Code hash of SET_RENT
(data (i32.const 264)
"\c2\1c\41\10\a5\22\d8\59\1c\4c\77\35\dd\2d\bf\a1"
"\13\0b\50\93\76\9b\92\31\97\b7\c5\74\26\aa\38\2a"
"\ab\d6\58\65\1e\83\6e\4a\18\0d\f2\6d\bc\42\ba\e9"
"\3d\64\76\e5\30\5b\33\46\bb\4d\43\99\38\21\ee\32"
)

;; Rent allowance
Expand Down
19 changes: 12 additions & 7 deletions frame/contracts/fixtures/set_rent.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(module
(import "env" "ext_dispatch_call" (func $ext_dispatch_call (param i32 i32)))
(import "env" "ext_transfer" (func $ext_transfer (param i32 i32 i32 i32) (result i32)))
(import "env" "ext_set_storage" (func $ext_set_storage (param i32 i32 i32)))
(import "env" "ext_clear_storage" (func $ext_clear_storage (param i32)))
(import "env" "ext_set_rent_allowance" (func $ext_set_rent_allowance (param i32 i32)))
Expand All @@ -23,11 +23,13 @@
)
)

;; transfer 50 to ALICE
;; transfer 50 to CHARLIE
(func $call_2
(call $ext_dispatch_call
(i32.const 68)
(i32.const 11)
(call $assert
(i32.eq
(call $ext_transfer (i32.const 68) (i32.const 8) (i32.const 76) (i32.const 8))
(i32.const 0)
)
)
)

Expand Down Expand Up @@ -96,6 +98,9 @@
;; Encoding of 10 in balance
(data (i32.const 0) "\28")

;; Encoding of call transfer 50 to CHARLIE
(data (i32.const 68) "\00\00\03\00\00\00\00\00\00\00\C8")
;; encoding of Charlies's account id
(data (i32.const 68) "\03")

;; encoding of 50 balance
(data (i32.const 76) "\32")
)
48 changes: 8 additions & 40 deletions frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use frame_support::{
};

pub type AccountIdOf<T> = <T as frame_system::Trait>::AccountId;
pub type CallOf<T> = <T as Trait>::Call;
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;
Expand Down Expand Up @@ -150,9 +149,6 @@ pub trait Ext {
input_data: Vec<u8>,
) -> ExecResult;

/// Notes a call dispatch.
fn note_dispatch_call(&mut self, call: CallOf<Self::T>);

/// Restores the given destination contract sacrificing the current one.
///
/// Since this function removes the self contract eagerly, if succeeded, no further actions should
Expand Down Expand Up @@ -273,23 +269,11 @@ impl<T: Trait> Token<T> for ExecFeeToken {
}
}

#[cfg_attr(any(feature = "std", test), derive(PartialEq, Eq, Clone))]
#[derive(sp_runtime::RuntimeDebug)]
pub enum DeferredAction<T: Trait> {
DispatchRuntimeCall {
/// The account id of the contract who dispatched this call.
origin: T::AccountId,
/// The call to dispatch.
call: <T as Trait>::Call,
},
}

pub struct ExecutionContext<'a, T: Trait + '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 deferred: Vec<DeferredAction<T>>,
pub config: &'a Config<T>,
pub vm: &'a V,
pub loader: &'a L,
Expand All @@ -313,7 +297,6 @@ where
self_trie_id: None,
self_account: origin,
depth: 0,
deferred: Vec::new(),
config: &cfg,
vm: &vm,
loader: &loader,
Expand All @@ -330,7 +313,6 @@ where
self_trie_id: trie_id,
self_account: dest,
depth: self.depth + 1,
deferred: Vec::new(),
config: self.config,
vm: self.vm,
loader: self.loader,
Expand Down Expand Up @@ -531,21 +513,14 @@ where
where F: FnOnce(&mut ExecutionContext<T, V, L>) -> ExecResult
{
use frame_support::storage::TransactionOutcome::*;
let (output, deferred) = {
let mut nested = self.nested(dest, trie_id);
let output = frame_support::storage::with_transaction(|| {
let output = func(&mut nested);
match output {
Ok(ref rv) if rv.is_success() => Commit(output),
_ => Rollback(output),
}
})?;
(output, nested.deferred)
};
if output.is_success() {
self.deferred.extend(deferred);
}
Ok(output)
let mut nested = self.nested(dest, trie_id);
frame_support::storage::with_transaction(|| {
let output = func(&mut nested);
match output {
Ok(ref rv) if rv.is_success() => Commit(output),
_ => Rollback(output),
}
})
}

/// Returns whether a contract, identified by address, is currently live in the execution
Expand Down Expand Up @@ -766,13 +741,6 @@ where
self.ctx.call(to.clone(), value, gas_meter, input_data)
}

fn note_dispatch_call(&mut self, call: CallOf<Self::T>) {
self.ctx.deferred.push(DeferredAction::DispatchRuntimeCall {
origin: self.ctx.self_account.clone(),
call,
});
}

fn restore_to(
&mut self,
dest: AccountIdOf<Self::T>,
Expand Down
44 changes: 6 additions & 38 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,13 @@ use sp_runtime::{
},
RuntimeDebug,
};
use frame_support::dispatch::{
PostDispatchInfo, DispatchResult, Dispatchable, DispatchResultWithPostInfo
};
use frame_support::{
Parameter, decl_module, decl_event, decl_storage, decl_error,
parameter_types, IsSubType, storage::child::ChildInfo,
decl_module, decl_event, decl_storage, decl_error,
parameter_types, storage::child::ChildInfo,
dispatch::{DispatchResult, DispatchResultWithPostInfo},
traits::{OnUnbalanced, Currency, Get, Time, Randomness},
};
use frame_support::traits::{OnUnbalanced, Currency, Get, Time, Randomness};
use frame_support::weights::GetDispatchInfo;
use frame_system::{self as system, ensure_signed, RawOrigin, ensure_root};
use frame_system::{self as system, ensure_signed, ensure_root};
use pallet_contracts_primitives::{RentProjection, ContractAccessError};

pub type CodeHash<T> = <T as frame_system::Trait>::Hash;
Expand Down Expand Up @@ -316,12 +313,6 @@ pub trait Trait: frame_system::Trait + pallet_transaction_payment::Trait {
type Time: Time;
type Randomness: Randomness<Self::Hash>;

/// The outer call dispatch type.
type Call:
Parameter +
Dispatchable<PostInfo=PostDispatchInfo, Origin=<Self as frame_system::Trait>::Origin> +
IsSubType<Module<Self>, Self> + GetDispatchInfo;

/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;

Expand Down Expand Up @@ -635,30 +626,7 @@ impl<T: Trait> Module<T> {
let vm = WasmVm::new(&cfg.schedule);
let loader = WasmLoader::new(&cfg.schedule);
let mut ctx = ExecutionContext::top_level(origin.clone(), &cfg, &vm, &loader);

let result = func(&mut ctx, gas_meter);

// Execute deferred actions.
ctx.deferred.into_iter().for_each(|deferred| {
use self::exec::DeferredAction::*;
match deferred {
DispatchRuntimeCall {
origin: who,
call,
} => {
let info = call.get_dispatch_info();
let result = call.dispatch(RawOrigin::Signed(who.clone()).into());
let post_info = match result {
Ok(post_info) => post_info,
Err(err) => err.post_info,
};
gas_meter.refund(post_info.calc_unspent(&info));
Self::deposit_event(RawEvent::Dispatched(who, result.is_ok()));
}
}
});

result
func(&mut ctx, gas_meter)
}
}

Expand Down
Loading