move genesis parameters to zebra-chain (#1151)

This commit is contained in:
Alfredo Garcia 2020-10-12 18:08:23 -03:00 committed by GitHub
parent c93f0b3a2e
commit c0a14ecc8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 16 deletions

View File

@ -12,9 +12,11 @@
//! Typically, consensus parameters are accessed via a function that takes a //! Typically, consensus parameters are accessed via a function that takes a
//! `Network` and `block::Height`. //! `Network` and `block::Height`.
mod genesis;
mod network; mod network;
mod network_upgrade; mod network_upgrade;
pub use genesis::*;
pub use network::Network; pub use network::Network;
pub use network_upgrade::*; pub use network_upgrade::*;

View File

@ -1,6 +1,6 @@
//! Genesis consensus parameters for each Zcash network. //! Genesis consensus parameters for each Zcash network.
use zebra_chain::{block, parameters::Network}; use crate::{block, parameters::Network};
/// The previous block hash for the genesis block. /// The previous block hash for the genesis block.
/// ///

View File

@ -30,11 +30,11 @@ use tower::{Service, ServiceExt};
use tracing::instrument; use tracing::instrument;
use zebra_chain::{ use zebra_chain::{
block::{self, Block}, block::{self, Block},
parameters::Network, parameters::{Network, GENESIS_PREVIOUS_BLOCK_HASH},
}; };
use zebra_state as zs; use zebra_state as zs;
use crate::{parameters, BoxError}; use crate::BoxError;
pub(crate) mod list; pub(crate) mod list;
mod types; mod types;
@ -568,7 +568,7 @@ where
// Since genesis blocks are hard-coded in zcashd, and not verified // Since genesis blocks are hard-coded in zcashd, and not verified
// like other blocks, the genesis parent hash is set by the // like other blocks, the genesis parent hash is set by the
// consensus parameters. // consensus parameters.
BeforeGenesis => parameters::GENESIS_PREVIOUS_BLOCK_HASH, BeforeGenesis => GENESIS_PREVIOUS_BLOCK_HASH,
InitialTip(hash) | PreviousCheckpoint(hash) => hash, InitialTip(hash) | PreviousCheckpoint(hash) => hash,
FinalCheckpoint => return, FinalCheckpoint => return,
}; };

View File

@ -8,7 +8,7 @@
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
use crate::{parameters, BoxError}; use crate::BoxError;
use std::{ use std::{
collections::{BTreeMap, HashSet}, collections::{BTreeMap, HashSet},
@ -17,7 +17,7 @@ use std::{
}; };
use zebra_chain::block; use zebra_chain::block;
use zebra_chain::parameters::Network; use zebra_chain::parameters::{genesis_hash, Network};
const MAINNET_CHECKPOINTS: &str = include_str!("main-checkpoints.txt"); const MAINNET_CHECKPOINTS: &str = include_str!("main-checkpoints.txt");
const TESTNET_CHECKPOINTS: &str = include_str!("test-checkpoints.txt"); const TESTNET_CHECKPOINTS: &str = include_str!("test-checkpoints.txt");
@ -73,7 +73,7 @@ impl CheckpointList {
}; };
match checkpoint_list.hash(block::Height(0)) { match checkpoint_list.hash(block::Height(0)) {
Some(hash) if hash == parameters::genesis_hash(network) => checkpoint_list, Some(hash) if hash == genesis_hash(network) => checkpoint_list,
Some(_) => { Some(_) => {
panic!("The hard-coded genesis checkpoint does not match the network genesis hash") panic!("The hard-coded genesis checkpoint does not match the network genesis hash")
} }
@ -102,8 +102,8 @@ impl CheckpointList {
// Check that the list starts with the correct genesis block // Check that the list starts with the correct genesis block
match checkpoints.iter().next() { match checkpoints.iter().next() {
Some((block::Height(0), hash)) Some((block::Height(0), hash))
if (hash == &parameters::genesis_hash(Network::Mainnet) if (hash == &genesis_hash(Network::Mainnet)
|| hash == &parameters::genesis_hash(Network::Testnet)) => {} || hash == &genesis_hash(Network::Testnet)) => {}
Some((block::Height(0), _)) => { Some((block::Height(0), _)) => {
Err("the genesis checkpoint does not match the Mainnet or Testnet genesis hash")? Err("the genesis checkpoint does not match the Mainnet or Testnet genesis hash")?
} }

View File

@ -12,11 +12,9 @@
//! Typically, consensus parameters are accessed via a function that takes a //! Typically, consensus parameters are accessed via a function that takes a
//! `Network` and `block::Height`. //! `Network` and `block::Height`.
pub mod genesis;
pub mod minimum_difficulty; pub mod minimum_difficulty;
pub mod subsidy; pub mod subsidy;
pub use genesis::*;
pub use minimum_difficulty::*; pub use minimum_difficulty::*;
pub use subsidy::*; pub use subsidy::*;

View File

@ -6,7 +6,7 @@ use tracing::trace;
use zebra_chain::serialization::{ZcashDeserialize, ZcashSerialize}; use zebra_chain::serialization::{ZcashDeserialize, ZcashSerialize};
use zebra_chain::{ use zebra_chain::{
block::{self, Block}, block::{self, Block},
parameters::Network, parameters::{Network, GENESIS_PREVIOUS_BLOCK_HASH},
}; };
use crate::{BoxError, Config, HashOrHeight, QueuedBlock}; use crate::{BoxError, Config, HashOrHeight, QueuedBlock};
@ -89,7 +89,7 @@ impl FinalizedState {
.expect("inability to look up tip is unrecoverable") .expect("inability to look up tip is unrecoverable")
.map(|(_, hash)| hash) .map(|(_, hash)| hash)
// if the state is empty, return the genesis previous block hash // if the state is empty, return the genesis previous block hash
.unwrap_or(block::Hash([0; 32])) .unwrap_or(GENESIS_PREVIOUS_BLOCK_HASH)
} }
/// Returns the height of the current finalized tip block. /// Returns the height of the current finalized tip block.

View File

@ -11,9 +11,9 @@ use tracing_futures::Instrument;
use zebra_chain::{ use zebra_chain::{
block::{self, Block}, block::{self, Block},
parameters::Network, parameters::{genesis_hash, Network},
}; };
use zebra_consensus::{checkpoint, parameters}; use zebra_consensus::checkpoint;
use zebra_network as zn; use zebra_network as zn;
use zebra_state as zs; use zebra_state as zs;
@ -162,7 +162,7 @@ where
verifier, verifier,
prospective_tips: HashSet::new(), prospective_tips: HashSet::new(),
pending_blocks: Box::pin(FuturesUnordered::new()), pending_blocks: Box::pin(FuturesUnordered::new()),
genesis_hash: parameters::genesis_hash(chain), genesis_hash: genesis_hash(chain),
} }
} }