Skip to content
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

Introduce Weight v2 support for EVM (frontier) #2316

Merged
merged 96 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
50a835a
Update evm to 0.39
tgmichel May 23, 2023
cdefcf4
Adapted tests
May 25, 2023
d2e36ed
Removed unused imports
May 25, 2023
5c17976
Wip fallible discriminant
tgmichel May 26, 2023
eacaed5
fmt
tgmichel May 26, 2023
7ca772f
wip fix test assets costs
tgmichel May 26, 2023
e3f3ced
fix test assets costs
tgmichel May 29, 2023
b837dc9
TODO temp ignore precompile macro tests
tgmichel May 29, 2023
5f0fa96
Merge branch 'upgrade-evm-0.39' into tgm-evm-weight-v2
tgmichel May 29, 2023
38fa014
update frontier pin
tgmichel May 29, 2023
7f93c3b
update tests
tgmichel May 29, 2023
9229540
just hardcode `GasLimitPovSizeRatio` as a constant
tgmichel May 29, 2023
23712a8
Merge branch 'master' into tgm-evm-weight-v2
tgmichel May 29, 2023
b2cd44e
Merge remote-tracking branch 'origin/master' into tgm-evm-weight-v2
tgmichel May 30, 2023
b5609dc
fix xcm ts tests
tgmichel May 30, 2023
3ba8899
oops
tgmichel May 30, 2023
81c6d35
configure runtime api weigh_limit
tgmichel May 30, 2023
3ad6b40
suggestions
tgmichel May 30, 2023
3a3caaf
Updates EVM PoV to support PoV Gasometer
crystalin May 30, 2023
336f920
fix test evm-over-pov
librelois May 30, 2023
0c6250a
Update evm pin
tgmichel May 30, 2023
2a75fac
update ts tests
tgmichel May 30, 2023
8702ef2
Update evm pin 2
tgmichel May 30, 2023
934f01d
editorconfig
tgmichel May 30, 2023
3fd8117
update frontier pin
tgmichel May 30, 2023
47d37a2
prettier
tgmichel May 30, 2023
b89db41
fix
tgmichel May 30, 2023
9d08665
compute properly eth tx limits in ts tests
librelois May 30, 2023
e16c6fc
compute safely EXTRINSIC_GAS_LIMIT
librelois May 30, 2023
496f081
typo
librelois May 30, 2023
2f2dea4
runtime api TODO fix
tgmichel May 30, 2023
7d8bd35
Adds test for Gasometer PoV limit/estimate check
crystalin May 30, 2023
7c7622e
Merge branch 'tgm-evm-weight-v2' of github.com:purestake/moonbeam int…
crystalin May 30, 2023
9fb2777
runtime api eth_call estimate tx len
tgmichel May 31, 2023
94d3759
fix ts tests estimate gas
tgmichel May 31, 2023
ddf8459
prettier
tgmichel May 31, 2023
f2b68b4
suggestion
tgmichel May 31, 2023
fe44d2d
suggestion
tgmichel May 31, 2023
1e70241
optimize estimated_transaction_len
librelois May 31, 2023
73d2185
prettier gas_limit check
tgmichel May 31, 2023
93bee9e
fix xcm to evm encoded tx len
tgmichel May 31, 2023
7e6063d
Revert "fix xcm to evm encoded tx len"
tgmichel May 31, 2023
535bd5b
account for proof size in precompiles try_dispatch
librelois May 31, 2023
ac65f3c
fmt
librelois May 31, 2023
785c514
precompile handler: add helper function record_db_read
librelois May 31, 2023
a238173
migrate precompile db reads: xcm-utils
librelois May 31, 2023
ffa061b
migrate precompile db reads: xcm-transactor
librelois May 31, 2023
6801477
migrate precompile db reads: assets-erc20::eip2612
tgmichel May 31, 2023
c3afd77
migrate precompile db reads: precompile utils
librelois May 31, 2023
aed6160
Revert "migrate precompile db reads: assets-erc20::eip2612"
tgmichel May 31, 2023
faea500
migrate precompile db reads: assets-erc20::eip2612
librelois May 31, 2023
17d194b
fix rust tests
librelois May 31, 2023
ff97ebe
Update precompiles/xcm-transactor/src/functions.rs
librelois May 31, 2023
c6e657e
migrate precompile db reads: pallet-democracy
Agusrodri May 31, 2023
e45a1a2
migrate precompile db reads: fix pallet-democracy
librelois Jun 1, 2023
4e3416d
more precise comment
librelois Jun 1, 2023
c5b73f4
account AssetId
librelois Jun 1, 2023
d12626d
migrate precompile db reads: assets-erc20
tgmichel Jun 1, 2023
5962539
migrate precompile db reads: assets-erc20 (fix)
tgmichel Jun 1, 2023
2a51315
migrate precompile db reads: author-mapping
tgmichel Jun 1, 2023
fd805a2
migrate precompile db reads: balances-erc20::eip2612
tgmichel Jun 1, 2023
b1f72fe
migrate precompile db reads: balances-erc20
tgmichel Jun 1, 2023
e0b9684
migrate precompile db reads: balances-erc20::eip2612 (fix)
tgmichel Jun 1, 2023
312835a
migrate precompile db reads: call-permit
tgmichel Jun 1, 2023
2ae4d60
migrate precompile db reads: collective
tgmichel Jun 1, 2023
e5711ce
migrate precompile db reads: conviction-voting
tgmichel Jun 1, 2023
6697ab6
migrate precompile db reads: crowdloan-rewards
tgmichel Jun 1, 2023
c24ec2b
wip migrate precompile db reads: parachain-staking
tgmichel Jun 1, 2023
4e3806f
migrate precompile db reads: parachain-staking
tgmichel Jun 2, 2023
079e9d3
migrate precompile db reads: precompile-registry
tgmichel Jun 2, 2023
c58c6f5
migrate precompile db reads: proxy
tgmichel Jun 2, 2023
6ed722a
precompile-registry add some comments
tgmichel Jun 2, 2023
5fb1d84
migrate precompile db reads: referenda
tgmichel Jun 2, 2023
d9197a0
conviction-voting fix
tgmichel Jun 2, 2023
f17a118
call-permit update
tgmichel Jun 2, 2023
9e6e6c7
REMOVE precompile db reads: relay-encoder
tgmichel Jun 2, 2023
9dc6344
migrate precompile db reads: gmp
tgmichel Jun 2, 2023
41d777a
record arbitrary cost on relay encoder precompile to prevent free spam
librelois Jun 2, 2023
2aed45f
migrate precompile db reads: precompile-registry rework
librelois Jun 2, 2023
fc5ad64
Merge branch 'master' into tgm-evm-weight-v2
librelois Jun 2, 2023
391d924
refactor randomness pallet & precompile to comply with weight v2
librelois Jun 2, 2023
de7a54d
add test for precompile batch PoV check
Agusrodri Jun 2, 2023
3581171
fix rust tests compilation
librelois Jun 2, 2023
478dd33
adapt some rust tests
librelois Jun 2, 2023
8e8cdd4
suggestion
tgmichel Jun 5, 2023
9703082
Add back missing db read precompile_set
tgmichel Jun 5, 2023
bd15f1f
editorconfig + prettier
tgmichel Jun 5, 2023
c7c971e
update cumulus pin
librelois Jun 5, 2023
8749b94
update frontier pin
tgmichel Jun 5, 2023
2563ae8
fix ts precompile xcm utils tests
tgmichel Jun 5, 2023
8f69ebf
add more tests for precompile PoV and fmt
Agusrodri Jun 5, 2023
8986424
update cumulus pin
librelois Jun 5, 2023
d200e2e
comply prettier & editorconfig
librelois Jun 5, 2023
db0f970
fix more ts tests (update frontier pin)
tgmichel Jun 5, 2023
f402f12
Merge branch 'master' into tgm-evm-weight-v2
librelois Jun 6, 2023
73b6c3e
suggestion
tgmichel Jun 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
142 changes: 62 additions & 80 deletions Cargo.lock

