Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Oct 22, 2024
1 parent 21930ed commit 0bd6835
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 5 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pallet-timestamp = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-transaction-payment-rpc-runtime-api = { workspace = true }
pallet-uniques = { workspace = true }
pallet-revive = { workspace = true }
pallet-utility = { workspace = true }
sp-api = { workspace = true }
sp-block-builder = { workspace = true }
Expand Down Expand Up @@ -145,6 +146,7 @@ runtime-benchmarks = [
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"xcm-runtime-apis/runtime-benchmarks",
"pallet-revive/runtime-benchmarks"
]
try-runtime = [
"cumulus-pallet-aura-ext/try-runtime",
Expand Down Expand Up @@ -180,6 +182,7 @@ try-runtime = [
"parachain-info/try-runtime",
"polkadot-runtime-common/try-runtime",
"sp-runtime/try-runtime",
"pallet-revive/try-runtime"
]
std = [
"assets-common/std",
Expand Down Expand Up @@ -260,6 +263,7 @@ std = [
"xcm-executor/std",
"xcm-runtime-apis/std",
"xcm/std",
"pallet-revive/std"
]

# Enable the metadata hash generation in the wasm builder.
Expand Down
176 changes: 175 additions & 1 deletion cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,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;

Check failure on line 953 in cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

cannot find type `Nothing` in this scope
type DepositPerItem = DepositPerItem;
type DepositPerByte = DepositPerByte;
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
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
Expand Down Expand Up @@ -1012,9 +1058,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 {

Check failure on line 1066 in cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

cannot find trait `EthExtra` in this scope
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_transaction_payment::ChargeAssetTxPayment::<Runtime>::from(tip, None),

Check failure on line 1079 in cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

failed to resolve: could not find `ChargeAssetTxPayment` in `pallet_transaction_payment`
cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim<Runtime>::new(),

Check failure on line 1080 in cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

comparison operators cannot be chained
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 = (
Expand Down Expand Up @@ -1983,6 +2054,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,

Check failure on line 2061 in cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

cannot find type `H160` in this scope

Check failure on line 2061 in cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

cannot find type `H160` in this scope
dest: Option<H160>,

Check failure on line 2062 in cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

cannot find type `H160` in this scope

Check failure on line 2062 in cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

cannot find type `H160` in this scope
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,

Check failure on line 2094 in cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

cannot find type `H160` in this scope
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,

Check failure on line 2151 in cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

cannot find type `H160` in this scope
key: [u8; 32],
) -> pallet_revive::GetStorageResult {
Revive::get_storage(
address,
key
)
}
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Expand Down
7 changes: 7 additions & 0 deletions prdoc/pr_5502.prdoc
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: westend-runtime
bump: major

0 comments on commit 0bd6835

Please sign in to comment.