Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 10 additions & 186 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId};
use frame_support::{
construct_runtime, derive_impl,
dispatch::{DispatchClass, DispatchInfo},
dispatch::DispatchClass,
genesis_builder_helper::{build_state, get_preset},
ord_parameter_types, parameter_types,
traits::{
Expand All @@ -62,20 +62,18 @@ use frame_system::{
};
use pallet_asset_conversion_tx_payment::SwapAssetAdapter;
use pallet_nfts::{DestroyWitness, PalletFeatures};
use pallet_revive::{evm::runtime::EthExtra, AddressMapper, NonceAlreadyIncremented};
use pallet_revive::evm::runtime::EthExtra;
use pallet_xcm::EnsureXcm;
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, H160, U256};
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
generic, impl_opaque_keys,
traits::{
AccountIdConversion, BlakeTwo256, Block as BlockT, Saturating, TransactionExtension, Verify,
},
traits::{AccountIdConversion, BlakeTwo256, Block as BlockT, Saturating, Verify},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Perbill, Permill, RuntimeDebug,
};
Expand Down Expand Up @@ -1482,7 +1480,11 @@ mod benches {
);
}

impl_runtime_apis! {
pallet_revive::impl_runtime_apis_plus_revive!(
Runtime,
Executive,
EthExtraImpl,

impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION)
Expand Down Expand Up @@ -2288,185 +2290,7 @@ impl_runtime_apis! {
genesis_config_presets::preset_names()
}
}

impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber> for Runtime
{
fn balance(address: H160) -> U256 {
Revive::evm_balance(&address)
}

fn block_gas_limit() -> U256 {
Revive::evm_block_gas_limit()
}

fn gas_price() -> U256 {
Revive::evm_gas_price()
}

fn nonce(address: H160) -> Nonce {
let account = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&address);
System::account_nonce(account)
}

fn eth_transact(tx: pallet_revive::evm::GenericTransaction) -> Result<pallet_revive::EthTransactInfo<Balance>, pallet_revive::EthTransactError>
{
let blockweights: BlockWeights = <Runtime as frame_system::Config>::BlockWeights::get();
let tx_fee = |pallet_call, mut dispatch_info: DispatchInfo| {
let call = RuntimeCall::Revive(pallet_call);
dispatch_info.extension_weight = EthExtraImpl::get_eth_extension(0, 0u32.into()).weight(&call);
let uxt: UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic::new_bare(call).into();

pallet_transaction_payment::Pallet::<Runtime>::compute_fee(
uxt.encoded_size() as u32,
&dispatch_info,
0u32.into(),
)
};

Revive::bare_eth_transact(tx, blockweights.max_block, tx_fee)
}

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> {
let blockweights= <Runtime as frame_system::Config>::BlockWeights::get();
Revive::bare_call(
RuntimeOrigin::signed(origin),
dest,
value,
gas_limit.unwrap_or(blockweights.max_block),
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
input_data,
)
}

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>
{
let blockweights= <Runtime as frame_system::Config>::BlockWeights::get();
Revive::bare_instantiate(
RuntimeOrigin::signed(origin),
value,
gas_limit.unwrap_or(blockweights.max_block),
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
code,
data,
salt,
NonceAlreadyIncremented::No,
)
}

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
)
}

fn get_storage_var_key(
address: H160,
key: Vec<u8>,
) -> pallet_revive::GetStorageResult {
Revive::get_storage_var_key(
address,
key
)
}

fn trace_block(
block: Block,
tracer_type: pallet_revive::evm::TracerType,
) -> Vec<(u32, pallet_revive::evm::Trace)> {
use pallet_revive::tracing::trace;
let mut tracer = Revive::evm_tracer(tracer_type);
let mut traces = vec![];
let (header, extrinsics) = block.deconstruct();
Executive::initialize_block(&header);
for (index, ext) in extrinsics.into_iter().enumerate() {
trace(tracer.as_tracing(), || {
let _ = Executive::apply_extrinsic(ext);
});

if let Some(tx_trace) = tracer.collect_trace() {
traces.push((index as u32, tx_trace));
}
}

traces
}

fn trace_tx(
block: Block,
tx_index: u32,
tracer_type: pallet_revive::evm::TracerType,
) -> Option<pallet_revive::evm::Trace> {
use pallet_revive::tracing::trace;
let mut tracer = Revive::evm_tracer(tracer_type);
let (header, extrinsics) = block.deconstruct();

Executive::initialize_block(&header);
for (index, ext) in extrinsics.into_iter().enumerate() {
if index as u32 == tx_index {
trace(tracer.as_tracing(), || {
let _ = Executive::apply_extrinsic(ext);
});
break;
} else {
let _ = Executive::apply_extrinsic(ext);
}
}

tracer.collect_trace()
}

fn trace_call(
tx: pallet_revive::evm::GenericTransaction,
tracer_type: pallet_revive::evm::TracerType,
)
-> Result<pallet_revive::evm::Trace, pallet_revive::EthTransactError>
{
use pallet_revive::tracing::trace;
let mut tracer = Revive::evm_tracer(tracer_type);
let result = trace(tracer.as_tracing(), || Self::eth_transact(tx));

if let Some(trace) = tracer.collect_trace() {
Ok(trace)
} else if let Err(err) = result {
Err(err)
} else {
Ok(tracer.empty_trace())
}
}
}
}
);

cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
Expand Down
10 changes: 10 additions & 0 deletions prdoc/pr_8652.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: '[pallet-revive] impl_revive_api macro'
doc:
- audience: Runtime Dev
description: Move pallet-revive runtime api implementation in a macro, so that we
don't repeat the code for every runtime.
crates:
- name: asset-hub-westend-runtime
bump: patch
- name: pallet-revive
bump: minor
12 changes: 12 additions & 0 deletions prdoc/pr_8662.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
title: '[pallet-revive] update dry-run logic'
doc:
- audience: Runtime Dev
description: |-
- Revert #8504
- Add a `prepare_dry_run` that run before dry_run
- Add `dry_run_*` wrapper fn for bare_call / bare_instantiate
Comment thread
pgherveou marked this conversation as resolved.
Outdated

depends on #8652
Comment thread
pgherveou marked this conversation as resolved.
Outdated
crates:
- name: pallet-revive
bump: patch
Comment thread
pgherveou marked this conversation as resolved.
Outdated
Loading
Loading