Large diffs are not rendered by default.

36 changes: 20 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -226,28 +226,38 @@ ethereum = { version = "0.14.0", default-features = false, features = [
"with-codec",
] }
ethereum-types = { version = "0.14", default-features = false }
evm = { version = "0.39.0", default-features = false, features = [
"with-codec",
] }
evm-gasometer = { version = "0.39.0", default-features = false }
evm-runtime = { version = "0.39.0", default-features = false }
evm = { git = "https://github.com/purestake/evm", branch = "tgm-record-external-cost", default-features = false }
evm-gasometer = { git = "https://github.com/purestake/evm", branch = "tgm-record-external-cost", default-features = false }
evm-runtime = { git = "https://github.com/purestake/evm", branch = "tgm-record-external-cost", default-features = false }
fp-ethereum = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
fp-evm = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
fp-rpc = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
fp-self-contained = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
pallet-base-fee = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
pallet-ethereum = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false, features = [
"forbid-evm-reentrancy",
"evm-with-weight-limit",
] }
pallet-evm = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false, features = [
"forbid-evm-reentrancy",
"evm-with-weight-limit",
] }
pallet-evm-precompile-blake2 = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false, features = [
"evm-with-weight-limit",
] }
pallet-evm-precompile-bn128 = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false, features = [
"evm-with-weight-limit",
] }
pallet-evm-precompile-dispatch = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false, features = [
"evm-with-weight-limit",
] }
pallet-evm-precompile-modexp = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false, features = [
"evm-with-weight-limit",
] }
pallet-evm-precompile-blake2 = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
pallet-evm-precompile-bn128 = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
pallet-evm-precompile-dispatch = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
pallet-evm-precompile-modexp = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
pallet-evm-precompile-sha3fips = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
pallet-evm-precompile-simple = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false }
pallet-evm-precompile-simple = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40", default-features = false, features = [
"evm-with-weight-limit",
] }

