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

Add contract creation allow lists to EVM domains #3350

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/pallet-domains/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ mod benchmarks {
bundle_slot_probability: (1, 1),
operator_allow_list: OperatorAllowList::Anyone,
initial_balances: Default::default(),
domain_runtime_config: Default::default(),
};

assert_ok!(Domains::<T>::set_permissioned_action_allowed_by(
Expand Down Expand Up @@ -910,6 +911,7 @@ mod benchmarks {
bundle_slot_probability: (1, 1),
operator_allow_list: OperatorAllowList::Anyone,
initial_balances: Default::default(),
domain_runtime_config: Default::default(),
};

assert_ok!(Domains::<T>::set_permissioned_action_allowed_by(
Expand Down
36 changes: 27 additions & 9 deletions crates/pallet-domains/src/domain_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use scale_info::TypeInfo;
use sp_core::Get;
use sp_domains::{
calculate_max_bundle_weight_and_size, derive_domain_block_hash, DomainBundleLimit, DomainId,
DomainSudoCall, DomainsDigestItem, DomainsTransfersTracker, OnDomainInstantiated,
OperatorAllowList, RuntimeId, RuntimeType,
DomainRuntimeConfig, DomainSudoCall, DomainsDigestItem, DomainsTransfersTracker,
OnDomainInstantiated, OperatorAllowList, RuntimeId, RuntimeType,
};
use sp_runtime::traits::{CheckedAdd, Zero};
use sp_runtime::DigestItem;
Expand Down Expand Up @@ -56,6 +56,7 @@ pub enum Error {
DuplicateInitialAccounts,
FailedToGenerateRawGenesis(crate::runtime_registry::Error),
BundleLimitCalculationOverflow,
InvalidConfigForRuntimeType,
}

#[derive(TypeInfo, Debug, Encode, Decode, Clone, PartialEq, Eq)]
Expand All @@ -71,10 +72,12 @@ pub struct DomainConfig<AccountId: Ord, Balance> {
/// The probability of successful bundle in a slot (active slots coefficient). This defines the
/// expected bundle production rate, must be `> 0` and `≤ 1`.
pub bundle_slot_probability: (u64, u64),
/// Allowed operators to operate for this domain.
/// Accounts allowed to operate on this domain.
pub operator_allow_list: OperatorAllowList<AccountId>,
// Initial balances for Domain.
// Initial balances for this domain.
pub initial_balances: Vec<(MultiAccountId, Balance)>,
/// Configurations for a specific type of domain runtime, for example, EVM.
pub domain_runtime_config: DomainRuntimeConfig,
}

/// Parameters of the `instantiate_domain` call, it is similar to `DomainConfig` except the `max_bundle_size/weight`
Expand All @@ -90,6 +93,7 @@ pub struct DomainConfigParams<AccountId: Ord, Balance> {
pub bundle_slot_probability: (u64, u64),
pub operator_allow_list: OperatorAllowList<AccountId>,
pub initial_balances: Vec<(MultiAccountId, Balance)>,
pub domain_runtime_config: DomainRuntimeConfig,
}

pub fn into_domain_config<T: Config>(
Expand All @@ -102,6 +106,7 @@ pub fn into_domain_config<T: Config>(
bundle_slot_probability,
operator_allow_list,
initial_balances,
domain_runtime_config,
} = domain_config_params;

let DomainBundleLimit {
Expand All @@ -126,6 +131,7 @@ pub fn into_domain_config<T: Config>(
bundle_slot_probability,
operator_allow_list,
initial_balances,
domain_runtime_config,
})
}

Expand Down Expand Up @@ -251,16 +257,26 @@ pub(crate) fn do_instantiate_domain<T: Config>(
runtime_object
});

let domain_runtime_info = match runtime_obj.runtime_type {
RuntimeType::Evm => {
let domain_runtime_info = match (
runtime_obj.runtime_type,
&domain_config.domain_runtime_config,
) {
(RuntimeType::Evm, DomainRuntimeConfig::Evm(domain_runtime_config)) => {
let evm_chain_id = NextEVMChainId::<T>::get();
let next_evm_chain_id = evm_chain_id.checked_add(1).ok_or(Error::MaxEVMChainId)?;
NextEVMChainId::<T>::set(next_evm_chain_id);
DomainRuntimeInfo::EVM {

DomainRuntimeInfo::Evm {
chain_id: evm_chain_id,
domain_runtime_config: domain_runtime_config.clone(),
}
}
(RuntimeType::AutoId, DomainRuntimeConfig::AutoId(domain_runtime_config)) => {
DomainRuntimeInfo::AutoId {
domain_runtime_config: domain_runtime_config.clone(),
}
}
RuntimeType::AutoId => DomainRuntimeInfo::AutoId,
_ => return Err(Error::InvalidConfigForRuntimeType),
};

// burn total issuance on domain from owners account and track the domain balance
Expand All @@ -285,7 +301,7 @@ pub(crate) fn do_instantiate_domain<T: Config>(
let raw_genesis = into_complete_raw_genesis::<T>(
runtime_obj,
domain_id,
domain_runtime_info,
&domain_runtime_info,
total_issuance,
domain_config.initial_balances.clone(),
)
Expand Down Expand Up @@ -398,6 +414,7 @@ mod tests {
bundle_slot_probability: (0, 0),
operator_allow_list: OperatorAllowList::Anyone,
initial_balances: Default::default(),
domain_runtime_config: Default::default(),
};

let mut ext = new_test_ext();
Expand Down Expand Up @@ -555,6 +572,7 @@ mod tests {
bundle_slot_probability: (1, 1),
operator_allow_list: OperatorAllowList::Anyone,
initial_balances: vec![(MultiAccountId::Raw(vec![0, 1, 2, 3, 4, 5]), 1_000_000 * SSC)],
domain_runtime_config: Default::default(),
};

let mut ext = new_test_ext();
Expand Down
10 changes: 6 additions & 4 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod tests;
pub mod block_tree;
mod bundle_storage_fund;
pub mod domain_registry;
pub mod migration_v2_to_v3;
pub mod runtime_registry;
mod staking;
mod staking_epoch;
Expand Down Expand Up @@ -161,7 +162,7 @@ pub type BlockTreeNodeFor<T> = crate::block_tree::BlockTreeNode<
>;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
Copy link
Member

Choose a reason for hiding this comment

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

Is this due to Taurus being on storage version 2 already ?

const STORAGE_VERSION: StorageVersion = StorageVersion::new(3);

/// The number of bundle of a particular domain to be included in the block is probabilistic
/// and based on the consensus chain slot probability and domain bundle slot probability, usually
Expand Down Expand Up @@ -1312,7 +1313,7 @@ mod pallet {
let block_number = frame_system::Pallet::<T>::current_block_number();
let runtime_id = do_register_runtime::<T>(
runtime_name,
runtime_type.clone(),
runtime_type,
raw_genesis_storage,
block_number,
)
Expand Down Expand Up @@ -1825,6 +1826,7 @@ mod pallet {
bundle_slot_probability: genesis_domain.bundle_slot_probability,
operator_allow_list: genesis_domain.operator_allow_list,
initial_balances: genesis_domain.initial_balances,
domain_runtime_config: genesis_domain.domain_runtime_config,
};
let domain_owner = genesis_domain.owner_account_id;
let domain_id = do_instantiate_domain::<T>(
Expand Down Expand Up @@ -2111,12 +2113,12 @@ impl<T: Config> Pallet<T> {
) -> Option<(DomainInstanceData, BlockNumberFor<T>)> {
let domain_obj = DomainRegistry::<T>::get(domain_id)?;
let runtime_object = RuntimeRegistry::<T>::get(domain_obj.domain_config.runtime_id)?;
let runtime_type = runtime_object.runtime_type.clone();
let runtime_type = runtime_object.runtime_type;
let total_issuance = domain_obj.domain_config.total_issuance()?;
let raw_genesis = into_complete_raw_genesis::<T>(
runtime_object,
domain_id,
domain_obj.domain_runtime_info,
&domain_obj.domain_runtime_info,
total_issuance,
domain_obj.domain_config.initial_balances,
)
Expand Down
Loading
Loading