@@ -20,7 +20,7 @@ use std::collections::BTreeMap;
20
20
use std:: sync:: Arc ;
21
21
use hash:: { KECCAK_EMPTY_LIST_RLP } ;
22
22
use engines:: block_reward:: { self , RewardKind } ;
23
- use ethash:: { quick_get_difficulty, slow_hash_block_number, EthashManager , OptimizeFor } ;
23
+ use ethash:: { self , quick_get_difficulty, slow_hash_block_number, EthashManager , OptimizeFor } ;
24
24
use ethereum_types:: { H256 , H64 , U256 , Address } ;
25
25
use unexpected:: { OutOfBounds , Mismatch } ;
26
26
use block:: * ;
@@ -302,7 +302,7 @@ impl Engine<EthereumMachine> for Arc<Ethash> {
302
302
return Err ( From :: from ( BlockError :: DifficultyOutOfBounds ( OutOfBounds { min : Some ( min_difficulty) , max : None , found : header. difficulty ( ) . clone ( ) } ) ) )
303
303
}
304
304
305
- let difficulty = Ethash :: boundary_to_difficulty ( & H256 ( quick_get_difficulty (
305
+ let difficulty = ethash :: boundary_to_difficulty ( & H256 ( quick_get_difficulty (
306
306
& header. bare_hash ( ) . 0 ,
307
307
seal. nonce . low_u64 ( ) ,
308
308
& seal. mix_hash . 0
@@ -324,7 +324,7 @@ impl Engine<EthereumMachine> for Arc<Ethash> {
324
324
325
325
let result = self . pow . compute_light ( header. number ( ) as u64 , & header. bare_hash ( ) . 0 , seal. nonce . low_u64 ( ) ) ;
326
326
let mix = H256 ( result. mix_hash ) ;
327
- let difficulty = Ethash :: boundary_to_difficulty ( & H256 ( result. value ) ) ;
327
+ let difficulty = ethash :: boundary_to_difficulty ( & H256 ( result. value ) ) ;
328
328
trace ! ( target: "miner" , "num: {num}, seed: {seed}, h: {h}, non: {non}, mix: {mix}, res: {res}" ,
329
329
num = header. number( ) as u64 ,
330
330
seed = H256 ( slow_hash_block_number( header. number( ) as u64 ) ) ,
@@ -447,25 +447,6 @@ impl Ethash {
447
447
}
448
448
target
449
449
}
450
-
451
- /// Convert an Ethash boundary to its original difficulty. Basically just `f(x) = 2^256 / x`.
452
- pub fn boundary_to_difficulty ( boundary : & H256 ) -> U256 {
453
- let d = U256 :: from ( * boundary) ;
454
- if d <= U256 :: one ( ) {
455
- U256 :: max_value ( )
456
- } else {
457
- ( ( U256 :: one ( ) << 255 ) / d) << 1
458
- }
459
- }
460
-
461
- /// Convert an Ethash difficulty to the target boundary. Basically just `f(x) = 2^256 / x`.
462
- pub fn difficulty_to_boundary ( difficulty : & U256 ) -> H256 {
463
- if * difficulty <= U256 :: one ( ) {
464
- U256 :: max_value ( ) . into ( )
465
- } else {
466
- ( ( ( U256 :: one ( ) << 255 ) / * difficulty) << 1 ) . into ( )
467
- }
468
- }
469
450
}
470
451
471
452
fn ecip1017_eras_block_reward ( era_rounds : u64 , mut reward : U256 , block_number : u64 ) -> ( u64 , U256 ) {
@@ -766,16 +747,6 @@ mod tests {
766
747
}
767
748
}
768
749
769
- #[ test]
770
- fn test_difficulty_to_boundary ( ) {
771
- // result of f(0) is undefined, so do not assert the result
772
- let _ = Ethash :: difficulty_to_boundary ( & U256 :: from ( 0 ) ) ;
773
- assert_eq ! ( Ethash :: difficulty_to_boundary( & U256 :: from( 1 ) ) , H256 :: from( U256 :: max_value( ) ) ) ;
774
- assert_eq ! ( Ethash :: difficulty_to_boundary( & U256 :: from( 2 ) ) , H256 :: from_str( "8000000000000000000000000000000000000000000000000000000000000000" ) . unwrap( ) ) ;
775
- assert_eq ! ( Ethash :: difficulty_to_boundary( & U256 :: from( 4 ) ) , H256 :: from_str( "4000000000000000000000000000000000000000000000000000000000000000" ) . unwrap( ) ) ;
776
- assert_eq ! ( Ethash :: difficulty_to_boundary( & U256 :: from( 32 ) ) , H256 :: from_str( "0800000000000000000000000000000000000000000000000000000000000000" ) . unwrap( ) ) ;
777
- }
778
-
779
750
#[ test]
780
751
fn difficulty_frontier ( ) {
781
752
let machine = new_homestead_test_machine ( ) ;
0 commit comments