Move weight constants in the `Weight` type
deprecate constants::MAX_BLOCK_WEIGHT and constants::MIN_TRANSACTION_WEIGHT to nicely redirect users to the constants in the Weight type
This commit is contained in:
parent
ca7c60a09d
commit
fc7c251502
|
@ -32,10 +32,15 @@ pub const TARGET_BLOCK_SPACING: u32 = 600;
|
||||||
pub const DIFFCHANGE_INTERVAL: u32 = 2016;
|
pub const DIFFCHANGE_INTERVAL: u32 = 2016;
|
||||||
/// How much time on average should occur between diffchanges.
|
/// How much time on average should occur between diffchanges.
|
||||||
pub const DIFFCHANGE_TIMESPAN: u32 = 14 * 24 * 3600;
|
pub const DIFFCHANGE_TIMESPAN: u32 = 14 * 24 * 3600;
|
||||||
|
|
||||||
|
#[deprecated(since = "0.31.0", note = "Use Weight::MAX_BLOCK instead")]
|
||||||
/// The maximum allowed weight for a block, see BIP 141 (network rule).
|
/// The maximum allowed weight for a block, see BIP 141 (network rule).
|
||||||
pub const MAX_BLOCK_WEIGHT: u32 = 4_000_000;
|
pub const MAX_BLOCK_WEIGHT: u32 = 4_000_000;
|
||||||
|
|
||||||
|
#[deprecated(since = "0.31.0", note = "Use Weight::MIN_TRANSACTION instead")]
|
||||||
/// The minimum transaction weight for a valid serialized transaction.
|
/// The minimum transaction weight for a valid serialized transaction.
|
||||||
pub const MIN_TRANSACTION_WEIGHT: u32 = 4 * 60;
|
pub const MIN_TRANSACTION_WEIGHT: u32 = 4 * 60;
|
||||||
|
|
||||||
/// The factor that non-witness serialization data is multiplied by during weight calculation.
|
/// The factor that non-witness serialization data is multiplied by during weight calculation.
|
||||||
pub const WITNESS_SCALE_FACTOR: usize = 4;
|
pub const WITNESS_SCALE_FACTOR: usize = 4;
|
||||||
/// The maximum allowed number of signature check operations in a block.
|
/// The maximum allowed number of signature check operations in a block.
|
||||||
|
|
|
@ -29,6 +29,12 @@ impl Weight {
|
||||||
/// Maximum possible value.
|
/// Maximum possible value.
|
||||||
pub const MAX: Weight = Weight(u64::max_value());
|
pub const MAX: Weight = Weight(u64::max_value());
|
||||||
|
|
||||||
|
/// The maximum allowed weight for a block, see BIP 141 (network rule).
|
||||||
|
pub const MAX_BLOCK: Weight = Weight(4_000_000);
|
||||||
|
|
||||||
|
/// The minimum transaction weight for a valid serialized transaction.
|
||||||
|
pub const MIN_TRANSACTION: Weight = Weight(4 * 60);
|
||||||
|
|
||||||
/// Directly constructs `Weight` from weight units.
|
/// Directly constructs `Weight` from weight units.
|
||||||
pub const fn from_wu(wu: u64) -> Self { Weight(wu) }
|
pub const fn from_wu(wu: u64) -> Self { Weight(wu) }
|
||||||
|
|
||||||
|
@ -249,6 +255,12 @@ impl Div<u64> for Weight {
|
||||||
fn div(self, rhs: u64) -> Self::Output { Weight(self.0 / rhs) }
|
fn div(self, rhs: u64) -> Self::Output { Weight(self.0 / rhs) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Div<Weight> for Weight {
|
||||||
|
type Output = u64;
|
||||||
|
|
||||||
|
fn div(self, rhs: Weight) -> Self::Output { self.to_wu() / rhs.to_wu() }
|
||||||
|
}
|
||||||
|
|
||||||
impl DivAssign<u64> for Weight {
|
impl DivAssign<u64> for Weight {
|
||||||
fn div_assign(&mut self, rhs: u64) { self.0 /= rhs }
|
fn div_assign(&mut self, rhs: u64) { self.0 /= rhs }
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,8 @@ use hashes::Hash;
|
||||||
|
|
||||||
use self::MerkleBlockError::*;
|
use self::MerkleBlockError::*;
|
||||||
use crate::blockdata::block::{self, Block};
|
use crate::blockdata::block::{self, Block};
|
||||||
use crate::blockdata::constants::{MAX_BLOCK_WEIGHT, MIN_TRANSACTION_WEIGHT};
|
|
||||||
use crate::blockdata::transaction::Transaction;
|
use crate::blockdata::transaction::Transaction;
|
||||||
|
use crate::blockdata::weight::Weight;
|
||||||
use crate::consensus::encode::{self, Decodable, Encodable};
|
use crate::consensus::encode::{self, Decodable, Encodable};
|
||||||
use crate::hash_types::{TxMerkleNode, Txid};
|
use crate::hash_types::{TxMerkleNode, Txid};
|
||||||
use crate::io;
|
use crate::io;
|
||||||
|
@ -276,7 +276,7 @@ impl PartialMerkleTree {
|
||||||
return Err(NoTransactions);
|
return Err(NoTransactions);
|
||||||
};
|
};
|
||||||
// check for excessively high numbers of transactions
|
// check for excessively high numbers of transactions
|
||||||
if self.num_transactions > MAX_BLOCK_WEIGHT / MIN_TRANSACTION_WEIGHT {
|
if self.num_transactions as u64 > Weight::MAX_BLOCK / Weight::MIN_TRANSACTION {
|
||||||
return Err(TooManyTransactions);
|
return Err(TooManyTransactions);
|
||||||
}
|
}
|
||||||
// there can never be more hashes provided than one for every txid
|
// there can never be more hashes provided than one for every txid
|
||||||
|
|
Loading…
Reference in New Issue