diff --git a/client/rpc/finality/src/lib.rs b/client/rpc/finality/src/lib.rs index 988d8d316c..b4241a8953 100644 --- a/client/rpc/finality/src/lib.rs +++ b/client/rpc/finality/src/lib.rs @@ -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)] @@ -72,14 +73,14 @@ where async fn is_tx_finalized(&self, tx_hash: H256) -> RpcResult { 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::( &client, self.backend.as_ref(), tx_hash, true, ) - .await? + .await { is_block_finalized_inner::(self.backend.as_ref(), &client, ethereum_block_hash) .await @@ -107,10 +108,11 @@ async fn is_block_finalized_inner, C: HeaderBackend + ' raw_hash: H256, ) -> RpcResult { let substrate_hash = - match frontier_backend_client::load_hash::(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::(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, }; diff --git a/pallets/erc20-xcm-bridge/src/lib.rs b/pallets/erc20-xcm-bridge/src/lib.rs index c7fd547721..e864e8df6f 100644 --- a/pallets/erc20-xcm-bridge/src/lib.rs +++ b/pallets/erc20-xcm-bridge/src/lib.rs @@ -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}; @@ -125,8 +125,7 @@ pub mod pallet { Default::default(), false, false, - Some(weight_limit), - Some(0), + Some(TransactionPov::new(weight_limit, 0)), &::config(), ) .map_err(|_| Erc20TransferError::EvmCallFail)?; diff --git a/pallets/ethereum-xcm/src/lib.rs b/pallets/ethereum-xcm/src/lib.rs index a894c47a93..05d1c83a91 100644 --- a/pallets/ethereum-xcm/src/lib.rs +++ b/pallets/ethereum-xcm/src/lib.rs @@ -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}, @@ -326,16 +326,14 @@ impl Pallet { let tx_hash = transaction.hash(); let transaction_data: TransactionData = (&transaction).into(); - let (weight_limit, proof_size_base_cost) = + let transaction_pov = match ::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::::new( @@ -351,8 +349,7 @@ impl Pallet { 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. diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index aae1b1bf14..e54182a7c5 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -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}; @@ -129,7 +129,6 @@ impl EvmCaller { false, false, None, - None, &::config(), contract_adress, ) @@ -174,8 +173,7 @@ impl EvmCaller { Default::default(), false, false, - Some(weight_limit), - Some(0), + Some(TransactionPov::new(weight_limit, 0)), &::config(), ) .map_err(|_| EvmError::EvmCallFail)?; @@ -220,8 +218,7 @@ impl EvmCaller { Default::default(), false, false, - Some(weight_limit), - Some(0), + Some(TransactionPov::new(weight_limit, 0)), &::config(), ) .map_err(|_| EvmError::EvmCallFail)?; @@ -275,8 +272,7 @@ impl EvmCaller { Default::default(), false, false, - Some(weight_limit), - Some(0), + Some(TransactionPov::new(weight_limit, 0)), &::config(), ) .map_err(|_| EvmError::EvmCallFail)?; @@ -312,8 +308,7 @@ impl EvmCaller { Default::default(), false, false, - Some(weight_limit), - Some(0), + Some(TransactionPov::new(weight_limit, 0)), &::config(), ) .map_err(|_| Error::::EvmInternalError)?; @@ -350,8 +345,7 @@ impl EvmCaller { Default::default(), false, false, - Some(weight_limit), - Some(0), + Some(TransactionPov::new(weight_limit, 0)), &::config(), ) .map_err(|_| Error::::EvmInternalError)?; diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index 38912cb7d4..edc93104a3 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -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. @@ -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 ::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 _ = ::Runner::call( @@ -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, ::config(), ); }); @@ -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 ::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), }; ::Runner::call( @@ -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(::config()), ).map_err(|err| err.error.into()) } @@ -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 ::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 @@ -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(::config()), ).map_err(|err| err.error.into()) } @@ -741,7 +739,7 @@ macro_rules! impl_runtime_apis_plus_common { } } - impl xcm_fee_payment_runtime_api::XcmPaymentApi for Runtime { + impl xcm_runtime_apis::fees::runtime_decl_for_xcm_payment_api::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets( xcm_version: xcm::Version ) -> Result, XcmPaymentApiError> { diff --git a/runtime/common/src/impl_xcm_evm_runner.rs b/runtime/common/src/impl_xcm_evm_runner.rs index 07102147e1..9628dc578a 100644 --- a/runtime/common/src/impl_xcm_evm_runner.rs +++ b/runtime/common/src/impl_xcm_evm_runner.rs @@ -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}; @@ -51,8 +51,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm { access_list: Vec<(H160, Vec)>, _is_transactional: bool, _validate: bool, - _weight_limit: Option, - _transaction_len: Option, + _transaction_pov: Option, _config: &fp_evm::Config, ) -> Result> { // The `with_precompile_handle` function will execute the closure (and return the @@ -139,8 +138,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm { _access_list: Vec<(H160, Vec)>, _is_transactional: bool, _validate: bool, - _weight_limit: Option, - _transaction_len: Option, + _transaction_pov: Option, _config: &fp_evm::Config, ) -> Result> { unimplemented!() @@ -158,8 +156,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm { _access_list: Vec<(H160, Vec)>, _is_transactional: bool, _validate: bool, - _weight_limit: Option, - _transaction_len: Option, + _transaction_pov: Option, _config: &fp_evm::Config, ) -> Result> { unimplemented!() @@ -176,8 +173,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm { access_list: Vec<(H160, Vec)>, is_transactional: bool, validate: bool, - weight_limit: Option, - transaction_len: Option, + transaction_pov: Option, config: &fp_evm::Config, force_address: H160, ) -> Result> { @@ -230,8 +226,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm { _nonce: Option, _access_list: Vec<(H160, Vec)>, _is_transactional: bool, - _weight_limit: Option, - _transaction_len: Option, + _transaction_pov: Option, _evm_config: &fp_evm::Config, ) -> Result<(), RunnerError> { unimplemented!() diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 6a591538cd..2b91c5745d 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -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}; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 551e4f965c..e0adbda8c1 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -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; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index f1975cbc68..712b5506c1 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -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")]