From 0491ea8495847d1ae92dbdd1c796506c1022dc99 Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 2 Jun 2022 14:42:09 +0800 Subject: [PATCH 01/10] Add a new config --- modules/dispatch/src/lib.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/dispatch/src/lib.rs b/modules/dispatch/src/lib.rs index f467bab0d..1e8d9dcd2 100644 --- a/modules/dispatch/src/lib.rs +++ b/modules/dispatch/src/lib.rs @@ -47,7 +47,7 @@ pub use pallet::*; #[frame_support::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; + use frame_support::{pallet_prelude::*, traits::EnsureOrigin}; use frame_system::pallet_prelude::*; #[pallet::config] @@ -94,6 +94,10 @@ pub mod pallet { /// /// Used when deriving target chain AccountIds from source chain AccountIds. type AccountIdConverter: sp_runtime::traits::Convert; + // TODO: add docs + // type EthereumCallOrigin: EnsureOrigin; + // TODO: update the trait + type EthereumTransactValidator: EthereumTransactCall<>::Call>; } type BridgeMessageIdOf = >::BridgeMessageId; @@ -274,6 +278,13 @@ impl, I: 'static> MessageDispatch return dispatch_result } + // If the call is Ethereum Transact dispatch call + if let Some(dispatch_info) = T::EthereumTransactValidator::dispatch(&call) { + // TODO: add event + + return dispatch_result; + } + // verify weight // (we want passed weight to be at least equal to pre-dispatch weight of the call // because otherwise Calls may be dispatched at lower price) @@ -420,6 +431,13 @@ where proof } +use frame_support::weights::PostDispatchInfo; +pub trait EthereumTransactCall { + fn is_ethereum_call(t: &T) -> bool; + fn validate(t: &T) -> bool; + fn dispatch(t: &T) -> Option>; +} + #[cfg(test)] mod tests { // From construct_runtime macro From f2842273ce7d210a98bab7bbb1c13f332ff59d97 Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 2 Jun 2022 15:05:54 +0800 Subject: [PATCH 02/10] Add toml patch --- modules/fee-market/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/fee-market/Cargo.toml b/modules/fee-market/Cargo.toml index a5d3c4ca7..1a7cc4f80 100644 --- a/modules/fee-market/Cargo.toml +++ b/modules/fee-market/Cargo.toml @@ -24,9 +24,9 @@ sp-io = { default-features = false, git = "https://github.com/darwi sp-runtime = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" } sp-std = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" } # darwinia-bridges-substrate -bp-messages = { default-features = false, git = "https://github.com/darwinia-network/darwinia-bridges-substrate", branch = "darwinia-v0.12.2" } -bp-runtime = { default-features = false, git = "https://github.com/darwinia-network/darwinia-bridges-substrate", branch = "darwinia-v0.12.2" } -pallet-bridge-messages = { default-features = false, git = "https://github.com/darwinia-network/darwinia-bridges-substrate", branch = "darwinia-v0.12.2" } +bp-messages = { default-features = false, path = "../../primitives/messages" } +bp-runtime = { default-features = false, path = "../../primitives/runtime" } +pallet-bridge-messages = { default-features = false, path = "../messages" } [dev-dependencies] pallet-balances = { git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" } From f7f6db53a1ba854a4431b7001066684d41c2ad8b Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 2 Jun 2022 17:01:48 +0800 Subject: [PATCH 03/10] Add more things --- Cargo.lock | 282 ++++++++------------ modules/dispatch/src/lib.rs | 80 ++++-- relays/client-crab-parachain/src/lib.rs | 6 +- relays/client-crab-parachain/src/runtime.rs | 7 +- 4 files changed, 172 insertions(+), 203 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b697e7ca..67229d850 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -623,8 +623,8 @@ name = "bp-crab" version = "0.1.0" dependencies = [ "bp-darwinia-core", - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-messages", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-runtime 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -637,8 +637,8 @@ name = "bp-crab-parachain" version = "0.1.0" dependencies = [ "bp-darwinia-core", - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-messages", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-runtime 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -651,8 +651,8 @@ name = "bp-darwinia" version = "0.1.0" dependencies = [ "bp-darwinia-core", - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-messages", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-runtime 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -664,8 +664,8 @@ dependencies = [ name = "bp-darwinia-core" version = "0.1.0" dependencies = [ - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-messages", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "parity-scale-codec", @@ -696,9 +696,9 @@ dependencies = [ name = "bp-kusama" version = "0.1.0" dependencies = [ - "bp-messages 0.1.0", + "bp-messages", "bp-polkadot-core", - "bp-runtime 0.1.0", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "smallvec", "sp-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -711,19 +711,7 @@ dependencies = [ name = "bp-message-dispatch" version = "0.1.0" dependencies = [ - "bp-runtime 0.1.0", - "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "parity-scale-codec", - "scale-info", - "sp-std 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", -] - -[[package]] -name = "bp-message-dispatch" -version = "0.1.0" -source = "git+https://github.com/darwinia-network/darwinia-bridges-substrate?branch=darwinia-v0.12.2#8661e19b7926a22788ccfcd06af967c1dc55e459" -dependencies = [ - "bp-runtime 0.1.0 (git+https://github.com/darwinia-network/darwinia-bridges-substrate?branch=darwinia-v0.12.2)", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "parity-scale-codec", "scale-info", @@ -735,7 +723,7 @@ name = "bp-messages" version = "0.1.0" dependencies = [ "bitvec", - "bp-runtime 0.1.0", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "hex", @@ -748,29 +736,12 @@ dependencies = [ "sp-std 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", ] -[[package]] -name = "bp-messages" -version = "0.1.0" -source = "git+https://github.com/darwinia-network/darwinia-bridges-substrate?branch=darwinia-v0.12.2#8661e19b7926a22788ccfcd06af967c1dc55e459" -dependencies = [ - "bitvec", - "bp-runtime 0.1.0 (git+https://github.com/darwinia-network/darwinia-bridges-substrate?branch=darwinia-v0.12.2)", - "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "impl-trait-for-tuples", - "parity-scale-codec", - "scale-info", - "serde", - "sp-core 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "sp-std 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", -] - [[package]] name = "bp-millau" version = "0.1.0" dependencies = [ - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-messages", + "bp-runtime", "fixed-hash", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -793,8 +764,8 @@ name = "bp-pangolin" version = "0.1.0" dependencies = [ "bp-darwinia-core", - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-messages", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-runtime 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -807,8 +778,8 @@ name = "bp-pangolin-parachain" version = "0.1.0" dependencies = [ "bp-darwinia-core", - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-messages", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-runtime 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -821,8 +792,8 @@ name = "bp-pangoro" version = "0.1.0" dependencies = [ "bp-darwinia-core", - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-messages", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-runtime 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -835,7 +806,7 @@ name = "bp-parachains" version = "0.1.0" dependencies = [ "bp-polkadot-core", - "bp-runtime 0.1.0", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "parity-scale-codec", "scale-info", @@ -847,9 +818,9 @@ dependencies = [ name = "bp-polkadot" version = "0.1.0" dependencies = [ - "bp-messages 0.1.0", + "bp-messages", "bp-polkadot-core", - "bp-runtime 0.1.0", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "smallvec", "sp-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -862,8 +833,8 @@ dependencies = [ name = "bp-polkadot-core" version = "0.1.0" dependencies = [ - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-messages", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "hex", @@ -882,8 +853,8 @@ dependencies = [ name = "bp-rialto" version = "0.1.0" dependencies = [ - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-messages", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -896,8 +867,8 @@ dependencies = [ name = "bp-rialto-parachain" version = "0.1.0" dependencies = [ - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-messages", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -910,9 +881,9 @@ dependencies = [ name = "bp-rococo" version = "0.1.0" dependencies = [ - "bp-messages 0.1.0", + "bp-messages", "bp-polkadot-core", - "bp-runtime 0.1.0", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "parity-scale-codec", "smallvec", @@ -940,24 +911,6 @@ dependencies = [ "sp-trie 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", ] -[[package]] -name = "bp-runtime" -version = "0.1.0" -source = "git+https://github.com/darwinia-network/darwinia-bridges-substrate?branch=darwinia-v0.12.2#8661e19b7926a22788ccfcd06af967c1dc55e459" -dependencies = [ - "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "hash-db", - "num-traits", - "parity-scale-codec", - "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "sp-io 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "sp-runtime 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "sp-state-machine 0.10.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "sp-std 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "sp-trie 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", -] - [[package]] name = "bp-test-utils" version = "0.1.0" @@ -976,7 +929,7 @@ dependencies = [ name = "bp-token-swap" version = "0.1.0" dependencies = [ - "bp-runtime 0.1.0", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "hex", "hex-literal", @@ -993,7 +946,7 @@ version = "0.1.0" dependencies = [ "bp-header-chain", "bp-polkadot-core", - "bp-runtime 0.1.0", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "parity-scale-codec", "scale-info", @@ -1008,10 +961,10 @@ dependencies = [ name = "bp-wococo" version = "0.1.0" dependencies = [ - "bp-messages 0.1.0", + "bp-messages", "bp-polkadot-core", "bp-rococo", - "bp-runtime 0.1.0", + "bp-runtime", "parity-scale-codec", "sp-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "sp-runtime 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -1022,16 +975,16 @@ dependencies = [ name = "bridge-runtime-common" version = "0.1.0" dependencies = [ - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", + "bp-message-dispatch", + "bp-messages", "bp-polkadot-core", - "bp-runtime 0.1.0", + "bp-runtime", "ed25519-dalek", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "hash-db", "pallet-bridge-dispatch", "pallet-bridge-grandpa", - "pallet-bridge-messages 0.1.0", + "pallet-bridge-messages", "pallet-bridge-parachains", "pallet-transaction-payment 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "parity-scale-codec", @@ -4638,8 +4591,8 @@ version = "0.1.0" dependencies = [ "async-std", "async-trait", - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-messages", + "bp-runtime", "futures 0.3.18", "hex", "log", @@ -4655,10 +4608,10 @@ version = "0.1.0" dependencies = [ "beefy-primitives 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "bp-header-chain", - "bp-messages 0.1.0", + "bp-messages", "bp-millau", "bp-rialto", - "bp-runtime 0.1.0", + "bp-runtime", "bp-westend", "bridge-runtime-common", "frame-benchmarking 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -4673,7 +4626,7 @@ dependencies = [ "pallet-beefy-mmr 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", "pallet-bridge-grandpa", - "pallet-bridge-messages 0.1.0", + "pallet-bridge-messages", "pallet-bridge-parachains", "pallet-bridge-token-swap", "pallet-grandpa 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -5412,8 +5365,8 @@ dependencies = [ name = "pallet-bridge-dispatch" version = "0.1.0" dependencies = [ - "bp-message-dispatch 0.1.0", - "bp-runtime 0.1.0", + "bp-message-dispatch", + "bp-runtime", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "log", @@ -5430,7 +5383,7 @@ name = "pallet-bridge-grandpa" version = "0.1.0" dependencies = [ "bp-header-chain", - "bp-runtime 0.1.0", + "bp-runtime", "bp-test-utils", "finality-grandpa", "frame-benchmarking 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -5454,9 +5407,9 @@ name = "pallet-bridge-messages" version = "0.1.0" dependencies = [ "bitvec", - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-message-dispatch", + "bp-messages", + "bp-runtime", "frame-benchmarking 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -5472,27 +5425,6 @@ dependencies = [ "sp-std 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", ] -[[package]] -name = "pallet-bridge-messages" -version = "0.1.0" -source = "git+https://github.com/darwinia-network/darwinia-bridges-substrate?branch=darwinia-v0.12.2#8661e19b7926a22788ccfcd06af967c1dc55e459" -dependencies = [ - "bitvec", - "bp-message-dispatch 0.1.0 (git+https://github.com/darwinia-network/darwinia-bridges-substrate?branch=darwinia-v0.12.2)", - "bp-messages 0.1.0 (git+https://github.com/darwinia-network/darwinia-bridges-substrate?branch=darwinia-v0.12.2)", - "bp-runtime 0.1.0 (git+https://github.com/darwinia-network/darwinia-bridges-substrate?branch=darwinia-v0.12.2)", - "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "log", - "num-traits", - "parity-scale-codec", - "scale-info", - "serde", - "sp-core 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "sp-runtime 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "sp-std 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", -] - [[package]] name = "pallet-bridge-parachains" version = "0.1.0" @@ -5500,7 +5432,7 @@ dependencies = [ "bp-header-chain", "bp-parachains", "bp-polkadot-core", - "bp-runtime 0.1.0", + "bp-runtime", "bp-test-utils", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -5520,9 +5452,9 @@ dependencies = [ name = "pallet-bridge-token-swap" version = "0.1.0" dependencies = [ - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-message-dispatch", + "bp-messages", + "bp-runtime", "bp-token-swap", "frame-benchmarking 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -5530,7 +5462,7 @@ dependencies = [ "log", "pallet-balances 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", - "pallet-bridge-messages 0.1.0", + "pallet-bridge-messages", "parity-scale-codec", "scale-info", "serde", @@ -5615,13 +5547,13 @@ name = "pallet-fee-market" version = "0.1.0" dependencies = [ "bitvec", - "bp-messages 0.1.0 (git+https://github.com/darwinia-network/darwinia-bridges-substrate?branch=darwinia-v0.12.2)", - "bp-runtime 0.1.0 (git+https://github.com/darwinia-network/darwinia-bridges-substrate?branch=darwinia-v0.12.2)", + "bp-messages", + "bp-runtime", "frame-benchmarking 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-balances 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "pallet-bridge-messages 0.1.0 (git+https://github.com/darwinia-network/darwinia-bridges-substrate?branch=darwinia-v0.12.2)", + "pallet-bridge-messages", "pallet-timestamp 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "parity-scale-codec", "scale-info", @@ -7255,9 +7187,9 @@ dependencies = [ "bp-darwinia-core", "bp-header-chain", "bp-kusama", - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-message-dispatch", + "bp-messages", + "bp-runtime", "bridge-runtime-common", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", @@ -7277,9 +7209,9 @@ dependencies = [ "bp-crab-parachain", "bp-darwinia-core", "bp-header-chain", - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-message-dispatch", + "bp-messages", + "bp-runtime", "bridge-runtime-common", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", @@ -7300,9 +7232,9 @@ dependencies = [ "bp-darwinia-core", "bp-header-chain", "bp-kusama", - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-message-dispatch", + "bp-messages", + "bp-runtime", "bridge-runtime-common", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", @@ -7320,11 +7252,11 @@ version = "0.1.0" dependencies = [ "bp-header-chain", "bp-kusama", - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", + "bp-message-dispatch", + "bp-messages", "bp-polkadot", "bp-polkadot-core", - "bp-runtime 0.1.0", + "bp-runtime", "bridge-runtime-common", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", @@ -7340,7 +7272,7 @@ dependencies = [ name = "relay-millau-client" version = "0.1.0" dependencies = [ - "bp-messages 0.1.0", + "bp-messages", "bp-millau", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -7359,13 +7291,13 @@ version = "0.1.0" dependencies = [ "bp-darwinia-core", "bp-header-chain", - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", + "bp-message-dispatch", + "bp-messages", "bp-pangolin", "bp-pangolin-parachain", "bp-pangoro", "bp-rococo", - "bp-runtime 0.1.0", + "bp-runtime", "bridge-runtime-common", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", @@ -7383,12 +7315,12 @@ version = "0.1.0" dependencies = [ "bp-darwinia-core", "bp-header-chain", - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", + "bp-message-dispatch", + "bp-messages", "bp-pangolin", "bp-pangolin-parachain", "bp-rococo", - "bp-runtime 0.1.0", + "bp-runtime", "bridge-runtime-common", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", @@ -7406,11 +7338,11 @@ version = "0.1.0" dependencies = [ "bp-darwinia-core", "bp-header-chain", - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", + "bp-message-dispatch", + "bp-messages", "bp-pangolin", "bp-pangoro", - "bp-runtime 0.1.0", + "bp-runtime", "bridge-runtime-common", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", @@ -7428,11 +7360,11 @@ version = "0.1.0" dependencies = [ "bp-header-chain", "bp-kusama", - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", + "bp-message-dispatch", + "bp-messages", "bp-polkadot", "bp-polkadot-core", - "bp-runtime 0.1.0", + "bp-runtime", "bridge-runtime-common", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", @@ -7448,7 +7380,7 @@ dependencies = [ name = "relay-rialto-client" version = "0.1.0" dependencies = [ - "bp-messages 0.1.0", + "bp-messages", "bp-rialto", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -7479,16 +7411,16 @@ name = "relay-rococo-client" version = "0.1.0" dependencies = [ "bp-header-chain", - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", + "bp-message-dispatch", + "bp-messages", "bp-polkadot-core", "bp-rococo", - "bp-runtime 0.1.0", + "bp-runtime", "bp-wococo", "bridge-runtime-common", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", - "pallet-bridge-messages 0.1.0", + "pallet-bridge-messages", "parity-scale-codec", "relay-substrate-client", "relay-utils", @@ -7504,8 +7436,8 @@ dependencies = [ "async-std", "async-trait", "bp-header-chain", - "bp-messages 0.1.0", - "bp-runtime 0.1.0", + "bp-messages", + "bp-runtime", "finality-relay", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-system 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -7514,7 +7446,7 @@ dependencies = [ "log", "num-traits", "pallet-balances 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "pallet-bridge-messages 0.1.0", + "pallet-bridge-messages", "pallet-transaction-payment 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-transaction-payment-rpc-runtime-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "parity-scale-codec", @@ -7544,7 +7476,7 @@ dependencies = [ "async-std", "async-trait", "backoff", - "bp-runtime 0.1.0", + "bp-runtime", "env_logger 0.8.4", "futures 0.3.18", "isahc", @@ -7576,16 +7508,16 @@ name = "relay-wococo-client" version = "0.1.0" dependencies = [ "bp-header-chain", - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", + "bp-message-dispatch", + "bp-messages", "bp-polkadot-core", "bp-rococo", - "bp-runtime 0.1.0", + "bp-runtime", "bp-wococo", "bridge-runtime-common", "frame-support 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", - "pallet-bridge-messages 0.1.0", + "pallet-bridge-messages", "parity-scale-codec", "relay-substrate-client", "relay-utils", @@ -7676,11 +7608,11 @@ version = "0.1.0" dependencies = [ "beefy-primitives 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "bp-header-chain", - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", + "bp-message-dispatch", + "bp-messages", "bp-millau", "bp-rialto", - "bp-runtime 0.1.0", + "bp-runtime", "bridge-runtime-common", "frame-benchmarking 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "frame-executive 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -7697,7 +7629,7 @@ dependencies = [ "pallet-beefy-mmr 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", "pallet-bridge-grandpa", - "pallet-bridge-messages 0.1.0", + "pallet-bridge-messages", "pallet-grandpa 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-mmr 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-mmr-primitives 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", @@ -10786,15 +10718,15 @@ dependencies = [ "async-std", "bp-header-chain", "bp-kusama", - "bp-message-dispatch 0.1.0", - "bp-messages 0.1.0", + "bp-message-dispatch", + "bp-messages", "bp-millau", "bp-polkadot", "bp-polkadot-core", "bp-rialto", "bp-rialto-parachain", "bp-rococo", - "bp-runtime 0.1.0", + "bp-runtime", "bp-token-swap", "bp-westend", "bp-wococo", @@ -10813,7 +10745,7 @@ dependencies = [ "pallet-balances 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", "pallet-bridge-dispatch", "pallet-bridge-grandpa", - "pallet-bridge-messages 0.1.0", + "pallet-bridge-messages", "pallet-bridge-token-swap", "parachains-relay", "parity-scale-codec", @@ -10854,13 +10786,13 @@ dependencies = [ "async-std", "async-trait", "bp-header-chain", - "bp-messages 0.1.0", + "bp-messages", "bp-millau", "bp-parachains", "bp-polkadot-core", "bp-rialto", "bp-rococo", - "bp-runtime 0.1.0", + "bp-runtime", "bp-wococo", "bridge-runtime-common", "finality-grandpa", @@ -10871,7 +10803,7 @@ dependencies = [ "messages-relay", "num-traits", "pallet-bridge-grandpa", - "pallet-bridge-messages 0.1.0", + "pallet-bridge-messages", "pallet-bridge-parachains", "parachains-relay", "parity-scale-codec", diff --git a/modules/dispatch/src/lib.rs b/modules/dispatch/src/lib.rs index 1e8d9dcd2..e80cc0a97 100644 --- a/modules/dispatch/src/lib.rs +++ b/modules/dispatch/src/lib.rs @@ -36,10 +36,13 @@ use frame_support::{ dispatch::Dispatchable, ensure, traits::{Contains, Get}, - weights::{extract_actual_weight, GetDispatchInfo}, + weights::{extract_actual_weight, GetDispatchInfo, PostDispatchInfo}, }; use frame_system::RawOrigin; -use sp_runtime::traits::{BadOrigin, Convert, IdentifyAccount, MaybeDisplay, Verify}; +use sp_runtime::{ + traits::{BadOrigin, Convert, IdentifyAccount, MaybeDisplay, Verify}, + transaction_validity::TransactionValidityError, +}; use sp_std::{fmt::Debug, prelude::*}; pub use pallet::*; @@ -47,7 +50,7 @@ pub use pallet::*; #[frame_support::pallet] pub mod pallet { use super::*; - use frame_support::{pallet_prelude::*, traits::EnsureOrigin}; + use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; #[pallet::config] @@ -94,10 +97,14 @@ pub mod pallet { /// /// Used when deriving target chain AccountIds from source chain AccountIds. type AccountIdConverter: sp_runtime::traits::Convert; - // TODO: add docs - // type EthereumCallOrigin: EnsureOrigin; - // TODO: update the trait - type EthereumTransactValidator: EthereumTransactCall<>::Call>; + /// A dispatcher used to handle Ethereum class call. + /// + /// The Ethereum call's origin is defined standalone in the `pallet-ethereum` and the call + /// validation rules is different from normal substrate pallet call. + type EthereumCallDispatcher: EthereumCallDispatch< + >::Call, + Self::AccountId, + >; } type BridgeMessageIdOf = >::BridgeMessageId; @@ -138,6 +145,9 @@ pub mod pallet { ), /// Message has been dispatched with given result. MessageDispatched(ChainId, BridgeMessageIdOf, DispatchResult), + EthereumCallDispatched(ChainId, BridgeMessageIdOf, DispatchResult), + // TODO: Give TransactionValidityError TypeInfo derive + // EthereumCallValidateError(ChainId, BridgeMessageIdOf, TransactionValidityError), /// Phantom member, never used. Needed to handle multiple pallet instances. _Dummy(PhantomData), } @@ -278,13 +288,6 @@ impl, I: 'static> MessageDispatch return dispatch_result } - // If the call is Ethereum Transact dispatch call - if let Some(dispatch_info) = T::EthereumTransactValidator::dispatch(&call) { - // TODO: add event - - return dispatch_result; - } - // verify weight // (we want passed weight to be at least equal to pre-dispatch weight of the call // because otherwise Calls may be dispatched at lower price) @@ -308,6 +311,39 @@ impl, I: 'static> MessageDispatch return dispatch_result } + // Dispatch Ethereum call earlier before pay + match T::EthereumCallDispatcher::dispatch(&call, &origin_account) { + Ok(Some(result)) => { + Self::deposit_event(Event::MessageDispatched( + source_chain, + id, + result.map(drop).map_err(|e| e.error), + )); + return dispatch_result + }, + Ok(None) => { + log::trace!( + target: "runtime::bridge-dispatch", + "It's a non-Ethereum call", + ); + }, + Err(err) => { + log::trace!( + target: "runtime::bridge-dispatch", + "Message {:?}/{:?} ethereum call validation failed before dispatch validation failed {:?}", + source_chain, + id, + err, + ); + // Self::deposit_event(Event::EthereumCallValidateError( + // source_chain, + // id, + // result.map(drop).map_err(|e| e.error), + // )); + return dispatch_result + }, + } + // pay dispatch fee right before dispatch let pay_dispatch_fee_at_target_chain = message.dispatch_fee_payment == DispatchFeePayment::AtTargetChain; @@ -431,11 +467,17 @@ where proof } -use frame_support::weights::PostDispatchInfo; -pub trait EthereumTransactCall { - fn is_ethereum_call(t: &T) -> bool; - fn validate(t: &T) -> bool; - fn dispatch(t: &T) -> Option>; +/// The trait is designed for validating and dispatching Ethereum class calls. Return None +/// if the call isn't an Ethereum class call. Return Ok(dispatch_result) or validation error if +/// dispatched. +pub trait EthereumCallDispatch { + fn dispatch( + c: &Call, + origin: &AccountId, + ) -> Result< + Option>, + TransactionValidityError, + >; } #[cfg(test)] diff --git a/relays/client-crab-parachain/src/lib.rs b/relays/client-crab-parachain/src/lib.rs index a43e9cec5..38cd1f291 100644 --- a/relays/client-crab-parachain/src/lib.rs +++ b/relays/client-crab-parachain/src/lib.rs @@ -14,8 +14,7 @@ use relay_substrate_client::{ pub mod runtime; /// CrabParachain header id. -pub type HeaderId = - relay_utils::HeaderId; +pub type HeaderId = relay_utils::HeaderId; /// CrabParachain chain definition. #[derive(Debug, Clone, Copy)] @@ -49,8 +48,7 @@ impl Chain for CrabParachainChain { const AVERAGE_BLOCK_INTERVAL: Duration = Duration::from_millis(bp_crab_parachain::MILLISECS_PER_BLOCK); const STORAGE_PROOF_OVERHEAD: u32 = bp_crab_parachain::EXTRA_STORAGE_PROOF_SIZE; - const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = - bp_crab_parachain::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE; + const MAXIMAL_ENCODED_ACCOUNT_ID_SIZE: u32 = bp_crab_parachain::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE; type SignedBlock = bp_crab_parachain::SignedBlock; type Call = crate::runtime::Call; diff --git a/relays/client-crab-parachain/src/runtime.rs b/relays/client-crab-parachain/src/runtime.rs index 9d35a765e..dec81e23e 100644 --- a/relays/client-crab-parachain/src/runtime.rs +++ b/relays/client-crab-parachain/src/runtime.rs @@ -3,9 +3,9 @@ use frame_support::weights::Weight; use scale_info::TypeInfo; use sp_runtime::FixedU128; +use bp_crab_parachain::Balance; use bp_darwinia_core::DarwiniaLike; use bp_messages::{LaneId, UnrewardedRelayersState}; -use bp_crab_parachain::Balance; use bp_runtime::Chain; /// Unchecked crab extrinsic. @@ -111,10 +111,7 @@ impl sp_runtime::traits::Dispatchable for Call { #[allow(non_camel_case_types)] pub enum FeemarketCall { #[codec(index = 0)] - enroll_and_lock_collateral( - bp_crab_parachain::Balance, - Option, - ), + enroll_and_lock_collateral(bp_crab_parachain::Balance, Option), #[codec(index = 1)] update_locked_collateral(bp_crab_parachain::Balance), #[codec(index = 2)] From 8963ce01d74811f8e98fd71fbeecbcb050b72f16 Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 2 Jun 2022 17:36:42 +0800 Subject: [PATCH 04/10] Add empty implementation --- modules/dispatch/src/lib.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/modules/dispatch/src/lib.rs b/modules/dispatch/src/lib.rs index e80cc0a97..919d9a842 100644 --- a/modules/dispatch/src/lib.rs +++ b/modules/dispatch/src/lib.rs @@ -102,8 +102,8 @@ pub mod pallet { /// The Ethereum call's origin is defined standalone in the `pallet-ethereum` and the call /// validation rules is different from normal substrate pallet call. type EthereumCallDispatcher: EthereumCallDispatch< - >::Call, - Self::AccountId, + Call = >::Call, + AccountId = Self::AccountId, >; } @@ -470,16 +470,34 @@ where /// The trait is designed for validating and dispatching Ethereum class calls. Return None /// if the call isn't an Ethereum class call. Return Ok(dispatch_result) or validation error if /// dispatched. -pub trait EthereumCallDispatch { +pub trait EthereumCallDispatch { + type Call; + type AccountId; + fn dispatch( - c: &Call, - origin: &AccountId, + c: &Self::Call, + origin: &Self::AccountId, ) -> Result< Option>, TransactionValidityError, >; } +impl EthereumCallDispatch for () { + type Call = (); + type AccountId = (); + + fn dispatch( + _c: &Self::Call, + _origin: &Self::AccountId, + ) -> Result< + Option>, + TransactionValidityError, + > { + Ok(None) + } +} + #[cfg(test)] mod tests { // From construct_runtime macro From c8b5e1548fc13304665236f011f33ce61df01539 Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 2 Jun 2022 17:52:14 +0800 Subject: [PATCH 05/10] Code clean --- modules/dispatch/src/lib.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/modules/dispatch/src/lib.rs b/modules/dispatch/src/lib.rs index 919d9a842..8ee6d1371 100644 --- a/modules/dispatch/src/lib.rs +++ b/modules/dispatch/src/lib.rs @@ -483,21 +483,6 @@ pub trait EthereumCallDispatch { >; } -impl EthereumCallDispatch for () { - type Call = (); - type AccountId = (); - - fn dispatch( - _c: &Self::Call, - _origin: &Self::AccountId, - ) -> Result< - Option>, - TransactionValidityError, - > { - Ok(None) - } -} - #[cfg(test)] mod tests { // From construct_runtime macro From 4f8b71104f0ee3afcc74ec3e33fe7b133ae708b7 Mon Sep 17 00:00:00 2001 From: bear Date: Mon, 6 Jun 2022 13:46:23 +0800 Subject: [PATCH 06/10] Handle error properly --- modules/dispatch/src/lib.rs | 42 +++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/modules/dispatch/src/lib.rs b/modules/dispatch/src/lib.rs index 8ee6d1371..244e3052c 100644 --- a/modules/dispatch/src/lib.rs +++ b/modules/dispatch/src/lib.rs @@ -31,7 +31,7 @@ use bp_runtime::{ messages::{DispatchFeePayment, MessageDispatchResult}, ChainId, SourceAccount, }; -use codec::Encode; +use codec::{Decode, Encode}; use frame_support::{ dispatch::Dispatchable, ensure, @@ -39,9 +39,10 @@ use frame_support::{ weights::{extract_actual_weight, GetDispatchInfo, PostDispatchInfo}, }; use frame_system::RawOrigin; +use scale_info::TypeInfo; use sp_runtime::{ traits::{BadOrigin, Convert, IdentifyAccount, MaybeDisplay, Verify}, - transaction_validity::TransactionValidityError, + transaction_validity::{InvalidTransaction, TransactionValidityError}, }; use sp_std::{fmt::Debug, prelude::*}; @@ -146,8 +147,9 @@ pub mod pallet { /// Message has been dispatched with given result. MessageDispatched(ChainId, BridgeMessageIdOf, DispatchResult), EthereumCallDispatched(ChainId, BridgeMessageIdOf, DispatchResult), - // TODO: Give TransactionValidityError TypeInfo derive - // EthereumCallValidateError(ChainId, BridgeMessageIdOf, TransactionValidityError), + EthereumCallValidityError(ChainId, BridgeMessageIdOf, EthereumCallValidityError), + // TODO: https://github.com/paritytech/substrate/pull/11599 + // EthereumCallValidityError(ChainId, BridgeMessageIdOf, TransactionValidityError), /// Phantom member, never used. Needed to handle multiple pallet instances. _Dummy(PhantomData), } @@ -335,11 +337,7 @@ impl, I: 'static> MessageDispatch id, err, ); - // Self::deposit_event(Event::EthereumCallValidateError( - // source_chain, - // id, - // result.map(drop).map_err(|e| e.error), - // )); + Self::deposit_event(Event::EthereumCallValidityError(source_chain, id, err.into())); return dispatch_result }, } @@ -483,6 +481,32 @@ pub trait EthereumCallDispatch { >; } +#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo)] +pub enum EthereumCallValidityError { + InvalidChainId, + InvalidGasLimit, + InvalidNonce, + InvalidPayment, + UnknownError, +} + +impl From for EthereumCallValidityError { + fn from(validate_err: TransactionValidityError) -> Self { + match validate_err { + TransactionValidityError::Invalid(InvalidTransaction::Future) | + TransactionValidityError::Invalid(InvalidTransaction::Stale) => + EthereumCallValidityError::InvalidNonce, + TransactionValidityError::Invalid(InvalidTransaction::Custom(3)) => + EthereumCallValidityError::InvalidGasLimit, + TransactionValidityError::Invalid(InvalidTransaction::Custom(1)) => + EthereumCallValidityError::InvalidChainId, + TransactionValidityError::Invalid(InvalidTransaction::Payment) => + EthereumCallValidityError::InvalidPayment, + _ => EthereumCallValidityError::UnknownError, + } + } +} + #[cfg(test)] mod tests { // From construct_runtime macro From e0f3eb4e23cefe1375ece80e2928b20d765a235e Mon Sep 17 00:00:00 2001 From: bear Date: Mon, 6 Jun 2022 14:08:28 +0800 Subject: [PATCH 07/10] Fix test --- modules/dispatch/src/lib.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/modules/dispatch/src/lib.rs b/modules/dispatch/src/lib.rs index 244e3052c..9d26632f1 100644 --- a/modules/dispatch/src/lib.rs +++ b/modules/dispatch/src/lib.rs @@ -513,6 +513,7 @@ mod tests { #![allow(clippy::from_over_into)] use super::*; + use crate as call_dispatch; use codec::Decode; use frame_support::{parameter_types, weights::Weight}; use frame_system::{EventRecord, Phase}; @@ -560,11 +561,26 @@ mod tests { } } + pub struct EthereumCallDispatcher; + + impl EthereumCallDispatch for EthereumCallDispatcher { + type AccountId = AccountId; + type Call = Call; + + fn dispatch( + _c: &Self::Call, + _origin: &Self::AccountId, + ) -> Result< + Option>, + TransactionValidityError, + > { + Ok(None) + } + } + type Block = frame_system::mocking::MockBlock; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; - use crate as call_dispatch; - frame_support::construct_runtime! { pub enum TestRuntime where Block = Block, @@ -619,6 +635,7 @@ mod tests { type CallFilter = TestCallFilter; type EncodedCall = EncodedCall; type AccountIdConverter = AccountIdConverter; + type EthereumCallDispatcher = EthereumCallDispatcher; } #[derive(Decode, Encode)] From eee8b13eed173ae0b0196d84e69abb9713ef686b Mon Sep 17 00:00:00 2001 From: bear Date: Tue, 7 Jun 2022 15:48:25 +0800 Subject: [PATCH 08/10] Fix dispatch result --- modules/dispatch/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/dispatch/src/lib.rs b/modules/dispatch/src/lib.rs index 9d26632f1..4661a42c4 100644 --- a/modules/dispatch/src/lib.rs +++ b/modules/dispatch/src/lib.rs @@ -321,6 +321,7 @@ impl, I: 'static> MessageDispatch id, result.map(drop).map_err(|e| e.error), )); + dispatch_result.dispatch_result = result.is_ok(); return dispatch_result }, Ok(None) => { From 530cae9fda17ecf9ade5c9d5865d466d21604494 Mon Sep 17 00:00:00 2001 From: bear Date: Wed, 8 Jun 2022 15:28:48 +0800 Subject: [PATCH 09/10] Use another approach --- modules/dispatch/src/lib.rs | 102 ------------------------------------ 1 file changed, 102 deletions(-) diff --git a/modules/dispatch/src/lib.rs b/modules/dispatch/src/lib.rs index 4661a42c4..dee2cb722 100644 --- a/modules/dispatch/src/lib.rs +++ b/modules/dispatch/src/lib.rs @@ -98,14 +98,6 @@ pub mod pallet { /// /// Used when deriving target chain AccountIds from source chain AccountIds. type AccountIdConverter: sp_runtime::traits::Convert; - /// A dispatcher used to handle Ethereum class call. - /// - /// The Ethereum call's origin is defined standalone in the `pallet-ethereum` and the call - /// validation rules is different from normal substrate pallet call. - type EthereumCallDispatcher: EthereumCallDispatch< - Call = >::Call, - AccountId = Self::AccountId, - >; } type BridgeMessageIdOf = >::BridgeMessageId; @@ -146,10 +138,6 @@ pub mod pallet { ), /// Message has been dispatched with given result. MessageDispatched(ChainId, BridgeMessageIdOf, DispatchResult), - EthereumCallDispatched(ChainId, BridgeMessageIdOf, DispatchResult), - EthereumCallValidityError(ChainId, BridgeMessageIdOf, EthereumCallValidityError), - // TODO: https://github.com/paritytech/substrate/pull/11599 - // EthereumCallValidityError(ChainId, BridgeMessageIdOf, TransactionValidityError), /// Phantom member, never used. Needed to handle multiple pallet instances. _Dummy(PhantomData), } @@ -313,36 +301,6 @@ impl, I: 'static> MessageDispatch return dispatch_result } - // Dispatch Ethereum call earlier before pay - match T::EthereumCallDispatcher::dispatch(&call, &origin_account) { - Ok(Some(result)) => { - Self::deposit_event(Event::MessageDispatched( - source_chain, - id, - result.map(drop).map_err(|e| e.error), - )); - dispatch_result.dispatch_result = result.is_ok(); - return dispatch_result - }, - Ok(None) => { - log::trace!( - target: "runtime::bridge-dispatch", - "It's a non-Ethereum call", - ); - }, - Err(err) => { - log::trace!( - target: "runtime::bridge-dispatch", - "Message {:?}/{:?} ethereum call validation failed before dispatch validation failed {:?}", - source_chain, - id, - err, - ); - Self::deposit_event(Event::EthereumCallValidityError(source_chain, id, err.into())); - return dispatch_result - }, - } - // pay dispatch fee right before dispatch let pay_dispatch_fee_at_target_chain = message.dispatch_fee_payment == DispatchFeePayment::AtTargetChain; @@ -466,48 +424,6 @@ where proof } -/// The trait is designed for validating and dispatching Ethereum class calls. Return None -/// if the call isn't an Ethereum class call. Return Ok(dispatch_result) or validation error if -/// dispatched. -pub trait EthereumCallDispatch { - type Call; - type AccountId; - - fn dispatch( - c: &Self::Call, - origin: &Self::AccountId, - ) -> Result< - Option>, - TransactionValidityError, - >; -} - -#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo)] -pub enum EthereumCallValidityError { - InvalidChainId, - InvalidGasLimit, - InvalidNonce, - InvalidPayment, - UnknownError, -} - -impl From for EthereumCallValidityError { - fn from(validate_err: TransactionValidityError) -> Self { - match validate_err { - TransactionValidityError::Invalid(InvalidTransaction::Future) | - TransactionValidityError::Invalid(InvalidTransaction::Stale) => - EthereumCallValidityError::InvalidNonce, - TransactionValidityError::Invalid(InvalidTransaction::Custom(3)) => - EthereumCallValidityError::InvalidGasLimit, - TransactionValidityError::Invalid(InvalidTransaction::Custom(1)) => - EthereumCallValidityError::InvalidChainId, - TransactionValidityError::Invalid(InvalidTransaction::Payment) => - EthereumCallValidityError::InvalidPayment, - _ => EthereumCallValidityError::UnknownError, - } - } -} - #[cfg(test)] mod tests { // From construct_runtime macro @@ -562,23 +478,6 @@ mod tests { } } - pub struct EthereumCallDispatcher; - - impl EthereumCallDispatch for EthereumCallDispatcher { - type AccountId = AccountId; - type Call = Call; - - fn dispatch( - _c: &Self::Call, - _origin: &Self::AccountId, - ) -> Result< - Option>, - TransactionValidityError, - > { - Ok(None) - } - } - type Block = frame_system::mocking::MockBlock; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; @@ -636,7 +535,6 @@ mod tests { type CallFilter = TestCallFilter; type EncodedCall = EncodedCall; type AccountIdConverter = AccountIdConverter; - type EthereumCallDispatcher = EthereumCallDispatcher; } #[derive(Decode, Encode)] From 34597c8fddb93649d2504f4e52aecec321bc69ea Mon Sep 17 00:00:00 2001 From: bear Date: Wed, 8 Jun 2022 16:52:48 +0800 Subject: [PATCH 10/10] Add `IntoDispatchOrigin` trait --- modules/dispatch/src/lib.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/dispatch/src/lib.rs b/modules/dispatch/src/lib.rs index dee2cb722..8d4b59ae1 100644 --- a/modules/dispatch/src/lib.rs +++ b/modules/dispatch/src/lib.rs @@ -98,6 +98,12 @@ pub mod pallet { /// /// Used when deriving target chain AccountIds from source chain AccountIds. type AccountIdConverter: sp_runtime::traits::Convert; + + type IntoDispatchOrigin: IntoDispatchOrigin< + Self::AccountId, + >::Call, + Self::Origin, + >; } type BridgeMessageIdOf = >::BridgeMessageId; @@ -325,7 +331,8 @@ impl, I: 'static> MessageDispatch dispatch_result.dispatch_fee_paid_during_dispatch = pay_dispatch_fee_at_target_chain; // finally dispatch message - let origin = RawOrigin::Signed(origin_account).into(); + // let origin = RawOrigin::Signed(origin_account).into(); + let origin = T::IntoDispatchOrigin::into_dispatch_origin(origin_account, call.clone()); log::trace!(target: "runtime::bridge-dispatch", "Message being dispatched is: {:.4096?}", &call); let result = call.dispatch(origin); @@ -424,6 +431,10 @@ where proof } +pub trait IntoDispatchOrigin { + fn into_dispatch_origin(id: AccountId, call: Call) -> Origin; +} + #[cfg(test)] mod tests { // From construct_runtime macro