swap best_chain_len and related constants to u32 for consistency (#1257)
This commit is contained in:
parent
a0c7e34d63
commit
e8a3a28869
|
|
@ -1,17 +1,14 @@
|
||||||
use zebra_chain::block;
|
|
||||||
|
|
||||||
/// The maturity threshold for transparent coinbase outputs.
|
/// The maturity threshold for transparent coinbase outputs.
|
||||||
///
|
///
|
||||||
/// A transaction MUST NOT spend a transparent output of a coinbase transaction
|
/// A transaction MUST NOT spend a transparent output of a coinbase transaction
|
||||||
/// from a block less than 100 blocks prior to the spend. Note that transparent
|
/// from a block less than 100 blocks prior to the spend. Note that transparent
|
||||||
/// outputs of coinbase transactions include Founders' Reward outputs.
|
/// outputs of coinbase transactions include Founders' Reward outputs.
|
||||||
pub const MIN_TRASPARENT_COINBASE_MATURITY: block::Height = block::Height(100);
|
pub const MIN_TRASPARENT_COINBASE_MATURITY: u32 = 100;
|
||||||
|
|
||||||
/// The maximum chain reorganisation height.
|
/// The maximum chain reorganisation height.
|
||||||
///
|
///
|
||||||
/// Allowing reorganisations past this height could allow double-spends of
|
/// Allowing reorganisations past this height could allow double-spends of
|
||||||
/// coinbase transactions.
|
/// coinbase transactions.
|
||||||
pub const MAX_BLOCK_REORG_HEIGHT: block::Height =
|
pub const MAX_BLOCK_REORG_HEIGHT: u32 = MIN_TRASPARENT_COINBASE_MATURITY - 1;
|
||||||
block::Height(MIN_TRASPARENT_COINBASE_MATURITY.0 - 1);
|
|
||||||
|
|
||||||
pub const SLED_FORMAT_VERSION: u32 = 1;
|
pub const SLED_FORMAT_VERSION: u32 = 1;
|
||||||
|
|
|
||||||
|
|
@ -493,13 +493,11 @@ impl NonFinalizedState {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the length of the non-finalized portion of the current best chain.
|
/// Returns the length of the non-finalized portion of the current best chain.
|
||||||
pub fn best_chain_len(&self) -> block::Height {
|
pub fn best_chain_len(&self) -> u32 {
|
||||||
block::Height(
|
self.best_chain()
|
||||||
self.best_chain()
|
.expect("only called after inserting a block")
|
||||||
.expect("only called after inserting a block")
|
.blocks
|
||||||
.blocks
|
.len() as u32
|
||||||
.len() as u32,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if `hash` is contained in the non-finalized portion of any
|
/// Returns `true` if `hash` is contained in the non-finalized portion of any
|
||||||
|
|
|
||||||
|
|
@ -48,10 +48,10 @@ fn test_block_locator_heights() {
|
||||||
block::Height(min_height),
|
block::Height(min_height),
|
||||||
"locators must end with the specified final height"
|
"locators must end with the specified final height"
|
||||||
);
|
);
|
||||||
assert!(height - final_height.0 <= constants::MAX_BLOCK_REORG_HEIGHT.0,
|
assert!(height - final_height.0 <= constants::MAX_BLOCK_REORG_HEIGHT,
|
||||||
format!("locator for {} must not be more than the maximum reorg height {} below the tip, but {} is {} blocks below the tip",
|
format!("locator for {} must not be more than the maximum reorg height {} below the tip, but {} is {} blocks below the tip",
|
||||||
height,
|
height,
|
||||||
constants::MAX_BLOCK_REORG_HEIGHT.0,
|
constants::MAX_BLOCK_REORG_HEIGHT,
|
||||||
final_height.0,
|
final_height.0,
|
||||||
height - final_height.0));
|
height - final_height.0));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub fn block_locator_heights(tip_height: block::Height) -> Vec<block::Height> {
|
||||||
// Stop at the reorg limit, or the genesis block.
|
// Stop at the reorg limit, or the genesis block.
|
||||||
let min_locator_height = tip_height
|
let min_locator_height = tip_height
|
||||||
.0
|
.0
|
||||||
.saturating_sub(constants::MAX_BLOCK_REORG_HEIGHT.0);
|
.saturating_sub(constants::MAX_BLOCK_REORG_HEIGHT);
|
||||||
let locators = iter::successors(Some(1u32), |h| h.checked_mul(2))
|
let locators = iter::successors(Some(1u32), |h| h.checked_mul(2))
|
||||||
.flat_map(move |step| tip_height.0.checked_sub(step));
|
.flat_map(move |step| tip_height.0.checked_sub(step));
|
||||||
let locators = iter::once(tip_height.0)
|
let locators = iter::once(tip_height.0)
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ fn main() -> Result<()> {
|
||||||
// Zcash reorg limit.
|
// Zcash reorg limit.
|
||||||
let height_limit = height_limit
|
let height_limit = height_limit
|
||||||
.0
|
.0
|
||||||
.checked_sub(zebra_state::MAX_BLOCK_REORG_HEIGHT.0)
|
.checked_sub(zebra_state::MAX_BLOCK_REORG_HEIGHT)
|
||||||
.map(block::Height)
|
.map(block::Height)
|
||||||
.expect("zcashd has some mature blocks: wait for zcashd to sync more blocks");
|
.expect("zcashd has some mature blocks: wait for zcashd to sync more blocks");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue