Skip to content

Commit

Permalink
Merge pull request #51 from fernandolguevara/feat-no-difficulty-scaling
Browse files Browse the repository at this point in the history
feat(cli): add option for no difficulty scaling
  • Loading branch information
grunch authored Nov 15, 2024
2 parents 1e737d5 + 743c8d2 commit e8a5ec3
Show file tree
Hide file tree
Showing 2 changed files with 10 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
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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 @@ -134,6 +135,8 @@ fn main() -> Result<()> {
"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 @@ -274,7 +277,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 e8a5ec3

Please sign in to comment.