-
Notifications
You must be signed in to change notification settings - Fork 810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pallet-revive] Add pallet to AH westend #5502
Merged
Merged
Changes from 4 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ use frame_support::{ | |
fungible, fungibles, | ||
tokens::{imbalance::ResolveAssetTo, nonfungibles_v2::Inspect}, | ||
AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, InstanceFilter, | ||
TransformOrigin, | ||
Nothing, TransformOrigin, | ||
}, | ||
weights::{ConstantMultiplier, Weight, WeightToFee as _}, | ||
BoundedVec, PalletId, | ||
|
@@ -58,13 +58,14 @@ use frame_system::{ | |
}; | ||
use pallet_asset_conversion_tx_payment::SwapAssetAdapter; | ||
use pallet_nfts::{DestroyWitness, PalletFeatures}; | ||
use pallet_revive::evm::runtime::EthExtra; | ||
use parachains_common::{ | ||
impls::DealWithFees, message_queue::*, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, | ||
BlockNumber, CollectionId, Hash, Header, ItemId, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO, | ||
NORMAL_DISPATCH_RATIO, | ||
}; | ||
use sp_api::impl_runtime_apis; | ||
use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; | ||
use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160}; | ||
use sp_runtime::{ | ||
create_runtime_str, generic, impl_opaque_keys, | ||
traits::{AccountIdConversion, BlakeTwo256, Block as BlockT, Saturating, Verify}, | ||
|
@@ -934,6 +935,52 @@ impl pallet_xcm_bridge_hub_router::Config<ToRococoXcmRouterInstance> for Runtime | |
type FeeAsset = xcm_config::bridging::XcmBridgeHubRouterFeeAssetId; | ||
} | ||
|
||
parameter_types! { | ||
pub const DepositPerItem: Balance = deposit(1, 0); | ||
pub const DepositPerByte: Balance = deposit(0, 1); | ||
pub CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(30); | ||
} | ||
|
||
type EventRecord = frame_system::EventRecord< | ||
<Runtime as frame_system::Config>::RuntimeEvent, | ||
<Runtime as frame_system::Config>::Hash, | ||
>; | ||
|
||
impl pallet_revive::Config for Runtime { | ||
type Time = Timestamp; | ||
type Currency = Balances; | ||
type RuntimeEvent = RuntimeEvent; | ||
type RuntimeCall = RuntimeCall; | ||
type CallFilter = Nothing; | ||
type DepositPerItem = DepositPerItem; | ||
type DepositPerByte = DepositPerByte; | ||
type WeightPrice = pallet_transaction_payment::Pallet<Self>; | ||
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets just keep the default weights here like this until we can get rid of the riscv feature |
||
type ChainExtension = (); | ||
type AddressMapper = pallet_revive::DefaultAddressMapper; | ||
type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>; | ||
type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>; | ||
type UnsafeUnstableInterface = ConstBool<false>; | ||
type UploadOrigin = EnsureSigned<Self::AccountId>; | ||
type InstantiateOrigin = EnsureSigned<Self::AccountId>; | ||
type RuntimeHoldReason = RuntimeHoldReason; | ||
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent; | ||
type Debug = (); | ||
type Xcm = pallet_xcm::Pallet<Self>; | ||
type ChainId = ConstU64<420_420_421>; | ||
} | ||
|
||
impl TryFrom<RuntimeCall> for pallet_revive::Call<Runtime> { | ||
type Error = (); | ||
|
||
fn try_from(value: RuntimeCall) -> Result<Self, Self::Error> { | ||
match value { | ||
RuntimeCall::Revive(call) => Ok(call), | ||
_ => Err(()), | ||
} | ||
} | ||
} | ||
|
||
// Create the runtime by composing the FRAME pallets that were previously configured. | ||
construct_runtime!( | ||
pub enum Runtime | ||
|
@@ -982,6 +1029,7 @@ construct_runtime!( | |
AssetsFreezer: pallet_assets_freezer::<Instance1> = 57, | ||
ForeignAssetsFreezer: pallet_assets_freezer::<Instance2> = 58, | ||
PoolAssetsFreezer: pallet_assets_freezer::<Instance3> = 59, | ||
Revive: pallet_revive = 60, | ||
|
||
StateTrieMigration: pallet_state_trie_migration = 70, | ||
|
||
|
@@ -1012,9 +1060,34 @@ pub type TxExtension = ( | |
cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim<Runtime>, | ||
frame_metadata_hash_extension::CheckMetadataHash<Runtime>, | ||
); | ||
|
||
/// Default extensions applied to Ethereum transactions. | ||
#[derive(Clone, PartialEq, Eq, Debug)] | ||
pub struct EthExtraImpl; | ||
|
||
impl EthExtra for EthExtraImpl { | ||
type Config = Runtime; | ||
type Extension = TxExtension; | ||
|
||
fn get_eth_extension(nonce: u32, tip: Balance) -> Self::Extension { | ||
( | ||
frame_system::CheckNonZeroSender::<Runtime>::new(), | ||
frame_system::CheckSpecVersion::<Runtime>::new(), | ||
frame_system::CheckTxVersion::<Runtime>::new(), | ||
frame_system::CheckGenesis::<Runtime>::new(), | ||
frame_system::CheckMortality::from(generic::Era::Immortal), | ||
frame_system::CheckNonce::<Runtime>::from(nonce), | ||
frame_system::CheckWeight::<Runtime>::new(), | ||
pallet_asset_conversion_tx_payment::ChargeAssetTxPayment::<Runtime>::from(tip, None), | ||
cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim::<Runtime>::new(), | ||
frame_metadata_hash_extension::CheckMetadataHash::<Runtime>::new(false), | ||
) | ||
} | ||
} | ||
|
||
/// Unchecked extrinsic type as expected by this runtime. | ||
pub type UncheckedExtrinsic = | ||
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>; | ||
pallet_revive::evm::runtime::UncheckedExtrinsic<Address, Signature, EthExtraImpl>; | ||
|
||
/// Migrations to apply on runtime upgrade. | ||
pub type Migrations = ( | ||
|
@@ -1249,6 +1322,7 @@ mod benches { | |
[cumulus_pallet_xcmp_queue, XcmpQueue] | ||
[pallet_xcm_bridge_hub_router, ToRococo] | ||
[pallet_asset_conversion_ops, AssetConversionMigration] | ||
[pallet_revive, Revive] | ||
// XCM | ||
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>] | ||
// NOTE: Make sure you point to the individual modules below. | ||
|
@@ -1983,6 +2057,109 @@ impl_runtime_apis! { | |
PolkadotXcm::is_trusted_teleporter(asset, location) | ||
} | ||
} | ||
|
||
impl pallet_revive::ReviveApi<Block, AccountId, Balance, BlockNumber, EventRecord> for Runtime | ||
{ | ||
fn eth_transact( | ||
from: H160, | ||
dest: Option<H160>, | ||
value: Balance, | ||
input: Vec<u8>, | ||
gas_limit: Option<Weight>, | ||
storage_deposit_limit: Option<Balance>, | ||
) -> pallet_revive::EthContractResult<Balance> | ||
{ | ||
use pallet_revive::AddressMapper; | ||
let blockweights = <Runtime as frame_system::Config>::BlockWeights::get(); | ||
let origin = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&from); | ||
|
||
let encoded_size = |pallet_call| { | ||
let call = RuntimeCall::Revive(pallet_call); | ||
let uxt: UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic::new_bare(call).into(); | ||
uxt.encoded_size() as u32 | ||
}; | ||
|
||
Revive::bare_eth_transact( | ||
origin, | ||
dest, | ||
value, | ||
input, | ||
gas_limit.unwrap_or(blockweights.max_block), | ||
storage_deposit_limit.unwrap_or(u128::MAX), | ||
encoded_size, | ||
pallet_revive::DebugInfo::UnsafeDebug, | ||
pallet_revive::CollectEvents::UnsafeCollect, | ||
) | ||
} | ||
|
||
fn call( | ||
origin: AccountId, | ||
dest: H160, | ||
value: Balance, | ||
gas_limit: Option<Weight>, | ||
storage_deposit_limit: Option<Balance>, | ||
input_data: Vec<u8>, | ||
) -> pallet_revive::ContractResult<pallet_revive::ExecReturnValue, Balance, EventRecord> { | ||
let blockweights= <Runtime as frame_system::Config>::BlockWeights::get(); | ||
Revive::bare_call( | ||
RuntimeOrigin::signed(origin), | ||
dest, | ||
value, | ||
gas_limit.unwrap_or(blockweights.max_block), | ||
storage_deposit_limit.unwrap_or(u128::MAX), | ||
input_data, | ||
pallet_revive::DebugInfo::UnsafeDebug, | ||
pallet_revive::CollectEvents::UnsafeCollect, | ||
) | ||
} | ||
|
||
fn instantiate( | ||
origin: AccountId, | ||
value: Balance, | ||
gas_limit: Option<Weight>, | ||
storage_deposit_limit: Option<Balance>, | ||
code: pallet_revive::Code, | ||
data: Vec<u8>, | ||
salt: Option<[u8; 32]>, | ||
) -> pallet_revive::ContractResult<pallet_revive::InstantiateReturnValue, Balance, EventRecord> | ||
{ | ||
let blockweights= <Runtime as frame_system::Config>::BlockWeights::get(); | ||
Revive::bare_instantiate( | ||
RuntimeOrigin::signed(origin), | ||
value, | ||
gas_limit.unwrap_or(blockweights.max_block), | ||
storage_deposit_limit.unwrap_or(u128::MAX), | ||
code, | ||
data, | ||
salt, | ||
pallet_revive::DebugInfo::UnsafeDebug, | ||
pallet_revive::CollectEvents::UnsafeCollect, | ||
) | ||
} | ||
|
||
fn upload_code( | ||
origin: AccountId, | ||
code: Vec<u8>, | ||
storage_deposit_limit: Option<Balance>, | ||
) -> pallet_revive::CodeUploadResult<Balance> | ||
{ | ||
Revive::bare_upload_code( | ||
RuntimeOrigin::signed(origin), | ||
code, | ||
storage_deposit_limit.unwrap_or(u128::MAX), | ||
) | ||
} | ||
|
||
fn get_storage( | ||
address: H160, | ||
key: [u8; 32], | ||
) -> pallet_revive::GetStorageResult { | ||
Revive::get_storage( | ||
address, | ||
key | ||
) | ||
} | ||
} | ||
} | ||
|
||
cumulus_pallet_parachain_system::register_validate_block! { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
title: '[pallet-revive] Add pallet to AH westend' | ||
doc: | ||
- audience: Runtime Dev | ||
description: 'Add pallet-revive to Westend runtime, and configure the runtime to accept Ethereum signed transaction' | ||
crates: | ||
- name: asset-hub-westend-runtime | ||
bump: major |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to be able to run the benchmarks you need to forward the
riscv
feature. Hopefully we can soon switch to an upstream toolchain and get rid of this feature. I think we should just use the default weights until then.