Skip to content

Commit

Permalink
apply TransactionPov changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzamontiel committed Aug 30, 2024
1 parent 0fa229f commit 4382107
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 56 deletions.
12 changes: 7 additions & 5 deletions client/rpc/finality/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use sp_core::H256;
use sp_runtime::traits::Block;
use std::ops::Deref;
use std::{marker::PhantomData, sync::Arc};
use fc_rpc::internal_err;

/// An RPC endpoint to check for finality of blocks and transactions in Moonbeam
#[rpc(server)]
Expand Down Expand Up @@ -72,14 +73,14 @@ where
async fn is_tx_finalized(&self, tx_hash: H256) -> RpcResult<bool> {
let client = self.client.clone();

if let Some((ethereum_block_hash, _ethereum_index)) =
if let Ok(Some((ethereum_block_hash, _ethereum_index))) =
frontier_backend_client::load_transactions::<B, C>(
&client,
self.backend.as_ref(),
tx_hash,
true,
)
.await?
.await
{
is_block_finalized_inner::<B, C>(self.backend.as_ref(), &client, ethereum_block_hash)
.await
Expand Down Expand Up @@ -107,10 +108,11 @@ async fn is_block_finalized_inner<B: Block<Hash = H256>, C: HeaderBackend<B> + '
raw_hash: H256,
) -> RpcResult<bool> {
let substrate_hash =
match frontier_backend_client::load_hash::<B, C>(client, backend, raw_hash).await? {
// If we find this hash in the frontier data base, we know it is an eth hash
match frontier_backend_client::load_hash::<B, C>(client, backend, raw_hash)
.await
.map_err(|err| internal_err(format!("{:?}", err)))?
{
Some(hash) => hash,
// Otherwise, we assume this is a Substrate hash.
None => raw_hash,
};

Expand Down
5 changes: 2 additions & 3 deletions pallets/erc20-xcm-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub mod pallet {
use crate::errors::*;
use crate::xcm_holding_ext::*;
use ethereum_types::BigEndianHash;
use fp_evm::{ExitReason, ExitSucceed};
use fp_evm::{ExitReason, ExitSucceed, TransactionPov};
use frame_support::pallet_prelude::*;
use pallet_evm::{GasWeightMapping, Runner};
use sp_core::{H160, H256, U256};
Expand Down Expand Up @@ -125,8 +125,7 @@ pub mod pallet {
Default::default(),
false,
false,
Some(weight_limit),
Some(0),
Some(TransactionPov::new(weight_limit, 0)),
&<T as pallet_evm::Config>::config(),
)
.map_err(|_| Erc20TransferError::EvmCallFail)?;
Expand Down
15 changes: 6 additions & 9 deletions pallets/ethereum-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod tests;

use ethereum_types::{H160, H256, U256};
use fp_ethereum::{TransactionData, ValidatedTransaction};
use fp_evm::{CheckEvmTransaction, CheckEvmTransactionConfig, TransactionValidationError};
use fp_evm::{CheckEvmTransaction, CheckEvmTransactionConfig, TransactionPov, TransactionValidationError};
use frame_support::{
dispatch::{DispatchResultWithPostInfo, Pays, PostDispatchInfo},
traits::{EnsureOrigin, Get, ProcessMessage},
Expand Down Expand Up @@ -326,16 +326,14 @@ impl<T: Config> Pallet<T> {
let tx_hash = transaction.hash();
let transaction_data: TransactionData = (&transaction).into();

let (weight_limit, proof_size_base_cost) =
let transaction_pov =
match <T as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
transaction_data.gas_limit.unique_saturated_into(),
true,
) {
weight_limit if weight_limit.proof_size() > 0 => (
Some(weight_limit),
Some(Self::transaction_len(&transaction)),
),
_ => (None, None),
weight_limit if weight_limit.proof_size() > 0 =>
Some(TransactionPov::new(weight_limit, Self::transaction_len(&transaction))),
_ => None,
};

let _ = CheckEvmTransaction::<T::InvalidEvmTransactionError>::new(
Expand All @@ -351,8 +349,7 @@ impl<T: Config> Pallet<T> {
is_transactional: true,
},
transaction_data.into(),
weight_limit,
proof_size_base_cost,
transaction_pov
)
// We only validate the gas limit against the evm transaction cost.
// No need to validate fee payment, as it is handled by the xcm executor.
Expand Down
18 changes: 6 additions & 12 deletions pallets/moonbeam-foreign-assets/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use crate::{AssetId, Error, Pallet};
use ethereum_types::{BigEndianHash, H160, H256, U256};
use fp_evm::{ExitReason, ExitSucceed};
use fp_evm::{ExitReason, ExitSucceed, TransactionPov};
use frame_support::ensure;
use frame_support::pallet_prelude::Weight;
use pallet_evm::{GasWeightMapping, Runner};
Expand Down Expand Up @@ -129,7 +129,6 @@ impl<T: crate::Config> EvmCaller<T> {
false,
false,
None,
None,
&<T as pallet_evm::Config>::config(),
contract_adress,
)
Expand Down Expand Up @@ -174,8 +173,7 @@ impl<T: crate::Config> EvmCaller<T> {
Default::default(),
false,
false,
Some(weight_limit),
Some(0),
Some(TransactionPov::new(weight_limit, 0)),
&<T as pallet_evm::Config>::config(),
)
.map_err(|_| EvmError::EvmCallFail)?;
Expand Down Expand Up @@ -220,8 +218,7 @@ impl<T: crate::Config> EvmCaller<T> {
Default::default(),
false,
false,
Some(weight_limit),
Some(0),
Some(TransactionPov::new(weight_limit, 0)),
&<T as pallet_evm::Config>::config(),
)
.map_err(|_| EvmError::EvmCallFail)?;
Expand Down Expand Up @@ -275,8 +272,7 @@ impl<T: crate::Config> EvmCaller<T> {
Default::default(),
false,
false,
Some(weight_limit),
Some(0),
Some(TransactionPov::new(weight_limit, 0)),
&<T as pallet_evm::Config>::config(),
)
.map_err(|_| EvmError::EvmCallFail)?;
Expand Down Expand Up @@ -312,8 +308,7 @@ impl<T: crate::Config> EvmCaller<T> {
Default::default(),
false,
false,
Some(weight_limit),
Some(0),
Some(TransactionPov::new(weight_limit, 0)),
&<T as pallet_evm::Config>::config(),
)
.map_err(|_| Error::<T>::EvmInternalError)?;
Expand Down Expand Up @@ -350,8 +345,7 @@ impl<T: crate::Config> EvmCaller<T> {
Default::default(),
false,
false,
Some(weight_limit),
Some(0),
Some(TransactionPov::new(weight_limit, 0)),
&<T as pallet_evm::Config>::config(),
)
.map_err(|_| Error::<T>::EvmInternalError)?;
Expand Down
30 changes: 14 additions & 16 deletions runtime/common/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ macro_rules! impl_runtime_apis_plus_common {
#[cfg(feature = "evm-tracing")]
{
use moonbeam_evm_tracer::tracer::EvmTracer;
use fp_evm::TransactionPov;

// Initialize block: calls the "on_initialize" hook on every pallet
// in AllPalletsWithSystem.
Expand Down Expand Up @@ -323,15 +324,15 @@ macro_rules! impl_runtime_apis_plus_common {

let gas_limit = gas_limit.min(u64::MAX.into()).low_u64();

let (weight_limit, proof_size_base_cost) =
let transaction_pov =
match <Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
gas_limit,
without_base_extrinsic_weight
) {
weight_limit if weight_limit.proof_size() > 0 => {
(Some(weight_limit), Some(estimated_transaction_len as u64))
(Some(TransactionPov::new(weight_limit, estimated_transaction_len as u64)))
}
_ => (None, None),
_ => (None),
};

let _ = <Runtime as pallet_evm::Config>::Runner::call(
Expand All @@ -346,8 +347,7 @@ macro_rules! impl_runtime_apis_plus_common {
access_list.unwrap_or_default(),
is_transactional,
validate,
weight_limit,
proof_size_base_cost,
transaction_pov,
<Runtime as pallet_evm::Config>::config(),
);
});
Expand Down Expand Up @@ -459,15 +459,15 @@ macro_rules! impl_runtime_apis_plus_common {
let gas_limit = gas_limit.min(u64::MAX.into()).low_u64();
let without_base_extrinsic_weight = true;

let (weight_limit, proof_size_base_cost) =
let transaction_pov =
match <Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
gas_limit,
without_base_extrinsic_weight
) {
weight_limit if weight_limit.proof_size() > 0 => {
(Some(weight_limit), Some(estimated_transaction_len as u64))
(Some(TransactionPov::new(weight_limit, estimated_transaction_len as u64)))
}
_ => (None, None),
_ => (None),
};

<Runtime as pallet_evm::Config>::Runner::call(
Expand All @@ -482,8 +482,7 @@ macro_rules! impl_runtime_apis_plus_common {
access_list.unwrap_or_default(),
is_transactional,
validate,
weight_limit,
proof_size_base_cost,
transaction_pov,
config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),
).map_err(|err| err.error.into())
}
Expand Down Expand Up @@ -536,15 +535,15 @@ macro_rules! impl_runtime_apis_plus_common {
};
let without_base_extrinsic_weight = true;

let (weight_limit, proof_size_base_cost) =
let transaction_pov =
match <Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
gas_limit,
without_base_extrinsic_weight
) {
weight_limit if weight_limit.proof_size() > 0 => {
(Some(weight_limit), Some(estimated_transaction_len as u64))
(Some(TransactionPov::new(weight_limit, estimated_transaction_len as u64)))
}
_ => (None, None),
_ => (None),
};

#[allow(clippy::or_fun_call)] // suggestion not helpful here
Expand All @@ -559,8 +558,7 @@ macro_rules! impl_runtime_apis_plus_common {
access_list.unwrap_or_default(),
is_transactional,
validate,
weight_limit,
proof_size_base_cost,
transaction_pov,
config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),
).map_err(|err| err.error.into())
}
Expand Down Expand Up @@ -741,7 +739,7 @@ macro_rules! impl_runtime_apis_plus_common {
}
}

impl xcm_fee_payment_runtime_api::XcmPaymentApi<Block> for Runtime {
impl xcm_runtime_apis::fees::runtime_decl_for_xcm_payment_api::XcmPaymentApi<Block> for Runtime {
fn query_acceptable_payment_assets(
xcm_version: xcm::Version
) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
Expand Down
17 changes: 6 additions & 11 deletions runtime/common/src/impl_xcm_evm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#[macro_export]
macro_rules! impl_evm_runner_precompile_or_eth_xcm {
{} => {
use fp_evm::{CallInfo, CallOrCreateInfo, Context, Transfer};
use fp_evm::{CallInfo, CallOrCreateInfo, Context, Transfer, TransactionPov};
use frame_support::dispatch::CallableCallFor;
use pallet_evm::{Runner, RunnerError};
use precompile_utils::{prelude::*, evm::handle::with_precompile_handle};
Expand Down Expand Up @@ -51,8 +51,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm {
access_list: Vec<(H160, Vec<H256>)>,
_is_transactional: bool,
_validate: bool,
_weight_limit: Option<Weight>,
_transaction_len: Option<u64>,
_transaction_pov: Option<TransactionPov>,
_config: &fp_evm::Config,
) -> Result<CallInfo, RunnerError<Self::Error>> {
// The `with_precompile_handle` function will execute the closure (and return the
Expand Down Expand Up @@ -139,8 +138,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm {
_access_list: Vec<(H160, Vec<H256>)>,
_is_transactional: bool,
_validate: bool,
_weight_limit: Option<Weight>,
_transaction_len: Option<u64>,
_transaction_pov: Option<TransactionPov>,
_config: &fp_evm::Config,
) -> Result<fp_evm::CreateInfo, RunnerError<Self::Error>> {
unimplemented!()
Expand All @@ -158,8 +156,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm {
_access_list: Vec<(H160, Vec<H256>)>,
_is_transactional: bool,
_validate: bool,
_weight_limit: Option<Weight>,
_transaction_len: Option<u64>,
_transaction_pov: Option<TransactionPov>,
_config: &fp_evm::Config,
) -> Result<fp_evm::CreateInfo, RunnerError<Self::Error>> {
unimplemented!()
Expand All @@ -176,8 +173,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm {
access_list: Vec<(H160, Vec<H256>)>,
is_transactional: bool,
validate: bool,
weight_limit: Option<Weight>,
transaction_len: Option<u64>,
transaction_pov: Option<TransactionPov>,
config: &fp_evm::Config,
force_address: H160,
) -> Result<fp_evm::CreateInfo, RunnerError<Self::Error>> {
Expand Down Expand Up @@ -230,8 +226,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm {
_nonce: Option<U256>,
_access_list: Vec<(H160, Vec<H256>)>,
_is_transactional: bool,
_weight_limit: Option<Weight>,
_transaction_len: Option<u64>,
_transaction_pov: Option<TransactionPov>,
_evm_config: &fp_evm::Config,
) -> Result<(), RunnerError<Self::Error>> {
unimplemented!()
Expand Down
1 change: 1 addition & 0 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ use xcm::{
use xcm_config::AssetType;
use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;
use xcm_primitives::UnitsToWeightRatio;
use fp_evm::TransactionPov;

use smallvec::smallvec;
use sp_runtime::serde::{Deserialize, Serialize};
Expand Down
1 change: 1 addition & 0 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ use xcm::{
use xcm_config::AssetType;
use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;
use xcm_primitives::UnitsToWeightRatio;
use fp_evm::TransactionPov;

#[cfg(feature = "std")]
use sp_version::NativeVersion;
Expand Down
1 change: 1 addition & 0 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ use xcm::{
use xcm_config::AssetType;
use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;
use xcm_primitives::UnitsToWeightRatio;
use fp_evm::TransactionPov;

use smallvec::smallvec;
#[cfg(feature = "std")]
Expand Down

0 comments on commit 4382107

Please sign in to comment.