mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +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
|
||||
/// check
|
||||
/// Initializes the blockchain and returns a new Chain instance. Does a check
|
||||
/// on the current chain head to make sure it exists and creates one based
|
||||
/// on
|
||||
/// the genesis block if necessary.
|
||||
/// on the genesis block if necessary.
|
||||
pub fn init(
|
||||
db_root: String,
|
||||
adapter: Arc<ChainAdapter>,
|
||||
|
@ -96,7 +94,13 @@ impl Chain {
|
|||
// saving a new tip based on genesis
|
||||
let tip = Tip::new(gen.hash());
|
||||
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
|
||||
}
|
||||
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;
|
||||
|
||||
/// Mining parameter modes
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub enum MiningParameterMode {
|
||||
/// For CI testing
|
||||
AutomatedTesting,
|
||||
|
@ -105,21 +105,19 @@ pub fn coinbase_maturity() -> u64 {
|
|||
/// Are we in automated testing mode?
|
||||
pub fn is_automated_testing_mode() -> bool {
|
||||
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
|
||||
if let MiningParameterMode::AutomatedTesting = *param_ref {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
MiningParameterMode::AutomatedTesting == *param_ref
|
||||
}
|
||||
|
||||
/// 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?
|
||||
pub fn is_production_mode() -> bool {
|
||||
let param_ref = MINING_PARAMETER_MODE.read().unwrap();
|
||||
if let MiningParameterMode::Production = *param_ref {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
MiningParameterMode::Production == *param_ref
|
||||
}
|
||||
|
||||
|
||||
|
@ -135,60 +133,71 @@ pub fn get_genesis_nonce() -> u64 {
|
|||
// won't make a difference
|
||||
MiningParameterMode::AutomatedTesting => 0,
|
||||
// Magic nonce for current genesis block at cuckoo16
|
||||
MiningParameterMode::UserTesting => 22141,
|
||||
MiningParameterMode::UserTesting => 27944,
|
||||
// Magic nonce for current genesis at cuckoo30
|
||||
MiningParameterMode::Production => 1429942738856787200,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the genesis POW for production, because it takes far too long to
|
||||
/// mine at production values
|
||||
/// using the internal miner
|
||||
|
||||
/// Returns the genesis POW for cuckoo16 (UserTesting) and cuckoo30 (Production)
|
||||
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,
|
||||
]
|
||||
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"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,9 +97,8 @@ pub fn pow20<T: MiningWorker>(
|
|||
/// Otherwise,
|
||||
/// uses the internal miner
|
||||
///
|
||||
|
||||
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 diff = gen.header.difficulty.clone();
|
||||
|
||||
|
@ -132,12 +131,14 @@ pub fn pow_size<T: MiningWorker + ?Sized>(
|
|||
) -> Result<(), Error> {
|
||||
let start_nonce = bh.nonce;
|
||||
|
||||
// if we're in production mode, try the pre-mined solution first
|
||||
if global::is_production_mode() {
|
||||
let p = Proof::new(global::get_genesis_pow().to_vec());
|
||||
if p.clone().to_difficulty() >= diff {
|
||||
bh.pow = p;
|
||||
return Ok(());
|
||||
// try the pre-mined solution first for the genesis block (height 0)
|
||||
if bh.height == 0 {
|
||||
if global::is_production_mode() || global::is_user_testing_mode() {
|
||||
let p = Proof::new(global::get_genesis_pow().to_vec());
|
||||
if p.clone().to_difficulty() >= diff {
|
||||
bh.pow = p;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue