diff --git a/Cargo.lock b/Cargo.lock index faae99caf4..986cd6313a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -404,7 +404,7 @@ dependencies = [ [[package]] name = "astar-collator" -version = "5.12.0" +version = "5.13.0" dependencies = [ "astar-primitives", "astar-runtime", @@ -529,7 +529,7 @@ dependencies = [ [[package]] name = "astar-runtime" -version = "5.12.0" +version = "5.13.0" dependencies = [ "array-bytes 6.1.0", "astar-primitives", @@ -5475,7 +5475,7 @@ checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" [[package]] name = "local-runtime" -version = "5.12.0" +version = "5.13.0" dependencies = [ "array-bytes 6.1.0", "astar-primitives", @@ -5507,6 +5507,7 @@ dependencies = [ "pallet-dapps-staking", "pallet-democracy", "pallet-ethereum", + "pallet-ethereum-checked", "pallet-evm", "pallet-evm-precompile-assets-erc20", "pallet-evm-precompile-blake2", @@ -5540,6 +5541,7 @@ dependencies = [ "sp-consensus-aura", "sp-core", "sp-inherents", + "sp-io", "sp-offchain", "sp-runtime", "sp-session", @@ -7084,7 +7086,7 @@ dependencies = [ [[package]] name = "pallet-dapps-staking" -version = "3.9.0" +version = "3.10.0" dependencies = [ "astar-primitives", "frame-benchmarking", @@ -8231,12 +8233,14 @@ dependencies = [ name = "pallet-xvm" version = "0.2.1" dependencies = [ + "astar-primitives", "frame-benchmarking", "frame-support", "frame-system", "impl-trait-for-tuples", "log", "pallet-contracts", + "pallet-ethereum-checked", "pallet-evm", "parity-scale-codec", "scale-info", @@ -12292,7 +12296,7 @@ dependencies = [ [[package]] name = "shibuya-runtime" -version = "5.12.0" +version = "5.14.0" dependencies = [ "array-bytes 6.1.0", "astar-primitives", @@ -12338,6 +12342,7 @@ dependencies = [ "pallet-dapps-staking", "pallet-democracy", "pallet-ethereum", + "pallet-ethereum-checked", "pallet-evm", "pallet-evm-chain-id", "pallet-evm-precompile-assets-erc20", @@ -12399,7 +12404,7 @@ dependencies = [ [[package]] name = "shiden-runtime" -version = "5.12.0" +version = "5.13.0" dependencies = [ "array-bytes 6.1.0", "astar-primitives", diff --git a/Cargo.toml b/Cargo.toml index c8447d204b..f803ea3fae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,6 +62,7 @@ num_enum = { version = "0.5.3", default-features = false } num-traits = { version = "0.2", default-features = false } rand = { version = "0.8.5", default-features = false } bounded-collections = { version = "0.1.5", default-features = false } +hex = { version = "0.4.3", default-features = false } # (native) array-bytes = "6.0.0" @@ -74,7 +75,6 @@ serde_json = "1.0.92" tokio = { version = "1.24.2", features = ["macros", "sync"] } url = "2.2.2" jsonrpsee = { version = "0.16.2", features = ["server"] } -hex = { version = "0.4.3", features = ["serde"] } hex-literal = "0.4.1" regex = "1.6.0" rlp = "0.5" @@ -276,6 +276,7 @@ pallet-dapps-staking = { path = "./pallets/dapps-staking", default-features = fa pallet-xc-asset-config = { path = "./pallets/xc-asset-config", default-features = false } pallet-xvm = { path = "./pallets/pallet-xvm", default-features = false } pallet-xcm = { path = "./pallets/pallet-xcm", default-features = false } +pallet-ethereum-checked = { path = "./pallets/ethereum-checked", default-features = false } astar-primitives = { path = "./primitives", default-features = false } diff --git a/bin/collator/Cargo.toml b/bin/collator/Cargo.toml index efb2e2ecf5..52e73779c2 100644 --- a/bin/collator/Cargo.toml +++ b/bin/collator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "astar-collator" -version = "5.12.0" +version = "5.13.0" description = "Astar collator implementation in Rust." build = "build.rs" default-run = "astar-collator" diff --git a/bin/collator/res/astar.json b/bin/collator/res/astar.json index 596118fe0d..8eae801a4c 100644 --- a/bin/collator/res/astar.json +++ b/bin/collator/res/astar.json @@ -3,11 +3,12 @@ "id": "astar", "chainType": "Live", "bootNodes": [ - "/dnsaddr/bootnode.astar.network/p2p/12D3KooWMaG4prEjqt1C6Mfas8LCFs31f5k11jw4nRuV52KR3yaB", - "/ip4/51.91.105.142/tcp/30333/ws/p2p/12D3KooWGrSwcPyA5V9qCR4RiiXZ7ErERiZ6jnpp1PhjYgxP8qSL", - "/ip4/35.197.38.107/tcp/30333/ws/p2p/12D3KooWHV4YxifTpBkLWPPaF8EfoMSXeGNWWxXqUokGsBGxwioK", - "/dns/wss-bootnode-02.astar.network/tcp/443/wss/p2p/12D3KooWGrSwcPyA5V9qCR4RiiXZ7ErERiZ6jnpp1PhjYgxP8qSL", - "/dns/wss-bootnode-03.astar.network/tcp/443/wss/p2p/12D3KooWHV4YxifTpBkLWPPaF8EfoMSXeGNWWxXqUokGsBGxwioK", + "/ip4/109.238.14.102/tcp/30333/ws/p2p/12D3KooWPH9bkXRkPcHGKd7DSgYfLLVE1Cw7QNr2M4kKwdVwGZXN", + "/ip4/199.85.208.179/tcp/30333/ws/p2p/12D3KooWMwrAXhSuzCrtiwfVQuB4oLAZj3CLxVzMrqBJB4GKjnQa", + "/ip4/131.153.79.50/tcp/30333/ws/p2p/12D3KooWB2XY9Uw1ZR8qtD5DQ4TKivJkQdqM5c6hyY9ixSDAASBa", + "/dns/bootnode-01.astar.network/tcp/443/wss/p2p/12D3KooWPH9bkXRkPcHGKd7DSgYfLLVE1Cw7QNr2M4kKwdVwGZXN", + "/dns/bootnode-02.astar.network/tcp/443/wss/p2p/12D3KooWMwrAXhSuzCrtiwfVQuB4oLAZj3CLxVzMrqBJB4GKjnQa", + "/dns/bootnode-03.astar.network/tcp/443/wss/p2p/12D3KooWB2XY9Uw1ZR8qtD5DQ4TKivJkQdqM5c6hyY9ixSDAASBa", "/dns4/astar-bootnode-1-tls.p2p.onfinality.io/tcp/443/wss/p2p/12D3KooWERrQFE8ss7zYfcHp8ULVCc1N7gur7GqZ8ESuZB1Nmioh" ], "telemetryEndpoints": null, diff --git a/bin/collator/res/astar.raw.json b/bin/collator/res/astar.raw.json index 41fbebc793..475cc7e0f7 100644 --- a/bin/collator/res/astar.raw.json +++ b/bin/collator/res/astar.raw.json @@ -3,11 +3,12 @@ "id": "astar", "chainType": "Live", "bootNodes": [ - "/dnsaddr/bootnode.astar.network/p2p/12D3KooWMaG4prEjqt1C6Mfas8LCFs31f5k11jw4nRuV52KR3yaB", - "/ip4/51.91.105.142/tcp/30333/ws/p2p/12D3KooWGrSwcPyA5V9qCR4RiiXZ7ErERiZ6jnpp1PhjYgxP8qSL", - "/ip4/35.197.38.107/tcp/30333/ws/p2p/12D3KooWHV4YxifTpBkLWPPaF8EfoMSXeGNWWxXqUokGsBGxwioK", - "/dns/wss-bootnode-02.astar.network/tcp/443/wss/p2p/12D3KooWGrSwcPyA5V9qCR4RiiXZ7ErERiZ6jnpp1PhjYgxP8qSL", - "/dns/wss-bootnode-03.astar.network/tcp/443/wss/p2p/12D3KooWHV4YxifTpBkLWPPaF8EfoMSXeGNWWxXqUokGsBGxwioK", + "/ip4/109.238.14.102/tcp/30333/ws/p2p/12D3KooWPH9bkXRkPcHGKd7DSgYfLLVE1Cw7QNr2M4kKwdVwGZXN", + "/ip4/199.85.208.179/tcp/30333/ws/p2p/12D3KooWMwrAXhSuzCrtiwfVQuB4oLAZj3CLxVzMrqBJB4GKjnQa", + "/ip4/131.153.79.50/tcp/30333/ws/p2p/12D3KooWB2XY9Uw1ZR8qtD5DQ4TKivJkQdqM5c6hyY9ixSDAASBa", + "/dns/bootnode-01.astar.network/tcp/443/wss/p2p/12D3KooWPH9bkXRkPcHGKd7DSgYfLLVE1Cw7QNr2M4kKwdVwGZXN", + "/dns/bootnode-02.astar.network/tcp/443/wss/p2p/12D3KooWMwrAXhSuzCrtiwfVQuB4oLAZj3CLxVzMrqBJB4GKjnQa", + "/dns/bootnode-03.astar.network/tcp/443/wss/p2p/12D3KooWB2XY9Uw1ZR8qtD5DQ4TKivJkQdqM5c6hyY9ixSDAASBa", "/dns4/astar-bootnode-1-tls.p2p.onfinality.io/tcp/443/wss/p2p/12D3KooWERrQFE8ss7zYfcHp8ULVCc1N7gur7GqZ8ESuZB1Nmioh" ], "telemetryEndpoints": null, diff --git a/bin/collator/res/shiden.json b/bin/collator/res/shiden.json index dd7e2ebb37..9decaadd9b 100644 --- a/bin/collator/res/shiden.json +++ b/bin/collator/res/shiden.json @@ -3,11 +3,12 @@ "id": "shiden", "chainType": "Live", "bootNodes": [ - "/ip4/54.64.145.3/tcp/30333/ws/p2p/12D3KooWDYfspdMj1tQJZuiecmKKaQjGuSX2cy5rExtqcMqmiNrR", - "/ip4/54.38.192.54/tcp/30333/ws/p2p/12D3KooWAgdZ27WhBzLRinaE7iTR1pXxKTsSJniXYu1xAEJD7LzS", - "/ip4/34.168.164.206/tcp/30333/p2p/12D3KooWAQhseqYAL3NfqS38151wVbABeogWB3AbfnzvBUic2ozp", - "/dns/wss-bootnode-01.shiden.astar.network/tcp/443/wss/p2p/12D3KooWDYfspdMj1tQJZuiecmKKaQjGuSX2cy5rExtqcMqmiNrR", - "/dns/wss-bootnode-02.shiden.astar.network/tcp/443/wss/p2p/12D3KooWAgdZ27WhBzLRinaE7iTR1pXxKTsSJniXYu1xAEJD7LzS" + "/ip4/199.85.208.173/tcp/30333/ws/p2p/12D3KooWFPzN2cH31unDY8Wx7x2XpnsYBJWfFJNL9HGLida1dZY1", + "/ip4/51.89.41.58/tcp/30333/ws/p2p/12D3KooWJwbUzXmA46QA71UkzgVnvSd9Nx4HhY48HLCwWcHYiC9d", + "/ip4/131.153.79.58/tcp/30333/ws/p2p/12D3KooWCzR5i4pYhc1SXEEwViasCmn8HkTwo1zK7h8TiUUp2eLX", + "/dns/bootnode-01.shiden.astar.network/tcp/443/wss/p2p/12D3KooWDYfspdMj1tQJZuiecmKKaQjGuSX2cy5rExtqcMqmiNrR", + "/dns/bootnode-02.shiden.astar.network/tcp/443/wss/p2p/12D3KooWAgdZ27WhBzLRinaE7iTR1pXxKTsSJniXYu1xAEJD7LzS", + "/dns/bootnode-03.shiden.astar.network/tcp/443/wss/p2p/12D3KooWCzR5i4pYhc1SXEEwViasCmn8HkTwo1zK7h8TiUUp2eLX" ], "telemetryEndpoints": null, "protocolId": "shiden", diff --git a/bin/collator/res/shiden.raw.json b/bin/collator/res/shiden.raw.json index 1df3665bdb..9d47524baf 100644 --- a/bin/collator/res/shiden.raw.json +++ b/bin/collator/res/shiden.raw.json @@ -3,11 +3,12 @@ "id": "shiden", "chainType": "Live", "bootNodes": [ - "/ip4/54.64.145.3/tcp/30333/ws/p2p/12D3KooWDYfspdMj1tQJZuiecmKKaQjGuSX2cy5rExtqcMqmiNrR", - "/ip4/54.38.192.54/tcp/30333/ws/p2p/12D3KooWAgdZ27WhBzLRinaE7iTR1pXxKTsSJniXYu1xAEJD7LzS", - "/ip4/34.168.164.206/tcp/30333/p2p/12D3KooWAQhseqYAL3NfqS38151wVbABeogWB3AbfnzvBUic2ozp", - "/dns/wss-bootnode-01.shiden.astar.network/tcp/443/wss/p2p/12D3KooWDYfspdMj1tQJZuiecmKKaQjGuSX2cy5rExtqcMqmiNrR", - "/dns/wss-bootnode-02.shiden.astar.network/tcp/443/wss/p2p/12D3KooWAgdZ27WhBzLRinaE7iTR1pXxKTsSJniXYu1xAEJD7LzS" + "/ip4/199.85.208.173/tcp/30333/ws/p2p/12D3KooWFPzN2cH31unDY8Wx7x2XpnsYBJWfFJNL9HGLida1dZY1", + "/ip4/51.89.41.58/tcp/30333/ws/p2p/12D3KooWJwbUzXmA46QA71UkzgVnvSd9Nx4HhY48HLCwWcHYiC9d", + "/ip4/131.153.79.58/tcp/30333/ws/p2p/12D3KooWCzR5i4pYhc1SXEEwViasCmn8HkTwo1zK7h8TiUUp2eLX", + "/dns/bootnode-01.shiden.astar.network/tcp/443/wss/p2p/12D3KooWDYfspdMj1tQJZuiecmKKaQjGuSX2cy5rExtqcMqmiNrR", + "/dns/bootnode-02.shiden.astar.network/tcp/443/wss/p2p/12D3KooWAgdZ27WhBzLRinaE7iTR1pXxKTsSJniXYu1xAEJD7LzS", + "/dns/bootnode-03.shiden.astar.network/tcp/443/wss/p2p/12D3KooWCzR5i4pYhc1SXEEwViasCmn8HkTwo1zK7h8TiUUp2eLX" ], "telemetryEndpoints": null, "protocolId": "shiden", diff --git a/chain-extensions/xvm/src/lib.rs b/chain-extensions/xvm/src/lib.rs index 94a0eacd4c..9e348bbbce 100644 --- a/chain-extensions/xvm/src/lib.rs +++ b/chain-extensions/xvm/src/lib.rs @@ -18,8 +18,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use frame_support::dispatch::Encode; -use frame_support::weights::Weight; +use frame_support::{dispatch::Encode, weights::Weight}; use pallet_contracts::{ chain_extension::{ChainExtension, Environment, Ext, InitState, RetVal}, Origin, @@ -102,8 +101,7 @@ where pallet_xvm::Pallet::::xvm_bare_call(xvm_context, caller, to, input); let actual_weight = pallet_xvm::consumed_weight(&call_result); - // TODO: implement proof of size refund. - env.adjust_weight(charged_weight, Weight::from_parts(actual_weight, 0)); + env.adjust_weight(charged_weight, actual_weight); match call_result { Ok(success) => { diff --git a/pallets/dapps-staking/Cargo.toml b/pallets/dapps-staking/Cargo.toml index c06c1400bf..ecbf8ca1ed 100644 --- a/pallets/dapps-staking/Cargo.toml +++ b/pallets/dapps-staking/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-dapps-staking" -version = "3.9.0" +version = "3.10.0" description = "FRAME pallet to staking for dapps" authors.workspace = true edition.workspace = true diff --git a/pallets/dapps-staking/src/benchmarking.rs b/pallets/dapps-staking/src/benchmarking.rs index aad7705064..ce259ad217 100644 --- a/pallets/dapps-staking/src/benchmarking.rs +++ b/pallets/dapps-staking/src/benchmarking.rs @@ -22,7 +22,7 @@ use super::*; use crate::Pallet as DappsStaking; use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; -use frame_support::traits::{Get, OnFinalize, OnInitialize}; +use frame_support::traits::{Currency, Get, OnFinalize, OnInitialize}; use frame_system::{Pallet as System, RawOrigin}; use sp_runtime::traits::{One, TrailingZeroInput}; diff --git a/pallets/dapps-staking/src/lib.rs b/pallets/dapps-staking/src/lib.rs index 1530ba5f24..d9da78d259 100644 --- a/pallets/dapps-staking/src/lib.rs +++ b/pallets/dapps-staking/src/lib.rs @@ -67,7 +67,6 @@ #![cfg_attr(not(feature = "std"), no_std)] use astar_primitives::Balance; -use frame_support::traits::Currency; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_runtime::{traits::Zero, RuntimeDebug}; @@ -541,7 +540,7 @@ pub enum RewardDestination { impl Default for RewardDestination { fn default() -> Self { - RewardDestination::StakeBalance + RewardDestination::FreeBalance } } diff --git a/pallets/dapps-staking/src/tests.rs b/pallets/dapps-staking/src/tests.rs index 23ca758304..761251b74e 100644 --- a/pallets/dapps-staking/src/tests.rs +++ b/pallets/dapps-staking/src/tests.rs @@ -17,7 +17,11 @@ // along with Astar. If not, see . use super::{pallet::pallet::Error, pallet::pallet::Event, *}; -use frame_support::{assert_noop, assert_ok, traits::OnInitialize, weights::Weight}; +use frame_support::{ + assert_noop, assert_ok, + traits::{Currency, OnInitialize}, + weights::Weight, +}; use mock::{Balance, Balances, MockSmartContract, *}; use sp_core::H160; use sp_runtime::{ @@ -1911,6 +1915,19 @@ fn changing_reward_destination_for_empty_ledger_is_not_ok() { }); } +#[test] +fn default_reward_destination_is_free_balance() { + ExternalityBuilder::build().execute_with(|| { + initialize_first_block(); + + let staker = 1; + assert_eq!( + DappsStaking::ledger(&staker).reward_destination, + RewardDestination::FreeBalance + ); + }); +} + #[test] fn claim_dapp_with_zero_stake_periods_is_ok() { ExternalityBuilder::build().execute_with(|| { diff --git a/pallets/ethereum-checked/Cargo.toml b/pallets/ethereum-checked/Cargo.toml index 6bb34e881e..c9aaca3e8a 100644 --- a/pallets/ethereum-checked/Cargo.toml +++ b/pallets/ethereum-checked/Cargo.toml @@ -8,6 +8,7 @@ homepage.workspace = true repository.workspace = true [dependencies] +hex = { workspace = true, optional = true } parity-scale-codec = { workspace = true } scale-info = { workspace = true } @@ -26,7 +27,6 @@ astar-primitives = { workspace = true } [dev-dependencies] ethereum = { workspace = true } -hex = { workspace = true } pallet-balances = { workspace = true } pallet-ethereum = { workspace = true } pallet-evm = { workspace = true } @@ -36,6 +36,7 @@ sp-io = { workspace = true } [features] default = ["std"] std = [ + "hex/std", "parity-scale-codec/std", "scale-info/std", "ethereum/std", @@ -55,9 +56,12 @@ std = [ "astar-primitives/std", ] runtime-benchmarks = [ + "hex", "frame-benchmarking", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "sp-runtime/runtime-benchmarks", + "pallet-ethereum/runtime-benchmarks", + "astar-primitives/runtime-benchmarks", ] try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/ethereum-checked/src/benchmarking.rs b/pallets/ethereum-checked/src/benchmarking.rs new file mode 100644 index 0000000000..b45458afe6 --- /dev/null +++ b/pallets/ethereum-checked/src/benchmarking.rs @@ -0,0 +1,70 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Astar is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Astar. If not, see . + +use super::*; + +use astar_primitives::ethereum_checked::MAX_ETHEREUM_TX_INPUT_SIZE; +use frame_benchmarking::v2::*; + +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn transact_without_apply() { + let origin = T::XcmTransactOrigin::try_successful_origin().unwrap(); + let target = + H160::from_slice(&hex::decode("dfb975d018f03994a3b943808e3aa0964bd78463").unwrap()); + // Calling `store(3)` + let input = BoundedVec::>::try_from( + hex::decode("6057361d0000000000000000000000000000000000000000000000000000000000000003") + .unwrap(), + ) + .unwrap(); + let checked_tx = CheckedEthereumTx { + gas_limit: U256::from(1_000_000), + target, + value: U256::zero(), + input, + maybe_access_list: None, + }; + + #[block] + { + Pallet::::transact_without_apply(origin, checked_tx).unwrap(); + } + + assert_eq!(Nonce::::get(), U256::one()) + } + + impl_benchmark_test_suite!( + Pallet, + crate::benchmarking::tests::new_test_ext(), + crate::mock::TestRuntime, + ); +} + +#[cfg(test)] +mod tests { + use crate::mock; + use sp_io::TestExternalities; + + pub fn new_test_ext() -> TestExternalities { + mock::ExtBuilder::default().build() + } +} diff --git a/pallets/ethereum-checked/src/lib.rs b/pallets/ethereum-checked/src/lib.rs index 303a063255..e55b0e96f0 100644 --- a/pallets/ethereum-checked/src/lib.rs +++ b/pallets/ethereum-checked/src/lib.rs @@ -49,8 +49,8 @@ use scale_info::TypeInfo; use ethereum_types::{H160, U256}; use fp_ethereum::{TransactionData, ValidatedTransaction}; use fp_evm::{ - CallInfo, CallOrCreateInfo, CheckEvmTransaction, CheckEvmTransactionConfig, - InvalidEvmTransactionError, + CallInfo, CallOrCreateInfo, CheckEvmTransaction, CheckEvmTransactionConfig, ExitReason, + ExitSucceed, InvalidEvmTransactionError, }; use pallet_evm::GasWeightMapping; @@ -70,9 +70,19 @@ use astar_primitives::ethereum_checked::{ pub use pallet::*; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; + +// TODO: after integrated into Astar/Shiden runtime, redo benchmarking with them. +// The reason is that `EVMChainId` storage read only happens in Shibuya +pub mod weights; +pub use weights::WeightInfo; + mod mock; mod tests; +pub type WeightInfoOf = ::WeightInfo; + /// Origin for dispatch-able calls. #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub enum RawOrigin { @@ -135,6 +145,9 @@ pub mod pallet { /// Origin for `transact` call. type XcmTransactOrigin: EnsureOrigin; + + /// Weight information for extrinsics in this pallet. + type WeightInfo: WeightInfo; } #[pallet::origin] @@ -152,8 +165,7 @@ pub mod pallet { #[pallet::call_index(0)] #[pallet::weight({ let weight_limit = T::GasWeightMapping::gas_to_weight(tx.gas_limit.unique_saturated_into(), false); - // `Nonce` storage read 1, write 1. - weight_limit.saturating_add(T::DbWeight::get().reads_writes(1, 1)) + weight_limit.saturating_add(WeightInfoOf::::transact_without_apply()) })] pub fn transact(origin: OriginFor, tx: CheckedEthereumTx) -> DispatchResultWithPostInfo { let source = T::XcmTransactOrigin::ensure_origin(origin)?; @@ -161,6 +173,7 @@ pub mod pallet { T::AccountMapping::into_h160(source), tx.into(), CheckedEthereumTxKind::Xcm, + false, ) .map(|(post_info, _)| post_info) } @@ -173,6 +186,7 @@ impl Pallet { source: H160, checked_tx: CheckedEthereumTx, tx_kind: CheckedEthereumTxKind, + skip_apply: bool, ) -> Result<(PostDispatchInfo, CallInfo), DispatchErrorWithPostInfo> { let chain_id = T::ChainId::get(); let nonce = Nonce::::get(); @@ -198,8 +212,11 @@ impl Pallet { .validate_common() .map_err(|_| DispatchErrorWithPostInfo { post_info: PostDispatchInfo { - // `Nonce` storage read 1. - actual_weight: Some(T::DbWeight::get().reads(1)), + // actual_weight = overhead - nonce_write_1 + actual_weight: Some( + WeightInfoOf::::transact_without_apply() + .saturating_sub(T::DbWeight::get().writes(1)), + ), pays_fee: Pays::Yes, }, error: DispatchError::Other("Failed to validate Ethereum tx"), @@ -207,6 +224,21 @@ impl Pallet { Nonce::::put(nonce.saturating_add(U256::one())); + if skip_apply { + return Ok(( + PostDispatchInfo { + actual_weight: Some(WeightInfoOf::::transact_without_apply()), + pays_fee: Pays::Yes, + }, + CallInfo { + exit_reason: ExitReason::Succeed(ExitSucceed::Returned), + value: Default::default(), + used_gas: checked_tx.gas_limit, + logs: Default::default(), + }, + )); + } + // Execute the tx. let (post_info, apply_info) = T::ValidatedTransaction::apply(source, tx)?; match apply_info { @@ -226,6 +258,23 @@ impl Pallet { }; T::GasWeightMapping::weight_to_gas(weight_limit) } + + /// Similar to `transact` dispatch-able call that transacts an Ethereum transaction, + /// but not to apply it. This is to benchmark the weight overhead in addition to `gas_limit`. + #[cfg(feature = "runtime-benchmarks")] + pub fn transact_without_apply( + origin: OriginFor, + tx: CheckedEthereumTx, + ) -> DispatchResultWithPostInfo { + let source = T::XcmTransactOrigin::ensure_origin(origin)?; + Self::do_transact( + T::AccountMapping::into_h160(source), + tx.into(), + CheckedEthereumTxKind::Xcm, + true, + ) + .map(|(post_info, _)| post_info) + } } impl CheckedEthereumTransact for Pallet { @@ -233,6 +282,6 @@ impl CheckedEthereumTransact for Pallet { source: H160, checked_tx: CheckedEthereumTx, ) -> Result<(PostDispatchInfo, CallInfo), DispatchErrorWithPostInfo> { - Self::do_transact(source, checked_tx, CheckedEthereumTxKind::Xvm) + Self::do_transact(source, checked_tx, CheckedEthereumTxKind::Xvm, false) } } diff --git a/pallets/ethereum-checked/src/mock.rs b/pallets/ethereum-checked/src/mock.rs index 13d586e2d2..b63a34c23d 100644 --- a/pallets/ethereum-checked/src/mock.rs +++ b/pallets/ethereum-checked/src/mock.rs @@ -195,6 +195,7 @@ impl pallet_ethereum_checked::Config for TestRuntime { type ValidatedTransaction = pallet_ethereum::ValidatedTransaction; type AccountMapping = MockAccountMapping; type XcmTransactOrigin = EnsureXcmEthereumTx; + type WeightInfo = (); } pub(crate) type AccountId = AccountId32; diff --git a/pallets/ethereum-checked/src/tests.rs b/pallets/ethereum-checked/src/tests.rs index d474f94282..7d77601fd9 100644 --- a/pallets/ethereum-checked/src/tests.rs +++ b/pallets/ethereum-checked/src/tests.rs @@ -72,6 +72,18 @@ fn transact_works() { _ => panic!("unexpected transaction type"), } assert_eq!(Nonce::::get(), U256::from(2)); + + let retrieve_tx = CheckedEthereumTx { + gas_limit: U256::from(1_000_000), + target: contract_address(), + value: U256::zero(), + // Calling `retrieve` + input: bounded_input("2e64cec1"), + maybe_access_list: None, + }; + let (_, call_info) = + EthereumChecked::xvm_transact(ALICE_H160, retrieve_tx).expect("failed to retrieve"); + assert_eq!(U256::from_big_endian(&(call_info.value)), 3.into()); }); } diff --git a/pallets/ethereum-checked/src/weights.rs b/pallets/ethereum-checked/src/weights.rs new file mode 100644 index 0000000000..eed089746c --- /dev/null +++ b/pallets/ethereum-checked/src/weights.rs @@ -0,0 +1,87 @@ +// This file is part of Astar. + +// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Astar is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Astar. If not, see . + +//! Autogenerated weights for pallet_ethereum_checked +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-07-17, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `devserver-01`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/astar-collator +// benchmark +// pallet +// --chain=shibuya-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_ethereum_checked +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --output=./benchmark-results/ethereum_checked_weights.rs +// --template=./scripts/templates/weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for pallet_ethereum_checked. +pub trait WeightInfo { + fn transact_without_apply() -> Weight; +} + +/// Weights for pallet_ethereum_checked using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: EVMChainId ChainId (r:1 w:0) + /// Proof: EVMChainId ChainId (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) + /// Storage: EthereumChecked Nonce (r:1 w:1) + /// Proof: EthereumChecked Nonce (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) + fn transact_without_apply() -> Weight { + // Proof Size summary in bytes: + // Measured: `150` + // Estimated: `3010` + // Minimum execution time: 8_838_000 picoseconds. + Weight::from_parts(9_229_000, 3010) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + /// Storage: EVMChainId ChainId (r:1 w:0) + /// Proof: EVMChainId ChainId (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) + /// Storage: EthereumChecked Nonce (r:1 w:1) + /// Proof: EthereumChecked Nonce (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) + fn transact_without_apply() -> Weight { + // Proof Size summary in bytes: + // Measured: `150` + // Estimated: `3010` + // Minimum execution time: 8_838_000 picoseconds. + Weight::from_parts(9_229_000, 3010) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } +} diff --git a/pallets/pallet-xvm/Cargo.toml b/pallets/pallet-xvm/Cargo.toml index 8955ff752c..0d0fa29d1c 100644 --- a/pallets/pallet-xvm/Cargo.toml +++ b/pallets/pallet-xvm/Cargo.toml @@ -23,18 +23,23 @@ sp-std = { workspace = true } # Benchmarks frame-benchmarking = { workspace = true, optional = true } -# EVM support +# EVM pallet-evm = { workspace = true, optional = true } # Substrate WASM VM support pallet-contracts = { workspace = true, optional = true } +# Astar +astar-primitives = { workspace = true } +pallet-ethereum-checked = { workspace = true, optional = true } + [dev-dependencies] [features] default = ["std"] evm = [ "pallet-evm", + "pallet-ethereum-checked", ] wasm = [ "pallet-contracts", @@ -50,9 +55,12 @@ std = [ "sp-core/std", "sp-runtime/std", "sp-std/std", + "astar-primitives/std", + "pallet-ethereum-checked/std", ] runtime-benchmarks = [ "frame-benchmarking", + "pallet-ethereum-checked/runtime-benchmarks", ] try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/pallet-xvm/src/evm.rs b/pallets/pallet-xvm/src/evm.rs index e810f3b4b2..383e43a862 100644 --- a/pallets/pallet-xvm/src/evm.rs +++ b/pallets/pallet-xvm/src/evm.rs @@ -19,20 +19,27 @@ //! EVM support for XVM pallet. use crate::*; -use pallet_evm::{GasWeightMapping, Runner}; -use sp_core::{H160, U256}; -use sp_runtime::traits::{Get, UniqueSaturatedInto}; +use frame_support::{traits::ConstU32, BoundedVec}; +use pallet_evm::GasWeightMapping; +use sp_core::U256; +use sp_runtime::traits::Get; + +use astar_primitives::ethereum_checked::{ + AccountMapping as AccountMappingT, CheckedEthereumTransact, CheckedEthereumTx, + MAX_ETHEREUM_TX_INPUT_SIZE, +}; /// EVM adapter for XVM calls. /// /// This adapter supports generic XVM calls and encode it into EVM native calls /// using Solidity ABI codec (https://docs.soliditylang.org/en/v0.8.16/abi-spec.html). -pub struct EVM(sp_std::marker::PhantomData<(I, T)>); +pub struct EVM(sp_std::marker::PhantomData<(I, T, Transact)>); -impl SyncVM for EVM +impl SyncVM for EVM where I: Get, - T: pallet_evm::Config + frame_system::Config, + T: frame_system::Config + pallet_evm::Config + pallet_ethereum_checked::Config, + Transact: CheckedEthereumTransact, { fn id() -> VmId { I::get() @@ -44,61 +51,47 @@ where "Start EVM XVM: {:?}, {:?}, {:?}", from, to, input, ); - let value = U256::zero(); - // Tells the EVM executor that no fees should be charged for this execution. - let max_fee_per_gas = U256::zero(); + let value = U256::zero(); let gas_limit = T::GasWeightMapping::weight_to_gas(context.max_weight); - log::trace!( - target: "xvm::EVM::xvm_call", - "EVM xvm call gas limit: {:?} or as weight: {:?}", gas_limit, context.max_weight); - let evm_to = Decode::decode(&mut to.as_ref()).map_err(|_| XvmCallError { + + let source = T::AccountMapping::into_h160(from); + let target = Decode::decode(&mut to.as_ref()).map_err(|_| XvmCallError { error: XvmError::EncodingFailure, consumed_weight: PLACEHOLDER_WEIGHT, })?; + let bounded_input = BoundedVec::>::try_from(input) + .map_err(|_| XvmCallError { + error: XvmError::InputTooLarge, + consumed_weight: PLACEHOLDER_WEIGHT, + })?; - let is_transactional = true; - // Since this is in the context of XVM, no standard validation is required. - let validate = false; - let info = T::Runner::call( - H160::from_slice(&from.encode()[0..20]), - evm_to, - input, - value, - gas_limit, - Some(max_fee_per_gas), - None, - None, - Vec::new(), - is_transactional, - validate, - // TODO: set this properly before merging the PR - None, - // TODO: set this properly before merging the PR - None, - T::config(), + let (post_dispatch_info, call_info) = Transact::xvm_transact( + source, + CheckedEthereumTx { + gas_limit: U256::from(gas_limit), + target, + value, + input: bounded_input, + maybe_access_list: None, + }, ) .map_err(|e| { - let consumed_weight = e.weight.ref_time(); + let consumed_weight = e.post_info.actual_weight.unwrap_or_default(); XvmCallError { - error: XvmError::ExecutionError(Into::<&str>::into(e.error.into()).into()), + error: XvmError::ExecutionError(Into::<&str>::into(e.error).into()), consumed_weight, } })?; log::trace!( target: "xvm::EVM::xvm_call", - "EVM XVM call result: exit_reason: {:?}, used_gas: {:?}", info.exit_reason, info.used_gas, + "EVM XVM call result: exit_reason: {:?}, used_gas: {:?}", call_info.exit_reason, call_info.used_gas, ); Ok(XvmCallOk { - output: info.value, - consumed_weight: T::GasWeightMapping::gas_to_weight( - // Temporary, will be updated once XVM is adjusted for the new code - info.used_gas.effective.unique_saturated_into(), - false, - ) - .ref_time(), + output: call_info.value, + consumed_weight: post_dispatch_info.actual_weight.unwrap_or_default(), }) } } diff --git a/pallets/pallet-xvm/src/lib.rs b/pallets/pallet-xvm/src/lib.rs index 67675d9231..c38b8bcb64 100644 --- a/pallets/pallet-xvm/src/lib.rs +++ b/pallets/pallet-xvm/src/lib.rs @@ -52,7 +52,7 @@ pub type VmId = u8; // TODO: remove later after solution is properly benchmarked // Just a arbitrary weight constant to avoid having ZERO weight in some parts of execution -pub const PLACEHOLDER_WEIGHT: u64 = 1_000_000; +pub const PLACEHOLDER_WEIGHT: Weight = Weight::from_parts(1_000_000, 0); #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)] pub enum XvmError { @@ -61,6 +61,7 @@ pub enum XvmError { ContextConversionFailed, OutOfGas, ExecutionError(Vec), + InputTooLarge, // extend this list as part of improved error handling } @@ -77,7 +78,7 @@ pub struct XvmCallOk { /// Output of XVM call. E.g. if call was a query, this will contain query response. output: Vec, /// Total consumed weight. This is in context of Substrate (1 unit of weight ~ 1 ps of execution time) - consumed_weight: u64, + consumed_weight: Weight, } impl XvmCallOk { @@ -93,7 +94,7 @@ pub struct XvmCallError { // TODO: use XvmError enum from pallet? Perhaps that's a better approach. Or at least provide mapping? error: XvmError, /// Total consumed weight. This is in context of Substrate (1 unit of weight ~ 1 ps of execution time) - consumed_weight: u64, + consumed_weight: Weight, } impl XvmCallError { @@ -105,7 +106,7 @@ impl XvmCallError { /// Result for executing X-VM calls pub type XvmResult = Result; -pub fn consumed_weight(result: &XvmResult) -> u64 { +pub fn consumed_weight(result: &XvmResult) -> Weight { match result { Ok(res) => res.consumed_weight, Err(err) => err.consumed_weight, diff --git a/pallets/pallet-xvm/src/wasm.rs b/pallets/pallet-xvm/src/wasm.rs index f13d43b8f4..e83bdf1d9b 100644 --- a/pallets/pallet-xvm/src/wasm.rs +++ b/pallets/pallet-xvm/src/wasm.rs @@ -77,7 +77,7 @@ where "WASM XVM call result: {:?}", call_result ); - let consumed_weight = call_result.gas_consumed.ref_time(); + let consumed_weight = call_result.gas_consumed; match call_result.result { Ok(success) => Ok(XvmCallOk { diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 42551da3a3..4c8eef897c 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -51,5 +51,6 @@ std = [ "xcm-builder/std", "xcm-executor/std", "pallet-xc-asset-config/std", + "fp-evm/std", ] runtime-benchmarks = ["xcm-builder/runtime-benchmarks"] diff --git a/runtime/astar/Cargo.toml b/runtime/astar/Cargo.toml index 4d522ff9a8..ac14982491 100644 --- a/runtime/astar/Cargo.toml +++ b/runtime/astar/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "astar-runtime" -version = "5.12.0" +version = "5.13.0" build = "build.rs" authors.workspace = true edition.workspace = true diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs index 7145096e34..5e199d54b1 100644 --- a/runtime/astar/src/lib.rs +++ b/runtime/astar/src/lib.rs @@ -141,7 +141,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("astar"), impl_name: create_runtime_str!("astar"), authoring_version: 1, - spec_version: 62, + spec_version: 63, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, diff --git a/runtime/local/Cargo.toml b/runtime/local/Cargo.toml index 292dc087f6..b5873f0088 100644 --- a/runtime/local/Cargo.toml +++ b/runtime/local/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "local-runtime" -version = "5.12.0" +version = "5.13.0" build = "build.rs" authors.workspace = true edition.workspace = true @@ -26,6 +26,7 @@ pallet-contracts = { workspace = true } pallet-contracts-primitives = { workspace = true } pallet-democracy = { workspace = true } pallet-ethereum = { workspace = true } +pallet-ethereum-checked = { workspace = true } pallet-evm = { workspace = true } pallet-evm-precompile-blake2 = { workspace = true } pallet-evm-precompile-bn128 = { workspace = true } @@ -50,6 +51,7 @@ sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } sp-core = { workspace = true } sp-inherents = { workspace = true } +sp-io = { workspace = true } sp-offchain = { workspace = true } sp-runtime = { workspace = true } sp-session = { workspace = true } @@ -149,6 +151,7 @@ std = [ "sp-std/std", "sp-transaction-pool/std", "sp-version/std", + "sp-io/std", "frame-benchmarking/std", "frame-try-runtime/std", "pallet-collective/std", @@ -156,6 +159,7 @@ std = [ "pallet-scheduler/std", "pallet-treasury/std", "pallet-xvm/std", + "pallet-ethereum-checked/std", "moonbeam-evm-tracer/std", "moonbeam-rpc-primitives-debug/std", "moonbeam-rpc-primitives-txpool/std", @@ -176,6 +180,7 @@ runtime-benchmarks = [ "pallet-ethereum/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", + "pallet-ethereum-checked/runtime-benchmarks", "astar-primitives/runtime-benchmarks", ] try-runtime = [ @@ -209,6 +214,7 @@ try-runtime = [ "pallet-preimage/try-runtime", "pallet-base-fee/try-runtime", "pallet-evm/try-runtime", + "pallet-ethereum-checked/try-runtime", ] evm-tracing = [ "moonbeam-evm-tracer", diff --git a/runtime/local/src/lib.rs b/runtime/local/src/lib.rs index be31dcdf9a..d4e2184f6b 100644 --- a/runtime/local/src/lib.rs +++ b/runtime/local/src/lib.rs @@ -441,6 +441,31 @@ impl pallet_utility::Config for Runtime { type WeightInfo = pallet_utility::weights::SubstrateWeight; } +///TODO: Placeholder account mapping. This would be replaced once account abstraction is finished. +pub struct HashedAccountMapping; +impl astar_primitives::ethereum_checked::AccountMapping for HashedAccountMapping { + fn into_h160(account_id: AccountId) -> H160 { + let data = (b"evm:", account_id); + return H160::from_slice(&data.using_encoded(sp_io::hashing::blake2_256)[0..20]); + } +} + +parameter_types! { + /// Equal to normal class dispatch weight limit. + pub XvmTxWeightLimit: Weight = NORMAL_DISPATCH_RATIO * Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, u64::MAX); + pub ReservedXcmpWeight: Weight = Weight::zero(); +} + +impl pallet_ethereum_checked::Config for Runtime { + type ReservedXcmpWeight = ReservedXcmpWeight; + type XvmTxWeightLimit = XvmTxWeightLimit; + type InvalidEvmTransactionError = pallet_ethereum::InvalidTransactionWrapper; + type ValidatedTransaction = pallet_ethereum::ValidatedTransaction; + type AccountMapping = HashedAccountMapping; + type XcmTransactOrigin = pallet_ethereum_checked::EnsureXcmEthereumTx; + type WeightInfo = pallet_ethereum_checked::weights::SubstrateWeight; +} + parameter_types! { pub EvmId: u8 = 0x0F; pub WasmId: u8 = 0x1F; @@ -448,7 +473,10 @@ parameter_types! { use pallet_xvm::{evm, wasm}; impl pallet_xvm::Config for Runtime { - type SyncVM = (evm::EVM, wasm::WASM); + type SyncVM = ( + evm::EVM, + wasm::WASM, + ); type AsyncVM = (); type RuntimeEvent = RuntimeEvent; } @@ -998,6 +1026,7 @@ construct_runtime!( Xvm: pallet_xvm, Proxy: pallet_proxy, Preimage: pallet_preimage, + EthereumChecked: pallet_ethereum_checked, } ); @@ -1110,6 +1139,7 @@ mod benches { [pallet_timestamp, Timestamp] [pallet_dapps_staking, DappsStaking] [pallet_block_reward, BlockReward] + [pallet_ethereum_checked, EthereumChecked] ); } diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml index c7b7ca2782..1c423f2736 100644 --- a/runtime/shibuya/Cargo.toml +++ b/runtime/shibuya/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shibuya-runtime" -version = "5.12.0" +version = "5.14.0" build = "build.rs" authors.workspace = true edition.workspace = true @@ -103,6 +103,7 @@ pallet-chain-extension-xvm = { workspace = true } pallet-collator-selection = { workspace = true } pallet-custom-signatures = { workspace = true } pallet-dapps-staking = { workspace = true } +pallet-ethereum-checked = { workspace = true } pallet-evm-precompile-assets-erc20 = { workspace = true } pallet-evm-precompile-dapps-staking = { workspace = true } pallet-evm-precompile-sr25519 = { workspace = true } @@ -204,6 +205,7 @@ std = [ "pallet-xcm/std", "pallet-xc-asset-config/std", "pallet-xvm/std", + "pallet-ethereum-checked/std", "pallet-scheduler/std", "parachain-info/std", "polkadot-parachain/std", @@ -250,6 +252,7 @@ runtime-benchmarks = [ "xcm-builder/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", + "pallet-ethereum-checked/runtime-benchmarks", "polkadot-runtime/runtime-benchmarks", "orml-xtokens/runtime-benchmarks", "astar-primitives/runtime-benchmarks", @@ -298,6 +301,7 @@ try-runtime = [ "pallet-preimage/try-runtime", "pallet-base-fee/try-runtime", "pallet-evm/try-runtime", + "pallet-ethereum-checked/try-runtime", "orml-xtokens/try-runtime", ] evm-tracing = [ diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index d7466ec8d8..3856a235c1 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -165,7 +165,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("shibuya"), impl_name: create_runtime_str!("shibuya"), authoring_version: 1, - spec_version: 102, + spec_version: 104, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, @@ -761,6 +761,30 @@ impl pallet_transaction_payment::Config for Runtime { type LengthToFee = ConstantMultiplier; } +///TODO: Placeholder account mapping. This would be replaced once account abstraction is finished. +pub struct HashedAccountMapping; +impl astar_primitives::ethereum_checked::AccountMapping for HashedAccountMapping { + fn into_h160(account_id: AccountId) -> H160 { + let data = (b"evm:", account_id); + return H160::from_slice(&data.using_encoded(sp_io::hashing::blake2_256)[0..20]); + } +} + +parameter_types! { + /// Equal to normal class dispatch weight limit. + pub XvmTxWeightLimit: Weight = NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT; +} + +impl pallet_ethereum_checked::Config for Runtime { + type ReservedXcmpWeight = ReservedXcmpWeight; + type XvmTxWeightLimit = XvmTxWeightLimit; + type InvalidEvmTransactionError = pallet_ethereum::InvalidTransactionWrapper; + type ValidatedTransaction = pallet_ethereum::ValidatedTransaction; + type AccountMapping = HashedAccountMapping; + type XcmTransactOrigin = pallet_ethereum_checked::EnsureXcmEthereumTx; + type WeightInfo = pallet_ethereum_checked::weights::SubstrateWeight; +} + parameter_types! { pub EvmId: u8 = 0x0F; pub WasmId: u8 = 0x1F; @@ -769,7 +793,10 @@ parameter_types! { use pallet_xvm::{evm, wasm}; impl pallet_xvm::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type SyncVM = (evm::EVM, wasm::WASM); + type SyncVM = ( + evm::EVM, + wasm::WASM, + ); type AsyncVM = (); } @@ -1267,6 +1294,7 @@ construct_runtime!( Ethereum: pallet_ethereum = 61, BaseFee: pallet_base_fee = 62, EVMChainId: pallet_evm_chain_id = 63, + EthereumChecked: pallet_ethereum_checked = 64, Contracts: pallet_contracts = 70, @@ -1408,6 +1436,7 @@ mod benches { [pallet_xc_asset_config, XcAssetConfig] [pallet_collator_selection, CollatorSelection] [pallet_xcm, PolkadotXcm] + [pallet_ethereum_checked, EthereumChecked] ); } diff --git a/runtime/shiden/Cargo.toml b/runtime/shiden/Cargo.toml index 319c2104e8..aec9cdcc3d 100644 --- a/runtime/shiden/Cargo.toml +++ b/runtime/shiden/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shiden-runtime" -version = "5.12.0" +version = "5.13.0" build = "build.rs" authors.workspace = true edition.workspace = true diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index 43de5a137f..22053b7081 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/src/lib.rs @@ -143,7 +143,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("shiden"), impl_name: create_runtime_str!("shiden"), authoring_version: 1, - spec_version: 102, + spec_version: 103, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, diff --git a/tests/xcm-simulator/src/tests/general.rs b/tests/xcm-simulator/src/tests/general.rs index 8449acaec4..1931f5d069 100644 --- a/tests/xcm-simulator/src/tests/general.rs +++ b/tests/xcm-simulator/src/tests/general.rs @@ -207,6 +207,10 @@ fn remote_dapps_staking_staker_claim() { smart_contract.clone(), stake_amount, )); + assert_ok!(parachain::DappsStaking::set_reward_destination( + parachain::RuntimeOrigin::signed(ALICE), + pallet_dapps_staking::RewardDestination::StakeBalance, + )); // advance enough blocks so we at least get to era 4 advance_parachain_block_to(20); diff --git a/vendor/evm-tracing/Cargo.toml b/vendor/evm-tracing/Cargo.toml index 7a2a330bf8..557126f6f2 100644 --- a/vendor/evm-tracing/Cargo.toml +++ b/vendor/evm-tracing/Cargo.toml @@ -9,7 +9,7 @@ version = "0.1.0" [dependencies] ethereum-types = { workspace = true, features = ["std"] } -hex = { workspace = true } +hex = { workspace = true, features = ["serde"] } serde = { workspace = true } serde_json = { workspace = true }