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

contracts: New contract events + unconfusions #4685

Merged
merged 9 commits into from
Jan 21, 2020
2 changes: 1 addition & 1 deletion frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ where
fn deposit_event(&mut self, topics: Vec<T::Hash>, data: Vec<u8>) {
self.ctx.deferred.push(DeferredAction::DepositEvent {
topics,
event: RawEvent::Contract(self.ctx.self_account.clone(), data),
event: RawEvent::ContractExecution(self.ctx.self_account.clone(), data),
});
}

Expand Down
26 changes: 23 additions & 3 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ decl_module! {
// If poking the contract has lead to eviction of the contract, give out the rewards.
if rent::try_evict::<T>(&dest, handicap) == rent::RentOutcome::Evicted {
T::Currency::deposit_into_existing(&rewarded, T::SurchargeReward::get())?;
Self::deposit_event(RawEvent::Evicted(dest));
Robbepop marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -786,7 +787,12 @@ impl<T: Trait> Module<T> {
rent_allowance,
delta,
} => {
let _result = Self::restore_to(donor, dest, code_hash, rent_allowance, delta);
let result = Self::restore_to(
donor.clone(), dest.clone(), code_hash.clone(), rent_allowance.clone(), delta
);
Self::deposit_event(
RawEvent::Restored(donor, dest, code_hash, rent_allowance, result.is_ok())
);
}
}
});
Expand Down Expand Up @@ -896,6 +902,20 @@ decl_event! {
/// Contract deployed by address at the specified address.
Instantiated(AccountId, AccountId),

/// Contract has been evicted and is now in tombstone state.
Evicted(AccountId),

/// Restoration for a contract has been initiated.
///
/// # Params
///
/// - `donor`: `AccountId`: Account ID of the restoring contract
/// - `dest`: `AccountId`: Account ID of the restored contract
/// - `code_hash`: `Hash`: Code hash of the restored contract
/// - `rent_allowance: `Balance`: Rent allowance of the restored contract
/// - `success`: `bool`: True if the restoration was successful
Restored(AccountId, AccountId, Hash, Balance, bool),

/// Code with the specified hash has been stored.
CodeStored(Hash),

Expand All @@ -906,8 +926,8 @@ decl_event! {
/// successful execution or not.
Dispatched(AccountId, bool),

/// An event from contract of account.
Contract(AccountId, Vec<u8>),
/// An event deposited upon execution of a contract from the account.
ContractExecution(AccountId, Vec<u8>),
}
}

Expand Down
8 changes: 4 additions & 4 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ fn instantiate_and_call_and_deposit_event() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: MetaEvent::contract(RawEvent::Contract(BOB, vec![1, 2, 3, 4])),
event: MetaEvent::contract(RawEvent::ContractExecution(BOB, vec![1, 2, 3, 4])),
topics: vec![],
},
EventRecord {
Expand Down Expand Up @@ -650,7 +650,7 @@ fn dispatch_call_not_dispatched_after_top_level_transaction_failure() {
100_000,
vec![],
),
"during execution"
"contract trapped during execution"
);
assert_eq!(System::events(), vec![
EventRecord {
Expand Down Expand Up @@ -1533,7 +1533,7 @@ fn storage_max_value_limit() {
100_000,
Encode::encode(&(self::MaxValueSize::get() + 1)),
),
"during execution"
"contract trapped during execution"
);
});
}
Expand Down Expand Up @@ -2056,7 +2056,7 @@ fn cannot_self_destruct_while_live() {
100_000,
vec![0],
),
"during execution"
"contract trapped during execution"
);

// Check that BOB is still alive.
Expand Down
4 changes: 2 additions & 2 deletions frame/contracts/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ mod tests {
MockExt::default(),
&mut gas_meter
),
Err(ExecError { reason: DispatchError::Other("during execution"), buffer: _ })
Err(ExecError { reason: DispatchError::Other("contract trapped during execution"), buffer: _ })
Robbepop marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand Down Expand Up @@ -1472,7 +1472,7 @@ mod tests {
MockExt::default(),
&mut gas_meter
),
Err(ExecError { reason: DispatchError::Other("during execution"), buffer: _ })
Err(ExecError { reason: DispatchError::Other("contract trapped during execution"), buffer: _ })
);
}

Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub(crate) fn to_execution_result<E: Ext>(
Err(ExecError { reason: "validation error".into(), buffer: runtime.scratch_buf }),
// Any other kind of a trap should result in a failure.
Err(sp_sandbox::Error::Execution) | Err(sp_sandbox::Error::OutOfBounds) =>
Err(ExecError { reason: "during execution".into(), buffer: runtime.scratch_buf }),
Err(ExecError { reason: "contract trapped during execution".into(), buffer: runtime.scratch_buf }),
}
}

Expand Down