diff --git a/chain/src/pipe.rs b/chain/src/pipe.rs index b85d8cb1fd..f985d2f349 100644 --- a/chain/src/pipe.rs +++ b/chain/src/pipe.rs @@ -19,7 +19,6 @@ use crate::core::core::hash::Hashed; use crate::core::core::verifier_cache::VerifierCache; use crate::core::core::Committed; use crate::core::core::{Block, BlockHeader, BlockSums}; -use crate::core::global; use crate::core::pow; use crate::error::{Error, ErrorKind}; use crate::store; @@ -326,10 +325,7 @@ fn validate_header(header: &BlockHeader, ctx: &mut BlockContext<'_>) -> Result<( return Err(ErrorKind::InvalidBlockVersion(header.version).into()); } - // TODO: remove CI check from here somehow - if header.timestamp > Utc::now() + Duration::seconds(12 * (consensus::BLOCK_TIME_SEC as i64)) - && !global::is_automated_testing_mode() - { + if header.timestamp > Utc::now() + Duration::seconds(12 * (consensus::BLOCK_TIME_SEC as i64)) { // refuse blocks more than 12 blocks intervals in future (as in bitcoin) // TODO add warning in p2p code if local time is too different from peers return Err(ErrorKind::InvalidBlockTime.into()); @@ -358,10 +354,9 @@ fn validate_header(header: &BlockHeader, ctx: &mut BlockContext<'_>) -> Result<( return Err(ErrorKind::InvalidBlockHeight.into()); } - // TODO - get rid of the automated testing mode check here somehow - if header.timestamp <= prev.timestamp && !global::is_automated_testing_mode() { + if header.timestamp <= prev.timestamp { // prevent time warp attacks and some timestamp manipulations by forcing strict - // time progression (but not in CI mode) + // time progression return Err(ErrorKind::InvalidBlockTime.into()); } diff --git a/chain/tests/chain_test_helper.rs b/chain/tests/chain_test_helper.rs index 4d58fdeaff..96bd2d9b91 100644 --- a/chain/tests/chain_test_helper.rs +++ b/chain/tests/chain_test_helper.rs @@ -102,7 +102,7 @@ where let mut b = core::core::Block::new(&prev, vec![], next_header_info.clone().difficulty, reward) .unwrap(); - b.header.timestamp = prev.timestamp + Duration::seconds(160); + b.header.timestamp = prev.timestamp + Duration::seconds(60); b.header.pow.secondary_scaling = next_header_info.secondary_scaling; chain.set_txhashset_roots(&mut b).unwrap(); diff --git a/chain/tests/test_txhashset.rs b/chain/tests/test_txhashset.rs index b93a98adf0..618747f859 100644 --- a/chain/tests/test_txhashset.rs +++ b/chain/tests/test_txhashset.rs @@ -17,9 +17,7 @@ use grin_core as core; use grin_util as util; -use std::collections::HashSet; -use std::fs::{self, File, OpenOptions}; -use std::iter::FromIterator; +use std::fs::{self, File}; use std::path::{Path, PathBuf}; use std::sync::Arc; diff --git a/core/src/genesis.rs b/core/src/genesis.rs index be41a48dbc..d3584dd57f 100644 --- a/core/src/genesis.rs +++ b/core/src/genesis.rs @@ -39,7 +39,7 @@ pub fn genesis_dev() -> core::Block { core::Block::with_header(core::BlockHeader { height: 0, // previous: core::hash::Hash([0xff; 32]), - timestamp: Utc.ymd(1997, 8, 4).and_hms(0, 0, 0), + timestamp: global::get_genesis_timestamp(), pow: ProofOfWork { nonce: global::get_genesis_nonce(), ..Default::default() diff --git a/core/src/global.rs b/core/src/global.rs index 05be24fb71..fea66b11b1 100644 --- a/core/src/global.rs +++ b/core/src/global.rs @@ -31,7 +31,8 @@ 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 @@ -296,18 +297,6 @@ pub fn txhashset_archive_interval() -> u64 { } } -/// Are we in automated testing mode? -pub fn is_automated_testing_mode() -> bool { - let param_ref = CHAIN_TYPE.read(); - ChainTypes::AutomatedTesting == *param_ref -} - -/// Are we in user testing mode? -pub fn is_user_testing_mode() -> bool { - let param_ref = CHAIN_TYPE.read(); - ChainTypes::UserTesting == *param_ref -} - /// Are we in production mode? /// Production defined as a live public network, testnet[n] or mainnet. pub fn is_production_mode() -> bool { @@ -324,12 +313,6 @@ pub fn is_floonet() -> bool { ChainTypes::Floonet == *param_ref } -/// Are we for real? -pub fn is_mainnet() -> bool { - let param_ref = CHAIN_TYPE.read(); - ChainTypes::Mainnet == *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 @@ -348,10 +331,14 @@ pub fn get_genesis_nonce() -> u64 { } } -/// Short name representing the current chain type ("floo", "main", etc.) -pub fn chain_shortname() -> String { +/// Genesis block timestamp. Dependant on chain type. +pub fn get_genesis_timestamp() -> DateTime { let param_ref = CHAIN_TYPE.read(); - param_ref.shortname() + 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 diff --git a/core/src/pow.rs b/core/src/pow.rs index 314e81a1aa..60d33fef57 100644 --- a/core/src/pow.rs +++ b/core/src/pow.rs @@ -72,9 +72,6 @@ pub fn verify_size(bh: &BlockHeader) -> Result<(), Error> { /// Mines a genesis block using the internal miner pub fn mine_genesis_block() -> Result { let mut gen = genesis::genesis_dev(); - if global::is_user_testing_mode() || global::is_automated_testing_mode() { - gen.header.timestamp = Utc::now(); - } // total_difficulty on the genesis header *is* the difficulty of that block let genesis_difficulty = gen.header.pow.total_difficulty; @@ -97,11 +94,6 @@ pub fn pow_size( ) -> Result<(), Error> { let start_nonce = bh.pow.nonce; - // set the nonce for faster solution finding in user testing - if bh.height == 0 && global::is_user_testing_mode() { - bh.pow.nonce = global::get_genesis_nonce(); - } - // try to find a cuckoo cycle on that header hash loop { // if we found a cycle (not guaranteed) and the proof hash is higher that the diff --git a/p2p/src/protocol.rs b/p2p/src/protocol.rs index cfe5a910e9..9e08266fc4 100644 --- a/p2p/src/protocol.rs +++ b/p2p/src/protocol.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - use crate::conn::{Message, MessageHandler, Response, Tracker}; use crate::core::core::{self, hash::Hash, hash::Hashed, CompactBlock};