mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
add premined pow solution for cuckoo16/UserTesting (#260)
* add premined pow solution for cuckoo16/UserTesting faster startup time * only check premined solution on genesis block (height 0)
This commit is contained in:
parent
54dbda6bc2
commit
596bbd9b6e
3 changed files with 88 additions and 74 deletions
|
@ -68,11 +68,9 @@ impl Chain {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initializes the blockchain and returns a new Chain instance. Does a
|
/// Initializes the blockchain and returns a new Chain instance. Does a check
|
||||||
/// check
|
|
||||||
/// on the current chain head to make sure it exists and creates one based
|
/// on the current chain head to make sure it exists and creates one based
|
||||||
/// on
|
/// on the genesis block if necessary.
|
||||||
/// the genesis block if necessary.
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
db_root: String,
|
db_root: String,
|
||||||
adapter: Arc<ChainAdapter>,
|
adapter: Arc<ChainAdapter>,
|
||||||
|
@ -96,7 +94,13 @@ impl Chain {
|
||||||
// saving a new tip based on genesis
|
// saving a new tip based on genesis
|
||||||
let tip = Tip::new(gen.hash());
|
let tip = Tip::new(gen.hash());
|
||||||
chain_store.save_head(&tip)?;
|
chain_store.save_head(&tip)?;
|
||||||
info!(LOGGER, "Saved genesis block with hash {}", gen.hash());
|
info!(
|
||||||
|
LOGGER,
|
||||||
|
"Saved genesis block with hash: {:?}, nonce: {:?}, pow: {:?}",
|
||||||
|
gen.hash(),
|
||||||
|
gen.header.nonce,
|
||||||
|
gen.header.pow,
|
||||||
|
);
|
||||||
tip
|
tip
|
||||||
}
|
}
|
||||||
Err(e) => return Err(Error::StoreErr(e, "chain init load head".to_owned())),
|
Err(e) => return Err(Error::StoreErr(e, "chain init load head".to_owned())),
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub const AUTOMATED_TESTING_COINBASE_MATURITY: u64 = 3;
|
||||||
pub const USER_TESTING_COINBASE_MATURITY: u64 = 3;
|
pub const USER_TESTING_COINBASE_MATURITY: u64 = 3;
|
||||||
|
|
||||||
/// Mining parameter modes
|
/// Mining parameter modes
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||||
pub enum MiningParameterMode {
|
pub enum MiningParameterMode {
|
||||||
/// For CI testing
|
/// For CI testing
|
||||||
AutomatedTesting,
|
AutomatedTesting,
|
||||||
|
@ -105,21 +105,19 @@ pub fn coinbase_maturity() -> u64 {
|
||||||
/// 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 = MINING_PARAMETER_MODE.read().unwrap();
|
||||||
if let MiningParameterMode::AutomatedTesting = *param_ref {
|
MiningParameterMode::AutomatedTesting == *param_ref
|
||||||
return true;
|
}
|
||||||
} else {
|
|
||||||
return false;
|
/// Are we in user testing mode?
|
||||||
}
|
pub fn is_user_testing_mode() -> bool {
|
||||||
|
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
|
||||||
|
MiningParameterMode::UserTesting == *param_ref
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Are we in production mode?
|
/// Are we in production mode?
|
||||||
pub fn is_production_mode() -> bool {
|
pub fn is_production_mode() -> bool {
|
||||||
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
|
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
|
||||||
if let MiningParameterMode::Production = *param_ref {
|
MiningParameterMode::Production == *param_ref
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,60 +133,71 @@ pub fn get_genesis_nonce() -> u64 {
|
||||||
// won't make a difference
|
// won't make a difference
|
||||||
MiningParameterMode::AutomatedTesting => 0,
|
MiningParameterMode::AutomatedTesting => 0,
|
||||||
// Magic nonce for current genesis block at cuckoo16
|
// Magic nonce for current genesis block at cuckoo16
|
||||||
MiningParameterMode::UserTesting => 22141,
|
MiningParameterMode::UserTesting => 27944,
|
||||||
// Magic nonce for current genesis at cuckoo30
|
// Magic nonce for current genesis at cuckoo30
|
||||||
MiningParameterMode::Production => 1429942738856787200,
|
MiningParameterMode::Production => 1429942738856787200,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the genesis POW for production, because it takes far too long to
|
/// Returns the genesis POW for cuckoo16 (UserTesting) and cuckoo30 (Production)
|
||||||
/// mine at production values
|
|
||||||
/// using the internal miner
|
|
||||||
|
|
||||||
pub fn get_genesis_pow() -> [u32; 42] {
|
pub fn get_genesis_pow() -> [u32; 42] {
|
||||||
// TODO: This is diff 26, probably just want a 10: mine one
|
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
|
||||||
[
|
match *param_ref {
|
||||||
7444824,
|
// pow solution for genesis block at cuckoo16
|
||||||
11926557,
|
MiningParameterMode::UserTesting => [
|
||||||
28520390,
|
0x37f, 0x9f6, 0x136d, 0x13d3, 0x155e, 0x16dd, 0x186b, 0x1b11, 0x208e, 0x23cd,
|
||||||
30594072,
|
0x24d1, 0x278f, 0x2a1b, 0x2a28, 0x2a44, 0x2ae2, 0x2c37, 0x36af, 0x391d, 0x3c2e,
|
||||||
50854023,
|
0x3d9a, 0x3f00, 0x429f, 0x45b2, 0x47ce, 0x47f1, 0x492f, 0x4bd8, 0x4fee, 0x51f0,
|
||||||
52797085,
|
0x5207, 0x58e5, 0x5905, 0x5aca, 0x5dfb, 0x628d, 0x7310, 0x75e5, 0x76d4, 0x76df,
|
||||||
57882033,
|
0x77bd, 0x7ab9
|
||||||
59816511,
|
],
|
||||||
61404804,
|
// pow solution for genesis block at cuckoo30
|
||||||
84947619,
|
// TODO - likely this is no longer correct (block header changes)
|
||||||
87779345,
|
MiningParameterMode::Production => [
|
||||||
115270337,
|
7444824,
|
||||||
162618676,
|
11926557,
|
||||||
166860710,
|
28520390,
|
||||||
178656003,
|
30594072,
|
||||||
178971372,
|
50854023,
|
||||||
200454733,
|
52797085,
|
||||||
209197630,
|
57882033,
|
||||||
221231015,
|
59816511,
|
||||||
228598741,
|
61404804,
|
||||||
241012783,
|
84947619,
|
||||||
245401183,
|
87779345,
|
||||||
279080304,
|
115270337,
|
||||||
295848517,
|
162618676,
|
||||||
327300943,
|
166860710,
|
||||||
329741709,
|
178656003,
|
||||||
366394532,
|
178971372,
|
||||||
382493153,
|
200454733,
|
||||||
389329248,
|
209197630,
|
||||||
404353381,
|
221231015,
|
||||||
406012911,
|
228598741,
|
||||||
418813499,
|
241012783,
|
||||||
426573907,
|
245401183,
|
||||||
452566575,
|
279080304,
|
||||||
456930760,
|
295848517,
|
||||||
463021458,
|
327300943,
|
||||||
474340589,
|
329741709,
|
||||||
476248039,
|
366394532,
|
||||||
478197093,
|
382493153,
|
||||||
487576917,
|
389329248,
|
||||||
495653489,
|
404353381,
|
||||||
501862896,
|
406012911,
|
||||||
]
|
418813499,
|
||||||
|
426573907,
|
||||||
|
452566575,
|
||||||
|
456930760,
|
||||||
|
463021458,
|
||||||
|
474340589,
|
||||||
|
476248039,
|
||||||
|
478197093,
|
||||||
|
487576917,
|
||||||
|
495653489,
|
||||||
|
501862896,
|
||||||
|
],
|
||||||
|
// TODO - for completeness do we provide one here for AutomatedTesting?
|
||||||
|
_ => panic!("unexpected"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,9 +97,8 @@ pub fn pow20<T: MiningWorker>(
|
||||||
/// 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, "Starting miner loop for Genesis Block");
|
info!(util::LOGGER, "Genesis block not found, initializing...");
|
||||||
let mut gen = genesis::genesis();
|
let mut gen = genesis::genesis();
|
||||||
let diff = gen.header.difficulty.clone();
|
let diff = gen.header.difficulty.clone();
|
||||||
|
|
||||||
|
@ -132,12 +131,14 @@ pub fn pow_size<T: MiningWorker + ?Sized>(
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let start_nonce = bh.nonce;
|
let start_nonce = bh.nonce;
|
||||||
|
|
||||||
// if we're in production mode, try the pre-mined solution first
|
// try the pre-mined solution first for the genesis block (height 0)
|
||||||
if global::is_production_mode() {
|
if bh.height == 0 {
|
||||||
let p = Proof::new(global::get_genesis_pow().to_vec());
|
if global::is_production_mode() || global::is_user_testing_mode() {
|
||||||
if p.clone().to_difficulty() >= diff {
|
let p = Proof::new(global::get_genesis_pow().to_vec());
|
||||||
bh.pow = p;
|
if p.clone().to_difficulty() >= diff {
|
||||||
return Ok(());
|
bh.pow = p;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue