diff --git a/chain/src/types.rs b/chain/src/types.rs index 560458d0..a6a1c3fc 100644 --- a/chain/src/types.rs +++ b/chain/src/types.rs @@ -70,7 +70,7 @@ impl Tip { height: 0, last_block_h: gbh, prev_block_h: gbh, - total_difficulty: Difficulty::one(), + total_difficulty: Difficulty::min(), } } diff --git a/chain/tests/store_indices.rs b/chain/tests/store_indices.rs index f4ae5a16..1d74b607 100644 --- a/chain/tests/store_indices.rs +++ b/chain/tests/store_indices.rs @@ -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(); { diff --git a/core/fuzz/src/main.rs b/core/fuzz/src/main.rs index 65c6adf0..2b623270 100644 --- a/core/fuzz/src/main.rs +++ b/core/fuzz/src/main.rs @@ -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 { diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 2ba2389a..d903d1a8 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -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) -> 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. diff --git a/core/src/genesis.rs b/core/src/genesis.rs index d2994fcf..cb4e88d3 100644 --- a/core/src/genesis.rs +++ b/core/src/genesis.rs @@ -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![ diff --git a/core/src/pow/types.rs b/core/src/pow/types.rs index 6c4e143e..b4fff5b6 100644 --- a/core/src/pow/types.rs +++ b/core/src/pow/types.rs @@ -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), diff --git a/core/tests/common/mod.rs b/core/tests/common/mod.rs index 66222a34..b9604642 100644 --- a/core/tests/common/mod.rs +++ b/core/tests/common/mod.rs @@ -92,7 +92,7 @@ where Block::new( &previous_header, txs.into_iter().cloned().collect(), - Difficulty::one(), + Difficulty::min(), reward_output, ).unwrap() } diff --git a/core/tests/consensus.rs b/core/tests/consensus.rs index 47855997..9dc5108c 100644 --- a/core/tests/consensus.rs +++ b/core/tests/consensus.rs @@ -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) diff --git a/p2p/src/serv.rs b/p2p/src/serv.rs index b53bf893..a194ace2 100644 --- a/p2p/src/serv.rs +++ b/p2p/src/serv.rs @@ -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 diff --git a/p2p/tests/peer_handshake.rs b/p2p/tests/peer_handshake.rs index 44ca7c76..e1afc30e 100644 --- a/p2p/tests/peer_handshake.rs +++ b/p2p/tests/peer_handshake.rs @@ -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); } diff --git a/pool/tests/block_building.rs b/pool/tests/block_building.rs index 4ffc54cd..960651f1 100644 --- a/pool/tests/block_building.rs +++ b/pool/tests/block_building.rs @@ -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); diff --git a/pool/tests/block_reconciliation.rs b/pool/tests/block_reconciliation.rs index e204efa5..f626f0d0 100644 --- a/pool/tests/block_reconciliation.rs +++ b/pool/tests/block_reconciliation.rs @@ -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 diff --git a/pool/tests/transaction_pool.rs b/pool/tests/transaction_pool.rs index eced1590..d8faf892 100644 --- a/pool/tests/transaction_pool.rs +++ b/pool/tests/transaction_pool.rs @@ -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);