From bf819de678db83b1748ff6e705ceac346daf0ca9 Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 10 Feb 2025 12:01:51 +1000 Subject: [PATCH 1/2] Hard-code EthereumAccountId type for allow list inherent --- domains/pallets/evm-tracker/src/lib.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/domains/pallets/evm-tracker/src/lib.rs b/domains/pallets/evm-tracker/src/lib.rs index 212d146769..1eecc71f3e 100644 --- a/domains/pallets/evm-tracker/src/lib.rs +++ b/domains/pallets/evm-tracker/src/lib.rs @@ -25,13 +25,14 @@ pub mod create_contract; pub mod traits; pub use check_nonce::CheckNonce; +use domain_runtime_primitives::EthereumAccountId; pub use pallet::*; use sp_core::U256; use sp_domains::PermissionedActionAllowedBy; #[frame_support::pallet] mod pallet { - use codec::Codec; + use domain_runtime_primitives::EthereumAccountId; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; use sp_core::U256; @@ -55,14 +56,18 @@ mod pallet { // When this type name is changed, evm_contract_creation_allowed_by_storage_key() also needs to // be updated. #[pallet::storage] - pub(super) type ContractCreationAllowedBy = - StorageValue<_, PermissionedActionAllowedBy, ValueQuery, DefaultToAnyone>; + pub(super) type ContractCreationAllowedBy = StorageValue< + _, + PermissionedActionAllowedBy, + ValueQuery, + DefaultToAnyone, + >; /// Default value for ContractCreationAllowedBy if it is not set. pub struct DefaultToAnyone; - impl Get> for DefaultToAnyone { - fn get() -> PermissionedActionAllowedBy { + impl Get> for DefaultToAnyone { + fn get() -> PermissionedActionAllowedBy { PermissionedActionAllowedBy::Anyone } } @@ -79,7 +84,7 @@ mod pallet { #[pallet::weight(::DbWeight::get().reads_writes(0, 1))] pub fn set_contract_creation_allowed_by( origin: OriginFor, - contract_creation_allowed_by: PermissionedActionAllowedBy, + contract_creation_allowed_by: PermissionedActionAllowedBy, ) -> DispatchResult { ensure_root(origin)?; ContractCreationAllowedBy::::put(contract_creation_allowed_by); @@ -109,7 +114,7 @@ impl Pallet { } /// Returns true if the supplied account is allowed to create contracts. - pub fn is_allowed_to_create_contracts(signer: &T::AccountId) -> bool { + pub fn is_allowed_to_create_contracts(signer: &EthereumAccountId) -> bool { ContractCreationAllowedBy::::get().is_allowed(signer) } @@ -120,7 +125,7 @@ impl Pallet { /// Returns the current contract creation allow list. /// Mainly used in tests. - pub fn contract_creation_allowed_by() -> PermissionedActionAllowedBy { + pub fn contract_creation_allowed_by() -> PermissionedActionAllowedBy { ContractCreationAllowedBy::::get() } } From cdff7ed39cb966fe1f3b36a0ff49e2cd9ab52a2f Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 10 Feb 2025 12:42:51 +1000 Subject: [PATCH 2/2] Add a create-contract-filter feature to pallet-evm-tracker --- domains/pallets/evm-tracker/Cargo.toml | 29 +++++++++++++------ .../evm-tracker/src/create_contract.rs | 2 +- domains/pallets/evm-tracker/src/lib.rs | 2 ++ domains/runtime/evm/Cargo.toml | 2 +- domains/test/runtime/evm/Cargo.toml | 2 +- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/domains/pallets/evm-tracker/Cargo.toml b/domains/pallets/evm-tracker/Cargo.toml index 365de7a8c6..40354a85dd 100644 --- a/domains/pallets/evm-tracker/Cargo.toml +++ b/domains/pallets/evm-tracker/Cargo.toml @@ -17,28 +17,39 @@ codec = { package = "parity-scale-codec", version = "3.6.12", default-features = domain-runtime-primitives = { version = "0.1.0", path = "../../primitives/runtime", default-features = false } frame-support = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" } frame-system = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" } -pallet-ethereum = { default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" } -pallet-evm = { version = "6.0.0-dev", default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" } -pallet-utility = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" } scale-info = { version = "2.11.2", default-features = false, features = ["derive"] } sp-core = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" } sp-domains = { version = "0.1.0", default-features = false, path = "../../../crates/sp-domains" } sp-runtime = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" } -subspace-runtime-primitives = { version = "0.1.0", path = "../../../crates/subspace-runtime-primitives", default-features = false } + +# optional contract creation filter dependencies +pallet-ethereum = { default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968", optional = true } +pallet-evm = { version = "6.0.0-dev", default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968", optional = true } +pallet-utility = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305", optional = true } +subspace-runtime-primitives = { version = "0.1.0", path = "../../../crates/subspace-runtime-primitives", default-features = false, optional = true } [features] -default = ["std"] +default = [ + "std", + "create-contract-filter", +] +create-contract-filter = [ + "pallet-ethereum", + "pallet-evm", + "pallet-utility", + "subspace-runtime-primitives", +] std = [ "codec/std", "domain-runtime-primitives/std", "frame-support/std", "frame-system/std", - "pallet-ethereum/std", - "pallet-evm/std", - "pallet-utility/std", + "pallet-ethereum?/std", + "pallet-evm?/std", + "pallet-utility?/std", "scale-info/std", "sp-core/std", "sp-domains/std", "sp-runtime/std", - "subspace-runtime-primitives/std", + "subspace-runtime-primitives?/std", ] diff --git a/domains/pallets/evm-tracker/src/create_contract.rs b/domains/pallets/evm-tracker/src/create_contract.rs index becbc67df0..daf05b0657 100644 --- a/domains/pallets/evm-tracker/src/create_contract.rs +++ b/domains/pallets/evm-tracker/src/create_contract.rs @@ -1,4 +1,4 @@ -//! Contract creation allow list implementations +//! Contract creation allow list filtering implementations. use crate::traits::{AccountIdFor, MaybeIntoEthCall, MaybeIntoEvmCall}; use codec::{Decode, Encode}; diff --git a/domains/pallets/evm-tracker/src/lib.rs b/domains/pallets/evm-tracker/src/lib.rs index 1eecc71f3e..251271b7e6 100644 --- a/domains/pallets/evm-tracker/src/lib.rs +++ b/domains/pallets/evm-tracker/src/lib.rs @@ -21,7 +21,9 @@ extern crate alloc; mod check_nonce; +#[cfg(feature = "create-contract-filter")] pub mod create_contract; +#[cfg(feature = "create-contract-filter")] pub mod traits; pub use check_nonce::CheckNonce; diff --git a/domains/runtime/evm/Cargo.toml b/domains/runtime/evm/Cargo.toml index db7c694d3c..89e7679652 100644 --- a/domains/runtime/evm/Cargo.toml +++ b/domains/runtime/evm/Cargo.toml @@ -36,7 +36,7 @@ pallet-domain-sudo = { version = "0.1.0", path = "../../pallets/domain-sudo", de pallet-ethereum = { default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" } pallet-evm = { version = "6.0.0-dev", default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" } pallet-evm-chain-id = { version = "1.0.0-dev", default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" } -pallet-evm-tracker = { version = "0.1.0", path = "../../pallets/evm-tracker", default-features = false } +pallet-evm-tracker = { version = "0.1.0", path = "../../pallets/evm-tracker", default-features = false, features = ["create-contract-filter"] } pallet-evm-precompile-modexp = { version = "2.0.0-dev", default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" } pallet-evm-precompile-sha3fips = { version = "2.0.0-dev", default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" } pallet-evm-precompile-simple = { version = "2.0.0-dev", default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" } diff --git a/domains/test/runtime/evm/Cargo.toml b/domains/test/runtime/evm/Cargo.toml index dd35612235..e09912be4c 100644 --- a/domains/test/runtime/evm/Cargo.toml +++ b/domains/test/runtime/evm/Cargo.toml @@ -35,7 +35,7 @@ pallet-domain-sudo = { version = "0.1.0", path = "../../../pallets/domain-sudo", pallet-ethereum = { default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" } pallet-evm = { version = "6.0.0-dev", default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" } pallet-evm-chain-id = { version = "1.0.0-dev", default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" } -pallet-evm-tracker = { version = "0.1.0", path = "../../../pallets/evm-tracker", default-features = false } +pallet-evm-tracker = { version = "0.1.0", path = "../../../pallets/evm-tracker", default-features = false, features = ["create-contract-filter"] } pallet-evm-precompile-modexp = { version = "2.0.0-dev", default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" } pallet-evm-precompile-sha3fips = { version = "2.0.0-dev", default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" } pallet-evm-precompile-simple = { version = "2.0.0-dev", default-features = false, git = "https://github.com/autonomys/frontier", rev = "f80f9e2bad338f3bf3854b256b3c4edea23e5968" }