From 4121c9a09fba775ae89d1e44082596dd229a6e9d Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 30 Jan 2024 07:54:44 +1100 Subject: [PATCH] Rename Params::pow_limit to max_attainable_target The maximum "attainable" target is a `rust-bitcoin` thing, Core use max unattainable. Deprecated the `Params::pow_limit` field and add a new field `max_attainable_target`. The `Params` type is `non_exhaustive` so this is not an API breaking change. --- bitcoin/src/consensus/params.rs | 14 +++++++++++++- bitcoin/src/pow.rs | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bitcoin/src/consensus/params.rs b/bitcoin/src/consensus/params.rs index 55655384..19522134 100644 --- a/bitcoin/src/consensus/params.rs +++ b/bitcoin/src/consensus/params.rs @@ -7,6 +7,8 @@ //! use crate::network::Network; +#[cfg(doc)] +use crate::pow::CompactTarget; use crate::pow::Target; /// Parameters that influence chain consensus. @@ -30,6 +32,12 @@ pub struct Params { /// Number of blocks with the same set of rules. pub miner_confirmation_window: u32, /// Proof of work limit value. It contains the lowest possible difficulty. + #[deprecated(since = "TBD", note = "field renamed to max_attainable_target")] + pub pow_limit: Target, + /// The maximum **attainable** target value for these params. + /// + /// Not all target values are attainable because consensus code uses the compact format to + /// represent targets (see [`CompactTarget`]). /// /// Note that this value differs from Bitcoin Core's powLimit field in that this value is /// attainable, but Bitcoin Core's is not. Specifically, because targets in Bitcoin are always @@ -37,7 +45,7 @@ pub struct Params { /// Still, this should not affect consensus as the only place where the non-compact form of /// this is used in Bitcoin Core's consensus algorithm is in comparison and there are no /// compact-expressible values between Bitcoin Core's and the limit expressed here. - pub pow_limit: Target, + pub max_attainable_target: Target, /// Expected amount of time to mine one block. pub pow_target_spacing: u64, /// Difficulty recalculation interval. @@ -62,6 +70,7 @@ impl Params { rule_change_activation_threshold: 1916, // 95% miner_confirmation_window: 2016, pow_limit: Target::MAX_ATTAINABLE_MAINNET, + max_attainable_target: Target::MAX_ATTAINABLE_MAINNET, pow_target_spacing: 10 * 60, // 10 minutes. pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks. allow_min_difficulty_blocks: false, @@ -78,6 +87,7 @@ impl Params { rule_change_activation_threshold: 1512, // 75% miner_confirmation_window: 2016, pow_limit: Target::MAX_ATTAINABLE_TESTNET, + max_attainable_target: Target::MAX_ATTAINABLE_TESTNET, pow_target_spacing: 10 * 60, // 10 minutes. pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks. allow_min_difficulty_blocks: true, @@ -94,6 +104,7 @@ impl Params { rule_change_activation_threshold: 1916, // 95% miner_confirmation_window: 2016, pow_limit: Target::MAX_ATTAINABLE_SIGNET, + max_attainable_target: Target::MAX_ATTAINABLE_SIGNET, pow_target_spacing: 10 * 60, // 10 minutes. pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks. allow_min_difficulty_blocks: false, @@ -110,6 +121,7 @@ impl Params { rule_change_activation_threshold: 108, // 75% miner_confirmation_window: 144, pow_limit: Target::MAX_ATTAINABLE_REGTEST, + max_attainable_target: Target::MAX_ATTAINABLE_REGTEST, pow_target_spacing: 10 * 60, // 10 minutes. pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks. allow_min_difficulty_blocks: true, diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs index 07c38ff7..eec84379 100644 --- a/bitcoin/src/pow.rs +++ b/bitcoin/src/pow.rs @@ -236,7 +236,7 @@ impl Target { // Panic here may be eaiser to debug than during the actual division. assert_ne!(self.0, U256::ZERO, "divide by zero"); - let max = params.as_ref().pow_limit; + let max = params.as_ref().max_attainable_target; let d = max.0 / self.0; d.saturating_to_u128() }