Skip to content

Commit

Permalink
Merge pull request #16 from karlsen-network/mainnet_karlsenhashv2
Browse files Browse the repository at this point in the history
Difficulty adjustment window fix for karlsenhashv2
  • Loading branch information
lemois-1337 authored Sep 3, 2024
2 parents 40c65a4 + 300091a commit 92395a9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 60 deletions.
114 changes: 57 additions & 57 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ members = [

[workspace.package]
rust-version = "1.78.0"
version = "2.0.1"
version = "2.1.0"
authors = ["Karlsen developers"]
license = "ISC"
repository = "https://github.com/karlsen-network/rusty-karlsen"
Expand All @@ -79,62 +79,62 @@ include = [
]

[workspace.dependencies]
# karlsen-testing-integration = { version = "2.0.1", path = "testing/integration" }
karlsen-addresses = { version = "2.0.1", path = "crypto/addresses" }
karlsen-addressmanager = { version = "2.0.1", path = "components/addressmanager" }
karlsen-bip32 = { version = "2.0.1", path = "wallet/bip32" }
karlsen-resolver = { version = "2.0.1", path = "rpr/wrpc/resolver" }
karlsen-cli = { version = "2.0.1", path = "cli" }
karlsen-connectionmanager = { version = "2.0.1", path = "components/connectionmanager" }
karlsen-consensus = { version = "2.0.1", path = "consensus" }
karlsen-consensus-core = { version = "2.0.1", path = "consensus/core" }
karlsen-consensus-client = { version = "2.0.1", path = "consensus/client" }
karlsen-consensus-notify = { version = "2.0.1", path = "consensus/notify" }
karlsen-consensus-wasm = { version = "2.0.1", path = "consensus/wasm" }
karlsen-consensusmanager = { version = "2.0.1", path = "components/consensusmanager" }
karlsen-core = { version = "2.0.1", path = "core" }
karlsen-daemon = { version = "2.0.1", path = "daemon" }
karlsen-database = { version = "2.0.1", path = "database" }
karlsen-grpc-client = { version = "2.0.1", path = "rpc/grpc/client" }
karlsen-grpc-core = { version = "2.0.1", path = "rpc/grpc/core" }
karlsen-grpc-server = { version = "2.0.1", path = "rpc/grpc/server" }
karlsen-hashes = { version = "2.0.1", path = "crypto/hashes" }
karlsen-index-core = { version = "2.0.1", path = "indexes/core" }
karlsen-index-processor = { version = "2.0.1", path = "indexes/processor" }
karlsen-math = { version = "2.0.1", path = "math" }
karlsen-merkle = { version = "2.0.1", path = "crypto/merkle" }
karlsen-metrics-core = { version = "2.0.1", path = "metrics/core" }
karlsen-mining = { version = "2.0.1", path = "mining" }
karlsen-mining-errors = { version = "2.0.1", path = "mining/errors" }
karlsen-muhash = { version = "2.0.1", path = "crypto/muhash" }
karlsen-notify = { version = "2.0.1", path = "notify" }
karlsen-p2p-flows = { version = "2.0.1", path = "protocol/flows" }
karlsen-p2p-lib = { version = "2.0.1", path = "protocol/p2p" }
karlsen-perf-monitor = { version = "2.0.1", path = "metrics/perf_monitor" }
karlsen-pow = { version = "2.0.1", path = "consensus/pow" }
karlsen-rpc-core = { version = "2.0.1", path = "rpc/core" }
karlsen-rpc-macros = { version = "2.0.1", path = "rpc/macros" }
karlsen-rpc-service = { version = "2.0.1", path = "rpc/service" }
karlsen-txscript = { version = "2.0.1", path = "crypto/txscript" }
karlsen-txscript-errors = { version = "2.0.1", path = "crypto/txscript/errors" }
karlsen-utils = { version = "2.0.1", path = "utils" }
karlsen-utils-tower = { version = "2.0.1", path = "utils/tower" }
karlsen-utxoindex = { version = "2.0.1", path = "indexes/utxoindex" }
karlsen-wallet = { version = "2.0.1", path = "wallet/native" }
karlsen-wallet-cli-wasm = { version = "2.0.1", path = "wallet/wasm" }
karlsen-wallet-keys = { version = "2.0.1", path = "wallet/keys" }
karlsen-wallet-core = { version = "2.0.1", path = "wallet/core" }
karlsen-wallet-macros = { version = "2.0.1", path = "wallet/macros" }
karlsen-wasm = { version = "2.0.1", path = "wasm" }
karlsen-wasm-core = { version = "2.0.1", path = "wasm/core" }
karlsen-wrpc-client = { version = "2.0.1", path = "rpc/wrpc/client" }
karlsen-wrpc-core = { version = "2.0.1", path = "rpc/wrpc/core" }
karlsen-wrpc-proxy = { version = "2.0.1", path = "rpc/wrpc/proxy" }
karlsen-wrpc-server = { version = "2.0.1", path = "rpc/wrpc/server" }
karlsen-wrpc-wasm = { version = "2.0.1", path = "rpc/wrpc/wasm" }
karlsen-wrpc-example-subscriber = { version = "2.0.1", path = "rpc/wrpc/examples/subscriber" }
karlsend = { version = "2.0.1", path = "karlsend" }
karlsen-alloc = { version = "2.0.1", path = "utils/alloc" }
# karlsen-testing-integration = { version = "2.1.0", path = "testing/integration" }
karlsen-addresses = { version = "2.1.0", path = "crypto/addresses" }
karlsen-addressmanager = { version = "2.1.0", path = "components/addressmanager" }
karlsen-bip32 = { version = "2.1.0", path = "wallet/bip32" }
karlsen-resolver = { version = "2.1.0", path = "rpr/wrpc/resolver" }
karlsen-cli = { version = "2.1.0", path = "cli" }
karlsen-connectionmanager = { version = "2.1.0", path = "components/connectionmanager" }
karlsen-consensus = { version = "2.1.0", path = "consensus" }
karlsen-consensus-core = { version = "2.1.0", path = "consensus/core" }
karlsen-consensus-client = { version = "2.1.0", path = "consensus/client" }
karlsen-consensus-notify = { version = "2.1.0", path = "consensus/notify" }
karlsen-consensus-wasm = { version = "2.1.0", path = "consensus/wasm" }
karlsen-consensusmanager = { version = "2.1.0", path = "components/consensusmanager" }
karlsen-core = { version = "2.1.0", path = "core" }
karlsen-daemon = { version = "2.1.0", path = "daemon" }
karlsen-database = { version = "2.1.0", path = "database" }
karlsen-grpc-client = { version = "2.1.0", path = "rpc/grpc/client" }
karlsen-grpc-core = { version = "2.1.0", path = "rpc/grpc/core" }
karlsen-grpc-server = { version = "2.1.0", path = "rpc/grpc/server" }
karlsen-hashes = { version = "2.1.0", path = "crypto/hashes" }
karlsen-index-core = { version = "2.1.0", path = "indexes/core" }
karlsen-index-processor = { version = "2.1.0", path = "indexes/processor" }
karlsen-math = { version = "2.1.0", path = "math" }
karlsen-merkle = { version = "2.1.0", path = "crypto/merkle" }
karlsen-metrics-core = { version = "2.1.0", path = "metrics/core" }
karlsen-mining = { version = "2.1.0", path = "mining" }
karlsen-mining-errors = { version = "2.1.0", path = "mining/errors" }
karlsen-muhash = { version = "2.1.0", path = "crypto/muhash" }
karlsen-notify = { version = "2.1.0", path = "notify" }
karlsen-p2p-flows = { version = "2.1.0", path = "protocol/flows" }
karlsen-p2p-lib = { version = "2.1.0", path = "protocol/p2p" }
karlsen-perf-monitor = { version = "2.1.0", path = "metrics/perf_monitor" }
karlsen-pow = { version = "2.1.0", path = "consensus/pow" }
karlsen-rpc-core = { version = "2.1.0", path = "rpc/core" }
karlsen-rpc-macros = { version = "2.1.0", path = "rpc/macros" }
karlsen-rpc-service = { version = "2.1.0", path = "rpc/service" }
karlsen-txscript = { version = "2.1.0", path = "crypto/txscript" }
karlsen-txscript-errors = { version = "2.1.0", path = "crypto/txscript/errors" }
karlsen-utils = { version = "2.1.0", path = "utils" }
karlsen-utils-tower = { version = "2.1.0", path = "utils/tower" }
karlsen-utxoindex = { version = "2.1.0", path = "indexes/utxoindex" }
karlsen-wallet = { version = "2.1.0", path = "wallet/native" }
karlsen-wallet-cli-wasm = { version = "2.1.0", path = "wallet/wasm" }
karlsen-wallet-keys = { version = "2.1.0", path = "wallet/keys" }
karlsen-wallet-core = { version = "2.1.0", path = "wallet/core" }
karlsen-wallet-macros = { version = "2.1.0", path = "wallet/macros" }
karlsen-wasm = { version = "2.1.0", path = "wasm" }
karlsen-wasm-core = { version = "2.1.0", path = "wasm/core" }
karlsen-wrpc-client = { version = "2.1.0", path = "rpc/wrpc/client" }
karlsen-wrpc-core = { version = "2.1.0", path = "rpc/wrpc/core" }
karlsen-wrpc-proxy = { version = "2.1.0", path = "rpc/wrpc/proxy" }
karlsen-wrpc-server = { version = "2.1.0", path = "rpc/wrpc/server" }
karlsen-wrpc-wasm = { version = "2.1.0", path = "rpc/wrpc/wasm" }
karlsen-wrpc-example-subscriber = { version = "2.1.0", path = "rpc/wrpc/examples/subscriber" }
karlsend = { version = "2.1.0", path = "karlsend" }
karlsen-alloc = { version = "2.1.0", path = "utils/alloc" }

# external
aes = "0.8.3"
Expand Down
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 92395a9

Please sign in to comment.