Skip to content

Commit

Permalink
Improve UX for EVM contract creation owner call, change host fns, cha…
Browse files Browse the repository at this point in the history
…nge runtime API
  • Loading branch information
teor2345 committed Feb 12, 2025
1 parent 97cebce commit 603a276
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 108 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use alloc::collections::btree_map::BTreeMap;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use codec::{Decode, Encode};
use domain_runtime_primitives::EthereumAccountId;
use frame_support::ensure;
use frame_support::pallet_prelude::StorageVersion;
use frame_support::traits::fungible::{Inspect, InspectHold};
Expand Down Expand Up @@ -205,7 +206,7 @@ mod pallet {
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use codec::FullCodec;
use domain_runtime_primitives::EVMChainId;
use domain_runtime_primitives::{EVMChainId, EthereumAccountId};
use frame_support::pallet_prelude::*;
use frame_support::traits::fungible::{Inspect, InspectHold, Mutate, MutateHold};
use frame_support::traits::tokens::Preservation;
Expand Down Expand Up @@ -1785,8 +1786,9 @@ mod pallet {
pub fn send_evm_domain_set_contract_creation_allowed_by_call(
origin: OriginFor<T>,
domain_id: DomainId,
// TODO: contract_creation_allowed_by: sp_domains::PermissionedActionAllowedBy<EthereumAccountId>,
call: Vec<u8>,
contract_creation_allowed_by: sp_domains::PermissionedActionAllowedBy<
EthereumAccountId,
>,
) -> DispatchResult {
let maybe_owner = ensure_signed(origin)?;

Expand All @@ -1812,7 +1814,7 @@ mod pallet {
domain_runtime_call(
domain_runtime,
StatelessDomainRuntimeCall::IsValidEvmDomainContractCreationAllowedByCall(
call.clone()
contract_creation_allowed_by.clone()
),
)
.unwrap_or(false),
Expand All @@ -1822,7 +1824,7 @@ mod pallet {
EvmDomainContractCreationAllowedByCalls::<T>::set(
domain_id,
EvmDomainContractCreationAllowedByCall {
maybe_call: Some(call),
maybe_call: Some(contract_creation_allowed_by),
},
);

Expand Down Expand Up @@ -3156,7 +3158,9 @@ impl<T: Config> Pallet<T> {
}

/// Returns EVM domain's "set contract creation allowed by" call, if any.
pub fn evm_domain_contract_creation_allowed_by_call(domain_id: DomainId) -> Option<Vec<u8>> {
pub fn evm_domain_contract_creation_allowed_by_call(
domain_id: DomainId,
) -> Option<sp_domains::PermissionedActionAllowedBy<EthereumAccountId>> {
EvmDomainContractCreationAllowedByCalls::<T>::get(domain_id).maybe_call
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/sp-domains-fraud-proof/src/host_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ where
.ok()
}
StatelessDomainRuntimeCall::IsValidEvmDomainContractCreationAllowedByCall(
encoded_extrinsic,
decoded_argument,
) => domain_stateless_runtime
.is_valid_evm_contract_creation_allowed_by_call(encoded_extrinsic)
.is_valid_evm_contract_creation_allowed_by_call(decoded_argument)
.ok(),
}
}
Expand Down
8 changes: 5 additions & 3 deletions crates/sp-domains-fraud-proof/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::storage_proof::FraudProofStorageKeyRequest;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use codec::{Decode, Encode};
use domain_runtime_primitives::EthereumAccountId;
#[cfg(feature = "std")]
pub use host_functions::{
FraudProofExtension, FraudProofHostFunctions, FraudProofHostFunctionsImpl,
Expand All @@ -34,7 +35,7 @@ pub use runtime_interface::fraud_proof_runtime_interface;
pub use runtime_interface::fraud_proof_runtime_interface::HostFunctions;
use scale_info::TypeInfo;
use sp_core::H256;
use sp_domains::DomainAllowlistUpdates;
use sp_domains::{DomainAllowlistUpdates, PermissionedActionAllowedBy};
use sp_runtime::traits::{Header as HeaderT, NumberFor};
use sp_runtime::transaction_validity::{InvalidTransaction, TransactionValidity};
use sp_runtime::OpaqueExtrinsic;
Expand Down Expand Up @@ -102,7 +103,8 @@ pub struct DomainInherentExtrinsicData {
pub consensus_transaction_byte_fee: Balance,
pub domain_chain_allowlist: DomainAllowlistUpdates,
pub maybe_sudo_runtime_call: Option<Vec<u8>>,
pub maybe_evm_domain_contract_creation_allowed_by_call: Option<Vec<u8>>,
pub maybe_evm_domain_contract_creation_allowed_by_call:
Option<PermissionedActionAllowedBy<EthereumAccountId>>,
}

impl PassBy for DomainInherentExtrinsicData {
Expand Down Expand Up @@ -139,7 +141,7 @@ pub enum StatelessDomainRuntimeCall {
IsInherentExtrinsic(OpaqueExtrinsic),
IsDecodableExtrinsic(OpaqueExtrinsic),
IsValidDomainSudoCall(Vec<u8>),
IsValidEvmDomainContractCreationAllowedByCall(Vec<u8>),
IsValidEvmDomainContractCreationAllowedByCall(PermissionedActionAllowedBy<EthereumAccountId>),
}

impl PassBy for StatelessDomainRuntimeCall {
Expand Down
4 changes: 2 additions & 2 deletions crates/sp-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ impl DomainSudoCall {
/// there is an empty runtime call inside
#[derive(Default, Debug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)]
pub struct EvmDomainContractCreationAllowedByCall {
pub maybe_call: Option<Vec<u8>>,
pub maybe_call: Option<PermissionedActionAllowedBy<EthereumAccountId>>,
}

impl EvmDomainContractCreationAllowedByCall {
Expand Down Expand Up @@ -1684,7 +1684,7 @@ sp_api::decl_runtime_apis! {
fn domain_sudo_call(domain_id: DomainId) -> Option<Vec<u8>>;

/// Returns the "set contract creation allowed by" call for the given EVM domain, if any.
fn evm_domain_contract_creation_allowed_by_call(domain_id: DomainId) -> Option<Vec<u8>>;
fn evm_domain_contract_creation_allowed_by_call(domain_id: DomainId) -> Option<PermissionedActionAllowedBy<EthereumAccountId>>;

/// Returns the last confirmed domain block execution receipt.
fn last_confirmed_domain_block_receipt(domain_id: DomainId) ->Option<ExecutionReceiptFor<DomainHeader, Block, Balance>>;
Expand Down
8 changes: 5 additions & 3 deletions crates/subspace-fake-runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
//! Provides "fake" runtime API implementation as a workaround for compile-time checks.
use domain_runtime_primitives::opaque::Header as DomainHeader;
use domain_runtime_primitives::{BlockNumber as DomainNumber, Hash as DomainHash};
use domain_runtime_primitives::{
BlockNumber as DomainNumber, EthereumAccountId, Hash as DomainHash,
};
use frame_support::weights::Weight;
use sp_consensus_subspace::{ChainConstants, PotParameters, SignedVote, SolutionRanges};
use sp_core::crypto::KeyTypeId;
use sp_core::{OpaqueMetadata, H256};
use sp_domains::bundle_producer_election::BundleProducerElectionParams;
use sp_domains::{
DomainAllowlistUpdates, DomainId, DomainInstanceData, ExecutionReceiptFor, OperatorId,
OperatorPublicKey,
OperatorPublicKey, PermissionedActionAllowedBy,
};
use sp_domains_fraud_proof::fraud_proof::FraudProof;
use sp_domains_fraud_proof::storage_proof::FraudProofStorageKeyRequest;
Expand Down Expand Up @@ -278,7 +280,7 @@ sp_api::impl_runtime_apis! {
unreachable!()
}

fn evm_domain_contract_creation_allowed_by_call(_domain_id: DomainId) -> Option<Vec<u8>>{
fn evm_domain_contract_creation_allowed_by_call(_domain_id: DomainId) -> Option<PermissionedActionAllowedBy<EthereumAccountId>>{
unreachable!()
}

Expand Down
8 changes: 4 additions & 4 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use core::num::NonZeroU64;
use domain_runtime_primitives::opaque::Header as DomainHeader;
use domain_runtime_primitives::{
maximum_domain_block_weight, AccountIdConverter, BlockNumber as DomainNumber,
Hash as DomainHash, MAX_OUTGOING_MESSAGES,
EthereumAccountId, Hash as DomainHash, MAX_OUTGOING_MESSAGES,
};
use frame_support::genesis_builder_helper::{build_state, get_preset};
use frame_support::inherent::ProvideInherent;
Expand All @@ -61,8 +61,8 @@ use sp_core::{ConstBool, OpaqueMetadata, H256};
use sp_domains::bundle_producer_election::BundleProducerElectionParams;
use sp_domains::{
ChannelId, DomainAllowlistUpdates, DomainId, DomainInstanceData, ExecutionReceiptFor,
OperatorId, OperatorPublicKey, OperatorRewardSource, DOMAIN_STORAGE_FEE_MULTIPLIER,
INITIAL_DOMAIN_TX_RANGE,
OperatorId, OperatorPublicKey, OperatorRewardSource, PermissionedActionAllowedBy,
DOMAIN_STORAGE_FEE_MULTIPLIER, INITIAL_DOMAIN_TX_RANGE,
};
use sp_domains_fraud_proof::fraud_proof::FraudProof;
use sp_domains_fraud_proof::storage_proof::{
Expand Down Expand Up @@ -1367,7 +1367,7 @@ impl_runtime_apis! {
Domains::domain_sudo_call(domain_id)
}

fn evm_domain_contract_creation_allowed_by_call(domain_id: DomainId) -> Option<Vec<u8>> {
fn evm_domain_contract_creation_allowed_by_call(domain_id: DomainId) -> Option<PermissionedActionAllowedBy<EthereumAccountId>> {
Domains::evm_domain_contract_creation_allowed_by_call(domain_id)
}

Expand Down
12 changes: 7 additions & 5 deletions domains/client/block-preprocessor/src/stateless_runtime.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use codec::{Codec, Encode};
use domain_runtime_primitives::opaque::AccountId;
use domain_runtime_primitives::{Balance, CheckExtrinsicsValidityError, DecodeExtrinsicError};
use domain_runtime_primitives::{
Balance, CheckExtrinsicsValidityError, DecodeExtrinsicError, EthereumAccountId,
};
use sc_client_api::execution_extensions::ExtensionsFactory;
use sc_executor::RuntimeVersionOf;
use sp_api::{ApiError, Core};
use sp_core::traits::{CallContext, CodeExecutor, FetchRuntimeCode, RuntimeCode};
use sp_core::Hasher;
use sp_domain_sudo::DomainSudoApi;
use sp_domains::core_api::DomainCoreApi;
use sp_domains::{ChainId, ChannelId, DomainAllowlistUpdates};
use sp_domains::{ChainId, ChannelId, DomainAllowlistUpdates, PermissionedActionAllowedBy};
use sp_evm_tracker::EvmTrackerApi;
use sp_messenger::messages::MessageKey;
use sp_messenger::{MessengerApi, RelayerApi};
Expand Down Expand Up @@ -388,12 +390,12 @@ where

pub fn is_valid_evm_contract_creation_allowed_by_call(
&self,
extrinsic: Vec<u8>,
decoded_argument: PermissionedActionAllowedBy<EthereumAccountId>,
) -> Result<bool, ApiError> {
<Self as EvmTrackerApi<Block>>::is_valid_evm_contract_creation_allowed_by_call(
self,
Default::default(),
extrinsic,
decoded_argument,
)
}

Expand All @@ -410,7 +412,7 @@ where

pub fn construct_evm_contract_creation_allowed_by_extrinsic(
&self,
inner_call: Vec<u8>,
inner_call: PermissionedActionAllowedBy<EthereumAccountId>,
) -> Result<Block::Extrinsic, ApiError> {
<Self as EvmTrackerApi<Block>>::construct_evm_contract_creation_allowed_by_extrinsic(
self,
Expand Down
4 changes: 4 additions & 0 deletions domains/primitives/evm-tracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ include = [
[dependencies]
async-trait = { version = "0.1.83", optional = true }
codec = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = ["derive"] }
domain-runtime-primitives = { version = "0.1.0", default-features = false, path = "../runtime" }
sp-api = { 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-inherents = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" }

[features]
default = ["std"]
std = [
"async-trait",
"codec/std",
"domain-runtime-primitives/std",
"sp-api/std",
"sp-domains/std",
"sp-inherents/std",
]
19 changes: 8 additions & 11 deletions domains/primitives/evm-tracker/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
//! Inherents for EVM tracker
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "std"))]
extern crate alloc;

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use codec::{Decode, Encode};
use domain_runtime_primitives::EthereumAccountId;
use sp_domains::PermissionedActionAllowedBy;
#[cfg(feature = "std")]
use sp_inherents::{Error, InherentData};
use sp_inherents::{InherentIdentifier, IsFatalError};
Expand All @@ -32,7 +29,7 @@ impl IsFatalError for InherentError {
#[derive(Debug, Encode, Decode)]
pub struct InherentType {
/// EVM tracker "set contract creation allowed by" call
pub maybe_call: Option<Vec<u8>>,
pub maybe_call: Option<PermissionedActionAllowedBy<EthereumAccountId>>,
}

/// Provides the set code inherent data.
Expand All @@ -44,7 +41,7 @@ pub struct InherentDataProvider {
#[cfg(feature = "std")]
impl InherentDataProvider {
/// Create new inherent data provider from the given `data`.
pub fn new(maybe_call: Option<Vec<u8>>) -> Self {
pub fn new(maybe_call: Option<PermissionedActionAllowedBy<EthereumAccountId>>) -> Self {
Self {
data: InherentType { maybe_call },
}
Expand Down Expand Up @@ -80,16 +77,16 @@ impl sp_inherents::InherentDataProvider for InherentDataProvider {

/// Trait to convert Unchecked extrinsic into a Pallet-specific call
pub trait IntoEvmTrackerCall<Call> {
fn into_evm_tracker_call(call: Vec<u8>) -> Call;
fn into_evm_tracker_call(call: PermissionedActionAllowedBy<EthereumAccountId>) -> Call;
}

sp_api::decl_runtime_apis! {
/// Api to check and verify the evm-tracker extrinsic calls
pub trait EvmTrackerApi {
/// Returns true if evm-tracker exists in the runtime, and extrinsic is valid.
fn is_valid_evm_contract_creation_allowed_by_call(extrinsic: Vec<u8>) -> bool;
/// Returns true if evm-tracker exists in the runtime, and the decoded argument is valid.
fn is_valid_evm_contract_creation_allowed_by_call(decoded_argument: PermissionedActionAllowedBy<EthereumAccountId>) -> bool;

/// Returns an encoded extrinsic for domain "set contract creation allowed by" call.
fn construct_evm_contract_creation_allowed_by_extrinsic(extrinsic: Vec<u8>) -> Block::Extrinsic;
fn construct_evm_contract_creation_allowed_by_extrinsic(decoded_argument: PermissionedActionAllowedBy<EthereumAccountId>) -> Block::Extrinsic;
}
}
Loading

0 comments on commit 603a276

Please sign in to comment.