Skip to content

Commit

Permalink
Merge pull request #2179 from subspace/domain-gemini-3g
Browse files Browse the repository at this point in the history
Preparing domain for gemini-3g
  • Loading branch information
nazar-pc authored Oct 30, 2023
2 parents 63e1e29 + 9649c6a commit e3e58ed
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 79 deletions.
51 changes: 43 additions & 8 deletions crates/subspace-node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@

//! Subspace chain configurations.
use crate::chain_spec_utils::{chain_spec_properties, get_account_id_from_seed};
use crate::chain_spec_utils::{
chain_spec_properties, get_account_id_from_seed, get_public_key_from_seed,
};
use crate::domain::evm_chain_spec::{self, SpecId};
use hex_literal::hex;
use parity_scale_codec::Encode;
use sc_service::{ChainType, NoExtension};
use sc_subspace_chain_specs::ConsensusChainSpec;
use sc_telemetry::TelemetryEndpoints;
use sp_consensus_subspace::FarmerPublicKey;
use sp_core::crypto::{Ss58Codec, UncheckedFrom};
use sp_domains::storage::RawGenesis;
use sp_domains::{OperatorAllowList, RuntimeType};
use sp_domains::{OperatorAllowList, OperatorPublicKey, RuntimeType};
use sp_runtime::{BuildStorage, Percent};
use std::collections::btree_set::BTreeSet;
use std::marker::PhantomData;
use std::num::NonZeroU32;
use subspace_core_primitives::PotKey;
Expand Down Expand Up @@ -91,6 +95,12 @@ struct GenesisParams {
confirmation_depth_k: u32,
}

struct GenesisDomainParams {
domain_name: String,
operator_allow_list: OperatorAllowList<AccountId>,
operator_signing_key: OperatorPublicKey,
}

