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

If miner has no mining key set, automatically set it to node seed #5498

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
14 changes: 13 additions & 1 deletion testnet/stacks-node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,12 @@ impl Config {
}

let miner = match config_file.miner {
Some(miner) => miner.into_config_default(miner_default_config)?,
Some(mut miner) => {
if miner.mining_key.is_none() && !node.seed.is_empty() {
miner.mining_key = Some(to_hex(&node.seed));
}
miner.into_config_default(miner_default_config)?
}
None => miner_default_config,
};

Expand Down Expand Up @@ -2546,6 +2551,13 @@ pub struct MinerConfigFile {

impl MinerConfigFile {
fn into_config_default(self, miner_default_config: MinerConfig) -> Result<MinerConfig, String> {
match &self.mining_key {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as a node.seed is set up, this will never trigger. Should it be removed? Or do we prefer this and remove the mining-key being automatically set?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if node.seed isn't configured and the node doesn't have miner.seed = true - will this cause the node to panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested it using stacks-regtest-env for the config with

  1. node.miner = false and node.seed empty with miner config data in it
  2. node.miner = false and node.seed empty without miner config in it specified.
  3. node.miner = true and node.seed specified
  4. node.miner = true and miner.mining_key specified
    On all these cases it didn't panic.

It only panicked when node.miner = true and node.seed and miner.mining_key were not provided.

Some(_) => {}
None => {
panic!("mining key not set");
}
}

let mining_key = self
.mining_key
.as_ref()
Expand Down
Loading