Skip to content

Commit e2400b5

Browse files
committed
Merge remote-tracking branch 'origin/main' into update-substrate-follow-up
# Conflicts: # crates/subspace-node/src/chain_spec.rs
2 parents b99087d + 8c1280c commit e2400b5

File tree

21 files changed

+679
-215
lines changed

21 files changed

+679
-215
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pallet-domains/src/domain_registry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ pub(crate) fn do_instantiate_domain<T: Config>(
215215
chain_id: evm_chain_id,
216216
}
217217
}
218+
RuntimeType::AutoId => DomainRuntimeInfo::AutoId,
218219
};
219220

220221
// burn total issuance on domain from owners account and track the domain balance

crates/pallet-domains/src/lib.rs

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ mod pallet {
192192
#[cfg(not(feature = "std"))]
193193
use alloc::string::String;
194194
#[cfg(not(feature = "std"))]
195+
use alloc::vec;
196+
#[cfg(not(feature = "std"))]
195197
use alloc::vec::Vec;
196198
use codec::FullCodec;
197199
use domain_runtime_primitives::EVMChainId;
@@ -219,7 +221,6 @@ mod pallet {
219221
use sp_std::boxed::Box;
220222
use sp_std::collections::btree_set::BTreeSet;
221223
use sp_std::fmt::Debug;
222-
use sp_std::vec;
223224
use subspace_core_primitives::U256;
224225
use subspace_runtime_primitives::StorageFee;
225226

@@ -1399,16 +1400,16 @@ mod pallet {
13991400

14001401
#[pallet::genesis_config]
14011402
pub struct GenesisConfig<T: Config> {
1402-
pub genesis_domain: Option<GenesisDomain<T::AccountId, BalanceOf<T>>>,
14031403
pub permissioned_action_allowed_by:
14041404
Option<sp_domains::PermissionedActionAllowedBy<T::AccountId>>,
1405+
pub genesis_domains: Vec<GenesisDomain<T::AccountId, BalanceOf<T>>>,
14051406
}
14061407

14071408
impl<T: Config> Default for GenesisConfig<T> {
14081409
fn default() -> Self {
14091410
GenesisConfig {
1410-
genesis_domain: None,
14111411
permissioned_action_allowed_by: None,
1412+
genesis_domains: vec![],
14121413
}
14131414
}
14141415
}
@@ -1421,46 +1422,58 @@ mod pallet {
14211422
{
14221423
PermissionedActionAllowedBy::<T>::put(permissioned_action_allowed_by)
14231424
}
1424-
if let Some(genesis_domain) = self.genesis_domain.as_ref().cloned() {
1425-
// Register the genesis domain runtime
1426-
let runtime_id = register_runtime_at_genesis::<T>(
1427-
genesis_domain.runtime_name,
1428-
genesis_domain.runtime_type,
1429-
genesis_domain.runtime_version,
1430-
genesis_domain.raw_genesis_storage,
1431-
Zero::zero(),
1432-
)
1433-
.expect("Genesis runtime registration must always succeed");
1434-
1435-
// Instantiate the genesis domain
1436-
let domain_config = DomainConfig {
1437-
domain_name: genesis_domain.domain_name,
1438-
runtime_id,
1439-
max_block_size: genesis_domain.max_block_size,
1440-
max_block_weight: genesis_domain.max_block_weight,
1441-
bundle_slot_probability: genesis_domain.bundle_slot_probability,
1442-
target_bundles_per_block: genesis_domain.target_bundles_per_block,
1443-
operator_allow_list: genesis_domain.operator_allow_list,
1444-
initial_balances: genesis_domain.initial_balances,
1445-
};
1446-
let domain_owner = genesis_domain.owner_account_id;
1447-
let domain_id =
1448-
do_instantiate_domain::<T>(domain_config, domain_owner.clone(), Zero::zero())
1449-
.expect("Genesis domain instantiation must always succeed");
1450-
1451-
// Register domain_owner as the genesis operator.
1452-
let operator_config = OperatorConfig {
1453-
signing_key: genesis_domain.signing_key.clone(),
1454-
minimum_nominator_stake: genesis_domain.minimum_nominator_stake,
1455-
nomination_tax: genesis_domain.nomination_tax,
1456-
};
1457-
let operator_stake = T::MinOperatorStake::get();
1458-
do_register_operator::<T>(domain_owner, domain_id, operator_stake, operator_config)
1425+
1426+
self.genesis_domains
1427+
.clone()
1428+
.into_iter()
1429+
.for_each(|genesis_domain| {
1430+
// Register the genesis domain runtime
1431+
let runtime_id = register_runtime_at_genesis::<T>(
1432+
genesis_domain.runtime_name,
1433+
genesis_domain.runtime_type,
1434+
genesis_domain.runtime_version,
1435+
genesis_domain.raw_genesis_storage,
1436+
Zero::zero(),
1437+
)
1438+
.expect("Genesis runtime registration must always succeed");
1439+
1440+
// Instantiate the genesis domain
1441+
let domain_config = DomainConfig {
1442+
domain_name: genesis_domain.domain_name,
1443+
runtime_id,
1444+
max_block_size: genesis_domain.max_block_size,
1445+
max_block_weight: genesis_domain.max_block_weight,
1446+
bundle_slot_probability: genesis_domain.bundle_slot_probability,
1447+
target_bundles_per_block: genesis_domain.target_bundles_per_block,
1448+
operator_allow_list: genesis_domain.operator_allow_list,
1449+
initial_balances: genesis_domain.initial_balances,
1450+
};
1451+
let domain_owner = genesis_domain.owner_account_id;
1452+
let domain_id = do_instantiate_domain::<T>(
1453+
domain_config,
1454+
domain_owner.clone(),
1455+
Zero::zero(),
1456+
)
1457+
.expect("Genesis domain instantiation must always succeed");
1458+
1459+
// Register domain_owner as the genesis operator.
1460+
let operator_config = OperatorConfig {
1461+
signing_key: genesis_domain.signing_key.clone(),
1462+
minimum_nominator_stake: genesis_domain.minimum_nominator_stake,
1463+
nomination_tax: genesis_domain.nomination_tax,
1464+
};
1465+
let operator_stake = T::MinOperatorStake::get();
1466+
do_register_operator::<T>(
1467+
domain_owner,
1468+
domain_id,
1469+
operator_stake,
1470+
operator_config,
1471+
)
14591472
.expect("Genesis operator registration must succeed");
14601473

1461-
do_finalize_domain_current_epoch::<T>(domain_id)
1462-
.expect("Genesis epoch must succeed");
1463-
}
1474+
do_finalize_domain_current_epoch::<T>(domain_id)
1475+
.expect("Genesis epoch must succeed");
1476+
});
14641477
}
14651478
}
14661479

crates/pallet-domains/src/runtime_registry.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use frame_support::PalletError;
1515
use frame_system::pallet_prelude::*;
1616
use frame_system::AccountInfo;
1717
use scale_info::TypeInfo;
18+
use sp_core::crypto::AccountId32;
1819
use sp_core::Hasher;
1920
use sp_domains::storage::{RawGenesis, StorageData, StorageKey};
2021
use sp_domains::{DomainId, DomainsDigestItem, RuntimeId, RuntimeType};
@@ -56,6 +57,7 @@ pub struct RuntimeObject<Number, Hash> {
5657
#[derive(TypeInfo, Debug, Encode, Decode, Clone, PartialEq, Eq, Copy)]
5758
pub enum DomainRuntimeInfo {
5859
EVM { chain_id: EVMChainId },
60+
AutoId,
5961
}
6062

6163
impl Default for DomainRuntimeInfo {
@@ -123,6 +125,25 @@ impl<Number, Hash> RuntimeObject<Number, Hash> {
123125
initial_balances,
124126
));
125127
}
128+
DomainRuntimeInfo::AutoId => {
129+
let initial_balances = initial_balances.into_iter().try_fold(
130+
Vec::<(AccountId32, BalanceOf<T>)>::new(),
131+
|mut balances, (account_id, balance)| {
132+
let account_id =
133+
domain_runtime_primitives::AccountIdConverter::try_convert_back(
134+
account_id,
135+
)
136+
.ok_or(Error::InvalidAccountIdType)?;
137+
138+
balances.push((account_id, balance));
139+
Ok(balances)
140+
},
141+
)?;
142+
raw_genesis.set_top_storages(derive_initial_balances_storages::<T, _>(
143+
total_issuance,
144+
initial_balances,
145+
));
146+
}
126147
}
127148

128149
Ok(raw_genesis)

crates/sc-domains/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ frame-benchmarking = { default-features = false, git = "https://github.com/subsp
2020
sc-client-api = { git = "https://github.com/subspace/polkadot-sdk", rev = "447bbc765020674614e9ac982163f7e11e5b03ea" }
2121
sc-executor = { git = "https://github.com/subspace/polkadot-sdk", rev = "447bbc765020674614e9ac982163f7e11e5b03ea" }
2222
sp-api = { git = "https://github.com/subspace/polkadot-sdk", rev = "447bbc765020674614e9ac982163f7e11e5b03ea" }
23+
sp-auto-id = { version = "0.1.0", path = "../../domains/primitives/auto-id" }
2324
sp-blockchain = { git = "https://github.com/subspace/polkadot-sdk", rev = "447bbc765020674614e9ac982163f7e11e5b03ea" }
2425
sp-core = { git = "https://github.com/subspace/polkadot-sdk", rev = "447bbc765020674614e9ac982163f7e11e5b03ea" }
2526
sp-domains = { version = "0.1.0", path = "../sp-domains" }

crates/sc-domains/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use std::sync::Arc;
3333
/// Host functions required for Subspace domain
3434
#[cfg(not(feature = "runtime-benchmarks"))]
3535
pub type HostFunctions = (
36+
sp_auto_id::auto_id_runtime_interface::HostFunctions,
3637
sp_io::SubstrateHostFunctions,
3738
sp_messenger_host_functions::HostFunctions,
3839
sp_subspace_mmr::DomainHostFunctions,
@@ -41,6 +42,7 @@ pub type HostFunctions = (
4142
/// Host functions required for Subspace domain
4243
#[cfg(feature = "runtime-benchmarks")]
4344
pub type HostFunctions = (
45+
sp_auto_id::auto_id_runtime_interface::HostFunctions,
4446
sp_io::SubstrateHostFunctions,
4547
sp_messenger_host_functions::HostFunctions,
4648
sp_subspace_mmr::DomainHostFunctions,
@@ -96,6 +98,10 @@ where
9698
),
9799
)));
98100

101+
exts.register(sp_auto_id::host_functions::HostFunctionExtension::new(
102+
Arc::new(sp_auto_id::host_functions::HostFunctionsImpl),
103+
));
104+
99105
exts
100106
}
101107
}

