Mining/POW Updates (#639)

* large updates for mining, fix async mode, will list changes in PR

* reset config and build defaults
This commit is contained in:
Yeastplume 2018-01-19 17:48:18 +00:00 committed by GitHub
parent 916d9cce57
commit f9726e8154
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 349 additions and 227 deletions

View file

@ -119,7 +119,7 @@ pub fn valid_header_version(height: u64, version: u16) -> bool {
}
/// The minimum mining difficulty we'll allow
pub const MINIMUM_DIFFICULTY: u64 = 10;
pub const MINIMUM_DIFFICULTY: u64 = 1;
/// Time window in blocks to calculate block time median
pub const MEDIAN_TIME_WINDOW: u64 = 11;
@ -209,7 +209,8 @@ where
let end_ts = window_end[window_end.len() / 2];
// Average difficulty and dampened average time
let diff_avg = diff_sum.clone() / Difficulty::from_num(DIFFICULTY_ADJUST_WINDOW);
let diff_avg = diff_sum.into_num() as f64 /
Difficulty::from_num(DIFFICULTY_ADJUST_WINDOW).into_num() as f64;
let ts_damp = (3 * BLOCK_TIME_WINDOW + (begin_ts - end_ts)) / 4;
// Apply time bounds
@ -222,9 +223,11 @@ where
};
let difficulty =
diff_avg * Difficulty::from_num(BLOCK_TIME_WINDOW) / Difficulty::from_num(adj_ts);
Ok(max(difficulty, Difficulty::minimum()))
diff_avg * Difficulty::from_num(BLOCK_TIME_WINDOW).into_num() as f64
/ Difficulty::from_num(adj_ts).into_num() as f64;
// All this ceil and f64 business is so that difficulty can always adjust
// for smaller numbers < 10
Ok(max(Difficulty::from_num(difficulty.ceil() as u64), Difficulty::minimum()))
}
/// Consensus rule that collections of items are sorted lexicographically.
@ -299,12 +302,12 @@ mod test {
let mut s1 = repeat(60, 500, sec);
let mut s2 = repeat_offs((sec * 60) as u64, 60, 1545, DIFFICULTY_ADJUST_WINDOW / 2);
s2.append(&mut s1);
assert_eq!(next_difficulty(s2).unwrap(), Difficulty::from_num(999));
assert_eq!(next_difficulty(s2).unwrap(), Difficulty::from_num(1000));
// too slow, diff goes down
assert_eq!(
next_difficulty(repeat(90, 1000, just_enough)).unwrap(),
Difficulty::from_num(889)
Difficulty::from_num(890)
);
assert_eq!(
next_difficulty(repeat(120, 1000, just_enough)).unwrap(),
@ -314,11 +317,11 @@ mod test {
// too fast, diff goes up
assert_eq!(
next_difficulty(repeat(55, 1000, just_enough)).unwrap(),
Difficulty::from_num(1021)
Difficulty::from_num(1022)
);
assert_eq!(
next_difficulty(repeat(45, 1000, just_enough)).unwrap(),
Difficulty::from_num(1067)
Difficulty::from_num(1068)
);
// hitting lower time bound, should always get the same result below
@ -341,10 +344,10 @@ mod test {
Difficulty::from_num(750)
);
// We should never drop below MINIMUM_DIFFICULTY (10)
// We should never drop below MINIMUM_DIFFICULTY (1)
assert_eq!(
next_difficulty(repeat(90, 10, just_enough)).unwrap(),
Difficulty::from_num(10)
next_difficulty(repeat(90, 0, just_enough)).unwrap(),
Difficulty::from_num(1)
);
}

View file

@ -28,9 +28,9 @@ use byteorder::{BigEndian, ByteOrder};
use consensus;
use core::hash::Hash;
use ser::{self, Readable, Reader, Writeable, Writer};
use util::logger::LOGGER;
use core::global;
/// The target is the 32-bytes hash block hashes must be lower than.
pub const MAX_TARGET: [u8; 8] = [0xf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff];
/// The difficulty is defined as the maximum target divided by the block hash.
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord)]
@ -65,11 +65,12 @@ impl Difficulty {
/// Computes the difficulty from a hash. Divides the maximum target by the
/// provided hash.
pub fn from_hash(h: &Hash) -> Difficulty {
let max_target = BigEndian::read_u64(&MAX_TARGET);
let max_target = BigEndian::read_u64(&global::max_proof_target());
// Use the first 64 bits of the given hash
let mut in_vec = h.to_vec();
in_vec.truncate(8);
let num = BigEndian::read_u64(&in_vec);
trace!(LOGGER, "Calculated difficulty: {}", max_target as f64 / num as f64);
Difficulty { num: max_target / num }
}

View file

@ -74,6 +74,37 @@ pub fn genesis_testnet1() -> core::Block {
}
}
/// Second testnet genesis block (cuckoo30). TBD and don't start getting excited
/// just because you see this reference here... this is for testing mining
/// at cuckoo 30
pub fn genesis_testnet2() -> core::Block {
core::Block {
header: core::BlockHeader {
height: 0,
previous: core::hash::Hash([0xff; 32]),
timestamp: time::Tm {
tm_year: 2017 - 1900,
tm_mon: 10,
tm_mday: 16,
tm_hour: 20,
..time::empty_tm()
},
nonce: 70081,
pow: core::Proof::new(vec![0x43ee48, 0x18d5a49, 0x2b76803, 0x3181a29, 0x39d6a8a, 0x39ef8d8,
0x478a0fb, 0x69c1f9e, 0x6da4bca, 0x6f8782c, 0x9d842d7, 0xa051397,
0xb56934c, 0xbf1f2c7, 0xc992c89, 0xce53a5a, 0xfa87225, 0x1070f99e,
0x107b39af, 0x1160a11b, 0x11b379a8, 0x12420e02, 0x12991602, 0x12cc4a71,
0x13d91075, 0x15c950d0, 0x1659b7be, 0x1682c2b4, 0x1796c62f, 0x191cf4c9,
0x19d71ac0, 0x1b812e44, 0x1d150efe, 0x1d15bd77, 0x1d172841, 0x1d51e967,
0x1ee1de39, 0x1f35c9b3, 0x1f557204, 0x1fbf884f, 0x1fcf80bf, 0x1fd59d40]),
..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 {

View file

@ -47,6 +47,12 @@ pub const AUTOMATED_TESTING_COINBASE_MATURITY: u64 = 3;
/// User testing coinbase maturity
pub const USER_TESTING_COINBASE_MATURITY: u64 = 3;
/// The target is the 32-bytes hash block hashes must be lower than.
pub const MAX_PROOF_TARGET: [u8; 8] = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff];
/// We want to slow this right down for user testing at cuckoo 16, so pick a smaller max
pub const MAX_PROOF_TARGET_TESTING: [u8; 8] = [0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff];
/// Types of chain a server can run with, dictates the genesis block and
/// and mining parameters used.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
@ -60,6 +66,9 @@ pub enum ChainTypes {
/// First test network
Testnet1,
/// Second test network
Testnet2,
/// Main production network
Mainnet,
}
@ -89,6 +98,7 @@ pub fn sizeshift() -> u8 {
ChainTypes::AutomatedTesting => AUTOMATED_TESTING_SIZESHIFT,
ChainTypes::UserTesting => USER_TESTING_SIZESHIFT,
ChainTypes::Testnet1 => USER_TESTING_SIZESHIFT,
ChainTypes::Testnet2 => DEFAULT_SIZESHIFT,
ChainTypes::Mainnet => DEFAULT_SIZESHIFT,
}
}
@ -100,6 +110,7 @@ pub fn proofsize() -> usize {
ChainTypes::AutomatedTesting => AUTOMATED_TESTING_PROOF_SIZE,
ChainTypes::UserTesting => USER_TESTING_PROOF_SIZE,
ChainTypes::Testnet1 => PROOFSIZE,
ChainTypes::Testnet2 => PROOFSIZE,
ChainTypes::Mainnet => PROOFSIZE,
}
}
@ -111,10 +122,23 @@ pub fn coinbase_maturity() -> u64 {
ChainTypes::AutomatedTesting => AUTOMATED_TESTING_COINBASE_MATURITY,
ChainTypes::UserTesting => USER_TESTING_COINBASE_MATURITY,
ChainTypes::Testnet1 => COINBASE_MATURITY,
ChainTypes::Testnet2 => COINBASE_MATURITY,
ChainTypes::Mainnet => COINBASE_MATURITY,
}
}
/// Max Proof Target
pub fn max_proof_target() -> [u8; 8] {
let param_ref = CHAIN_TYPE.read().unwrap();
match *param_ref {
ChainTypes::AutomatedTesting => MAX_PROOF_TARGET_TESTING,
ChainTypes::UserTesting => MAX_PROOF_TARGET_TESTING,
ChainTypes::Testnet1 => MAX_PROOF_TARGET_TESTING,
ChainTypes::Testnet2 => MAX_PROOF_TARGET,
ChainTypes::Mainnet => MAX_PROOF_TARGET,
}
}
/// Are we in automated testing mode?
pub fn is_automated_testing_mode() -> bool {
let param_ref = CHAIN_TYPE.read().unwrap();
@ -131,6 +155,7 @@ pub fn is_user_testing_mode() -> bool {
pub fn is_production_mode() -> bool {
let param_ref = CHAIN_TYPE.read().unwrap();
ChainTypes::Testnet1 == *param_ref ||
ChainTypes::Testnet2 == *param_ref ||
ChainTypes::Mainnet == *param_ref
}
@ -146,6 +171,7 @@ pub fn get_genesis_nonce() -> u64 {
ChainTypes::AutomatedTesting => 0,
// Magic nonce for current genesis block at cuckoo16
ChainTypes::UserTesting => 27944,
// Magic nonce for genesis block for testnet2 (cuckoo30)
_ => panic!("Pre-set"),
}

View file

@ -37,15 +37,19 @@ db_root = ".grin"
#parameters used for mining. Can be:
#AutomatedTesting - For CI builds and instant blockchain creation
#UserTesting - For regular user testing (cuckoo 16)
#Testnet1 - Full production cuckoo parameter (cuckoo 30)
#Testnet1 - Testnet1 genesis block (cuckoo 16)
#Testnet2 - Testnet2 genesis block (cuckoo 30)
#
#chain_type = "UserTesting"
chain_type = "Testnet1"
#7 = Bit flags for FULL_NODE, this structure needs to be changed
#internally to make it more configurable
capabilities = [7]
#skip waiting for sync on startup, (optional param, mostly for testing)
#skip_sync_wait = true
#The P2P server details (i.e. the server that communicates with other
#grin server nodes
@ -63,13 +67,13 @@ port = 13414
log_to_stdout = true
# Log level for stdout: Critical, Error, Warning, Info, Debug, Trace
stdout_log_level = "Info"
stdout_log_level = "Warning"
# Whether to log to a file
log_to_file = true
# Log level for file: Critical, Error, Warning, Info, Debug, Trace
file_log_level = "Debug"
file_log_level = "Info"
# Log file path
log_file_path = "grin.log"
@ -121,6 +125,7 @@ burn_reward = false
#testing value, optional
#slow_down_in_millis = 30
#########################################
### CUCKOO MINER PLUGIN CONFIGURATION ###
#########################################
@ -136,7 +141,12 @@ burn_reward = false
# in single-threaded mode
# You'll likely get the best performance using a
# single GPU and single CPU plugin in parallel
# single GPU plugin and single CPU plugin in parallel
# Parameters can be set per-device. On CPU plugins
# you'll likely only be using device 0 (for now),
# but in CUDA plugins the device number corresponds
# to the device ID. (use nvidia-smi to find this)
#The fastest cpu algorithm, but consumes the most memory
#Also requires instructions that aren't available on
@ -144,29 +154,47 @@ burn_reward = false
#instead
#[[mining.cuckoo_miner_plugin_config]]
#type_filter = "mean_cpu"
#parameter_list = {NUM_THREADS=4, NUM_TRIMS=68}
#[mining.cuckoo_miner_plugin_config.device_parameters.0]
#NUM_THREADS = 8
#Same as above, but for older processors. Will be slightly
#slower.
#As above, but for older processors
[[mining.cuckoo_miner_plugin_config]]
type_filter = "mean_compat_cpu"
parameter_list = {NUM_THREADS=1, NUM_TRIMS=68}
[mining.cuckoo_miner_plugin_config.device_parameters.0]
NUM_THREADS = 1
#note lean_cpu currently has a bug which prevents it from
#working with threads > 1
#[[mining.cuckoo_miner_plugin_config]]
#type_filter = "lean_cpu"
#parameter_list = {NUM_THREADS=1, NUM_TRIMS=7}
#[mining.cuckoo_miner_plugin_config.device_parameters.0]
#NUM_THREADS = 1
#CUDA verion of lean miner
#CUDA Miner (Included here for integration only, Not ready for use)
#Can currently be used only in Production (30) Mode
#This plugin is not built by default. To build:
#1) Ensure the latest cuda toolkit is installed
# (nvcc should be in your PATH)
#2) Uncomment the 'build-cuda-plugin' feature
# in pow/Cargo.toml
#
#Parameters can be set per device, as below. In sync mode
#device 0 is currently the only device used. In async mode
#device 0 is used by default, and all other devices are
#disabled unless explicitly enabled by setting the 'USE_DEVICE'
#param to 1 on each device, as demonstrated below.
#[[mining.cuckoo_miner_plugin_config]]
#type_filter = "lean_cuda"
#parameter_list = {}
#type_filter = "cuda"
#[mining.cuckoo_miner_plugin_config.device_parameters.0]
#NUM_BLOCKS = 64
#THREADS_PER_BLOCK = 32
#[mining.cuckoo_miner_plugin_config.device_parameters.1]
#USE_DEVICE=1
#NUM_BLOCKS = 64
#THREADS_PER_BLOCK = 32
#[mining.cuckoo_miner_plugin_config.device_parameters.2]
#USE_DEVICE=1
#NUM_BLOCKS = 64
#THREADS_PER_BLOCK = 32

View file

@ -51,7 +51,7 @@ use itertools::Itertools;
// Max number of transactions this miner will assemble in a block
const MAX_TX: u32 = 5000;
const PRE_NONCE_SIZE: usize = 113;
const PRE_NONCE_SIZE: usize = 146;
/// Serializer that outputs pre and post nonce portions of a block header
/// which can then be sent off to miner to mutate at will
@ -190,32 +190,45 @@ impl Miner {
// Start the miner working
let miner = plugin_miner.get_consumable();
let job_handle = miner.notify(1, &pre, &post, difficulty.into_num()).unwrap();
let job_handle = miner.notify(1, &pre, &post, 0).unwrap();
let mut sol = None;
while head.hash() == *latest_hash && time::get_time().sec < deadline {
if let Some(s) = job_handle.get_solution() {
sol = Some(Proof::new(s.solution_nonces.to_vec()));
let proof = Proof::new(s.solution_nonces.to_vec());
let proof_diff = proof.clone().to_difficulty();
trace!(LOGGER, "Found cuckoo solution for nonce {} of difficulty {} (difficulty target {})",
s.get_nonce_as_u64(),
proof_diff.into_num(),
difficulty.into_num());
if proof_diff >= b.header.difficulty {
sol = Some(proof);
b.header.nonce = s.get_nonce_as_u64();
// debug!(LOGGER, "Nonce: {}", b.header.nonce);
break;
}
}
if time::get_time().sec > next_stat_output {
let mut sps_total = 0.0;
for i in 0..plugin_miner.loaded_plugin_count() {
let stats = job_handle.get_stats(i);
if let Ok(stat_vec) = stats {
for s in stat_vec {
if s.in_use == 0 {continue;}
let last_solution_time_secs = s.last_solution_time as f64 / 1000000000.0;
let last_hashes_per_sec = 1.0 / last_solution_time_secs;
let status = match s.has_errored {
0 => "OK",
_ => "ERRORED",
};
debug!(
LOGGER,
"Mining: Plugin {} - Device {} ({}): Last Graph time: {}s; \
"Mining: Plugin {} - Device {} ({}) Status: {} : Last Graph time: {}s; \
Graphs per second: {:.*} - Total Attempts: {}",
i,
s.device_id,
s.device_name,
status,
last_solution_time_secs,
3,
last_hashes_per_sec,
@ -226,9 +239,9 @@ impl Miner {
}
}
}
debug!(LOGGER, "Total solutions per second: {}", sps_total);
next_stat_output = time::get_time().sec + stat_output_interval;
}
info!(LOGGER, "Mining at {} graphs per second", sps_total);
next_stat_output = time::get_time().sec + stat_output_interval;
}
// avoid busy wait
thread::sleep(Duration::from_millis(100));
@ -289,6 +302,10 @@ impl Miner {
let pow_hash = b.hash();
if let Ok(proof) = plugin_miner.mine(&pow_hash[..]) {
let proof_diff = proof.clone().to_difficulty();
trace!(LOGGER, "Found cuckoo solution for nonce {} of difficulty {} (difficulty target {})",
b.header.nonce,
proof_diff.into_num(),
b.header.difficulty.into_num());
if proof_diff >= b.header.difficulty {
sol = Some(proof);
break;
@ -298,17 +315,24 @@ impl Miner {
if time::get_time().sec >= next_stat_check {
let stats_vec = plugin_miner.get_stats(0).unwrap();
for s in stats_vec.into_iter() {
if s.in_use == 0 {continue;}
let last_solution_time_secs = s.last_solution_time as f64 / 1000000000.0;
let last_hashes_per_sec = 1.0 / last_solution_time_secs;
let status = match s.has_errored {
0 => "OK",
_ => "ERRORED",
};
debug!(
LOGGER,
"Plugin 0 - Device {} ({}) - Last Graph time: {}; Graphs per second: {:.*}",
"Plugin 0 - Device {} ({}) Status: {} - Last Graph time: {}; Graphs per second: {:.*}",
s.device_id,
s.device_name,
status,
last_solution_time_secs,
3,
last_hashes_per_sec
);
info!(LOGGER, "Mining at {} graphs per second", last_hashes_per_sec);
}
next_stat_check = time::get_time().sec + stat_check_interval;
}

View file

@ -93,6 +93,7 @@ impl Server {
let genesis = match config.chain_type {
global::ChainTypes::Testnet1 => genesis::genesis_testnet1(),
//global::ChainTypes::Testnet2 => genesis::genesis_testnet2(),
_ => pow::mine_genesis_block(config.mining_config.clone())?,
};
info!(

View file

@ -18,7 +18,7 @@ grin_util = { path = "../util" }
[dependencies.cuckoo_miner]
git = "https://github.com/mimblewimble/cuckoo-miner"
tag="grin_integration_16"
tag = "grin_integration_18"
#path = "../../cuckoo-miner"
#uncomment this feature to turn off plugin builds
#features=["no-plugin-build"]

View file

@ -59,16 +59,11 @@ impl Cuckoo {
let size = 1 << sizeshift;
let hashed = blake2::blake2b::blake2b(32, &[], header);
let hashed = hashed.as_bytes();
let k0 = u8_to_u64(hashed, 0);
let k1 = u8_to_u64(hashed, 8);
let mut v = [0; 4];
v[0] = k0 ^ 0x736f6d6570736575;
v[1] = k1 ^ 0x646f72616e646f6d;
v[2] = k0 ^ 0x6c7967656e657261;
v[3] = k1 ^ 0x7465646279746573;
Cuckoo {
v: v,
v: [u8_to_u64(hashed, 0),
u8_to_u64(hashed, 8),
u8_to_u64(hashed, 16),
u8_to_u64(hashed, 24)],
size: size,
mask: (1 << sizeshift) / 2 - 1,
}
@ -323,183 +318,182 @@ mod test {
use super::*;
use core::core::Proof;
static V1: [u32; 42] = [
0x1fe9,
0x2050,
0x4581,
0x6322,
0x65ab,
0xb3c1,
0xc1a4,
0xe257,
0x106ae,
0x17b11,
0x202d4,
0x2705d,
0x2deb2,
0x2f80e,
0x32298,
0x34782,
0x35c5a,
0x37458,
0x38f28,
0x406b2,
0x40e34,
0x40fc6,
0x42220,
0x42d13,
0x46c0f,
0x4fd47,
0x55ad2,
0x598f7,
0x5aa8f,
0x62aa3,
0x65725,
0x65dcb,
0x671c7,
0x6eb20,
0x752fe,
0x7594f,
0x79b9c,
0x7f775,
0x81635,
0x8401c,
0x844e5,
0x89fa8,
0x3bbd,
0x4e96,
0x1013b,
0x1172b,
0x1371b,
0x13e6a,
0x1aaa6,
0x1b575,
0x1e237,
0x1ee88,
0x22f94,
0x24223,
0x25b4f,
0x2e9f3,
0x33b49,
0x34063,
0x3454a,
0x3c081,
0x3d08e,
0x3d863,
0x4285a,
0x42f22,
0x43122,
0x4b853,
0x4cd0c,
0x4f280,
0x557d5,
0x562cf,
0x58e59,
0x59a62,
0x5b568,
0x644b9,
0x657e9,
0x66337,
0x6821c,
0x7866f,
0x7e14b,
0x7ec7c,
0x7eed7,
0x80643,
0x8628c,
0x8949e
];
static V2: [u32; 42] = [
0x2a37,
0x7557,
0xa3c3,
0xfce6,
0x1248e,
0x15837,
0x1827f,
0x18a93,
0x1a7dd,
0x1b56b,
0x1ceb4,
0x1f962,
0x1fe2a,
0x29cb9,
0x2f30e,
0x2f771,
0x336bf,
0x34355,
0x391d7,
0x39495,
0x3be0c,
0x463be,
0x4d0c2,
0x4eead,
0x50214,
0x520de,
0x52a86,
0x53818,
0x53b3b,
0x54c0b,
0x572fa,
0x5d79c,
0x5e3c2,
0x6769e,
0x6a0fe,
0x6d835,
0x6fc7c,
0x70f03,
0x79d4a,
0x7b03e,
0x81e09,
0x9bd44,
0x5e3a,
0x8a8b,
0x103d8,
0x1374b,
0x14780,
0x16110,
0x1b571,
0x1c351,
0x1c826,
0x28228,
0x2909f,
0x29516,
0x2c1c4,
0x334eb,
0x34cdd,
0x38a2c,
0x3ad23,
0x45ac5,
0x46afe,
0x50f43,
0x51ed6,
0x52ddd,
0x54a82,
0x5a46b,
0x5dbdb,
0x60f6f,
0x60fcd,
0x61c78,
0x63899,
0x64dab,
0x6affc,
0x6b569,
0x72639,
0x73987,
0x78806,
0x7b98e,
0x7c7d7,
0x7ddd4,
0x7fa88,
0x8277c,
0x832d9,
0x8ba6f
];
static V3: [u32; 42] = [
0x8158,
0x9f18,
0xc4ba,
0x108c7,
0x11caa,
0x13b82,
0x1618f,
0x1c83b,
0x1ec89,
0x24354,
0x28864,
0x2a0fb,
0x2ce50,
0x2e8fa,
0x32b36,
0x343e6,
0x34dc9,
0x36881,
0x3ffca,
0x40f79,
0x42721,
0x43b8c,
0x44b9d,
0x47ed3,
0x4cd34,
0x5278a,
0x5ab64,
0x5b4d4,
0x5d842,
0x5fa33,
0x6464e,
0x676ee,
0x685d6,
0x69df0,
0x6a5fd,
0x6bda3,
0x72544,
0x77974,
0x7908c,
0x80e67,
0x81ef4,
0x8d882,
0x308b,
0x9004,
0x91fc,
0x983e,
0x9d67,
0xa293,
0xb4cb,
0xb6c8,
0xccc8,
0xdddc,
0xf04d,
0x1372f,
0x16ec9,
0x17b61,
0x17d03,
0x1e3bc,
0x1fb0f,
0x29e6e,
0x2a2ca,
0x2a719,
0x3a078,
0x3b7cc,
0x3c71d,
0x40daa,
0x43e17,
0x46adc,
0x4b359,
0x4c3aa,
0x4ce92,
0x4d06e,
0x51140,
0x565ac,
0x56b1f,
0x58a8b,
0x5e410,
0x5e607,
0x5ebb5,
0x5f8ae,
0x7aeac,
0x7b902,
0x7d6af,
0x7f400
];
// cuckoo28 at 50% edges of letter 'u'
static V4: [u32; 42] = [
0x1CBBFD,
0x2C5452,
0x520338,
0x6740C5,
0x8C6997,
0xC77150,
0xFD4972,
0x1060FA7,
0x11BFEA0,
0x1343E8D,
0x14CE02A,
0x1533515,
0x1715E61,
0x1996D9B,
0x1CB296B,
0x1FCA180,
0x209A367,
0x20AD02E,
0x23CD2E4,
0x2A3B360,
0x2DD1C0C,
0x333A200,
0x33D77BC,
0x3620C78,
0x3DD7FB8,
0x3FBFA49,
0x41BDED2,
0x4A86FD9,
0x570DE24,
0x57CAB86,
0x594B886,
0x5C74C94,
0x5DE7572,
0x60ADD6F,
0x635918B,
0x6C9E120,
0x6EFA583,
0x7394ACA,
0x7556A23,
0x77F70AA,
0x7CF750A,
0x7F60790,
0xf7243,
0x11f130,
0x193812,
0x23b565,
0x279ac3,
0x69b270,
0xe0778f,
0xef51fc,
0x10bf6e8,
0x13ccf7d,
0x1551177,
0x1b6cfd2,
0x1f872c3,
0x2075681,
0x2e23ccc,
0x2e4c0aa,
0x2f607f1,
0x3007eeb,
0x3407e9a,
0x35423f9,
0x39e48bf,
0x45e3bf6,
0x46aa484,
0x47c0fe1,
0x4b1d5a6,
0x4bae0ba,
0x4dfdbaf,
0x5048eda,
0x537da6b,
0x5402887,
0x56b8897,
0x5bd8e8b,
0x622de20,
0x62be5ce,
0x62d538e,
0x6464518,
0x650a6d5,
0x66ec4fa,
0x66f9476,
0x6b1e5f6,
0x6fd5d88,
0x701f37b
];
/// Find a 42-cycle on Cuckoo20 at 75% easiness and verifiy against a few
@ -524,7 +518,10 @@ mod test {
assert!(Cuckoo::new(&[51], 20).verify(Proof::new(V3.to_vec().clone()), 70));
}
/// Just going to disable this for now, as it's painful to try and get a valid
/// cuckoo28 vector (TBD: 30 is more relevant now anyhow)
#[test]
#[ignore]
fn validate28_vectors() {
let mut test_header = [0; 32];
test_header[0] = 24;

View file

@ -98,7 +98,7 @@ pub fn pow20<T: MiningWorker>(
pub fn mine_genesis_block(
miner_config: Option<types::MinerConfig>,
) -> Result<core::core::Block, Error> {
let mut gen = genesis::genesis_dev();
let mut gen = genesis::genesis_testnet2();
let diff = gen.header.difficulty.clone();
let sz = global::sizeshift() as u32;
@ -142,10 +142,9 @@ pub fn pow_size<T: MiningWorker + ?Sized>(
// if we found a cycle (not guaranteed) and the proof hash is higher that the
// diff, we're all good
if let Ok(proof) = miner.mine(&pow_hash[..]) {
if proof.clone().to_difficulty() >= diff {
bh.pow = proof;
bh.pow = proof.clone();
return Ok(());
}
}

View file

@ -127,14 +127,27 @@ impl PluginMiner {
info!(
LOGGER,
"Mining plugin {} - {}",
"Cuckoo plugin {} - {}",
index,
caps[0].full_path.clone()
);
config.plugin_full_path = caps[0].full_path.clone();
if let Some(l) = miner_config.clone().cuckoo_miner_plugin_config {
if let Some(lp) = l[index].parameter_list.clone() {
config.parameter_list = lp.clone();
if let Some(dp) = l[index].device_parameters.clone() {
for (device, param_map) in dp.into_iter() {
for (param_name, param_value) in param_map.into_iter(){
let device_id = match device.parse::<u32>() {
Ok(n) => n,
Err(e) => {
error!(LOGGER, "Error initializing mining plugin: {:?}", e);
panic!("Unable to init mining plugin.");
},
};
debug!(LOGGER, "Cuckoo Plugin {}: Setting mining parameter {} to {} on Device {}",
index, param_name, param_value, device_id);
config.parameter_list.push((param_name, device_id, param_value));
}
}
}
}
cuckoo_configs.push(config);

View file

@ -11,7 +11,6 @@
// 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.
//! Mining configuration type
use std::collections::HashMap;
@ -22,15 +21,15 @@ pub struct CuckooMinerPluginConfig {
/// The type of plugin to load (i.e. filters on filename)
pub type_filter: String,
/// Parameters for this plugin
pub parameter_list: Option<HashMap<String, u32>>,
/// device params
pub device_parameters: Option<HashMap<String, HashMap<String, u32>>>
}
impl Default for CuckooMinerPluginConfig {
fn default() -> CuckooMinerPluginConfig {
CuckooMinerPluginConfig {
type_filter: String::new(),
parameter_list: None,
device_parameters: None,
}
}
}