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.
This commit is contained in:
Tobin C. Harding 2024-01-30 07:54:44 +11:00
parent f0f6d3f162
commit 4121c9a09f
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
2 changed files with 14 additions and 2 deletions

View File

@ -7,6 +7,8 @@
//! //!
use crate::network::Network; use crate::network::Network;
#[cfg(doc)]
use crate::pow::CompactTarget;
use crate::pow::Target; use crate::pow::Target;
/// Parameters that influence chain consensus. /// Parameters that influence chain consensus.
@ -30,6 +32,12 @@ pub struct Params {
/// Number of blocks with the same set of rules. /// Number of blocks with the same set of rules.
pub miner_confirmation_window: u32, pub miner_confirmation_window: u32,
/// Proof of work limit value. It contains the lowest possible difficulty. /// 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 /// 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 /// 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 /// 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 /// 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. /// 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. /// Expected amount of time to mine one block.
pub pow_target_spacing: u64, pub pow_target_spacing: u64,
/// Difficulty recalculation interval. /// Difficulty recalculation interval.
@ -62,6 +70,7 @@ impl Params {
rule_change_activation_threshold: 1916, // 95% rule_change_activation_threshold: 1916, // 95%
miner_confirmation_window: 2016, miner_confirmation_window: 2016,
pow_limit: Target::MAX_ATTAINABLE_MAINNET, pow_limit: Target::MAX_ATTAINABLE_MAINNET,
max_attainable_target: Target::MAX_ATTAINABLE_MAINNET,
pow_target_spacing: 10 * 60, // 10 minutes. pow_target_spacing: 10 * 60, // 10 minutes.
pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks. pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks.
allow_min_difficulty_blocks: false, allow_min_difficulty_blocks: false,
@ -78,6 +87,7 @@ impl Params {
rule_change_activation_threshold: 1512, // 75% rule_change_activation_threshold: 1512, // 75%
miner_confirmation_window: 2016, miner_confirmation_window: 2016,
pow_limit: Target::MAX_ATTAINABLE_TESTNET, pow_limit: Target::MAX_ATTAINABLE_TESTNET,
max_attainable_target: Target::MAX_ATTAINABLE_TESTNET,
pow_target_spacing: 10 * 60, // 10 minutes. pow_target_spacing: 10 * 60, // 10 minutes.
pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks. pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks.
allow_min_difficulty_blocks: true, allow_min_difficulty_blocks: true,
@ -94,6 +104,7 @@ impl Params {
rule_change_activation_threshold: 1916, // 95% rule_change_activation_threshold: 1916, // 95%
miner_confirmation_window: 2016, miner_confirmation_window: 2016,
pow_limit: Target::MAX_ATTAINABLE_SIGNET, pow_limit: Target::MAX_ATTAINABLE_SIGNET,
max_attainable_target: Target::MAX_ATTAINABLE_SIGNET,
pow_target_spacing: 10 * 60, // 10 minutes. pow_target_spacing: 10 * 60, // 10 minutes.
pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks. pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks.
allow_min_difficulty_blocks: false, allow_min_difficulty_blocks: false,
@ -110,6 +121,7 @@ impl Params {
rule_change_activation_threshold: 108, // 75% rule_change_activation_threshold: 108, // 75%
miner_confirmation_window: 144, miner_confirmation_window: 144,
pow_limit: Target::MAX_ATTAINABLE_REGTEST, pow_limit: Target::MAX_ATTAINABLE_REGTEST,
max_attainable_target: Target::MAX_ATTAINABLE_REGTEST,
pow_target_spacing: 10 * 60, // 10 minutes. pow_target_spacing: 10 * 60, // 10 minutes.
pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks. pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks.
allow_min_difficulty_blocks: true, allow_min_difficulty_blocks: true,

View File

@ -236,7 +236,7 @@ impl Target {
// Panic here may be eaiser to debug than during the actual division. // Panic here may be eaiser to debug than during the actual division.
assert_ne!(self.0, U256::ZERO, "divide by zero"); 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; let d = max.0 / self.0;
d.saturating_to_u128() d.saturating_to_u128()
} }