Genesis block for known chains, mine dev chains (#269)

Renamed mining parameter mode to chain type, with existing types
of CI testing, user testing, testnet1 or mainnet. The public
chains (testnet1 and mainnet) come with their fully pre-defined
genesis block.

Still need to set the nonce and cycle for testnet1 genesis.
This commit is contained in:
Ignotus Peverell 2017-11-15 16:49:15 -05:00 committed by GitHub
parent 6fb085a823
commit 91fdaa8320
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 167 additions and 190 deletions

View file

@ -33,7 +33,7 @@ use sumtree;
use types::*; use types::*;
use util::LOGGER; use util::LOGGER;
use core::global::{MiningParameterMode, MINING_PARAMETER_MODE}; use core::global;
const MAX_ORPHANS: usize = 20; const MAX_ORPHANS: usize = 20;
@ -184,16 +184,14 @@ impl Chain {
} }
fn ctx_from_head(&self, head: Tip, opts: Options) -> pipe::BlockContext { fn ctx_from_head(&self, head: Tip, opts: Options) -> pipe::BlockContext {
let opts_in = opts; let opts = if global::is_production_mode() {
let param_ref = MINING_PARAMETER_MODE.read().unwrap(); opts
let opts_in = match *param_ref { } else {
MiningParameterMode::AutomatedTesting => opts_in | EASY_POW, opts | EASY_POW
MiningParameterMode::UserTesting => opts_in | EASY_POW,
MiningParameterMode::Production => opts_in,
}; };
pipe::BlockContext { pipe::BlockContext {
opts: opts_in, opts: opts,
store: self.store.clone(), store: self.store.clone(),
head: head, head: head,
pow_verifier: self.pow_verifier, pow_verifier: self.pow_verifier,

View file

@ -30,7 +30,7 @@ use core::core::hash::Hashed;
use core::core::target::Difficulty; use core::core::target::Difficulty;
use core::consensus; use core::consensus;
use core::global; use core::global;
use core::global::MiningParameterMode; use core::global::ChainTypes;
use keychain::Keychain; use keychain::Keychain;
@ -43,7 +43,7 @@ fn clean_output_dir(dir_name: &str) {
fn setup(dir_name: &str) -> Chain { fn setup(dir_name: &str) -> Chain {
let _ = env_logger::init(); let _ = env_logger::init();
clean_output_dir(dir_name); clean_output_dir(dir_name);
global::set_mining_mode(MiningParameterMode::AutomatedTesting); global::set_mining_mode(ChainTypes::AutomatedTesting);
let mut genesis_block = None; let mut genesis_block = None;
if !chain::Chain::chain_exists(dir_name.to_string()) { if !chain::Chain::chain_exists(dir_name.to_string()) {
genesis_block = pow::mine_genesis_block(None); genesis_block = pow::mine_genesis_block(None);

View file

@ -28,7 +28,7 @@ use core::core::build;
use core::core::transaction; use core::core::transaction;
use core::consensus; use core::consensus;
use core::global; use core::global;
use core::global::MiningParameterMode; use core::global::ChainTypes;
use keychain::Keychain; use keychain::Keychain;
@ -42,7 +42,7 @@ fn clean_output_dir(dir_name: &str) {
fn test_coinbase_maturity() { fn test_coinbase_maturity() {
let _ = env_logger::init(); let _ = env_logger::init();
clean_output_dir(".grin"); clean_output_dir(".grin");
global::set_mining_mode(MiningParameterMode::AutomatedTesting); global::set_mining_mode(ChainTypes::AutomatedTesting);
let mut genesis_block = None; let mut genesis_block = None;
if !chain::Chain::chain_exists(".grin".to_string()) { if !chain::Chain::chain_exists(".grin".to_string()) {

View file

@ -17,18 +17,16 @@
use time; use time;
use core; use core;
use consensus::MINIMUM_DIFFICULTY; use consensus;
use core::target::Difficulty; use core::target::Difficulty;
use global; use global;
/// Genesis block definition. It has no rewards, no inputs, no outputs, no /// Genesis block definition for development networks. The proof of work size
/// fees and a height of zero. /// is small enough to mine it on the fly, so it does not contain its own
pub fn genesis() -> core::Block { /// proof of work solution. Can also be easily mutated for different tests.
let proof_size = global::proofsize(); pub fn genesis_dev() -> core::Block {
let empty_hash = core::hash::Hash([0x0; 32]);
core::Block { core::Block {
header: core::BlockHeader { header: core::BlockHeader {
version: 1,
height: 0, height: 0,
previous: core::hash::Hash([0xff; 32]), previous: core::hash::Hash([0xff; 32]),
timestamp: time::Tm { timestamp: time::Tm {
@ -37,13 +35,56 @@ pub fn genesis() -> core::Block {
tm_mday: 4, tm_mday: 4,
..time::empty_tm() ..time::empty_tm()
}, },
difficulty: Difficulty::from_num(MINIMUM_DIFFICULTY),
total_difficulty: Difficulty::from_num(MINIMUM_DIFFICULTY),
utxo_root: empty_hash,
range_proof_root: empty_hash,
kernel_root: empty_hash,
nonce: global::get_genesis_nonce(), nonce: global::get_genesis_nonce(),
pow: core::Proof::zero(proof_size), // TODO get actual PoW solution ..Default::default()
},
inputs: vec![],
outputs: vec![],
kernels: vec![],
}
}
/// First testnet genesis block, still subject to change (especially the date,
/// will hopefully come before Christmas).
pub fn genesis_testnet1() -> core::Block {
core::Block {
header: core::BlockHeader {
height: 0,
previous: core::hash::Hash([0xff; 32]),
timestamp: time::Tm {
tm_year: 2017 - 1900,
tm_mon: 12,
tm_mday: 25,
..time::empty_tm()
},
nonce: 1,
pow: core::Proof::zero(consensus::PROOFSIZE),
..Default::default()
},
inputs: vec![],
outputs: vec![],
kernels: vec![],
}
}
/// Placeholder for mainnet genesis block, will definitely change before
/// release so no use trying to pre-mine it.
pub fn genesis_main() -> core::Block {
core::Block {
header: core::BlockHeader {
height: 0,
previous: core::hash::Hash([0xff; 32]),
timestamp: time::Tm {
tm_year: 2018 - 1900,
tm_mon: 7,
tm_mday: 14,
..time::empty_tm()
},
difficulty: Difficulty::from_num(1000),
total_difficulty: Difficulty::from_num(1000),
nonce: global::get_genesis_nonce(),
pow: core::Proof::zero(consensus::PROOFSIZE),
..Default::default()
}, },
inputs: vec![], inputs: vec![],
outputs: vec![], outputs: vec![],

View file

@ -47,77 +47,85 @@ pub const AUTOMATED_TESTING_COINBASE_MATURITY: u64 = 3;
/// User testing coinbase maturity /// User testing coinbase maturity
pub const USER_TESTING_COINBASE_MATURITY: u64 = 3; pub const USER_TESTING_COINBASE_MATURITY: u64 = 3;
/// Mining parameter modes /// Types of chain a server can run with, dictates the genesis block and
/// and mining parameters used.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum MiningParameterMode { pub enum ChainTypes {
/// For CI testing /// For CI testing
AutomatedTesting, AutomatedTesting,
/// For User testing /// For User testing
UserTesting, UserTesting,
/// For production, use the values in consensus.rs /// First test network
Production, Testnet1,
/// Main production network
Mainnet,
} }
lazy_static!{ lazy_static!{
/// The mining parameter mode /// The mining parameter mode
pub static ref MINING_PARAMETER_MODE: RwLock<MiningParameterMode> = pub static ref CHAIN_TYPE: RwLock<ChainTypes> =
RwLock::new(MiningParameterMode::Production); RwLock::new(ChainTypes::Mainnet);
} }
/// Set the mining mode /// Set the mining mode
pub fn set_mining_mode(mode: MiningParameterMode) { pub fn set_mining_mode(mode: ChainTypes) {
let mut param_ref = MINING_PARAMETER_MODE.write().unwrap(); let mut param_ref = CHAIN_TYPE.write().unwrap();
*param_ref = mode; *param_ref = mode;
} }
/// The sizeshift /// The sizeshift
pub fn sizeshift() -> u8 { pub fn sizeshift() -> u8 {
let param_ref = MINING_PARAMETER_MODE.read().unwrap(); let param_ref = CHAIN_TYPE.read().unwrap();
match *param_ref { match *param_ref {
MiningParameterMode::AutomatedTesting => AUTOMATED_TESTING_SIZESHIFT, ChainTypes::AutomatedTesting => AUTOMATED_TESTING_SIZESHIFT,
MiningParameterMode::UserTesting => USER_TESTING_SIZESHIFT, ChainTypes::UserTesting => USER_TESTING_SIZESHIFT,
MiningParameterMode::Production => DEFAULT_SIZESHIFT, ChainTypes::Testnet1 => DEFAULT_SIZESHIFT,
ChainTypes::Mainnet => DEFAULT_SIZESHIFT,
} }
} }
/// The proofsize /// The proofsize
pub fn proofsize() -> usize { pub fn proofsize() -> usize {
let param_ref = MINING_PARAMETER_MODE.read().unwrap(); let param_ref = CHAIN_TYPE.read().unwrap();
match *param_ref { match *param_ref {
MiningParameterMode::AutomatedTesting => AUTOMATED_TESTING_PROOF_SIZE, ChainTypes::AutomatedTesting => AUTOMATED_TESTING_PROOF_SIZE,
MiningParameterMode::UserTesting => USER_TESTING_PROOF_SIZE, ChainTypes::UserTesting => USER_TESTING_PROOF_SIZE,
MiningParameterMode::Production => PROOFSIZE, ChainTypes::Testnet1 => PROOFSIZE,
ChainTypes::Mainnet => PROOFSIZE,
} }
} }
/// Coinbase maturity /// Coinbase maturity
pub fn coinbase_maturity() -> u64 { pub fn coinbase_maturity() -> u64 {
let param_ref = MINING_PARAMETER_MODE.read().unwrap(); let param_ref = CHAIN_TYPE.read().unwrap();
match *param_ref { match *param_ref {
MiningParameterMode::AutomatedTesting => AUTOMATED_TESTING_COINBASE_MATURITY, ChainTypes::AutomatedTesting => AUTOMATED_TESTING_COINBASE_MATURITY,
MiningParameterMode::UserTesting => USER_TESTING_COINBASE_MATURITY, ChainTypes::UserTesting => USER_TESTING_COINBASE_MATURITY,
MiningParameterMode::Production => COINBASE_MATURITY, ChainTypes::Testnet1 => COINBASE_MATURITY,
ChainTypes::Mainnet => COINBASE_MATURITY,
} }
} }
/// Are we in automated testing mode? /// Are we in automated testing mode?
pub fn is_automated_testing_mode() -> bool { pub fn is_automated_testing_mode() -> bool {
let param_ref = MINING_PARAMETER_MODE.read().unwrap(); let param_ref = CHAIN_TYPE.read().unwrap();
MiningParameterMode::AutomatedTesting == *param_ref ChainTypes::AutomatedTesting == *param_ref
} }
/// Are we in user testing mode? /// Are we in user testing mode?
pub fn is_user_testing_mode() -> bool { pub fn is_user_testing_mode() -> bool {
let param_ref = MINING_PARAMETER_MODE.read().unwrap(); let param_ref = CHAIN_TYPE.read().unwrap();
MiningParameterMode::UserTesting == *param_ref ChainTypes::UserTesting == *param_ref
} }
/// Are we in production mode? /// Are we in production mode (a live public network)?
pub fn is_production_mode() -> bool { pub fn is_production_mode() -> bool {
let param_ref = MINING_PARAMETER_MODE.read().unwrap(); let param_ref = CHAIN_TYPE.read().unwrap();
MiningParameterMode::Production == *param_ref ChainTypes::Testnet1 == *param_ref ||
ChainTypes::Mainnet == *param_ref
} }
@ -126,78 +134,14 @@ pub fn is_production_mode() -> bool {
/// as the genesis block POW solution turns out to be the same for every new /// as the genesis block POW solution turns out to be the same for every new
/// block chain /// block chain
/// at the moment /// at the moment
pub fn get_genesis_nonce() -> u64 { pub fn get_genesis_nonce() -> u64 {
let param_ref = MINING_PARAMETER_MODE.read().unwrap(); let param_ref = CHAIN_TYPE.read().unwrap();
match *param_ref { match *param_ref {
// won't make a difference // won't make a difference
MiningParameterMode::AutomatedTesting => 0, ChainTypes::AutomatedTesting => 0,
// Magic nonce for current genesis block at cuckoo16 // Magic nonce for current genesis block at cuckoo16
MiningParameterMode::UserTesting => 27944, ChainTypes::UserTesting => 27944,
// Magic nonce for current genesis at cuckoo30
MiningParameterMode::Production => 1429942738856787200,
}
}
/// Returns the genesis POW for cuckoo16 (UserTesting) and cuckoo30 (Production) _ => panic!("Pre-set"),
pub fn get_genesis_pow() -> [u32; 42] {
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
match *param_ref {
// pow solution for genesis block at cuckoo16
MiningParameterMode::UserTesting => [
0x37f, 0x9f6, 0x136d, 0x13d3, 0x155e, 0x16dd, 0x186b, 0x1b11, 0x208e, 0x23cd,
0x24d1, 0x278f, 0x2a1b, 0x2a28, 0x2a44, 0x2ae2, 0x2c37, 0x36af, 0x391d, 0x3c2e,
0x3d9a, 0x3f00, 0x429f, 0x45b2, 0x47ce, 0x47f1, 0x492f, 0x4bd8, 0x4fee, 0x51f0,
0x5207, 0x58e5, 0x5905, 0x5aca, 0x5dfb, 0x628d, 0x7310, 0x75e5, 0x76d4, 0x76df,
0x77bd, 0x7ab9
],
// pow solution for genesis block at cuckoo30
// TODO - likely this is no longer correct (block header changes)
MiningParameterMode::Production => [
7444824,
11926557,
28520390,
30594072,
50854023,
52797085,
57882033,
59816511,
61404804,
84947619,
87779345,
115270337,
162618676,
166860710,
178656003,
178971372,
200454733,
209197630,
221231015,
228598741,
241012783,
245401183,
279080304,
295848517,
327300943,
329741709,
366394532,
382493153,
389329248,
404353381,
406012911,
418813499,
426573907,
452566575,
456930760,
463021458,
474340589,
476248039,
478197093,
487576917,
495653489,
501862896,
],
// TODO - for completeness do we provide one here for AutomatedTesting?
_ => panic!("unexpected"),
} }
} }

View file

@ -32,13 +32,13 @@ seeding_type = "None"
#if seeding_type = List, the list of peers to connect to. #if seeding_type = List, the list of peers to connect to.
#seeds = ["192.168.0.1:8080","192.168.0.2:8080"] #seeds = ["192.168.0.1:8080","192.168.0.2:8080"]
#The mining parameter mode, which defines the set of cuckoo parameters #The chain type, which defines the genesis block and the set of cuckoo
#used for mining. Can be: #parameters used for mining. Can be:
#AutomatedTesting - For CI builds and instant blockchain creation #AutomatedTesting - For CI builds and instant blockchain creation
#UserTesting - For regular user testing (cuckoo 16) #UserTesting - For regular user testing (cuckoo 16)
#Production - Full production cuckoo parameter (cuckoo 30) #Testnet1 - Full production cuckoo parameter (cuckoo 30)
mining_parameter_mode = "UserTesting" chain_type = "UserTesting"
#7 = Bit flags for FULL_NODE, this structure needs to be changed #7 = Bit flags for FULL_NODE, this structure needs to be changed
#internally to make it more configurable #internally to make it more configurable

View file

@ -21,6 +21,7 @@ use core::core::{self, Output};
use core::core::block::BlockHeader; use core::core::block::BlockHeader;
use core::core::hash::{Hash, Hashed}; use core::core::hash::{Hash, Hashed};
use core::core::target::Difficulty; use core::core::target::Difficulty;
use core::global;
use p2p::{self, NetAdapter, PeerData, PeerStore, Server, State}; use p2p::{self, NetAdapter, PeerData, PeerStore, Server, State};
use pool; use pool;
use util::secp::pedersen::Commitment; use util::secp::pedersen::Commitment;
@ -28,7 +29,6 @@ use util::OneTime;
use store; use store;
use sync; use sync;
use util::LOGGER; use util::LOGGER;
use core::global::{MiningParameterMode, MINING_PARAMETER_MODE};
/// Implementation of the NetAdapter for the blockchain. Gets notified when new /// Implementation of the NetAdapter for the blockchain. Gets notified when new
/// blocks and transactions are received and forwards to the chain and pool /// blocks and transactions are received and forwards to the chain and pool
@ -286,11 +286,10 @@ impl NetToChainAdapter {
} else { } else {
chain::NONE chain::NONE
}; };
let param_ref = MINING_PARAMETER_MODE.read().unwrap(); let opts = if global::is_production_mode() {
let opts = match *param_ref { opts
MiningParameterMode::AutomatedTesting => opts | chain::EASY_POW, } else {
MiningParameterMode::UserTesting => opts | chain::EASY_POW, opts | chain::EASY_POW
MiningParameterMode::Production => opts,
}; };
opts opts
} }

View file

@ -28,6 +28,7 @@ use tokio_timer::Timer;
use adapters::*; use adapters::*;
use api; use api;
use chain; use chain;
use core::{global, genesis};
use miner; use miner;
use p2p; use p2p;
use pool; use pool;
@ -37,7 +38,6 @@ use types::*;
use pow; use pow;
use util::LOGGER; use util::LOGGER;
use core::global;
/// Grin server holding internal structures. /// Grin server holding internal structures.
pub struct Server { pub struct Server {
@ -91,7 +91,12 @@ impl Server {
let mut genesis_block = None; let mut genesis_block = None;
if !chain::Chain::chain_exists(config.db_root.clone()) { if !chain::Chain::chain_exists(config.db_root.clone()) {
let chain_type = config.chain_type.clone().unwrap();
if chain_type == global::ChainTypes::Testnet1 {
genesis_block = Some(genesis::genesis_testnet1());
} else {
genesis_block = pow::mine_genesis_block(config.mining_config.clone()); genesis_block = pow::mine_genesis_block(config.mining_config.clone());
}
} }
let shared_chain = Arc::new(chain::Chain::init( let shared_chain = Arc::new(chain::Chain::init(

View file

@ -21,7 +21,7 @@ use pool;
use store; use store;
use pow; use pow;
use wallet; use wallet;
use core::global::MiningParameterMode; use core::global::ChainTypes;
/// Error type wrapping underlying module errors. /// Error type wrapping underlying module errors.
#[derive(Debug)] #[derive(Debug)]
@ -91,8 +91,8 @@ pub struct ServerConfig {
/// Network address for the Rest API HTTP server. /// Network address for the Rest API HTTP server.
pub api_http_addr: String, pub api_http_addr: String,
/// Setup the server for tests and testnet /// Setup the server for tests, testnet or mainnet
pub mining_parameter_mode: Option<MiningParameterMode>, pub chain_type: Option<ChainTypes>,
/// Method used to get the list of seed nodes for initial bootstrap. /// Method used to get the list of seed nodes for initial bootstrap.
pub seeding_type: Seeding, pub seeding_type: Seeding,
@ -125,7 +125,7 @@ impl Default for ServerConfig {
seeds: None, seeds: None,
p2p_config: Some(p2p::P2PConfig::default()), p2p_config: Some(p2p::P2PConfig::default()),
mining_config: Some(pow::types::MinerConfig::default()), mining_config: Some(pow::types::MinerConfig::default()),
mining_parameter_mode: Some(MiningParameterMode::Production), chain_type: Some(ChainTypes::Testnet1),
pool_config: pool::PoolConfig::default(), pool_config: pool::PoolConfig::default(),
} }
} }

View file

@ -41,7 +41,7 @@ use tokio_timer::Timer;
use core::consensus; use core::consensus;
use core::global; use core::global;
use core::global::{MiningParameterMode, MINING_PARAMETER_MODE}; use core::global::ChainTypes;
use wallet::WalletConfig; use wallet::WalletConfig;
use framework::{LocalServerContainer, LocalServerContainerConfig, LocalServerContainerPool, use framework::{LocalServerContainer, LocalServerContainerConfig, LocalServerContainerPool,
@ -51,7 +51,7 @@ use framework::{LocalServerContainer, LocalServerContainerConfig, LocalServerCon
/// Block and mining into a wallet for a bit /// Block and mining into a wallet for a bit
#[test] #[test]
fn basic_genesis_mine() { fn basic_genesis_mine() {
global::set_mining_mode(MiningParameterMode::AutomatedTesting); global::set_mining_mode(ChainTypes::AutomatedTesting);
let test_name_dir = "genesis_mine"; let test_name_dir = "genesis_mine";
framework::clean_all_output(test_name_dir); framework::clean_all_output(test_name_dir);
@ -80,7 +80,7 @@ fn basic_genesis_mine() {
/// messages they all end up connected. /// messages they all end up connected.
#[test] #[test]
fn simulate_seeding() { fn simulate_seeding() {
global::set_mining_mode(MiningParameterMode::AutomatedTesting); global::set_mining_mode(ChainTypes::AutomatedTesting);
let test_name_dir = "simulate_seeding"; let test_name_dir = "simulate_seeding";
framework::clean_all_output(test_name_dir); framework::clean_all_output(test_name_dir);
@ -133,7 +133,7 @@ fn simulate_seeding() {
//#[test] //#[test]
#[allow(dead_code)] #[allow(dead_code)]
fn simulate_parallel_mining() { fn simulate_parallel_mining() {
global::set_mining_mode(MiningParameterMode::AutomatedTesting); global::set_mining_mode(ChainTypes::AutomatedTesting);
let test_name_dir = "simulate_parallel_mining"; let test_name_dir = "simulate_parallel_mining";
// framework::clean_all_output(test_name_dir); // framework::clean_all_output(test_name_dir);
@ -187,7 +187,7 @@ fn simulate_parallel_mining() {
#[test] #[test]
fn a_simulate_block_propagation() { fn a_simulate_block_propagation() {
util::init_test_logger(); util::init_test_logger();
global::set_mining_mode(MiningParameterMode::AutomatedTesting); global::set_mining_mode(ChainTypes::AutomatedTesting);
let test_name_dir = "grin-prop"; let test_name_dir = "grin-prop";
framework::clean_all_output(test_name_dir); framework::clean_all_output(test_name_dir);
@ -246,7 +246,7 @@ fn a_simulate_block_propagation() {
#[test] #[test]
fn simulate_full_sync() { fn simulate_full_sync() {
util::init_test_logger(); util::init_test_logger();
global::set_mining_mode(MiningParameterMode::AutomatedTesting); global::set_mining_mode(ChainTypes::AutomatedTesting);
let test_name_dir = "grin-sync"; let test_name_dir = "grin-sync";
framework::clean_all_output(test_name_dir); framework::clean_all_output(test_name_dir);

View file

@ -608,7 +608,7 @@ mod tests {
use keychain::Keychain; use keychain::Keychain;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use blake2; use blake2;
use core::global::MiningParameterMode; use core::global::ChainTypes;
use core::core::SwitchCommitHash; use core::core::SwitchCommitHash;
macro_rules! expect_output_parent { macro_rules! expect_output_parent {
@ -795,7 +795,7 @@ mod tests {
#[test] #[test]
fn test_immature_coinbase() { fn test_immature_coinbase() {
global::set_mining_mode(MiningParameterMode::AutomatedTesting); global::set_mining_mode(ChainTypes::AutomatedTesting);
let mut dummy_chain = DummyChainImpl::new(); let mut dummy_chain = DummyChainImpl::new();
let coinbase_output = test_coinbase_output(15); let coinbase_output = test_coinbase_output(15);
dummy_chain.update_utxo_set(DummyUtxoSet::empty().with_output(coinbase_output)); dummy_chain.update_utxo_set(DummyUtxoSet::empty().with_output(coinbase_output));

View file

@ -94,12 +94,10 @@ pub fn pow20<T: MiningWorker>(
} }
/// Mines a genesis block, using the config specified miner if specified. /// Mines a genesis block, using the config specified miner if specified.
/// Otherwise, /// Otherwise, uses the internal miner
/// uses the internal miner
///
pub fn mine_genesis_block(miner_config: Option<types::MinerConfig>) -> Option<core::core::Block> { pub fn mine_genesis_block(miner_config: Option<types::MinerConfig>) -> Option<core::core::Block> {
info!(util::LOGGER, "Genesis block not found, initializing..."); info!(util::LOGGER, "Genesis block not found, initializing...");
let mut gen = genesis::genesis(); let mut gen = genesis::genesis_dev();
let diff = gen.header.difficulty.clone(); let diff = gen.header.difficulty.clone();
let sz = global::sizeshift() as u32; let sz = global::sizeshift() as u32;
@ -120,9 +118,8 @@ pub fn mine_genesis_block(miner_config: Option<types::MinerConfig>) -> Option<co
} }
/// Runs a proof of work computation over the provided block using the provided /// Runs a proof of work computation over the provided block using the provided
/// Mining Worker, /// Mining Worker, until the required difficulty target is reached. May take a
/// until the required difficulty target is reached. May take a while for a low /// while for a low target...
/// target...
pub fn pow_size<T: MiningWorker + ?Sized>( pub fn pow_size<T: MiningWorker + ?Sized>(
miner: &mut T, miner: &mut T,
bh: &mut BlockHeader, bh: &mut BlockHeader,
@ -131,15 +128,9 @@ pub fn pow_size<T: MiningWorker + ?Sized>(
) -> Result<(), Error> { ) -> Result<(), Error> {
let start_nonce = bh.nonce; let start_nonce = bh.nonce;
// try the pre-mined solution first for the genesis block (height 0) // set the nonce for faster solution finding in user testing
if bh.height == 0 { if bh.height == 0 && global::is_user_testing_mode() {
if global::is_production_mode() || global::is_user_testing_mode() { bh.nonce = global::get_genesis_nonce();
let p = Proof::new(global::get_genesis_pow().to_vec());
if p.clone().to_difficulty() >= diff {
bh.pow = p;
return Ok(());
}
}
} }
// try to find a cuckoo cycle on that header hash // try to find a cuckoo cycle on that header hash
@ -176,14 +167,13 @@ mod test {
use core::core::target::Difficulty; use core::core::target::Difficulty;
use core::genesis; use core::genesis;
use core::consensus::MINIMUM_DIFFICULTY; use core::consensus::MINIMUM_DIFFICULTY;
use core::global::MiningParameterMode; use core::global::ChainTypes;
#[test] #[test]
fn genesis_pow() { fn genesis_pow() {
global::set_mining_mode(MiningParameterMode::AutomatedTesting); global::set_mining_mode(ChainTypes::AutomatedTesting);
let mut b = genesis::genesis(); let mut b = genesis::genesis_dev();
b.header.nonce = 310; b.header.nonce = 485;
let mut internal_miner = cuckoo::Miner::new( let mut internal_miner = cuckoo::Miner::new(
consensus::EASINESS, consensus::EASINESS,
global::sizeshift() as u32, global::sizeshift() as u32,

View file

@ -57,7 +57,7 @@ fn start_from_config_file(mut global_config: GlobalConfig) {
.unwrap() .unwrap()
.server .server
.clone() .clone()
.mining_parameter_mode .chain_type
.unwrap(), .unwrap(),
); );
@ -102,7 +102,7 @@ fn main() {
.unwrap() .unwrap()
.server .server
.clone() .clone()
.mining_parameter_mode .chain_type
.unwrap(), .unwrap(),
); );
} else { } else {