# Frontier (client)
fc-consensus = { git = "https://github.com/purestake/frontier", branch = "moonbeam-polkadot-v0.9.40" }
Expand Down Expand Up @@ -364,12 +374,6 @@ tracing-core = "0.1.29"
trie-root = "0.15.2"
url = "2.2.2"

[patch.crates-io]
evm = { git = "https://github.com/rust-blockchain/evm", rev = "842e03d068ddb6a3195a2dedc4a9b63caadb3355" }
evm-core = { git = "https://github.com/rust-blockchain/evm", rev = "842e03d068ddb6a3195a2dedc4a9b63caadb3355" }
evm-gasometer = { git = "https://github.com/rust-blockchain/evm", rev = "842e03d068ddb6a3195a2dedc4a9b63caadb3355" }
evm-runtime = { git = "https://github.com/rust-blockchain/evm", rev = "842e03d068ddb6a3195a2dedc4a9b63caadb3355" }

# The list of dependencies below (which can be both direct and indirect dependencies) are crates
# that are suspected to be CPU-intensive, and that are unlikely to require debugging (as some of
# their debug info might be missing) or to require to be frequently recompiled. We compile these
Expand Down
93 changes: 71 additions & 22 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,16 +614,31 @@ where
let overrides = crate::rpc::overrides_handle(client.clone());
let fee_history_limit = rpc_config.fee_history_limit;

rpc::spawn_essential_tasks(rpc::SpawnTasksParams {
task_manager: &task_manager,
client: client.clone(),
substrate_backend: backend.clone(),
frontier_backend: frontier_backend.clone(),
filter_pool: filter_pool.clone(),
overrides: overrides.clone(),
fee_history_limit,
fee_history_cache: fee_history_cache.clone(),
});
// Sinks for pubsub notifications.
// Everytime a new subscription is created, a new mpsc channel is added to the sink pool.
// The MappingSyncWorker sends through the channel on block import and the subscription emits a
// notification to the subscriber on receiving a message through this channel.
// This way we avoid race conditions when using native substrate block import notification
// stream.
let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks<
fc_mapping_sync::EthereumBlockNotification<Block>,
> = Default::default();
let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A question about the channel, if this is created per-subscription is it possible to OOM kill the client via flooding it with subscriptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the connection is kept open in the client end, the limit of channels is the number of websocket connections the server supports. Each time a new ethereum block is produced, channels associated to closed connections are removed from the pool.


rpc::spawn_essential_tasks(
rpc::SpawnTasksParams {
task_manager: &task_manager,
client: client.clone(),
substrate_backend: backend.clone(),
frontier_backend: frontier_backend.clone(),
filter_pool: filter_pool.clone(),
overrides: overrides.clone(),
fee_history_limit,
fee_history_cache: fee_history_cache.clone(),
},
sync_service.clone(),
pubsub_notification_sinks.clone(),
);

let ethapi_cmd = rpc_config.ethapi.clone();
let tracing_requesters =
Expand Down Expand Up @@ -669,6 +684,7 @@ where
let overrides = overrides.clone();
let fee_history_cache = fee_history_cache.clone();
let block_data_cache = block_data_cache.clone();
let pubsub_notification_sinks = pubsub_notification_sinks.clone();