crates/sc-subspace-chain-specs/res/chain-spec-raw-devnet.json

Lines changed: 21 additions & 16 deletions
Large diffs are not rendered by default.

crates/sp-domains/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ pub struct GenesisDomain<AccountId: Ord, Balance> {
833833
pub enum RuntimeType {
834834
#[default]
835835
Evm,
836+
AutoId,
836837
}
837838

838839
/// Type representing the runtime ID.

crates/subspace-malicious-operator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ include = [
1919
targets = ["x86_64-unknown-linux-gnu"]
2020

2121
[dependencies]
22+
auto-id-domain-runtime = { version = "0.1.0", path = "../../domains/runtime/auto-id" }
2223
clap = { version = "4.5.4", features = ["derive"] }
2324
cross-domain-message-gossip = { version = "0.1.0", path = "../../domains/client/cross-domain-message-gossip" }
2425
domain-client-message-relayer = { version = "0.1.0", path = "../../domains/client/relayer" }

crates/subspace-malicious-operator/src/chain_spec.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn subspace_genesis_config(
258258
permissioned_action_allowed_by: Some(
259259
genesis_domain_params.permissioned_action_allowed_by,
260260
),
261-
genesis_domain: Some(sp_domains::GenesisDomain {
261+
genesis_domains: vec![sp_domains::GenesisDomain {
262262
runtime_name: "evm".to_owned(),
263263
runtime_type: RuntimeType::Evm,
264264
runtime_version: evm_domain_runtime::VERSION,
@@ -276,38 +276,44 @@ fn subspace_genesis_config(
276276
nomination_tax: Percent::from_percent(5),
277277
minimum_nominator_stake: 100 * SSC,
278278
initial_balances: genesis_domain_params.initial_balances,
279-
}),
279+
}],
280280
},
281281
}
282282
}
283283

284284
// TODO: Workaround for https://github.com/paritytech/polkadot-sdk/issues/4001
285285
fn patch_domain_runtime_version(mut genesis_config: serde_json::Value) -> serde_json::Value {
286-
let Some(runtime_version) = genesis_config
286+
let Some(genesis_domains) = genesis_config
287287
.get_mut("domains")
288-
.and_then(|domains| domains.get_mut("genesisDomain"))
289-
.and_then(|genesis_domain| genesis_domain.get_mut("runtime_version"))
288+
.and_then(|domains| domains.get_mut("genesisDomains"))
289+
.and_then(|genesis_domains| genesis_domains.as_array_mut())
290290
else {
291291
return genesis_config;
292292
};
293293

294-
if let Some(spec_name) = runtime_version.get_mut("specName") {
295-
if let Some(spec_name_bytes) = spec_name
296-
.as_str()
297-
.map(|spec_name| spec_name.as_bytes().to_vec())
298-
{
299-
*spec_name = serde_json::to_value(spec_name_bytes)
300-
.expect("Bytes serialization doesn't fail; qed");
294+
for genesis_domain in genesis_domains {
295+
let Some(runtime_version) = genesis_domain.get_mut("runtime_version") else {
296+
continue;
297+
};
298+
299+
if let Some(spec_name) = runtime_version.get_mut("specName") {
300+
if let Some(spec_name_bytes) = spec_name
301+
.as_str()
302+
.map(|spec_name| spec_name.as_bytes().to_vec())
303+
{
304+
*spec_name = serde_json::to_value(spec_name_bytes)
305+
.expect("Bytes serialization doesn't fail; qed");
306+
}
301307
}
302-
}
303308

304-
if let Some(impl_name) = runtime_version.get_mut("implName") {
305-
if let Some(impl_name_bytes) = impl_name
306-
.as_str()
307-
.map(|impl_name| impl_name.as_bytes().to_vec())
308-
{
309-
*impl_name = serde_json::to_value(impl_name_bytes)
310-
.expect("Bytes serialization doesn't fail; qed");
309+
if let Some(impl_name) = runtime_version.get_mut("implName") {
310+
if let Some(impl_name_bytes) = impl_name
311+
.as_str()
312+
.map(|impl_name| impl_name.as_bytes().to_vec())
313+
{
314+
*impl_name = serde_json::to_value(impl_name_bytes)
315+
.expect("Bytes serialization doesn't fail; qed");
316+
}
311317
}
312318
}
313319

0 commit comments

Comments
 (0)