Skip to content

Commit

Permalink
Merge pull request #15 from okilisan/mainnet_karlsenhashv2
Browse files Browse the repository at this point in the history
difficulty adjustment window fix
  • Loading branch information
lemois-1337 authored Sep 3, 2024
2 parents fbd64bb + de8018f commit 0d0ffe3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions consensus/src/pipeline/header_processor/pre_pow_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ impl HeaderProcessor {
.calculate_difficulty_bits(ghostdag_data, &daa_window);
ctx.mergeset_non_daa = Some(daa_window.mergeset_non_daa);

if header.daa_score <= (self.hf_daa_score + 10) && header.daa_score >= self.hf_daa_score {
// if virtual_state.daa_score < (self.hf_daa_score + 10) || virtual_state.daa_score >= self.hf_daa_score {
if header.daa_score <= (self.hf_daa_score + self.difficulty_window_size as u64)
&& header.daa_score >= self.hf_daa_score
{
expected_bits = self.genesis.bits;
}

Expand Down
2 changes: 2 additions & 0 deletions consensus/src/pipeline/header_processor/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub struct HeaderProcessor {
pub(super) skip_proof_of_work: bool,
pub(super) max_block_level: BlockLevel,
pub(super) hf_daa_score: u64,
pub(super) difficulty_window_size: usize,

// DB
db: Arc<DB>,
Expand Down Expand Up @@ -217,6 +218,7 @@ impl HeaderProcessor {
skip_proof_of_work: params.skip_proof_of_work,
max_block_level: params.max_block_level,
hf_daa_score: params.hf_daa_score,
difficulty_window_size: params.legacy_difficulty_window_size,
}
}

Expand Down
4 changes: 3 additions & 1 deletion consensus/src/pipeline/virtual_processor/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub struct VirtualStateProcessor {
pub(super) mergeset_size_limit: u64,
pub(super) pruning_depth: u64,
pub(super) hf_daa_score: u64,
pub(super) difficulty_window_size: usize,

// Stores
pub(super) statuses_store: Arc<RwLock<DbStatusesStore>>,
Expand Down Expand Up @@ -199,6 +200,7 @@ impl VirtualStateProcessor {
mergeset_size_limit: params.mergeset_size_limit,
pruning_depth: params.pruning_depth,
hf_daa_score: params.hf_daa_score,
difficulty_window_size: params.legacy_difficulty_window_size,

db,
statuses_store: storage.statuses_store.clone(),
Expand Down Expand Up @@ -1226,7 +1228,7 @@ impl VirtualStateProcessor {
};
// todo: check bits to lower difficulty
let mut bits = virtual_state.bits;
if virtual_state.daa_score <= (self.hf_daa_score + 10)
if virtual_state.daa_score <= (self.hf_daa_score + self.difficulty_window_size as u64)
&& virtual_state.daa_score >= self.hf_daa_score
{
bits = self.genesis.bits;
Expand Down

0 comments on commit 0d0ffe3

Please sign in to comment.