pub fn gemini_3g_compiled() -> Result<ConsensusChainSpec<RuntimeGenesisConfig>, String> {
Ok(ConsensusChainSpec::from_genesis(
// Name
Expand Down Expand Up @@ -143,7 +153,7 @@ pub fn gemini_3g_compiled() -> Result<ConsensusChainSpec<RuntimeGenesisConfig>,
subspace_genesis_config(
SpecId::Gemini,
WASM_BINARY.expect("Wasm binary must be built for Gemini"),
sudo_account,
sudo_account.clone(),
balances,
vesting_schedules,
GenesisParams {
Expand All @@ -161,6 +171,15 @@ pub fn gemini_3g_compiled() -> Result<ConsensusChainSpec<RuntimeGenesisConfig>,
enable_balance_transfers: true,
confirmation_depth_k: 100, // TODO: Proper value here
},
GenesisDomainParams {
domain_name: "nova".to_owned(),
operator_allow_list: OperatorAllowList::Operators(BTreeSet::from_iter(vec![
sudo_account,
])),
operator_signing_key: OperatorPublicKey::unchecked_from(hex!(
"aa3b05b4d649666723e099cf3bafc2f2c04160ebe0e16ddc82f72d6ed97c4b6b"
)),
},
)
},
// Bootnodes
Expand Down Expand Up @@ -259,6 +278,13 @@ pub fn devnet_config_compiled() -> Result<ConsensusChainSpec<RuntimeGenesisConfi
enable_balance_transfers: true,
confirmation_depth_k: 100, // TODO: Proper value here
},
GenesisDomainParams {
domain_name: "evm-domain".to_owned(),
operator_allow_list: OperatorAllowList::Anyone,
operator_signing_key: OperatorPublicKey::unchecked_from(hex!(
"aa3b05b4d649666723e099cf3bafc2f2c04160ebe0e16ddc82f72d6ed97c4b6b"
)),
},
)
},
// Bootnodes
Expand Down Expand Up @@ -317,6 +343,11 @@ pub fn dev_config() -> Result<ConsensusChainSpec<RuntimeGenesisConfig>, String>
enable_balance_transfers: true,
confirmation_depth_k: 5,
},
GenesisDomainParams {
domain_name: "evm-domain".to_owned(),
operator_allow_list: OperatorAllowList::Anyone,
operator_signing_key: get_public_key_from_seed::<OperatorPublicKey>("Alice"),
},
)
},
// Bootnodes
Expand Down Expand Up @@ -380,6 +411,11 @@ pub fn local_config() -> Result<ConsensusChainSpec<RuntimeGenesisConfig>, String
enable_balance_transfers: true,
confirmation_depth_k: 1,
},
GenesisDomainParams {
domain_name: "evm-domain".to_owned(),
operator_allow_list: OperatorAllowList::Anyone,
operator_signing_key: get_public_key_from_seed::<OperatorPublicKey>("Alice"),
},
)
},
// Bootnodes
Expand Down Expand Up @@ -412,6 +448,7 @@ fn subspace_genesis_config(
// who, start, period, period_count, per_period
vesting: Vec<(AccountId, BlockNumber, BlockNumber, u32, Balance)>,
genesis_params: GenesisParams,
genesis_domain_params: GenesisDomainParams,
) -> RuntimeGenesisConfig {
let GenesisParams {
enable_rewards,
Expand All @@ -423,10 +460,8 @@ fn subspace_genesis_config(
confirmation_depth_k,
} = genesis_params;

let (domain_genesis_config, genesis_domain_params) =
evm_chain_spec::get_testnet_genesis_by_spec_id(spec_id);

let raw_genesis_storage = {
let domain_genesis_config = evm_chain_spec::get_testnet_genesis_by_spec_id(spec_id);
let storage = domain_genesis_config
.build_storage()
.expect("Failed to build genesis storage from genesis runtime config");
Expand Down Expand Up @@ -468,12 +503,12 @@ fn subspace_genesis_config(

// Domain config, mainly for placeholder the concrete value TBD
owner_account_id: sudo_account,
domain_name: "evm-domain".to_owned(),
domain_name: genesis_domain_params.domain_name,
max_block_size: MaxDomainBlockSize::get(),
max_block_weight: MaxDomainBlockWeight::get(),
bundle_slot_probability: (1, 1),
target_bundles_per_block: 10,
operator_allow_list: OperatorAllowList::Anyone,
operator_allow_list: genesis_domain_params.operator_allow_list,
signing_key: genesis_domain_params.operator_signing_key,
nomination_tax: Percent::from_percent(5),
minimum_nominator_stake: 100 * SSC,
Expand Down
8 changes: 4 additions & 4 deletions crates/subspace-node/src/domain/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ impl BuildGenesisStorageCmd {
let is_dev = self.shared_params.is_dev();
let chain_id = self.shared_params.chain_id(is_dev);
let domain_genesis_config = match chain_id.as_str() {
"gemini-3g" => evm_chain_spec::get_testnet_genesis_by_spec_id(SpecId::Gemini).0,
"devnet" => evm_chain_spec::get_testnet_genesis_by_spec_id(SpecId::DevNet).0,
"dev" => evm_chain_spec::get_testnet_genesis_by_spec_id(SpecId::Dev).0,
"" | "local" => evm_chain_spec::get_testnet_genesis_by_spec_id(SpecId::Local).0,
"gemini-3g" => evm_chain_spec::get_testnet_genesis_by_spec_id(SpecId::Gemini),
"devnet" => evm_chain_spec::get_testnet_genesis_by_spec_id(SpecId::DevNet),
"dev" => evm_chain_spec::get_testnet_genesis_by_spec_id(SpecId::Dev),
"" | "local" => evm_chain_spec::get_testnet_genesis_by_spec_id(SpecId::Local),
unknown_id => {
eprintln!(
"unknown chain {unknown_id:?}, expected gemini-3g, devnet, dev, or local",
Expand Down
95 changes: 30 additions & 65 deletions crates/subspace-node/src/domain/evm_chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@

//! EVM domain configurations.
use crate::chain_spec_utils::{chain_spec_properties, get_public_key_from_seed};
use crate::chain_spec_utils::chain_spec_properties;
use evm_domain_runtime::{
AccountId, BalancesConfig, EVMChainIdConfig, EVMConfig, Precompiles, RuntimeGenesisConfig,
SudoConfig, SystemConfig, WASM_BINARY,
};
use hex_literal::hex;
use sc_service::{ChainSpec as ChainSpecT, ChainType};
use sc_subspace_chain_specs::ExecutionChainSpec;
use sp_core::crypto::UncheckedFrom;
use sp_domains::storage::RawGenesis;
use sp_domains::OperatorPublicKey;
use std::str::FromStr;
use subspace_runtime_primitives::SSC;

Expand Down Expand Up @@ -138,14 +136,11 @@ pub fn devnet_config<F: Fn() -> RuntimeGenesisConfig + 'static + Send + Sync>(
}

pub fn load_chain_spec(spec_id: &str) -> Result<Box<dyn sc_cli::ChainSpec>, String> {
let constructor =
|spec_id: SpecId| -> RuntimeGenesisConfig { get_testnet_genesis_by_spec_id(spec_id).0 };

let chain_spec = match spec_id {
"dev" => development_config(move || constructor(SpecId::Dev)),
"gemini-3g" => gemini_3g_config(move || constructor(SpecId::Gemini)),
"devnet" => devnet_config(move || constructor(SpecId::DevNet)),
"" | "local" => local_testnet_config(move || constructor(SpecId::Local)),
"dev" => development_config(move || get_testnet_genesis_by_spec_id(SpecId::Dev)),
"gemini-3g" => gemini_3g_config(move || get_testnet_genesis_by_spec_id(SpecId::Gemini)),
"devnet" => devnet_config(move || get_testnet_genesis_by_spec_id(SpecId::DevNet)),
"" | "local" => local_testnet_config(move || get_testnet_genesis_by_spec_id(SpecId::Local)),
path => ChainSpec::from_json_file(std::path::PathBuf::from(path))?,
};
Ok(Box::new(chain_spec))
Expand All @@ -158,78 +153,48 @@ pub enum SpecId {
Local,
}

pub struct GenesisDomainParams {
pub operator_signing_key: OperatorPublicKey,
}

pub fn get_testnet_genesis_by_spec_id(
spec_id: SpecId,
) -> (RuntimeGenesisConfig, GenesisDomainParams) {
pub fn get_testnet_genesis_by_spec_id(spec_id: SpecId) -> RuntimeGenesisConfig {
match spec_id {
SpecId::Dev => {
let accounts = get_dev_accounts();
(
testnet_genesis(
accounts.clone(),
// Alith is Sudo
Some(accounts[0]),
1000,
),
GenesisDomainParams {
operator_signing_key: get_public_key_from_seed::<OperatorPublicKey>("Alice"),
},
testnet_genesis(
accounts.clone(),
// Alith is Sudo
Some(accounts[0]),
1000,
)
}
SpecId::Gemini => {
let sudo_account = AccountId::from_str("f31e60022e290708c17d6997c34de6a30d09438f")
.expect("Invalid Sudo account");
(
testnet_genesis(
vec![
// Sudo account
sudo_account,
],
Some(sudo_account),
1002,
),
GenesisDomainParams {
operator_signing_key: OperatorPublicKey::unchecked_from(hex!(
"aa3b05b4d649666723e099cf3bafc2f2c04160ebe0e16ddc82f72d6ed97c4b6b"
)),
},
testnet_genesis(
vec![
// Sudo account
sudo_account,
],
Some(sudo_account),
1002,
)
}
SpecId::DevNet => {
let sudo_account = AccountId::from_str("b66a91845249464309fad766fd0ece8144547736")
.expect("Invalid Sudo account");
(
testnet_genesis(
vec![
// Sudo account
sudo_account,
],
Some(sudo_account),
1003,
),
GenesisDomainParams {
operator_signing_key: OperatorPublicKey::unchecked_from(hex!(
"aa3b05b4d649666723e099cf3bafc2f2c04160ebe0e16ddc82f72d6ed97c4b6b"
)),
},
testnet_genesis(
vec![
// Sudo account
sudo_account,
],
Some(sudo_account),
1003,
)
}
SpecId::Local => {
let accounts = get_dev_accounts();
(
testnet_genesis(
accounts.clone(),
// Alith is sudo
Some(accounts[0]),
1001,
),
GenesisDomainParams {
operator_signing_key: get_public_key_from_seed::<OperatorPublicKey>("Alice"),
},
testnet_genesis(
accounts.clone(),
// Alith is sudo
Some(accounts[0]),
1001,
)
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("subspace"),
impl_name: create_runtime_str!("subspace"),
authoring_version: 0,
spec_version: 2,
spec_version: 0,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 0,
Expand Down Expand Up @@ -603,7 +603,8 @@ parameter_types! {
pub const StakeEpochDuration: DomainNumber = 100;
pub TreasuryAccount: AccountId = PalletId(*b"treasury").into_account_truncating();
pub const MaxPendingStakingOperation: u32 = 100;
pub const MaxNominators: u32 = 100;
// TODO: reset `MaxNominators` back to `100` once the gemini-3g chain spec is created
pub const MaxNominators: u32 = 0;
}

impl pallet_domains::Config for Runtime {
Expand Down

0 comments on commit e3e58ed

Please sign in to comment.