Skip to content

Commit 30804db

Browse files
atheiactions-useracatangiu
authored
Add pallet_revive to Kusama AssetHub (#755)
- [x] Run benchmarks - [x] Clarify if we need to do something to properly set the on chain storage version of the pallet: No Fixes paritytech/contract-issues#58 --------- Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Adrian Catangiu <adrian@parity.io>
1 parent 6936335 commit 30804db

File tree

7 files changed

+1344
-6
lines changed

7 files changed

+1344
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1717
- [[#711](https://github.com/polkadot-fellows/runtimes/pull/711)] Pallet-broker: add extrinsic to remove a lease ([SDK stable2503 #7026](https://github.com/paritytech/polkadot-sdk/pull/7026)).
1818
- [[#711](https://github.com/polkadot-fellows/runtimes/pull/711)] Pallet-broker: add extrinsic to remove an assignment ([SDK stable2503 #7080](https://github.com/paritytech/polkadot-sdk/pull/7080)).
1919
- [[#711](https://github.com/polkadot-fellows/runtimes/pull/711)] Pallet-broker: add extrinsic to reserve a system core without having to wait two sale boundaries ([SDK stable2503 #4273](https://github.com/paritytech/polkadot-sdk/pull/4273)).
20-
- [[#754](https://github.com/polkadot-fellows/runtimes/pull/754) Change to minimum price controller and configure minimum price of 10 DOT and 1 KSM for Coretime sales. Existing renewals will also be adjusted accordingly and are now no longer completely decoupled from the market. For details on this, please checkout [RFC-149](https://polkadot-fellows.github.io/RFCs/new/0149-rfc-1-renewal-adjustment.html).
20+
21+
- [[#755](https://github.com/polkadot-fellows/runtimes/pull/755)] Added `pallet_revive` to Kusama AssetHub.
2122

2223
### Changed
2324

@@ -34,6 +35,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
3435
- [[#711](https://github.com/polkadot-fellows/runtimes/pull/711)] Xcm: convert properly assets in xcmpayment apis ([SDK stable2503 #7134](https://github.com/paritytech/polkadot-sdk/pull/7134)).
3536
- [[#711](https://github.com/polkadot-fellows/runtimes/pull/711)] Ensure Consistent Topic IDs for Traceable Cross-Chain XCM ([SDK stable2503 #7691](https://github.com/paritytech/polkadot-sdk/pull/7691)).
3637

38+
- [[#754](https://github.com/polkadot-fellows/runtimes/pull/754)] Change to minimum price controller and configure minimum price of 10 DOT and 1 KSM for Coretime sales. Existing renewals will also be adjusted accordingly and are now no longer completely decoupled from the market. For details on this, please checkout [RFC-149](https://polkadot-fellows.github.io/RFCs/new/0149-rfc-1-renewal-adjustment.html).
39+
3740
### Fixed
3841

3942
- Update to SDK version `stable2503-5` ([polkadot-fellows/runtimes/pull/711](https://github.com/polkadot-fellows/runtimes/pull/711))

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ pallet-ranked-collective = { version = "40.1.0", default-features = false }
146146
pallet-recovery = { version = "40.0.0", default-features = false }
147147
pallet-referenda = { version = "40.1.0", default-features = false }
148148
pallet-remote-proxy = { path = "pallets/remote-proxy", default-features = false }
149+
pallet-revive = { version = "0.6.1", default-features = false }
149150
pallet-salary = { version = "25.0.0", default-features = false }
150151
pallet-scheduler = { version = "41.2.0", default-features = false }
151152
pallet-session = { version = "40.0.1", default-features = false }

system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pallet-nft-fractionalization = { workspace = true }
4444
pallet-nfts = { workspace = true }
4545
pallet-nfts-runtime-api = { workspace = true }
4646
pallet-proxy = { workspace = true }
47+
pallet-revive = { workspace = true }
4748
pallet-session = { workspace = true }
4849
pallet-state-trie-migration = { workspace = true }
4950
pallet-timestamp = { workspace = true }
@@ -139,6 +140,7 @@ runtime-benchmarks = [
139140
"pallet-nfts/runtime-benchmarks",
140141
"pallet-proxy/runtime-benchmarks",
141142
"pallet-remote-proxy/runtime-benchmarks",
143+
"pallet-revive/runtime-benchmarks",
142144
"pallet-state-trie-migration/runtime-benchmarks",
143145
"pallet-timestamp/runtime-benchmarks",
144146
"pallet-transaction-payment/runtime-benchmarks",
@@ -181,6 +183,7 @@ try-runtime = [
181183
"pallet-nfts/try-runtime",
182184
"pallet-proxy/try-runtime",
183185
"pallet-remote-proxy/try-runtime",
186+
"pallet-revive/try-runtime",
184187
"pallet-session/try-runtime",
185188
"pallet-state-trie-migration/try-runtime",
186189
"pallet-timestamp/try-runtime",
@@ -233,6 +236,7 @@ std = [
233236
"pallet-nfts/std",
234237
"pallet-proxy/std",
235238
"pallet-remote-proxy/std",
239+
"pallet-revive/std",
236240
"pallet-session/std",
237241
"pallet-state-trie-migration/std",
238242
"pallet-timestamp/std",

system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs

Lines changed: 244 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
4343
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
4444
use kusama_runtime_constants::time::MINUTES as RC_MINUTES;
4545
use pallet_proxy::ProxyDefinition;
46+
use pallet_revive::{evm::runtime::EthExtra, AddressMapper};
4647
use sp_api::impl_runtime_apis;
47-
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
48+
use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160, U256};
4849
use sp_runtime::{
4950
generic, impl_opaque_keys,
5051
traits::{
@@ -62,13 +63,13 @@ use sp_version::RuntimeVersion;
6263
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
6364
use frame_support::{
6465
construct_runtime,
65-
dispatch::DispatchClass,
66+
dispatch::{DispatchClass, DispatchInfo},
6667
genesis_builder_helper::{build_state, get_preset},
6768
ord_parameter_types, parameter_types,
6869
traits::{
6970
fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool,
7071
ConstU128, ConstU32, ConstU64, ConstU8, Contains, EitherOfDiverse, Equals, EverythingBut,
71-
InstanceFilter, TransformOrigin, WithdrawReasons,
72+
InstanceFilter, Nothing, TransformOrigin, WithdrawReasons,
7273
},
7374
weights::{ConstantMultiplier, Weight, WeightToFee as _},
7475
BoundedVec, PalletId,
@@ -82,7 +83,7 @@ use parachains_common::{
8283
message_queue::*, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, Hash,
8384
Header, Nonce, Signature,
8485
};
85-
use sp_runtime::RuntimeDebug;
86+
use sp_runtime::{traits::TransactionExtension, RuntimeDebug};
8687
pub use system_parachains_constants::async_backing::SLOT_DURATION;
8788
use system_parachains_constants::{
8889
async_backing::{
@@ -1029,6 +1030,38 @@ impl pallet_remote_proxy::Config for Runtime {
10291030
type WeightInfo = weights::pallet_remote_proxy::WeightInfo<Runtime>;
10301031
}
10311032

1033+
parameter_types! {
1034+
pub const DepositPerItem: Balance = system_para_deposit(1, 0);
1035+
pub const DepositPerByte: Balance = system_para_deposit(0, 1);
1036+
pub CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(30);
1037+
}
1038+
1039+
impl pallet_revive::Config for Runtime {
1040+
type Time = Timestamp;
1041+
type Currency = Balances;
1042+
type RuntimeEvent = RuntimeEvent;
1043+
type RuntimeCall = RuntimeCall;
1044+
type CallFilter = Nothing;
1045+
type DepositPerItem = DepositPerItem;
1046+
type DepositPerByte = DepositPerByte;
1047+
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
1048+
type WeightInfo = weights::pallet_revive::WeightInfo<Self>;
1049+
type ChainExtension = ();
1050+
type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
1051+
type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>;
1052+
type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>;
1053+
type UnsafeUnstableInterface = ConstBool<false>;
1054+
type UploadOrigin = EnsureSigned<Self::AccountId>;
1055+
type InstantiateOrigin = EnsureSigned<Self::AccountId>;
1056+
type RuntimeHoldReason = RuntimeHoldReason;
1057+
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
1058+
type Xcm = pallet_xcm::Pallet<Self>;
1059+
type ChainId = ConstU64<420_420_418>;
1060+
type NativeToEthRatio = ConstU32<1_000_000>; // 10^(18 - 12) Eth is 10^18, Native is 10^12.
1061+
type EthGasEncoder = ();
1062+
type FindAuthor = <Runtime as pallet_authorship::Config>::FindAuthor;
1063+
}
1064+
10321065
// Create the runtime by composing the FRAME pallets that were previously configured.
10331066
construct_runtime!(
10341067
pub enum Runtime
@@ -1077,6 +1110,8 @@ construct_runtime!(
10771110
PoolAssets: pallet_assets::<Instance3> = 55,
10781111
AssetConversion: pallet_asset_conversion = 56,
10791112

1113+
Revive: pallet_revive = 60,
1114+
10801115
// State trie migration pallet, only temporary.
10811116
StateTrieMigration: pallet_state_trie_migration = 70,
10821117
}
@@ -1102,9 +1137,45 @@ pub type TxExtension = (
11021137
pallet_asset_conversion_tx_payment::ChargeAssetTxPayment<Runtime>,
11031138
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
11041139
);
1140+
1141+
/// Default extensions applied to Ethereum transactions.
1142+
#[derive(Clone, PartialEq, Eq, Debug)]
1143+
pub struct EthExtraImpl;
1144+
1145+
impl EthExtra for EthExtraImpl {
1146+
type Config = Runtime;
1147+
type Extension = TxExtension;
1148+
1149+
fn get_eth_extension(nonce: u32, tip: Balance) -> Self::Extension {
1150+
(
1151+
frame_system::CheckNonZeroSender::<Runtime>::new(),
1152+
frame_system::CheckSpecVersion::<Runtime>::new(),
1153+
frame_system::CheckTxVersion::<Runtime>::new(),
1154+
frame_system::CheckGenesis::<Runtime>::new(),
1155+
frame_system::CheckMortality::from(generic::Era::Immortal),
1156+
frame_system::CheckNonce::<Runtime>::from(nonce),
1157+
frame_system::CheckWeight::<Runtime>::new(),
1158+
pallet_asset_conversion_tx_payment::ChargeAssetTxPayment::<Runtime>::from(tip, None),
1159+
frame_metadata_hash_extension::CheckMetadataHash::<Runtime>::new(false),
1160+
)
1161+
}
1162+
}
1163+
1164+
// This impl is no longer necessary post stable-2506.
1165+
impl TryFrom<RuntimeCall> for pallet_revive::Call<Runtime> {
1166+
type Error = ();
1167+
1168+
fn try_from(value: RuntimeCall) -> Result<Self, Self::Error> {
1169+
match value {
1170+
RuntimeCall::Revive(call) => Ok(call),
1171+
_ => Err(()),
1172+
}
1173+
}
1174+
}
1175+
11051176
/// Unchecked extrinsic type as expected by this runtime.
11061177
pub type UncheckedExtrinsic =
1107-
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
1178+
pallet_revive::evm::runtime::UncheckedExtrinsic<Address, Signature, EthExtraImpl>;
11081179

11091180
/// Migrations to apply on runtime upgrade.
11101181
pub type Migrations = (
@@ -1221,6 +1292,7 @@ mod benches {
12211292
[pallet_nfts, Nfts]
12221293
[pallet_proxy, Proxy]
12231294
[pallet_remote_proxy, RemoteProxyRelayChain]
1295+
[pallet_revive, Revive]
12241296
[pallet_session, SessionBench::<Runtime>]
12251297
[pallet_uniques, Uniques]
12261298
[pallet_utility, Utility]
@@ -1889,6 +1961,173 @@ impl_runtime_apis! {
18891961
}
18901962
}
18911963

1964+
impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber> for Runtime
1965+
{
1966+
fn balance(address: H160) -> U256 {
1967+
Revive::evm_balance(&address)
1968+
}
1969+
1970+
fn block_gas_limit() -> U256 {
1971+
Revive::evm_block_gas_limit()
1972+
}
1973+
1974+
fn gas_price() -> U256 {
1975+
Revive::evm_gas_price()
1976+
}
1977+
1978+
fn nonce(address: H160) -> Nonce {
1979+
let account = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&address);
1980+
System::account_nonce(account)
1981+
}
1982+
1983+
fn eth_transact(tx: pallet_revive::evm::GenericTransaction) -> Result<pallet_revive::EthTransactInfo<Balance>, pallet_revive::EthTransactError>
1984+
{
1985+
let blockweights: BlockWeights = <Runtime as frame_system::Config>::BlockWeights::get();
1986+
let tx_fee = |pallet_call, mut dispatch_info: DispatchInfo| {
1987+
let call = RuntimeCall::Revive(pallet_call);
1988+
dispatch_info.extension_weight = EthExtraImpl::get_eth_extension(0, 0u32.into()).weight(&call);
1989+
let uxt: UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic::new_bare(call).into();
1990+
1991+
pallet_transaction_payment::Pallet::<Runtime>::compute_fee(
1992+
uxt.encoded_size() as u32,
1993+
&dispatch_info,
1994+
0u32.into(),
1995+
)
1996+
};
1997+
1998+
Revive::bare_eth_transact(tx, blockweights.max_block, tx_fee)
1999+
}
2000+
2001+
fn call(
2002+
origin: AccountId,
2003+
dest: H160,
2004+
value: Balance,
2005+
gas_limit: Option<Weight>,
2006+
storage_deposit_limit: Option<Balance>,
2007+
input_data: Vec<u8>,
2008+
) -> pallet_revive::ContractResult<pallet_revive::ExecReturnValue, Balance> {
2009+
let blockweights= <Runtime as frame_system::Config>::BlockWeights::get();
2010+
Revive::bare_call(
2011+
RuntimeOrigin::signed(origin),
2012+
dest,
2013+
value,
2014+
gas_limit.unwrap_or(blockweights.max_block),
2015+
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
2016+
input_data,
2017+
)
2018+
}
2019+
2020+
fn instantiate(
2021+
origin: AccountId,
2022+
value: Balance,
2023+
gas_limit: Option<Weight>,
2024+
storage_deposit_limit: Option<Balance>,
2025+
code: pallet_revive::Code,
2026+
data: Vec<u8>,
2027+
salt: Option<[u8; 32]>,
2028+
) -> pallet_revive::ContractResult<pallet_revive::InstantiateReturnValue, Balance>
2029+
{
2030+
let blockweights= <Runtime as frame_system::Config>::BlockWeights::get();
2031+
Revive::bare_instantiate(
2032+
RuntimeOrigin::signed(origin),
2033+
value,
2034+
gas_limit.unwrap_or(blockweights.max_block),
2035+
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
2036+
code,
2037+
data,
2038+
salt,
2039+
)
2040+
}
2041+
2042+
fn upload_code(
2043+
origin: AccountId,
2044+
code: Vec<u8>,
2045+
storage_deposit_limit: Option<Balance>,
2046+
) -> pallet_revive::CodeUploadResult<Balance>
2047+
{
2048+
Revive::bare_upload_code(
2049+
RuntimeOrigin::signed(origin),
2050+
code,
2051+
storage_deposit_limit.unwrap_or(u128::MAX),
2052+
)
2053+
}
2054+
2055+
fn get_storage(
2056+
address: H160,
2057+
key: [u8; 32],
2058+
) -> pallet_revive::GetStorageResult {
2059+
Revive::get_storage(
2060+
address,
2061+
key
2062+
)
2063+
}
2064+
2065+
fn trace_block(
2066+
block: Block,
2067+
tracer_type: pallet_revive::evm::TracerType,
2068+
) -> Vec<(u32, pallet_revive::evm::Trace)> {
2069+
use pallet_revive::tracing::trace;
2070+
let mut tracer = Revive::evm_tracer(tracer_type);
2071+
let mut traces = vec![];
2072+
let (header, extrinsics) = block.deconstruct();
2073+
Executive::initialize_block(&header);
2074+
for (index, ext) in extrinsics.into_iter().enumerate() {
2075+
trace(tracer.as_tracing(), || {
2076+
let _ = Executive::apply_extrinsic(ext);
2077+
});
2078+
2079+
if let Some(tx_trace) = tracer.collect_trace() {
2080+
traces.push((index as u32, tx_trace));
2081+
}
2082+
}
2083+
2084+
traces
2085+
}
2086+
2087+
fn trace_tx(
2088+
block: Block,
2089+
tx_index: u32,
2090+
tracer_type: pallet_revive::evm::TracerType,
2091+
) -> Option<pallet_revive::evm::Trace> {
2092+
use pallet_revive::tracing::trace;
2093+
let mut tracer = Revive::evm_tracer(tracer_type);
2094+
let (header, extrinsics) = block.deconstruct();
2095+
2096+
Executive::initialize_block(&header);
2097+
for (index, ext) in extrinsics.into_iter().enumerate() {
2098+
if index as u32 == tx_index {
2099+
trace(tracer.as_tracing(), || {
2100+
let _ = Executive::apply_extrinsic(ext);
2101+
});
2102+
break;
2103+
} else {
2104+
let _ = Executive::apply_extrinsic(ext);
2105+
}
2106+
}
2107+
2108+
tracer.collect_trace()
2109+
}
2110+
2111+
fn trace_call(
2112+
tx: pallet_revive::evm::GenericTransaction,
2113+
tracer_type: pallet_revive::evm::TracerType,
2114+
)
2115+
-> Result<pallet_revive::evm::Trace, pallet_revive::EthTransactError>
2116+
{
2117+
use pallet_revive::tracing::trace;
2118+
let mut tracer = Revive::evm_tracer(tracer_type);
2119+
let result = trace(tracer.as_tracing(), || Self::eth_transact(tx));
2120+
2121+
if let Some(trace) = tracer.collect_trace() {
2122+
Ok(trace)
2123+
} else if let Err(err) = result {
2124+
Err(err)
2125+
} else {
2126+
Ok(tracer.empty_trace())
2127+
}
2128+
}
2129+
}
2130+
18922131
#[cfg(feature = "try-runtime")]
18932132
impl frame_try_runtime::TryRuntime<Block> for Runtime {
18942133
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {

system-parachains/asset-hubs/asset-hub-kusama/src/weights/mod.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)