[T4 ONLY] T4 PoW changes (#1663)
* T4 PoW changes * rustfmt * adjust sizeshift depending on pow type during ser/deser * update block size tests for cuckatoo sizeshift
This commit is contained in:
@@ -105,6 +105,28 @@ pub fn genesis_testnet3() -> core::Block {
|
||||
})
|
||||
}
|
||||
|
||||
/// 4th testnet genesis block (cuckatoo29 AR, 30+ AF). Temporary values for now (Pow won't verify)
|
||||
pub fn genesis_testnet4() -> core::Block {
|
||||
core::Block::with_header(core::BlockHeader {
|
||||
height: 0,
|
||||
previous: core::hash::Hash([0xff; 32]),
|
||||
timestamp: Utc.ymd(2018, 8, 30).and_hms(18, 0, 0),
|
||||
pow: ProofOfWork {
|
||||
total_difficulty: Difficulty::from_num(global::initial_block_difficulty()),
|
||||
scaling_difficulty: 1,
|
||||
nonce: 4956988373127691,
|
||||
proof: Proof::new(vec![
|
||||
0xa420dc, 0xc8ffee, 0x10e433e, 0x1de9428, 0x2ed4cea, 0x52d907b, 0x5af0e3f,
|
||||
0x6b8fcae, 0x8319b53, 0x845ca8c, 0x8d2a13e, 0x8d6e4cc, 0x9349e8d, 0xa7a33c5,
|
||||
0xaeac3cb, 0xb193e23, 0xb502e19, 0xb5d9804, 0xc9ac184, 0xd4f4de3, 0xd7a23b8,
|
||||
0xf1d8660, 0xf443756, 0x10b833d2, 0x11418fc5, 0x11b8aeaf, 0x131836ec, 0x132ab818,
|
||||
0x13a46a55, 0x13df89fe, 0x145d65b5, 0x166f9c3a, 0x166fe0ef, 0x178cb36f, 0x185baf68,
|
||||
0x1bbfe563, 0x1bd637b4, 0x1cfc8382, 0x1d1ed012, 0x1e391ca5, 0x1e999b4c, 0x1f7c6d21,
|
||||
]),
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
/// Placeholder for mainnet genesis block, will definitely change before
|
||||
/// release so no use trying to pre-mine it.
|
||||
pub fn genesis_main() -> core::Block {
|
||||
|
||||
+16
-9
@@ -22,7 +22,7 @@ use consensus::{
|
||||
DIFFICULTY_ADJUST_WINDOW, EASINESS, INITIAL_DIFFICULTY, MEDIAN_TIME_WINDOW, PROOFSIZE,
|
||||
REFERENCE_SIZESHIFT,
|
||||
};
|
||||
use pow::{self, CuckooContext, Difficulty, EdgeType, PoWContext};
|
||||
use pow::{self, CuckatooContext, Difficulty, EdgeType, PoWContext};
|
||||
/// 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,
|
||||
@@ -39,7 +39,7 @@ pub const AUTOMATED_TESTING_MIN_SIZESHIFT: u8 = 10;
|
||||
pub const AUTOMATED_TESTING_PROOF_SIZE: usize = 4;
|
||||
|
||||
/// User testing sizeshift
|
||||
pub const USER_TESTING_MIN_SIZESHIFT: u8 = 16;
|
||||
pub const USER_TESTING_MIN_SIZESHIFT: u8 = 19;
|
||||
|
||||
/// User testing proof size
|
||||
pub const USER_TESTING_PROOF_SIZE: usize = 42;
|
||||
@@ -69,6 +69,9 @@ pub const TESTNET2_INITIAL_DIFFICULTY: u64 = 1000;
|
||||
/// a 30x Cuckoo adjustment factor
|
||||
pub const TESTNET3_INITIAL_DIFFICULTY: u64 = 30000;
|
||||
|
||||
/// Testnet 4 initial block difficulty
|
||||
pub const TESTNET4_INITIAL_DIFFICULTY: u64 = 1;
|
||||
|
||||
/// Types of chain a server can run with, dictates the genesis block and
|
||||
/// and mining parameters used.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
@@ -83,13 +86,15 @@ pub enum ChainTypes {
|
||||
Testnet2,
|
||||
/// Third test network
|
||||
Testnet3,
|
||||
/// Fourth test network
|
||||
Testnet4,
|
||||
/// Main production network
|
||||
Mainnet,
|
||||
}
|
||||
|
||||
impl Default for ChainTypes {
|
||||
fn default() -> ChainTypes {
|
||||
ChainTypes::Testnet3
|
||||
ChainTypes::Testnet4
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,12 +133,12 @@ pub fn create_pow_context<T>(
|
||||
where
|
||||
T: EdgeType,
|
||||
{
|
||||
// Perform whatever tests, configuration etc are needed to determine desired context + edge size
|
||||
// + params
|
||||
// Hardcode to regular cuckoo for now
|
||||
CuckooContext::<T>::new(edge_bits, proof_size, EASINESS, max_sols)
|
||||
// Or switch to cuckatoo as follows:
|
||||
// CuckatooContext::<T>::new(edge_bits, proof_size, easiness_pct, max_sols)
|
||||
CuckatooContext::<T>::new(edge_bits, proof_size, EASINESS, max_sols)
|
||||
}
|
||||
|
||||
/// Return the type of the pos
|
||||
pub fn pow_type() -> PoWContextTypes {
|
||||
PoWContextTypes::Cuckatoo
|
||||
}
|
||||
|
||||
/// The minimum acceptable sizeshift
|
||||
@@ -193,6 +198,7 @@ pub fn initial_block_difficulty() -> u64 {
|
||||
ChainTypes::Testnet1 => TESTING_INITIAL_DIFFICULTY,
|
||||
ChainTypes::Testnet2 => TESTNET2_INITIAL_DIFFICULTY,
|
||||
ChainTypes::Testnet3 => TESTNET3_INITIAL_DIFFICULTY,
|
||||
ChainTypes::Testnet4 => TESTNET4_INITIAL_DIFFICULTY,
|
||||
ChainTypes::Mainnet => INITIAL_DIFFICULTY,
|
||||
}
|
||||
}
|
||||
@@ -225,6 +231,7 @@ pub fn is_production_mode() -> bool {
|
||||
ChainTypes::Testnet1 == *param_ref
|
||||
|| ChainTypes::Testnet2 == *param_ref
|
||||
|| ChainTypes::Testnet3 == *param_ref
|
||||
|| ChainTypes::Testnet4 == *param_ref
|
||||
|| ChainTypes::Mainnet == *param_ref
|
||||
}
|
||||
|
||||
|
||||
@@ -385,7 +385,10 @@ impl Readable for Proof {
|
||||
}
|
||||
|
||||
let mut nonces = Vec::with_capacity(global::proofsize());
|
||||
let nonce_bits = cuckoo_sizeshift as usize - 1;
|
||||
let mut nonce_bits = cuckoo_sizeshift as usize;
|
||||
if global::pow_type() == global::PoWContextTypes::Cuckoo {
|
||||
nonce_bits -= 1;
|
||||
}
|
||||
let bytes_len = BitVec::bytes_len(nonce_bits * global::proofsize());
|
||||
let bits = reader.read_fixed_bytes(bytes_len)?;
|
||||
let bitvec = BitVec { bits };
|
||||
@@ -411,7 +414,10 @@ impl Writeable for Proof {
|
||||
writer.write_u8(self.cuckoo_sizeshift)?;
|
||||
}
|
||||
|
||||
let nonce_bits = self.cuckoo_sizeshift as usize - 1;
|
||||
let mut nonce_bits = self.cuckoo_sizeshift as usize;
|
||||
if global::pow_type() == global::PoWContextTypes::Cuckoo {
|
||||
nonce_bits -= 1;
|
||||
}
|
||||
let mut bitvec = BitVec::new(nonce_bits * global::proofsize());
|
||||
for (n, nonce) in self.nonces.iter().enumerate() {
|
||||
for bit in 0..nonce_bits {
|
||||
|
||||
Reference in New Issue
Block a user