mirror of
https://github.com/mimblewimble/grin.git
synced 2025-05-09 18:51:15 +03:00
replace all Difficulty::one by ::min
This commit is contained in:
parent
41293e9ef7
commit
846b38308c
13 changed files with 20 additions and 21 deletions
chain
core
p2p
pool/tests
|
@ -70,7 +70,7 @@ impl Tip {
|
|||
height: 0,
|
||||
last_block_h: gbh,
|
||||
prev_block_h: gbh,
|
||||
total_difficulty: Difficulty::one(),
|
||||
total_difficulty: Difficulty::min(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ fn test_various_store_indices() {
|
|||
let genesis = pow::mine_genesis_block().unwrap();
|
||||
let reward = libtx::reward::output(&keychain, &key_id, 0, 1).unwrap();
|
||||
|
||||
let block = Block::new(&genesis.header, vec![], Difficulty::one(), reward).unwrap();
|
||||
let block = Block::new(&genesis.header, vec![], Difficulty::min(), reward).unwrap();
|
||||
let block_hash = block.hash();
|
||||
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ fn block() -> Block {
|
|||
|
||||
let reward = reward::output(&keychain, &key_id, 0, header.height).unwrap();
|
||||
|
||||
Block::new(&header, txs, Difficulty::one(), reward).unwrap()
|
||||
Block::new(&header, txs, Difficulty::min(), reward).unwrap()
|
||||
}
|
||||
|
||||
fn compact_block() -> CompactBlock {
|
||||
|
|
|
@ -290,8 +290,8 @@ where
|
|||
BLOCK_TIME_WINDOW,
|
||||
CLAMP_FACTOR,
|
||||
);
|
||||
// minimum of 3 avoids getting stuck due to dampening
|
||||
let difficulty = max(3, diff_sum * BLOCK_TIME_SEC / adj_ts);
|
||||
// minimum difficulty avoids getting stuck due to dampening
|
||||
let difficulty = max(MIN_DIFFICULTY, diff_sum * BLOCK_TIME_SEC / adj_ts);
|
||||
|
||||
HeaderInfo::from_diff_scaling(Difficulty::from_num(difficulty), sec_pow_scaling)
|
||||
}
|
||||
|
@ -320,8 +320,8 @@ pub fn secondary_pow_scaling(height: u64, diff_data: &Vec<HeaderInfo>) -> u32 {
|
|||
);
|
||||
let scale = scale_sum * target_pct / adj_count;
|
||||
|
||||
// minimum of 3 avoids getting stuck due to dampening
|
||||
max(3, min(scale, MAX_SECONDARY_SCALING)) as u32
|
||||
// minimum difficulty avoids getting stuck due to dampening
|
||||
max(MIN_DIFFICULTY, min(scale, MAX_SECONDARY_SCALING)) as u32
|
||||
}
|
||||
|
||||
/// Consensus rule that collections of items are sorted lexicographically.
|
||||
|
|
|
@ -44,7 +44,7 @@ pub fn genesis_testnet1() -> core::Block {
|
|||
height: 0,
|
||||
timestamp: Utc.ymd(2017, 11, 16).and_hms(20, 0, 0),
|
||||
pow: ProofOfWork {
|
||||
total_difficulty: Difficulty::one(),
|
||||
total_difficulty: Difficulty::min(),
|
||||
scaling_difficulty: 1,
|
||||
nonce: 28205,
|
||||
proof: Proof::new(vec![
|
||||
|
|
|
@ -236,7 +236,7 @@ impl Default for ProofOfWork {
|
|||
fn default() -> ProofOfWork {
|
||||
let proof_size = global::proofsize();
|
||||
ProofOfWork {
|
||||
total_difficulty: Difficulty::one(),
|
||||
total_difficulty: Difficulty::min(),
|
||||
scaling_difficulty: 1,
|
||||
nonce: 0,
|
||||
proof: Proof::zero(proof_size),
|
||||
|
|
|
@ -92,7 +92,7 @@ where
|
|||
Block::new(
|
||||
&previous_header,
|
||||
txs.into_iter().cloned().collect(),
|
||||
Difficulty::one(),
|
||||
Difficulty::min(),
|
||||
reward_output,
|
||||
).unwrap()
|
||||
}
|
||||
|
|
|
@ -381,7 +381,6 @@ fn adjustment_scenarios() {
|
|||
fn next_target_adjustment() {
|
||||
global::set_mining_mode(global::ChainTypes::AutomatedTesting);
|
||||
let cur_time = Utc::now().timestamp() as u64;
|
||||
let diff_one = Difficulty::one();
|
||||
let diff_min = Difficulty::min();
|
||||
|
||||
// Check we don't get stuck on difficulty <= MIN_DIFFICULTY (at 4x faster blocks at least)
|
||||
|
|
|
@ -232,7 +232,7 @@ pub struct DummyAdapter {}
|
|||
|
||||
impl ChainAdapter for DummyAdapter {
|
||||
fn total_difficulty(&self) -> Difficulty {
|
||||
Difficulty::one()
|
||||
Difficulty::min()
|
||||
}
|
||||
fn total_height(&self) -> u64 {
|
||||
0
|
||||
|
|
|
@ -75,7 +75,7 @@ fn peer_handshake() {
|
|||
let mut peer = Peer::connect(
|
||||
&mut socket,
|
||||
p2p::Capabilities::UNKNOWN,
|
||||
Difficulty::one(),
|
||||
Difficulty::min(),
|
||||
my_addr,
|
||||
&p2p::handshake::Handshake::new(Hash::from_vec(&vec![]), p2p_config.clone()),
|
||||
net_adapter,
|
||||
|
@ -86,10 +86,10 @@ fn peer_handshake() {
|
|||
peer.start(socket);
|
||||
thread::sleep(time::Duration::from_secs(1));
|
||||
|
||||
peer.send_ping(Difficulty::one(), 0).unwrap();
|
||||
peer.send_ping(Difficulty::min(), 0).unwrap();
|
||||
thread::sleep(time::Duration::from_secs(1));
|
||||
|
||||
let server_peer = server.peers.get_connected_peer(&my_addr).unwrap();
|
||||
assert_eq!(server_peer.info.total_difficulty(), Difficulty::one());
|
||||
assert_eq!(server_peer.info.total_difficulty(), Difficulty::min());
|
||||
assert!(server.peers.peer_count() > 0);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ fn test_transaction_pool_block_building() {
|
|||
let key_id = ExtKeychain::derive_key_id(1, height as u32, 0, 0, 0);
|
||||
let fee = txs.iter().map(|x| x.fee()).sum();
|
||||
let reward = libtx::reward::output(&keychain, &key_id, fee, height).unwrap();
|
||||
let block = Block::new(&prev_header, txs, Difficulty::one(), reward).unwrap();
|
||||
let block = Block::new(&prev_header, txs, Difficulty::min(), reward).unwrap();
|
||||
|
||||
chain.update_db_for_block(&block);
|
||||
block.header
|
||||
|
@ -115,7 +115,7 @@ fn test_transaction_pool_block_building() {
|
|||
let key_id = ExtKeychain::derive_key_id(1, 2, 0, 0, 0);
|
||||
let fees = txs.iter().map(|tx| tx.fee()).sum();
|
||||
let reward = libtx::reward::output(&keychain, &key_id, fees, 0).unwrap();
|
||||
Block::new(&header, txs, Difficulty::one(), reward)
|
||||
Block::new(&header, txs, Difficulty::min(), reward)
|
||||
}.unwrap();
|
||||
|
||||
chain.update_db_for_block(&block);
|
||||
|
|
|
@ -52,7 +52,7 @@ fn test_transaction_pool_block_reconciliation() {
|
|||
let height = 1;
|
||||
let key_id = ExtKeychain::derive_key_id(1, height as u32, 0, 0, 0);
|
||||
let reward = libtx::reward::output(&keychain, &key_id, 0, height).unwrap();
|
||||
let block = Block::new(&BlockHeader::default(), vec![], Difficulty::one(), reward).unwrap();
|
||||
let block = Block::new(&BlockHeader::default(), vec![], Difficulty::min(), reward).unwrap();
|
||||
|
||||
chain.update_db_for_block(&block);
|
||||
|
||||
|
@ -67,7 +67,7 @@ fn test_transaction_pool_block_reconciliation() {
|
|||
let key_id = ExtKeychain::derive_key_id(1, 2, 0, 0, 0);
|
||||
let fees = initial_tx.fee();
|
||||
let reward = libtx::reward::output(&keychain, &key_id, fees, 0).unwrap();
|
||||
let block = Block::new(&header, vec![initial_tx], Difficulty::one(), reward).unwrap();
|
||||
let block = Block::new(&header, vec![initial_tx], Difficulty::min(), reward).unwrap();
|
||||
|
||||
chain.update_db_for_block(&block);
|
||||
|
||||
|
@ -157,7 +157,7 @@ fn test_transaction_pool_block_reconciliation() {
|
|||
let key_id = ExtKeychain::derive_key_id(1, 3, 0, 0, 0);
|
||||
let fees = block_txs.iter().map(|tx| tx.fee()).sum();
|
||||
let reward = libtx::reward::output(&keychain, &key_id, fees, 0).unwrap();
|
||||
let block = Block::new(&header, block_txs, Difficulty::one(), reward).unwrap();
|
||||
let block = Block::new(&header, block_txs, Difficulty::min(), reward).unwrap();
|
||||
|
||||
chain.update_db_for_block(&block);
|
||||
block
|
||||
|
|
|
@ -53,7 +53,7 @@ fn test_the_transaction_pool() {
|
|||
let key_id = ExtKeychain::derive_key_id(1, height as u32, 0, 0, 0);
|
||||
let reward = libtx::reward::output(&keychain, &key_id, 0, height).unwrap();
|
||||
let mut block =
|
||||
Block::new(&BlockHeader::default(), vec![], Difficulty::one(), reward).unwrap();
|
||||
Block::new(&BlockHeader::default(), vec![], Difficulty::min(), reward).unwrap();
|
||||
|
||||
chain.update_db_for_block(&block);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue