mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 20:48:02 +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:
Generated
+8
-8
@@ -1280,9 +1280,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "evm"
|
||||
version = "0.16.1"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23a5c0ebf219b2b878bde1838282e0bb69828338df37fd136f1e93182ae35a59"
|
||||
checksum = "68224b0aa788720ef0c8a23030a4412a021ed73df069a922bee8f0db9ed617e2"
|
||||
dependencies = [
|
||||
"evm-core",
|
||||
"evm-gasometer",
|
||||
@@ -1295,18 +1295,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "evm-core"
|
||||
version = "0.16.1"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d944a07232006a3435df8aa014fd364ed04cb28d731782339e9c56436594f2d4"
|
||||
checksum = "4a040378759577447945c89da1b07d6e33fda32a97a104afe0ec3fa1c382949d"
|
||||
dependencies = [
|
||||
"primitive-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "evm-gasometer"
|
||||
version = "0.16.1"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a0d986953234d3786d0ca1beaaabab6a581d2128f8ec36c8c57e9c45e3d2b32"
|
||||
checksum = "7bb5bc051afad6bb0735c82b46656bbdfac41917861307a608b1404a546fec42"
|
||||
dependencies = [
|
||||
"evm-core",
|
||||
"evm-runtime",
|
||||
@@ -1315,9 +1315,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "evm-runtime"
|
||||
version = "0.16.1"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1833c22f9518007d3cc28e14ff586263543516a1c7a147b260c603e4deb95403"
|
||||
checksum = "7410f5677a52203d3fca02b0eb8f96f9799f3a45cff82946a8ed28379e6b1b04"
|
||||
dependencies = [
|
||||
"evm-core",
|
||||
"primitive-types",
|
||||
|
||||
@@ -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