Rustify core/src/core (#1122)
Small refactoring of one folder, if it makes sense I could extend the scope. * Remove some cloning (real and just verbosity in the code) * Naming conventions like to/into* * Some Clippy's suggestions I found that we don't use field init shorthand syntax, so I didn't touch this part, was it discussed before?
This commit is contained in:
@@ -15,8 +15,8 @@
|
||||
//! Server stat collection types, to be used by tests, logging or GUI/TUI
|
||||
//! to collect information about server status
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::time::SystemTime;
|
||||
|
||||
use chain;
|
||||
@@ -165,7 +165,7 @@ impl PeerStats {
|
||||
state: state.to_string(),
|
||||
addr: addr,
|
||||
version: peer.info.version,
|
||||
total_difficulty: peer.info.total_difficulty.into_num(),
|
||||
total_difficulty: peer.info.total_difficulty.to_num(),
|
||||
height: peer.info.height,
|
||||
direction: direction.to_string(),
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ impl Server {
|
||||
last_time = time;
|
||||
DiffBlock {
|
||||
block_number: height,
|
||||
difficulty: diff.into_num(),
|
||||
difficulty: diff.to_num(),
|
||||
time: time,
|
||||
duration: dur,
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::{thread, cmp};
|
||||
use std::time::Duration;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::time::Duration;
|
||||
use std::{cmp, thread};
|
||||
use time;
|
||||
|
||||
use chain;
|
||||
@@ -296,7 +296,7 @@ fn needs_syncing(
|
||||
info!(
|
||||
LOGGER,
|
||||
"synchronised at {} @ {} [{}]",
|
||||
local_diff.into_num(),
|
||||
local_diff.to_num(),
|
||||
ch.height,
|
||||
ch.last_block_h
|
||||
);
|
||||
@@ -338,8 +338,8 @@ fn needs_syncing(
|
||||
}
|
||||
|
||||
/// We build a locator based on sync_head.
|
||||
/// Even if sync_head is significantly out of date we will "reset" it once we start getting
|
||||
/// headers back from a peer.
|
||||
/// Even if sync_head is significantly out of date we will "reset" it once we
|
||||
/// start getting headers back from a peer.
|
||||
///
|
||||
/// TODO - this gets *expensive* with a large header chain to iterate over
|
||||
/// as we need to get each block header from the db
|
||||
|
||||
@@ -181,15 +181,14 @@ fn build_block(
|
||||
b.header.nonce = rng.gen();
|
||||
b.header.timestamp = time::at_utc(time::Timespec::new(now_sec, 0));
|
||||
|
||||
let b_difficulty =
|
||||
(b.header.total_difficulty.clone() - head.total_difficulty.clone()).into_num();
|
||||
let b_difficulty = (b.header.total_difficulty.clone() - head.total_difficulty.clone()).to_num();
|
||||
debug!(
|
||||
LOGGER,
|
||||
"Built new block with {} inputs and {} outputs, network difficulty: {}, cumulative difficulty {}",
|
||||
b.inputs.len(),
|
||||
b.outputs.len(),
|
||||
b_difficulty,
|
||||
b.header.clone().total_difficulty.clone().into_num(),
|
||||
b.header.clone().total_difficulty.to_num(),
|
||||
);
|
||||
|
||||
let roots_result = chain.set_txhashset_roots(&mut b, false);
|
||||
|
||||
@@ -446,7 +446,6 @@ impl StratumServer {
|
||||
// Reconstruct the block header with this nonce and pow added
|
||||
b = self.current_block.clone();
|
||||
b.header.nonce = submit_params.nonce;
|
||||
b.header.pow.proof_size = submit_params.pow.len();
|
||||
b.header.pow.nonces = submit_params.pow;
|
||||
let res = self.chain.process_block(b.clone(), chain::Options::MINE);
|
||||
if let Err(e) = res {
|
||||
@@ -644,7 +643,7 @@ impl StratumServer {
|
||||
self.current_block = new_block;
|
||||
self.current_difficulty = (self.current_block.header.total_difficulty.clone()
|
||||
- head.total_difficulty.clone())
|
||||
.into_num();
|
||||
.to_num();
|
||||
self.current_key_id = block_fees.key_id();
|
||||
current_hash = latest_hash;
|
||||
// set a new deadline for rebuilding with fresh transactions
|
||||
|
||||
@@ -17,23 +17,23 @@
|
||||
//! header with its proof-of-work. Any valid mined blocks are submitted to the
|
||||
//! network.
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use time;
|
||||
|
||||
use common::adapters::PoolToChainAdapter;
|
||||
use common::types::StratumServerConfig;
|
||||
use core::consensus;
|
||||
use core::core::Proof;
|
||||
use core::core::{Block, BlockHeader};
|
||||
use core::core::hash::{Hash, Hashed};
|
||||
use core::core::{Block, BlockHeader};
|
||||
use core::pow::cuckoo;
|
||||
use common::types::StratumServerConfig;
|
||||
use util::LOGGER;
|
||||
|
||||
use chain;
|
||||
use pool;
|
||||
use mining::mine_block;
|
||||
use core::global;
|
||||
use mining::mine_block;
|
||||
use pool;
|
||||
|
||||
// Max number of transactions this miner will assemble in a block
|
||||
const MAX_TX: u32 = 5000;
|
||||
@@ -108,7 +108,7 @@ impl Miner {
|
||||
global::sizeshift(),
|
||||
).mine()
|
||||
{
|
||||
let proof_diff = proof.clone().to_difficulty();
|
||||
let proof_diff = proof.to_difficulty();
|
||||
if proof_diff >= (b.header.total_difficulty.clone() - head.total_difficulty.clone())
|
||||
{
|
||||
sol = Some(proof);
|
||||
|
||||
Reference in New Issue
Block a user