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

feat(node): add aura authoring #8

Merged
merged 1 commit into from
Dec 11, 2024
Merged
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
33 changes: 25 additions & 8 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@

use polkadot_sdk::{
sc_service::{ChainType, Properties},
sp_keyring::AccountKeyring,
*,
};
use serde_json::{json, Value};
use torus_runtime::{BalancesConfig, SudoConfig, WASM_BINARY};
use torus_runtime::WASM_BINARY;

/// This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec;
Expand All @@ -38,8 +37,8 @@ pub fn development_config() -> Result<ChainSpec, String> {
WASM_BINARY.expect("Development wasm not available"),
Default::default(),
)
.with_name("Development")
.with_id("dev")
.with_name("Torus")
.with_id("torus")
.with_chain_type(ChainType::Development)
.with_genesis_config_patch(testnet_genesis())
.with_properties(props())
Expand All @@ -48,14 +47,32 @@ pub fn development_config() -> Result<ChainSpec, String> {

/// Configure initial storage state for FRAME pallets.
fn testnet_genesis() -> Value {
use polkadot_sdk::polkadot_sdk_frame::traits::Get;
use torus_runtime::interface::{Balance, MinimumBalance};
use polkadot_sdk::{
polkadot_sdk_frame::traits::Get,
sp_keyring::{Ed25519Keyring, Sr25519Keyring},
};

use torus_runtime::{
interface::{Balance, MinimumBalance},
BalancesConfig, SudoConfig,
};

let endowment = <MinimumBalance as Get<Balance>>::get().max(1) * 1000;
let balances = AccountKeyring::iter()
let balances = Sr25519Keyring::iter()
.map(|a| (a.to_account_id(), endowment))
.collect::<Vec<_>>();

let aura = [Sr25519Keyring::Alice, Sr25519Keyring::Bob];
let grandpa = [Ed25519Keyring::Alice, Ed25519Keyring::Bob];

json!({
"balances": BalancesConfig { balances },
"sudo": SudoConfig { key: Some(AccountKeyring::Alice.to_account_id()) },
"sudo": SudoConfig { key: Some(Sr25519Keyring::Alice.to_account_id()) },
"aura": {
"authorities": aura.iter().map(|x| (dbg!(x.public().to_string()))).collect::<Vec<_>>(),
},
"grandpa": {
"authorities": grandpa.iter().map(|x| (x.public().to_string(), 1)).collect::<Vec<_>>(),
},
})
}
10 changes: 7 additions & 3 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

use polkadot_sdk::{sc_cli::RunCmd, *};

#[derive(Debug, Clone)]
#[derive(Clone, Copy, Debug, Default)]
pub enum Consensus {
#[default]
Aura,
ManualSeal(u64),
InstantSeal,
}
Expand All @@ -27,7 +29,9 @@ impl std::str::FromStr for Consensus {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(if s == "instant-seal" {
Ok(if s == "aura" {
Consensus::Aura
} else if s == "instant-seal" {
Consensus::InstantSeal
} else if let Some(block_time) = s.strip_prefix("manual-seal-") {
Consensus::ManualSeal(block_time.parse().map_err(|_| "invalid block time")?)
Expand All @@ -42,7 +46,7 @@ pub struct Cli {
#[command(subcommand)]
pub subcommand: Option<Subcommand>,

#[clap(long, default_value = "manual-seal-3000")]
#[clap(long, default_value = "aura")]
pub consensus: Consensus,

#[clap(flatten)]
Expand Down
10 changes: 5 additions & 5 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn run() -> sc_cli::Result<()> {
task_manager,
import_queue,
..
} = service::new_partial(&config)?;
} = service::new_partial(&config, Default::default())?;
Ok((cmd.run(client, import_queue), task_manager))
})
}
Expand All @@ -86,7 +86,7 @@ pub fn run() -> sc_cli::Result<()> {
client,
task_manager,
..
} = service::new_partial(&config)?;
} = service::new_partial(&config, Default::default())?;
Ok((cmd.run(client, config.database), task_manager))
})
}
Expand All @@ -97,7 +97,7 @@ pub fn run() -> sc_cli::Result<()> {
client,
task_manager,
..
} = service::new_partial(&config)?;
} = service::new_partial(&config, Default::default())?;
Ok((cmd.run(client, config.chain_spec), task_manager))
})
}
Expand All @@ -109,7 +109,7 @@ pub fn run() -> sc_cli::Result<()> {
task_manager,
import_queue,
..
} = service::new_partial(&config)?;
} = service::new_partial(&config, Default::default())?;
Ok((cmd.run(client, import_queue), task_manager))
})
}
Expand All @@ -125,7 +125,7 @@ pub fn run() -> sc_cli::Result<()> {
task_manager,
backend,
..
} = service::new_partial(&config)?;
} = service::new_partial(&config, Default::default())?;
Ok((cmd.run(client, backend, None), task_manager))
})
}
Expand Down
Loading