mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 20:31:13 +00:00
Implement apply_state flag and allow fetching return data and used gas (#6590)
* pallet-evm: return Ok(()) when EVM execution fails * Bump spec version * Implement apply_state flag and allow fetching return data and used gas * Update evm version
This commit is contained in:
@@ -24,7 +24,7 @@ sp-std = { version = "2.0.0-rc4", default-features = false, path = "../../primit
|
||||
sp-io = { version = "2.0.0-rc4", default-features = false, path = "../../primitives/io" }
|
||||
primitive-types = { version = "0.7.0", default-features = false, features = ["rlp"] }
|
||||
rlp = { version = "0.4", default-features = false }
|
||||
evm = { version = "0.16", default-features = false }
|
||||
evm = { version = "0.17", default-features = false }
|
||||
sha3 = { version = "0.8", default-features = false }
|
||||
|
||||
[features]
|
||||
|
||||
@@ -310,11 +310,12 @@ decl_module! {
|
||||
gas_limit,
|
||||
gas_price,
|
||||
nonce,
|
||||
true,
|
||||
)? {
|
||||
ExitReason::Succeed(_) => {
|
||||
(ExitReason::Succeed(_), _, _) => {
|
||||
Module::<T>::deposit_event(Event::<T>::Executed(target));
|
||||
},
|
||||
ExitReason::Error(_) | ExitReason::Revert(_) | ExitReason::Fatal(_) => {
|
||||
(_, _, _) => {
|
||||
Module::<T>::deposit_event(Event::<T>::ExecutedFailed(target));
|
||||
},
|
||||
}
|
||||
@@ -344,12 +345,13 @@ decl_module! {
|
||||
value,
|
||||
gas_limit,
|
||||
gas_price,
|
||||
nonce
|
||||
nonce,
|
||||
true,
|
||||
)? {
|
||||
(create_address, ExitReason::Succeed(_)) => {
|
||||
(ExitReason::Succeed(_), create_address, _) => {
|
||||
Module::<T>::deposit_event(Event::<T>::Created(create_address));
|
||||
},
|
||||
(create_address, _) => {
|
||||
(_, create_address, _) => {
|
||||
Module::<T>::deposit_event(Event::<T>::CreatedFailed(create_address));
|
||||
},
|
||||
}
|
||||
@@ -380,12 +382,13 @@ decl_module! {
|
||||
value,
|
||||
gas_limit,
|
||||
gas_price,
|
||||
nonce
|
||||
nonce,
|
||||
true,
|
||||
)? {
|
||||
(create_address, ExitReason::Succeed(_)) => {
|
||||
(ExitReason::Succeed(_), create_address, _) => {
|
||||
Module::<T>::deposit_event(Event::<T>::Created(create_address));
|
||||
},
|
||||
(create_address, _) => {
|
||||
(_, create_address, _) => {
|
||||
Module::<T>::deposit_event(Event::<T>::CreatedFailed(create_address));
|
||||
},
|
||||
}
|
||||
@@ -435,23 +438,26 @@ impl<T: Trait> Module<T> {
|
||||
value: U256,
|
||||
gas_limit: u32,
|
||||
gas_price: U256,
|
||||
nonce: Option<U256>
|
||||
) -> Result<(H160, ExitReason), Error<T>> {
|
||||
nonce: Option<U256>,
|
||||
apply_state: bool,
|
||||
) -> Result<(ExitReason, H160, U256), Error<T>> {
|
||||
Self::execute_evm(
|
||||
source,
|
||||
value,
|
||||
gas_limit,
|
||||
gas_price,
|
||||
nonce,
|
||||
apply_state,
|
||||
|executor| {
|
||||
(executor.create_address(
|
||||
let address = executor.create_address(
|
||||
evm::CreateScheme::Legacy { caller: source },
|
||||
), executor.transact_create(
|
||||
);
|
||||
(executor.transact_create(
|
||||
source,
|
||||
value,
|
||||
init,
|
||||
gas_limit as usize,
|
||||
))
|
||||
), address)
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -464,8 +470,9 @@ impl<T: Trait> Module<T> {
|
||||
value: U256,
|
||||
gas_limit: u32,
|
||||
gas_price: U256,
|
||||
nonce: Option<U256>
|
||||
) -> Result<(H160, ExitReason), Error<T>> {
|
||||
nonce: Option<U256>,
|
||||
apply_state: bool,
|
||||
) -> Result<(ExitReason, H160, U256), Error<T>> {
|
||||
let code_hash = H256::from_slice(Keccak256::digest(&init).as_slice());
|
||||
Self::execute_evm(
|
||||
source,
|
||||
@@ -473,16 +480,18 @@ impl<T: Trait> Module<T> {
|
||||
gas_limit,
|
||||
gas_price,
|
||||
nonce,
|
||||
apply_state,
|
||||
|executor| {
|
||||
(executor.create_address(
|
||||
let address = executor.create_address(
|
||||
evm::CreateScheme::Create2 { caller: source, code_hash, salt },
|
||||
), executor.transact_create2(
|
||||
);
|
||||
(executor.transact_create2(
|
||||
source,
|
||||
value,
|
||||
init,
|
||||
salt,
|
||||
gas_limit as usize,
|
||||
))
|
||||
), address)
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -496,21 +505,23 @@ impl<T: Trait> Module<T> {
|
||||
gas_limit: u32,
|
||||
gas_price: U256,
|
||||
nonce: Option<U256>,
|
||||
) -> Result<ExitReason, Error<T>> {
|
||||
Ok(Self::execute_evm(
|
||||
apply_state: bool,
|
||||
) -> Result<(ExitReason, Vec<u8>, U256), Error<T>> {
|
||||
Self::execute_evm(
|
||||
source,
|
||||
value,
|
||||
gas_limit,
|
||||
gas_price,
|
||||
nonce,
|
||||
|executor| ((), executor.transact_call(
|
||||
apply_state,
|
||||
|executor| executor.transact_call(
|
||||
source,
|
||||
target,
|
||||
value,
|
||||
input,
|
||||
gas_limit as usize,
|
||||
)),
|
||||
)?.1)
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/// Execute an EVM operation.
|
||||
@@ -520,9 +531,10 @@ impl<T: Trait> Module<T> {
|
||||
gas_limit: u32,
|
||||
gas_price: U256,
|
||||
nonce: Option<U256>,
|
||||
apply_state: bool,
|
||||
f: F,
|
||||
) -> Result<(R, ExitReason), Error<T>> where
|
||||
F: FnOnce(&mut StackExecutor<Backend<T>>) -> (R, ExitReason),
|
||||
) -> Result<(ExitReason, R, U256), Error<T>> where
|
||||
F: FnOnce(&mut StackExecutor<Backend<T>>) -> (ExitReason, R),
|
||||
{
|
||||
let vicinity = Vicinity {
|
||||
gas_price,
|
||||
@@ -550,12 +562,15 @@ impl<T: Trait> Module<T> {
|
||||
|
||||
let (retv, reason) = f(&mut executor);
|
||||
|
||||
let used_gas = U256::from(executor.used_gas());
|
||||
let actual_fee = executor.fee(gas_price);
|
||||
executor.deposit(source, total_fee.saturating_sub(actual_fee));
|
||||
|
||||
let (values, logs) = executor.deconstruct();
|
||||
backend.apply(values, logs, true);
|
||||
if apply_state {
|
||||
let (values, logs) = executor.deconstruct();
|
||||
backend.apply(values, logs, true);
|
||||
}
|
||||
|
||||
Ok((retv, reason))
|
||||
Ok((retv, reason, used_gas))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user