SeedHashCompute remove needless new
impl (#9063)
This commit is contained in:
parent
c7d21841a4
commit
91122d9193
@ -91,7 +91,7 @@ impl NodeCacheBuilder {
|
|||||||
|
|
||||||
pub fn new<T: Into<Option<OptimizeFor>>>(optimize_for: T) -> Self {
|
pub fn new<T: Into<Option<OptimizeFor>>>(optimize_for: T) -> Self {
|
||||||
NodeCacheBuilder {
|
NodeCacheBuilder {
|
||||||
seedhash: Arc::new(Mutex::new(SeedHashCompute::new())),
|
seedhash: Arc::new(Mutex::new(SeedHashCompute::default())),
|
||||||
optimize_for: optimize_for.into().unwrap_or_default(),
|
optimize_for: optimize_for.into().unwrap_or_default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,20 +19,13 @@ use keccak::{keccak_256, H256};
|
|||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct SeedHashCompute {
|
pub struct SeedHashCompute {
|
||||||
prev_epoch: Cell<u64>,
|
prev_epoch: Cell<u64>,
|
||||||
prev_seedhash: Cell<H256>,
|
prev_seedhash: Cell<H256>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SeedHashCompute {
|
impl SeedHashCompute {
|
||||||
#[inline]
|
|
||||||
pub fn new() -> SeedHashCompute {
|
|
||||||
SeedHashCompute {
|
|
||||||
prev_epoch: Cell::new(0),
|
|
||||||
prev_seedhash: Cell::new([0u8; 32]),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn reset_cache(&self) {
|
fn reset_cache(&self) {
|
||||||
self.prev_epoch.set(0);
|
self.prev_epoch.set(0);
|
||||||
@ -77,20 +70,20 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_seed_compute_once() {
|
fn test_seed_compute_once() {
|
||||||
let seed_compute = SeedHashCompute::new();
|
let seed_compute = SeedHashCompute::default();
|
||||||
let hash = [241, 175, 44, 134, 39, 121, 245, 239, 228, 236, 43, 160, 195, 152, 46, 7, 199, 5, 253, 147, 241, 206, 98, 43, 3, 104, 17, 40, 192, 79, 106, 162];
|
let hash = [241, 175, 44, 134, 39, 121, 245, 239, 228, 236, 43, 160, 195, 152, 46, 7, 199, 5, 253, 147, 241, 206, 98, 43, 3, 104, 17, 40, 192, 79, 106, 162];
|
||||||
assert_eq!(seed_compute.hash_block_number(486382), hash);
|
assert_eq!(seed_compute.hash_block_number(486382), hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_seed_compute_zero() {
|
fn test_seed_compute_zero() {
|
||||||
let seed_compute = SeedHashCompute::new();
|
let seed_compute = SeedHashCompute::default();
|
||||||
assert_eq!(seed_compute.hash_block_number(0), [0u8; 32]);
|
assert_eq!(seed_compute.hash_block_number(0), [0u8; 32]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_seed_compute_after_older() {
|
fn test_seed_compute_after_older() {
|
||||||
let seed_compute = SeedHashCompute::new();
|
let seed_compute = SeedHashCompute::default();
|
||||||
// calculating an older value first shouldn't affect the result
|
// calculating an older value first shouldn't affect the result
|
||||||
let _ = seed_compute.hash_block_number(50000);
|
let _ = seed_compute.hash_block_number(50000);
|
||||||
let hash = [241, 175, 44, 134, 39, 121, 245, 239, 228, 236, 43, 160, 195, 152, 46, 7, 199, 5, 253, 147, 241, 206, 98, 43, 3, 104, 17, 40, 192, 79, 106, 162];
|
let hash = [241, 175, 44, 134, 39, 121, 245, 239, 228, 236, 43, 160, 195, 152, 46, 7, 199, 5, 253, 147, 241, 206, 98, 43, 3, 104, 17, 40, 192, 79, 106, 162];
|
||||||
@ -99,7 +92,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_seed_compute_after_newer() {
|
fn test_seed_compute_after_newer() {
|
||||||
let seed_compute = SeedHashCompute::new();
|
let seed_compute = SeedHashCompute::default();
|
||||||
// calculating an newer value first shouldn't affect the result
|
// calculating an newer value first shouldn't affect the result
|
||||||
let _ = seed_compute.hash_block_number(972764);
|
let _ = seed_compute.hash_block_number(972764);
|
||||||
let hash = [241, 175, 44, 134, 39, 121, 245, 239, 228, 236, 43, 160, 195, 152, 46, 7, 199, 5, 253, 147, 241, 206, 98, 43, 3, 104, 17, 40, 192, 79, 106, 162];
|
let hash = [241, 175, 44, 134, 39, 121, 245, 239, 228, 236, 43, 160, 195, 152, 46, 7, 199, 5, 253, 147, 241, 206, 98, 43, 3, 104, 17, 40, 192, 79, 106, 162];
|
||||||
|
@ -158,7 +158,7 @@ impl StratumJobDispatcher {
|
|||||||
/// New stratum job dispatcher given the miner and client
|
/// New stratum job dispatcher given the miner and client
|
||||||
fn new(miner: Weak<Miner>, client: Weak<Client>) -> StratumJobDispatcher {
|
fn new(miner: Weak<Miner>, client: Weak<Client>) -> StratumJobDispatcher {
|
||||||
StratumJobDispatcher {
|
StratumJobDispatcher {
|
||||||
seed_compute: Mutex::new(SeedHashCompute::new()),
|
seed_compute: Mutex::new(SeedHashCompute::default()),
|
||||||
client: client,
|
client: client,
|
||||||
miner: miner,
|
miner: miner,
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ impl WorkPoster {
|
|||||||
client: fetch,
|
client: fetch,
|
||||||
remote: remote,
|
remote: remote,
|
||||||
urls: urls,
|
urls: urls,
|
||||||
seed_compute: Mutex::new(SeedHashCompute::new()),
|
seed_compute: Mutex::new(SeedHashCompute::default()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> EthClient<C, SN, S
|
|||||||
miner: miner.clone(),
|
miner: miner.clone(),
|
||||||
accounts: accounts.clone(),
|
accounts: accounts.clone(),
|
||||||
external_miner: em.clone(),
|
external_miner: em.clone(),
|
||||||
seed_compute: Mutex::new(SeedHashCompute::new()),
|
seed_compute: Mutex::new(SeedHashCompute::default()),
|
||||||
options: options,
|
options: options,
|
||||||
eip86_transition: client.eip86_transition(),
|
eip86_transition: client.eip86_transition(),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user