Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into update-substrate-foll…
Browse files Browse the repository at this point in the history
…ow-up

# Conflicts:
#	crates/subspace-node/src/chain_spec.rs
  • Loading branch information
nazar-pc committed Apr 15, 2024
2 parents b99087d + 8c1280c commit 61d10f4
Show file tree
Hide file tree
Showing 21 changed files with 607 additions and 161 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/pallet-domains/src/domain_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ pub(crate) fn do_instantiate_domain<T: Config>(
chain_id: evm_chain_id,
}
}
RuntimeType::AutoId => DomainRuntimeInfo::AutoId,
};

// burn total issuance on domain from owners account and track the domain balance
Expand Down
95 changes: 54 additions & 41 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ mod pallet {
#[cfg(not(feature = "std"))]
use alloc::string::String;
#[cfg(not(feature = "std"))]
use alloc::vec;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use codec::FullCodec;
use domain_runtime_primitives::EVMChainId;
Expand Down Expand Up @@ -219,7 +221,6 @@ mod pallet {
use sp_std::boxed::Box;
use sp_std::collections::btree_set::BTreeSet;
use sp_std::fmt::Debug;
use sp_std::vec;
use subspace_core_primitives::U256;
use subspace_runtime_primitives::StorageFee;

Expand Down Expand Up @@ -1399,16 +1400,16 @@ mod pallet {

#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub genesis_domain: Option<GenesisDomain<T::AccountId, BalanceOf<T>>>,
pub permissioned_action_allowed_by:
Option<sp_domains::PermissionedActionAllowedBy<T::AccountId>>,
pub genesis_domains: Vec<GenesisDomain<T::AccountId, BalanceOf<T>>>,
}

impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
GenesisConfig {
genesis_domain: None,
permissioned_action_allowed_by: None,
genesis_domains: vec![],
}
}
}
Expand All @@ -1421,46 +1422,58 @@ mod pallet {
{
PermissionedActionAllowedBy::<T>::put(permissioned_action_allowed_by)
}
if let Some(genesis_domain) = self.genesis_domain.as_ref().cloned() {
// Register the genesis domain runtime
let runtime_id = register_runtime_at_genesis::<T>(
genesis_domain.runtime_name,
genesis_domain.runtime_type,
genesis_domain.runtime_version,
genesis_domain.raw_genesis_storage,
Zero::zero(),
)
.expect("Genesis runtime registration must always succeed");

// Instantiate the genesis domain
let domain_config = DomainConfig {
domain_name: genesis_domain.domain_name,
runtime_id,
max_block_size: genesis_domain.max_block_size,
max_block_weight: genesis_domain.max_block_weight,
bundle_slot_probability: genesis_domain.bundle_slot_probability,
target_bundles_per_block: genesis_domain.target_bundles_per_block,
operator_allow_list: genesis_domain.operator_allow_list,
initial_balances: genesis_domain.initial_balances,
};
let domain_owner = genesis_domain.owner_account_id;
let domain_id =
do_instantiate_domain::<T>(domain_config, domain_owner.clone(), Zero::zero())
.expect("Genesis domain instantiation must always succeed");

// Register domain_owner as the genesis operator.
let operator_config = OperatorConfig {
signing_key: genesis_domain.signing_key.clone(),
minimum_nominator_stake: genesis_domain.minimum_nominator_stake,
nomination_tax: genesis_domain.nomination_tax,
};
let operator_stake = T::MinOperatorStake::get();
do_register_operator::<T>(domain_owner, domain_id, operator_stake, operator_config)

self.genesis_domains
.clone()
.into_iter()
.for_each(|genesis_domain| {
// Register the genesis domain runtime
let runtime_id = register_runtime_at_genesis::<T>(
genesis_domain.runtime_name,
genesis_domain.runtime_type,
genesis_domain.runtime_version,
genesis_domain.raw_genesis_storage,
Zero::zero(),
)
.expect("Genesis runtime registration must always succeed");

// Instantiate the genesis domain
let domain_config = DomainConfig {
domain_name: genesis_domain.domain_name,
runtime_id,
max_block_size: genesis_domain.max_block_size,
max_block_weight: genesis_domain.max_block_weight,
bundle_slot_probability: genesis_domain.bundle_slot_probability,
target_bundles_per_block: genesis_domain.target_bundles_per_block,
operator_allow_list: genesis_domain.operator_allow_list,
initial_balances: genesis_domain.initial_balances,
};
let domain_owner = genesis_domain.owner_account_id;
let domain_id = do_instantiate_domain::<T>(
domain_config,
domain_owner.clone(),
Zero::zero(),
)
.expect("Genesis domain instantiation must always succeed");

// Register domain_owner as the genesis operator.
let operator_config = OperatorConfig {
signing_key: genesis_domain.signing_key.clone(),
minimum_nominator_stake: genesis_domain.minimum_nominator_stake,
nomination_tax: genesis_domain.nomination_tax,
};
let operator_stake = T::MinOperatorStake::get();
do_register_operator::<T>(
domain_owner,
domain_id,
operator_stake,
operator_config,
)
.expect("Genesis operator registration must succeed");

do_finalize_domain_current_epoch::<T>(domain_id)
.expect("Genesis epoch must succeed");
}
do_finalize_domain_current_epoch::<T>(domain_id)
.expect("Genesis epoch must succeed");
});
}
}

Expand Down
21 changes: 21 additions & 0 deletions crates/pallet-domains/src/runtime_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use frame_support::PalletError;
use frame_system::pallet_prelude::*;
use frame_system::AccountInfo;
use scale_info::TypeInfo;
use sp_core::crypto::AccountId32;
use sp_core::Hasher;
use sp_domains::storage::{RawGenesis, StorageData, StorageKey};
use sp_domains::{DomainId, DomainsDigestItem, RuntimeId, RuntimeType};
Expand Down Expand Up @@ -56,6 +57,7 @@ pub struct RuntimeObject<Number, Hash> {
#[derive(TypeInfo, Debug, Encode, Decode, Clone, PartialEq, Eq, Copy)]
pub enum DomainRuntimeInfo {
EVM { chain_id: EVMChainId },
AutoId,
}

impl Default for DomainRuntimeInfo {
Expand Down Expand Up @@ -123,6 +125,25 @@ impl<Number, Hash> RuntimeObject<Number, Hash> {
initial_balances,
));
}
DomainRuntimeInfo::AutoId => {
let initial_balances = initial_balances.into_iter().try_fold(
Vec::<(AccountId32, BalanceOf<T>)>::new(),
|mut balances, (account_id, balance)| {
let account_id =
domain_runtime_primitives::AccountIdConverter::try_convert_back(
account_id,
)
.ok_or(Error::InvalidAccountIdType)?;

balances.push((account_id, balance));
Ok(balances)
},
)?;
raw_genesis.set_top_storages(derive_initial_balances_storages::<T, _>(
total_issuance,
initial_balances,
));
}
}

Ok(raw_genesis)
Expand Down
1 change: 1 addition & 0 deletions crates/sc-domains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ frame-benchmarking = { default-features = false, git = "https://github.com/subsp
sc-client-api = { git = "https://github.com/subspace/polkadot-sdk", rev = "447bbc765020674614e9ac982163f7e11e5b03ea" }
sc-executor = { git = "https://github.com/subspace/polkadot-sdk", rev = "447bbc765020674614e9ac982163f7e11e5b03ea" }
sp-api = { git = "https://github.com/subspace/polkadot-sdk", rev = "447bbc765020674614e9ac982163f7e11e5b03ea" }
sp-auto-id = { version = "0.1.0", path = "../../domains/primitives/auto-id" }
sp-blockchain = { git = "https://github.com/subspace/polkadot-sdk", rev = "447bbc765020674614e9ac982163f7e11e5b03ea" }
sp-core = { git = "https://github.com/subspace/polkadot-sdk", rev = "447bbc765020674614e9ac982163f7e11e5b03ea" }
sp-domains = { version = "0.1.0", path = "../sp-domains" }
Expand Down
6 changes: 6 additions & 0 deletions crates/sc-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use std::sync::Arc;
/// Host functions required for Subspace domain
#[cfg(not(feature = "runtime-benchmarks"))]
pub type HostFunctions = (
sp_auto_id::auto_id_runtime_interface::HostFunctions,
sp_io::SubstrateHostFunctions,
sp_messenger_host_functions::HostFunctions,
sp_subspace_mmr::DomainHostFunctions,
Expand All @@ -41,6 +42,7 @@ pub type HostFunctions = (
/// Host functions required for Subspace domain
#[cfg(feature = "runtime-benchmarks")]
pub type HostFunctions = (
sp_auto_id::auto_id_runtime_interface::HostFunctions,
sp_io::SubstrateHostFunctions,
sp_messenger_host_functions::HostFunctions,
sp_subspace_mmr::DomainHostFunctions,
Expand Down Expand Up @@ -96,6 +98,10 @@ where
),
)));