move |deny_unsafe, subscription_task_executor| {
let deps = rpc::FullDeps {
Expand All @@ -690,6 +706,7 @@ where
xcm_senders: None,
block_data_cache: block_data_cache.clone(),
overrides: overrides.clone(),
forced_parent_hashes: None,
};
if ethapi_cmd.contains(&EthApiCmd::Debug) || ethapi_cmd.contains(&EthApiCmd::Trace) {
rpc::create_full(
Expand All @@ -699,10 +716,17 @@ where
tracing_requesters: tracing_requesters.clone(),
trace_filter_max_count: rpc_config.ethapi_trace_max_count,
}),
pubsub_notification_sinks.clone(),
)
.map_err(Into::into)
} else {
rpc::create_full(deps, subscription_task_executor, None).map_err(Into::into)
rpc::create_full(
deps,
subscription_task_executor,
None,
pubsub_notification_sinks.clone(),
)
.map_err(Into::into)
}
}
};
Expand Down Expand Up @@ -1090,16 +1114,32 @@ where
}),
);
}
rpc::spawn_essential_tasks(rpc::SpawnTasksParams {
task_manager: &task_manager,
client: client.clone(),
substrate_backend: backend.clone(),
frontier_backend: frontier_backend.clone(),
filter_pool: filter_pool.clone(),
overrides: overrides.clone(),
fee_history_limit,
fee_history_cache: fee_history_cache.clone(),
});

// Sinks for pubsub notifications.
// Everytime a new subscription is created, a new mpsc channel is added to the sink pool.
// The MappingSyncWorker sends through the channel on block import and the subscription emits a
// notification to the subscriber on receiving a message through this channel.
// This way we avoid race conditions when using native substrate block import notification
// stream.
let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks<
fc_mapping_sync::EthereumBlockNotification<Block>,
> = Default::default();
let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks);

rpc::spawn_essential_tasks(
rpc::SpawnTasksParams {
task_manager: &task_manager,
client: client.clone(),
substrate_backend: backend.clone(),
frontier_backend: frontier_backend.clone(),
filter_pool: filter_pool.clone(),
overrides: overrides.clone(),
fee_history_limit,
fee_history_cache: fee_history_cache.clone(),
},
sync_service.clone(),
pubsub_notification_sinks.clone(),
);
let ethapi_cmd = rpc_config.ethapi.clone();
let tracing_requesters =
if ethapi_cmd.contains(&EthApiCmd::Debug) || ethapi_cmd.contains(&EthApiCmd::Trace) {
Expand Down Expand Up @@ -1142,6 +1182,7 @@ where
let overrides = overrides.clone();
let fee_history_cache = fee_history_cache.clone();
let block_data_cache = block_data_cache.clone();
let pubsub_notification_sinks = pubsub_notification_sinks.clone();

move |deny_unsafe, subscription_task_executor| {
let deps = rpc::FullDeps {
Expand All @@ -1163,6 +1204,7 @@ where
xcm_senders: xcm_senders.clone(),
overrides: overrides.clone(),
block_data_cache: block_data_cache.clone(),
forced_parent_hashes: None,
};

if ethapi_cmd.contains(&EthApiCmd::Debug) || ethapi_cmd.contains(&EthApiCmd::Trace) {
Expand All @@ -1173,10 +1215,17 @@ where
tracing_requesters: tracing_requesters.clone(),
trace_filter_max_count: rpc_config.ethapi_trace_max_count,
}),
pubsub_notification_sinks.clone(),
)
.map_err(Into::into)
} else {
rpc::create_full(deps, subscription_task_executor, None).map_err(Into::into)
rpc::create_full(
deps,
subscription_task_executor,
None,
pubsub_notification_sinks.clone(),
)
.map_err(Into::into)
}
}
};
Expand Down
23 changes: 21 additions & 2 deletions node/service/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ pub struct FullDeps<C, P, A: ChainApi, BE> {
pub overrides: Arc<OverrideHandle<Block>>,
/// Cache for Ethereum block data.
pub block_data_cache: Arc<EthBlockDataCacheTask<Block>>,
/// Mandated parent hashes for a given block hash.
pub forced_parent_hashes: Option<BTreeMap<H256, H256>>,
}

pub struct TracingConfig {
Expand Down Expand Up @@ -169,6 +171,11 @@ pub fn create_full<C, P, BE, A>(
deps: FullDeps<C, P, A, BE>,
subscription_task_executor: SubscriptionTaskExecutor,
maybe_tracing_config: Option<TracingConfig>,
pubsub_notification_sinks: Arc<
fc_mapping_sync::EthereumBlockNotificationSinks<
fc_mapping_sync::EthereumBlockNotification<Block>,
>,
>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
BE: Backend<Block> + 'static,
Expand Down Expand Up @@ -215,6 +222,7 @@ where
xcm_senders,
overrides,
block_data_cache,
forced_parent_hashes,
} = deps;

io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?;
Expand Down Expand Up @@ -249,6 +257,7 @@ where
fee_history_cache,
fee_history_limit,
10,
forced_parent_hashes,
)
.replace_config::<MoonbeamEthConfig<C, BE>>()
.into_rpc(),
Expand Down Expand Up @@ -286,6 +295,7 @@ where
sync.clone(),
subscription_task_executor,
overrides,
pubsub_notification_sinks.clone(),
)
.into_rpc(),
)?;
Expand Down Expand Up @@ -345,8 +355,15 @@ pub struct SpawnTasksParams<'a, B: BlockT, C, BE> {
}

