Unverified Commit ddf40e9c authored by Robin Freyler's avatar Robin Freyler Committed by GitHub
Browse files

Always revert state upon encountering Result::Err (#975)

* always revert state upon encountering Result::Err

This fixes some misconception between ink! and SEAL.

* fix UI test

* decode result in case callee reverted

* compile fixes

* fix UI test

* fix UI test
parent 764a44a9
Pipeline #163194 passed with stages
in 27 minutes and 49 seconds
......@@ -231,15 +231,20 @@ impl EnvInstance {
let enc_transferred_value = scope.take_encoded(params.transferred_value());
let enc_input = scope.take_encoded(params.exec_input());
let output = &mut scope.take_rest();
ext::call(
let call_result = ext::call(
enc_callee,
gas_limit,
enc_transferred_value,
enc_input,
output,
)?;
let decoded = scale::Decode::decode(&mut &output[..])?;
Ok(decoded)
);
match call_result {
Ok(()) | Err(ext::Error::CalleeReverted) => {
let decoded = scale::Decode::decode(&mut &output[..])?;
Ok(decoded)
}
Err(actual_error) => Err(actual_error.into()),
}
}
}
......
......@@ -666,7 +666,6 @@ impl Dispatch<'_> {
}>>::IDS[#index]
}>>::MUTATES
);
let may_revert = ::core::cfg!(not(feature = "ink-as-dependency"));
let is_dynamic_storage_allocation_enabled = self
.contract
.config()
......@@ -681,7 +680,6 @@ impl Dispatch<'_> {
::ink_lang::codegen::ExecuteMessageConfig {
payable: #accepts_payment,
mutates: #mutates_storage,
may_revert: #may_revert,
dynamic_storage_alloc: #is_dynamic_storage_allocation_enabled,
},
move |storage: &mut #storage_ident| { #message_callable(storage, input) }
......
......@@ -107,13 +107,6 @@ pub struct ExecuteMessageConfig {
///
/// This is usually true for `&mut self` ink! messages.
pub mutates: bool,
/// Yields `true` if the ink! message execution might revert execution.
///
/// # Note
///
/// In ink! this is usually `true` for root ink! smart contracts and
/// `false` for dependency ink! smart contracts.
pub may_revert: bool,
/// Yields `true` if the dynamic storage allocator has been enabled.
///
/// # Note
......@@ -159,8 +152,7 @@ where
// will have more opportunities to optimize the whole conditional away. This is
// due to the fact that `is_result_type!` relies on constant information whereas
// is_result_err!` requires `&self`.
let revert_state =
config.may_revert && is_result_type!(Output) && is_result_err!(&result);
let revert_state = is_result_type!(Output) && is_result_err!(&result);
ink_env::return_value::<Output>(
ReturnFlags::default().set_reverted(revert_state),
&result,
......
......@@ -21,9 +21,9 @@ error[E0277]: the trait bound `NonCodecType: WrapperTypeEncode` is not satisfied
|
= note: required because of the requirements on the impl of `Encode` for `NonCodecType`
note: required by a bound in `execute_message`
--> src/codegen/dispatch/execution.rs:138:13
--> src/codegen/dispatch/execution.rs:131:13
|
138 | Output: scale::Encode + 'static,
131 | Output: scale::Encode + 'static,
| ^^^^^^^^^^^^^ required by this bound in `execute_message`
error[E0599]: the method `fire` exists for struct `ink_env::call::CallBuilder<DefaultEnvironment, Set<ink_env::AccountId>, Unset<u64>, Unset<u128>, Set<ExecutionInput<ArgumentList<ArgumentListEnd, ArgumentListEnd>>>, Set<ReturnType<NonCodecType>>>`, but its trait bounds were not satisfied
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment