From f345ab7f2f73e9f099dbddf11e92e1a8c2d0ec3f Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Fri, 31 May 2024 16:20:28 +0800 Subject: [PATCH] Allow dev accounts to be used as miners (#65) --- Cargo.lock | 1 + Cargo.toml | 1 + node/Cargo.toml | 1 + node/src/cli.rs | 4 ++-- node/src/command.rs | 2 +- 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5deb9986..aa9f869c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,6 +50,7 @@ dependencies = [ "sp-consensus-pow", "sp-core", "sp-inherents", + "sp-keyring", "sp-runtime", "sp-timestamp", "sp-transaction-pool", diff --git a/Cargo.toml b/Cargo.toml index ae994f01..abc7643a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,7 @@ sp-core = { branch = "release-polkadot-v1.5.0", default-features = false, git = sp-genesis-builder = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" } sp-inherents = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" } sp-io = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" } +sp-keyring = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" } sp-keystore = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" } sp-offchain = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" } sp-runtime = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" } diff --git a/node/Cargo.toml b/node/Cargo.toml index e4f759b9..a790acf4 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -45,6 +45,7 @@ sp-consensus = { workspace = true } sp-consensus-pow = { workspace = true } sp-core = { workspace = true } sp-inherents = { workspace = true } +sp-keyring = { workspace = true } sp-runtime = { workspace = true } sp-timestamp = { workspace = true } sp-transaction-pool = { workspace = true } diff --git a/node/src/cli.rs b/node/src/cli.rs index ff840bca..4e1ac61c 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -47,12 +47,12 @@ pub struct AcademyPowCli { } impl AcademyPowCli { - pub fn public_key_bytes(&self) -> [u8; 32] { + pub fn public_key_bytes(&self, keyring: Option) -> [u8; 32] { match &self.mining_account_id { Some(account_id) => *account_id.as_ref(), None => match self.mining_public_key { Some(public_key) => public_key.0, - None => [0u8; 32], + None => keyring.map(|k| k.to_raw_public()).unwrap_or([0u8; 32]), }, } } diff --git a/node/src/command.rs b/node/src/command.rs index 3a294f23..4f92b39e 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -147,7 +147,7 @@ pub fn run() -> sc_cli::Result<()> { } None => { // Get the mining account from the cli - let bytes: [u8; 32] = cli.pow.public_key_bytes(); + let bytes: [u8; 32] = cli.pow.public_key_bytes(cli.run.get_keyring()); let sr25519_public_key = Public(bytes); let runner = cli.create_runner(&cli.run)?;