/// Spawn the tasks that are required to run Moonbeam.
pub fn spawn_essential_tasks<B, C, BE>(params: SpawnTasksParams<B, C, BE>)
where
pub fn spawn_essential_tasks<B, C, BE>(
params: SpawnTasksParams<B, C, BE>,
sync: Arc<SyncingService<B>>,
pubsub_notification_sinks: Arc<
fc_mapping_sync::EthereumBlockNotificationSinks<
fc_mapping_sync::EthereumBlockNotification<B>,
>,
>,
) where
C: ProvideRuntimeApi<B> + BlockOf,
C: HeaderBackend<B> + HeaderMetadata<B, Error = BlockChainError> + 'static,
C: BlockchainEvents<B> + StorageProvider<B, BE>,
Expand All @@ -373,6 +390,8 @@ where
3,
0,
SyncStrategy::Parachain,
sync,
pubsub_notification_sinks,
)
.for_each(|()| futures::future::ready(())),
);
Expand Down
15 changes: 11 additions & 4 deletions pallets/erc20-xcm-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub mod pallet {
use ethereum_types::BigEndianHash;
use fp_evm::{ExitReason, ExitSucceed};
use frame_support::pallet_prelude::*;
use pallet_evm::Runner;
use pallet_evm::{GasWeightMapping, Runner};
use sp_core::{H160, H256, U256};
use sp_std::vec::Vec;
use xcm::latest::{
Expand Down Expand Up @@ -66,9 +66,9 @@ pub mod pallet {
Erc20Matcher::<T::Erc20MultilocationPrefix>::is_erc20_asset(asset)
}
pub fn weight_of_erc20_transfer() -> Weight {
Weight::from_parts(
T::Erc20TransferGasLimit::get().saturating_mul(T::WeightPerGas::get().ref_time()),
0,
pallet_evm::FixedGasWeightMapping::<T>::gas_to_weight(
tgmichel marked this conversation as resolved.
Show resolved Hide resolved
T::Erc20TransferGasLimit::get(),
true,
)
}
fn erc20_transfer(
Expand All @@ -85,6 +85,11 @@ pub mod pallet {
// append amount to be transferred
input.extend_from_slice(H256::from_uint(&amount).as_bytes());

let weight_limit = pallet_evm::FixedGasWeightMapping::<T>::gas_to_weight(
tgmichel marked this conversation as resolved.
Show resolved Hide resolved
T::Erc20TransferGasLimit::get(),
true,
);

let exec_info = T::EvmRunner::call(
from,
erc20_contract_address,
Expand All @@ -97,6 +102,8 @@ pub mod pallet {
Default::default(),
false,
false,
Some(weight_limit),
Some(0),
&<T as pallet_evm::Config>::config(),
)
.map_err(|_| Erc20TransferError::EvmCallFail)?;
Expand Down
2 changes: 1 addition & 1 deletion pallets/ethereum-xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = [ "Parity Technologies <admin@parity.io>" ]
description = "Xcm Transact compatibility for pallet-etherum."
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/paritytech/frontier/"
repository = "https://github.com/purestake/moonbeam/"
version = "1.0.0-dev"

[package.metadata.docs.rs]
Expand Down
22 changes: 22 additions & 0 deletions pallets/ethereum-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ pub mod pallet {
}

impl<T: Config> Pallet<T> {
fn transaction_len(transaction: &Transaction) -> u64 {
transaction
.encode()
.len()
// pallet + call indexes
.saturating_add(2) as u64
}

fn validate_and_apply(
source: H160,
xcm_transaction: EthereumXcmTransaction,
Expand All @@ -249,6 +257,18 @@ impl<T: Config> Pallet<T> {
if let Some(transaction) = transaction {
let transaction_data: TransactionData = (&transaction).into();

let (weight_limit, proof_size_base_cost) =
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)),
tgmichel marked this conversation as resolved.
Show resolved Hide resolved
),
_ => (None, None),
};

let _ = CheckEvmTransaction::<T::InvalidEvmTransactionError>::new(
CheckEvmTransactionConfig {
evm_config: T::config(),
Expand All @@ -262,6 +282,8 @@ impl<T: Config> Pallet<T> {
is_transactional: true,
},
transaction_data.into(),
weight_limit,
proof_size_base_cost,
)
// 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