2017-08-09 19:40:23 +03:00
|
|
|
// Copyright 2017 The Grin Developers
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
//! Values that should be shared across all modules, without necessarily
|
|
|
|
//! having to pass them all over the place, but aren't consensus values.
|
|
|
|
//! should be used sparingly.
|
|
|
|
|
|
|
|
/// An enum collecting sets of parameters used throughout the
|
|
|
|
/// code wherever mining is needed. This should allow for
|
|
|
|
/// different sets of parameters for different purposes,
|
|
|
|
/// e.g. CI, User testing, production values
|
|
|
|
|
2017-09-29 21:44:25 +03:00
|
|
|
use std::sync::RwLock;
|
2017-08-09 19:40:23 +03:00
|
|
|
use consensus::PROOFSIZE;
|
|
|
|
use consensus::DEFAULT_SIZESHIFT;
|
|
|
|
|
|
|
|
/// Define these here, as they should be developer-set, not really tweakable
|
|
|
|
/// by users
|
|
|
|
|
2017-08-10 03:54:10 +03:00
|
|
|
/// Automated testing sizeshift
|
2017-09-29 21:44:25 +03:00
|
|
|
pub const AUTOMATED_TESTING_SIZESHIFT: u8 = 10;
|
2017-08-09 19:40:23 +03:00
|
|
|
|
2017-08-10 03:54:10 +03:00
|
|
|
/// Automated testing proof size
|
2017-09-29 21:44:25 +03:00
|
|
|
pub const AUTOMATED_TESTING_PROOF_SIZE: usize = 4;
|
2017-08-09 19:40:23 +03:00
|
|
|
|
2017-08-10 03:54:10 +03:00
|
|
|
/// User testing sizeshift
|
2017-09-29 21:44:25 +03:00
|
|
|
pub const USER_TESTING_SIZESHIFT: u8 = 16;
|
2017-08-09 19:40:23 +03:00
|
|
|
|
2017-08-10 03:54:10 +03:00
|
|
|
/// User testing proof size
|
2017-09-29 21:44:25 +03:00
|
|
|
pub const USER_TESTING_PROOF_SIZE: usize = 42;
|
2017-08-09 19:40:23 +03:00
|
|
|
|
2017-08-10 03:54:10 +03:00
|
|
|
/// Mining parameter modes
|
2017-08-09 19:40:23 +03:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub enum MiningParameterMode {
|
|
|
|
/// For CI testing
|
|
|
|
AutomatedTesting,
|
|
|
|
|
|
|
|
/// For User testing
|
|
|
|
UserTesting,
|
|
|
|
|
|
|
|
/// For production, use the values in consensus.rs
|
|
|
|
Production,
|
|
|
|
}
|
|
|
|
|
|
|
|
lazy_static!{
|
2017-08-10 03:54:10 +03:00
|
|
|
/// The mining parameter mode
|
2017-09-29 21:44:25 +03:00
|
|
|
pub static ref MINING_PARAMETER_MODE: RwLock<MiningParameterMode> =
|
|
|
|
RwLock::new(MiningParameterMode::Production);
|
2017-08-09 19:40:23 +03:00
|
|
|
}
|
|
|
|
|
2017-08-10 03:54:10 +03:00
|
|
|
/// Set the mining mode
|
2017-09-29 21:44:25 +03:00
|
|
|
pub fn set_mining_mode(mode: MiningParameterMode) {
|
|
|
|
let mut param_ref = MINING_PARAMETER_MODE.write().unwrap();
|
|
|
|
*param_ref = mode;
|
2017-08-09 19:40:23 +03:00
|
|
|
}
|
|
|
|
|
2017-08-10 03:54:10 +03:00
|
|
|
/// The sizeshift
|
2017-08-09 19:40:23 +03:00
|
|
|
pub fn sizeshift() -> u8 {
|
2017-09-29 21:44:25 +03:00
|
|
|
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
|
2017-08-09 19:40:23 +03:00
|
|
|
match *param_ref {
|
|
|
|
MiningParameterMode::AutomatedTesting => AUTOMATED_TESTING_SIZESHIFT,
|
|
|
|
MiningParameterMode::UserTesting => USER_TESTING_SIZESHIFT,
|
|
|
|
MiningParameterMode::Production => DEFAULT_SIZESHIFT,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-10 03:54:10 +03:00
|
|
|
/// The proofsize
|
2017-08-09 19:40:23 +03:00
|
|
|
pub fn proofsize() -> usize {
|
2017-09-29 21:44:25 +03:00
|
|
|
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
|
2017-08-09 19:40:23 +03:00
|
|
|
match *param_ref {
|
|
|
|
MiningParameterMode::AutomatedTesting => AUTOMATED_TESTING_PROOF_SIZE,
|
|
|
|
MiningParameterMode::UserTesting => USER_TESTING_PROOF_SIZE,
|
|
|
|
MiningParameterMode::Production => PROOFSIZE,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-10 03:54:10 +03:00
|
|
|
/// Are we in automated testing mode?
|
2017-08-09 19:40:23 +03:00
|
|
|
pub fn is_automated_testing_mode() -> bool {
|
2017-09-29 21:44:25 +03:00
|
|
|
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
|
|
|
|
if let MiningParameterMode::AutomatedTesting = *param_ref {
|
2017-08-09 19:40:23 +03:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-08-12 00:05:59 +03:00
|
|
|
|
2017-08-22 21:23:54 +03:00
|
|
|
/// Are we in production mode?
|
|
|
|
pub fn is_production_mode() -> bool {
|
2017-09-29 21:44:25 +03:00
|
|
|
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
|
|
|
|
if let MiningParameterMode::Production = *param_ref {
|
2017-08-22 21:23:54 +03:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-29 21:44:25 +03:00
|
|
|
/// Helper function to get a nonce known to create a valid POW on
|
2017-08-12 00:05:59 +03:00
|
|
|
/// the genesis block, to prevent it taking ages. Should be fine for now
|
2017-09-29 21:44:25 +03:00
|
|
|
/// as the genesis block POW solution turns out to be the same for every new
|
|
|
|
/// block chain
|
2017-08-12 00:05:59 +03:00
|
|
|
/// at the moment
|
|
|
|
|
|
|
|
pub fn get_genesis_nonce() -> u64 {
|
2017-09-29 21:44:25 +03:00
|
|
|
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
|
2017-08-12 00:05:59 +03:00
|
|
|
match *param_ref {
|
2017-09-29 21:44:25 +03:00
|
|
|
// won't make a difference
|
|
|
|
MiningParameterMode::AutomatedTesting => 0,
|
|
|
|
// Magic nonce for current genesis block at cuckoo16
|
|
|
|
MiningParameterMode::UserTesting => 22141,
|
|
|
|
// Magic nonce for current genesis at cuckoo30
|
|
|
|
MiningParameterMode::Production => 1429942738856787200,
|
2017-08-12 00:05:59 +03:00
|
|
|
}
|
|
|
|
}
|
2017-08-22 21:23:54 +03:00
|
|
|
|
2017-09-29 21:44:25 +03:00
|
|
|
/// Returns the genesis POW for production, because it takes far too long to
|
|
|
|
/// mine at production values
|
2017-08-22 21:23:54 +03:00
|
|
|
/// using the internal miner
|
|
|
|
|
2017-09-29 21:44:25 +03:00
|
|
|
pub fn get_genesis_pow() -> [u32; 42] {
|
|
|
|
// TODO: This is diff 26, probably just want a 10: mine one
|
|
|
|
[
|
|
|
|
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,
|
|
|
|
]
|
2017-08-22 21:23:54 +03:00
|
|
|
}
|