- Ignores the zip 212 grace period on configured Testnets and Regtest
- Adds debug_validate_without_checkpoints field - Sets initial peers as an empty set on Regtest
This commit is contained in:
parent
b3db5b03e5
commit
7a756f73c9
|
@ -171,6 +171,14 @@ impl Network {
|
|||
Self::new_configured_testnet(testnet::Parameters::new_regtest(activation_heights))
|
||||
}
|
||||
|
||||
/// Returns true if the network is Mainnet or the default Testnet, or false otherwise.
|
||||
pub fn is_a_default_network(&self) -> bool {
|
||||
match self {
|
||||
Network::Mainnet => true,
|
||||
Network::Testnet(params) => params.is_default_testnet(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if the network is the default Testnet, or false otherwise.
|
||||
pub fn is_default_testnet(&self) -> bool {
|
||||
if let Self::Testnet(params) = self {
|
||||
|
@ -198,6 +206,15 @@ impl Network {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns true if blocks should be contextually validated without checkpoints on this network
|
||||
pub fn debug_validate_without_checkpoints(&self) -> bool {
|
||||
if let Self::Testnet(params) = self {
|
||||
params.debug_validate_without_checkpoints()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the [`NetworkKind`] for this network.
|
||||
pub fn kind(&self) -> NetworkKind {
|
||||
match self {
|
||||
|
@ -243,6 +260,8 @@ impl Network {
|
|||
/// Mandatory checkpoints are a Zebra-specific feature.
|
||||
/// If a Zcash consensus rule only applies before the mandatory checkpoint,
|
||||
/// Zebra can skip validation of that rule.
|
||||
///
|
||||
/// ZIP-212 grace period is only applied to default networks.
|
||||
pub fn mandatory_checkpoint_height(&self) -> Height {
|
||||
// Currently this is after the ZIP-212 grace period.
|
||||
//
|
||||
|
@ -252,8 +271,12 @@ impl Network {
|
|||
.activation_height(self)
|
||||
.expect("Canopy activation height must be present for both networks");
|
||||
|
||||
(canopy_activation + ZIP_212_GRACE_PERIOD_DURATION)
|
||||
.expect("ZIP-212 grace period ends at a valid block height")
|
||||
if self.is_a_default_network() {
|
||||
(canopy_activation + ZIP_212_GRACE_PERIOD_DURATION)
|
||||
.expect("ZIP-212 grace period ends at a valid block height")
|
||||
} else {
|
||||
canopy_activation
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the network name as defined in
|
||||
|
|
|
@ -73,6 +73,9 @@ pub struct ParametersBuilder {
|
|||
hrp_sapling_payment_address: String,
|
||||
/// A flag for disabling proof-of-work checks when Zebra is validating blocks
|
||||
disable_pow: bool,
|
||||
/// A flag for allowing Zebra to try contextually validating the first queued block
|
||||
/// for a given height below the mandatory checkpoint height.
|
||||
debug_validate_without_checkpoints: bool,
|
||||
}
|
||||
|
||||
impl Default for ParametersBuilder {
|
||||
|
@ -94,6 +97,7 @@ impl Default for ParametersBuilder {
|
|||
.parse()
|
||||
.expect("hard-coded hash parses"),
|
||||
disable_pow: false,
|
||||
debug_validate_without_checkpoints: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -240,6 +244,15 @@ impl ParametersBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
/// Sets the `debug_validate_without_checkpoints` flag to be used in the [`Parameters`] being built.
|
||||
pub fn with_debug_validate_without_checkpoints(
|
||||
mut self,
|
||||
debug_validate_without_checkpoints: bool,
|
||||
) -> Self {
|
||||
self.debug_validate_without_checkpoints = debug_validate_without_checkpoints;
|
||||
self
|
||||
}
|
||||
|
||||
/// Converts the builder to a [`Parameters`] struct
|
||||
pub fn finish(self) -> Parameters {
|
||||
let Self {
|
||||
|
@ -250,6 +263,7 @@ impl ParametersBuilder {
|
|||
hrp_sapling_extended_full_viewing_key,
|
||||
hrp_sapling_payment_address,
|
||||
disable_pow,
|
||||
debug_validate_without_checkpoints,
|
||||
} = self;
|
||||
Parameters {
|
||||
network_name,
|
||||
|
@ -259,6 +273,7 @@ impl ParametersBuilder {
|
|||
hrp_sapling_extended_full_viewing_key,
|
||||
hrp_sapling_payment_address,
|
||||
disable_pow,
|
||||
debug_validate_without_checkpoints,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -289,6 +304,9 @@ pub struct Parameters {
|
|||
hrp_sapling_payment_address: String,
|
||||
/// A flag for disabling proof-of-work checks when Zebra is validating blocks
|
||||
disable_pow: bool,
|
||||
/// A flag for allowing Zebra to try contextually validating the first queued block
|
||||
/// for a given height below the mandatory checkpoint height.
|
||||
debug_validate_without_checkpoints: bool,
|
||||
}
|
||||
|
||||
impl Default for Parameters {
|
||||
|
@ -316,6 +334,7 @@ impl Parameters {
|
|||
..Self::build()
|
||||
.with_genesis_hash(REGTEST_GENESIS_HASH)
|
||||
.with_disable_pow(true)
|
||||
.with_debug_validate_without_checkpoints(true)
|
||||
.with_sapling_hrps(
|
||||
zp_constants::regtest::HRP_SAPLING_EXTENDED_SPENDING_KEY,
|
||||
zp_constants::regtest::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
|
||||
|
@ -344,6 +363,7 @@ impl Parameters {
|
|||
hrp_sapling_extended_full_viewing_key,
|
||||
hrp_sapling_payment_address,
|
||||
disable_pow,
|
||||
debug_validate_without_checkpoints,
|
||||
} = Self::new_regtest(ConfiguredActivationHeights::default());
|
||||
|
||||
self.network_name == network_name
|
||||
|
@ -352,6 +372,7 @@ impl Parameters {
|
|||
&& self.hrp_sapling_extended_full_viewing_key == hrp_sapling_extended_full_viewing_key
|
||||
&& self.hrp_sapling_payment_address == hrp_sapling_payment_address
|
||||
&& self.disable_pow == disable_pow
|
||||
&& self.debug_validate_without_checkpoints == debug_validate_without_checkpoints
|
||||
}
|
||||
|
||||
/// Returns the network name
|
||||
|
@ -388,4 +409,9 @@ impl Parameters {
|
|||
pub fn disable_pow(&self) -> bool {
|
||||
self.disable_pow
|
||||
}
|
||||
|
||||
/// Returns true if blocks should be contextually validated without checkpoints on this network
|
||||
pub fn debug_validate_without_checkpoints(&self) -> bool {
|
||||
self.debug_validate_without_checkpoints
|
||||
}
|
||||
}
|
||||
|
|
|
@ -777,6 +777,19 @@ where
|
|||
.hash(height)
|
||||
.expect("every checkpoint height must have a hash"),
|
||||
),
|
||||
// Contextually validate and commit the first queued block for a height below the mandatory checkpoint height if
|
||||
// `debug_validate_without_checkpoints` is true for this network.
|
||||
WaitingForBlocks if self.network.debug_validate_without_checkpoints() => {
|
||||
if let Some((height, hash)) = self
|
||||
.queued
|
||||
.first_key_value()
|
||||
.and_then(|(h, blocks)| blocks.first().map(|block| (*h, block.block.hash)))
|
||||
{
|
||||
(height, hash)
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
WaitingForBlocks => {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -369,9 +369,13 @@ pub fn init_checkpoint_list(config: Config, network: &Network) -> (CheckpointLis
|
|||
|
||||
let max_checkpoint_height = if config.checkpoint_sync {
|
||||
list.max_height()
|
||||
} else {
|
||||
} else if network.is_a_default_network() {
|
||||
list.min_height_in_range(network.mandatory_checkpoint_height()..)
|
||||
.expect("hardcoded checkpoint list extends past canopy activation")
|
||||
} else {
|
||||
// Allow for validating blocks below mandatory checkpoint height on configured Testnets and Regtest without
|
||||
// actually checking the checkpoints if checkpoint sync is disabled.
|
||||
network.mandatory_checkpoint_height()
|
||||
};
|
||||
|
||||
(list, max_checkpoint_height)
|
||||
|
|
|
@ -672,8 +672,8 @@ impl<'de> Deserialize<'de> for Config {
|
|||
network: network_kind,
|
||||
testnet_parameters,
|
||||
regtest_activation_heights,
|
||||
initial_mainnet_peers,
|
||||
initial_testnet_peers,
|
||||
mut initial_mainnet_peers,
|
||||
mut initial_testnet_peers,
|
||||
cache_dir,
|
||||
peerset_initial_target_size,
|
||||
crawl_new_peer_interval,
|
||||
|
@ -700,7 +700,11 @@ impl<'de> Deserialize<'de> for Config {
|
|||
let network = match (network_kind, testnet_parameters) {
|
||||
(NetworkKind::Mainnet, _) => Network::Mainnet,
|
||||
(NetworkKind::Testnet, None) => Network::new_default_testnet(),
|
||||
(NetworkKind::Regtest, _) => Network::new_regtest(regtest_activation_heights),
|
||||
(NetworkKind::Regtest, _) => {
|
||||
initial_mainnet_peers = Default::default();
|
||||
initial_testnet_peers = Default::default();
|
||||
Network::new_regtest(regtest_activation_heights)
|
||||
}
|
||||
(
|
||||
NetworkKind::Testnet,
|
||||
Some(DTestnetParameters {
|
||||
|
|
Loading…
Reference in New Issue