Skip to content

Commit

Permalink
cleanup and simplify how we generate the genesis block in user_testin…
Browse files Browse the repository at this point in the history
…g (and automated_testing) modes (#2986)
  • Loading branch information
antiochp authored Aug 1, 2019
1 parent aa5c428 commit 4bd3aa1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 36 deletions.
6 changes: 2 additions & 4 deletions core/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use chrono::prelude::{TimeZone, Utc};

use crate::core;
use crate::global;
use crate::pow::{Difficulty, Proof, ProofOfWork};
use crate::util;
use crate::util::secp::constants::SINGLE_BULLET_PROOF_SIZE;
Expand All @@ -38,10 +37,9 @@ use crate::keychain::BlindingFactor;
pub fn genesis_dev() -> core::Block {
core::Block::with_header(core::BlockHeader {
height: 0,
// previous: core::hash::Hash([0xff; 32]),
timestamp: global::get_genesis_timestamp(),
timestamp: Utc.ymd(1997, 8, 4).and_hms(0, 0, 0),
pow: ProofOfWork {
nonce: global::get_genesis_nonce(),
nonce: 0,
..Default::default()
},
..Default::default()
Expand Down
30 changes: 0 additions & 30 deletions core/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ use crate::pow::{
/// different sets of parameters for different purposes,
/// e.g. CI, User testing, production values
use crate::util::RwLock;
use chrono::prelude::{TimeZone, Utc};
use chrono::{DateTime, Duration};
/// Define these here, as they should be developer-set, not really tweakable
/// by users
Expand Down Expand Up @@ -313,34 +311,6 @@ pub fn is_floonet() -> bool {
ChainTypes::Floonet == *param_ref
}

/// Helper function to get a nonce known to create a valid POW on
/// the genesis block, to prevent it taking ages. Should be fine for now
/// as the genesis block POW solution turns out to be the same for every new
/// block chain at the moment
pub fn get_genesis_nonce() -> u64 {
let param_ref = CHAIN_TYPE.read();
match *param_ref {
// won't make a difference
ChainTypes::AutomatedTesting => 0,
// Magic nonce for current genesis block at cuckatoo15
ChainTypes::UserTesting => 27944,
// Placeholder, obviously not the right value
ChainTypes::Floonet => 0,
// Placeholder, obviously not the right value
ChainTypes::Mainnet => 0,
}
}

/// Genesis block timestamp. Dependant on chain type.
pub fn get_genesis_timestamp() -> DateTime<Utc> {
let param_ref = CHAIN_TYPE.read();
match *param_ref {
ChainTypes::UserTesting => Utc::now(),
ChainTypes::AutomatedTesting => Utc::now() - Duration::minutes(60),
_ => Utc.ymd(1997, 8, 4).and_hms(0, 0, 0),
}
}

/// Converts an iterator of block difficulty data to more a more manageable
/// vector and pads if needed (which will) only be needed for the first few
/// blocks after genesis
Expand Down
4 changes: 2 additions & 2 deletions servers/src/grin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ impl Server {
));

let genesis = match config.chain_type {
global::ChainTypes::AutomatedTesting => genesis::genesis_dev(),
global::ChainTypes::UserTesting => genesis::genesis_dev(),
global::ChainTypes::AutomatedTesting => pow::mine_genesis_block().unwrap(),
global::ChainTypes::UserTesting => pow::mine_genesis_block().unwrap(),
global::ChainTypes::Floonet => genesis::genesis_floo(),
global::ChainTypes::Mainnet => genesis::genesis_main(),
};
Expand Down

0 comments on commit 4bd3aa1

Please sign in to comment.