Skip to content

Commit

Permalink
feat(cli): add option for no difficulty scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandolguevara committed Nov 12, 2024
1 parent acbb764 commit fd2f4be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ targets as a comma-separated list."
help = "Print verbose ouput on non-matching public keys"
)]
pub verbose_output: bool,
#[arg(
long,
default_value_t = false,
help = "When true, disables difficulty scaling and keeps it fixed throughout."
)]
pub no_scaling: bool,
}

pub fn check_args(
Expand Down
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fn main() -> Result<()> {
}

let mut difficulty: u8 = parsed_args.difficulty;
let no_scaling: bool = parsed_args.no_scaling;
let vanity_prefix: String = parsed_args.vanity_prefix;
let mut vanity_npub_prefixes: Vec<String> = Vec::new();
let mut vanity_npub_suffixes: Vec<String> = Vec::new();
Expand Down Expand Up @@ -89,10 +90,16 @@ fn main() -> Result<()> {
pow_difficulty = difficulty;
}

if no_scaling {
pow_difficulty = difficulty;
}

println!(
"Started mining process with a difficulty of: {difficulty} (pow: {pow_difficulty})"
);
}

println!("Difficulty scaling: {}", !no_scaling);

// benchmark cores
if !vanity_npub_prefixes.is_empty() || !vanity_npub_suffixes.is_empty() {
Expand Down Expand Up @@ -202,7 +209,7 @@ fn main() -> Result<()> {
// difficulty search
leading_zeroes = get_leading_zero_bits(&keys.public_key().serialize());
is_valid_pubkey = leading_zeroes > best_diff.load(Ordering::Relaxed);
if is_valid_pubkey {
if is_valid_pubkey && !no_scaling {
// update difficulty only if it was set in the first place
if best_diff.load(Ordering::Relaxed) > 0 {
best_diff
Expand Down

0 comments on commit fd2f4be

Please sign in to comment.