exts.register(sp_auto_id::host_functions::HostFunctionExtension::new(
Arc::new(sp_auto_id::host_functions::HostFunctionsImpl),
));

exts
}
}
37 changes: 21 additions & 16 deletions crates/sc-subspace-chain-specs/res/chain-spec-raw-devnet.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/sp-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ pub struct GenesisDomain<AccountId: Ord, Balance> {
pub enum RuntimeType {
#[default]
Evm,
AutoId,
}

/// Type representing the runtime ID.
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-malicious-operator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include = [
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
auto-id-domain-runtime = { version = "0.1.0", path = "../../domains/runtime/auto-id" }
clap = { version = "4.5.4", features = ["derive"] }
cross-domain-message-gossip = { version = "0.1.0", path = "../../domains/client/cross-domain-message-gossip" }
domain-client-message-relayer = { version = "0.1.0", path = "../../domains/client/relayer" }
Expand Down
4 changes: 2 additions & 2 deletions crates/subspace-malicious-operator/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fn subspace_genesis_config(
permissioned_action_allowed_by: Some(
genesis_domain_params.permissioned_action_allowed_by,
),
genesis_domain: Some(sp_domains::GenesisDomain {
genesis_domains: vec![sp_domains::GenesisDomain {
runtime_name: "evm".to_owned(),
runtime_type: RuntimeType::Evm,
runtime_version: evm_domain_runtime::VERSION,
Expand All @@ -276,7 +276,7 @@ fn subspace_genesis_config(
nomination_tax: Percent::from_percent(5),
minimum_nominator_stake: 100 * SSC,
initial_balances: genesis_domain_params.initial_balances,
}),
}],
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use domain_client_operator::{BootstrapResult, OperatorStreams};
use domain_eth_service::provider::EthProvider;
use domain_eth_service::DefaultEthConfig;
use domain_runtime_primitives::opaque::Block as DomainBlock;
use domain_service::providers::DefaultProvider;
use domain_service::{FullBackend, FullClient};
use evm_domain_runtime::AccountId as AccountId20;
use futures::StreamExt;
Expand All @@ -16,6 +17,7 @@ use sc_network::NetworkPeers;
use sc_service::PruningMode;
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sc_utils::mpsc::{TracingUnboundedReceiver, TracingUnboundedSender};
use sp_core::crypto::AccountId32;
use sp_core::traits::SpawnEssentialNamed;
use sp_domains::{DomainInstanceData, RuntimeType};
use sp_keystore::KeystorePtr;
Expand Down Expand Up @@ -196,6 +198,65 @@ where

domain_node.task_manager.future().await?;

Ok(())
}
RuntimeType::AutoId => {
let domain_params = domain_service::DomainParams {
domain_id,
domain_config,
domain_created_at,
consensus_client: consensus_client.clone(),
consensus_offchain_tx_pool_factory: consensus_offchain_tx_pool_factory.clone(),
consensus_network,
consensus_network_sync_oracle: consensus_sync_service.clone(),
operator_streams,
gossip_message_sink,
domain_message_receiver,
provider: DefaultProvider,
skip_empty_bundle_production: true,
skip_out_of_order_slot: false,
// Always set it to `None` to not running the normal bundle producer
maybe_operator_id: None,
consensus_state_pruning,
};

let mut domain_node = domain_service::new_full::<
_,
_,
_,
_,
_,
_,
auto_id_domain_runtime::RuntimeApi,
AccountId32,
_,
_,
>(domain_params)
.await?;

let malicious_bundle_producer = MaliciousBundleProducer::new(
domain_id,
domain_node.client.clone(),
consensus_client,
consensus_keystore,
consensus_offchain_tx_pool_factory,
domain_node.transaction_pool.clone(),
sudo_account,
);

domain_node
.task_manager
.spawn_essential_handle()
.spawn_essential_blocking(
"malicious-bundle-producer",
None,
Box::pin(malicious_bundle_producer.start(new_slot_notification_stream())),
);

domain_node.network_starter.start_network();

domain_node.task_manager.future().await?;

Ok(())
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ include = [
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
auto-id-domain-runtime = { version = "0.1.0", path = "../../domains/runtime/auto-id" }
bip39 = "2.0.0"
clap = { version = "4.5.4", features = ["derive"] }
cross-domain-message-gossip = { version = "0.1.0", path = "../../domains/client/cross-domain-message-gossip" }
Expand Down
Loading

0 comments on commit 61d10f4

Please sign in to comment.