Optimizing the code and making it more idiomatic (#2269)

This commit is contained in:
Elichai Turkel
2019-01-02 01:29:16 +02:00
committed by Ignotus Peverell
parent 23df6fa976
commit f2a29ce37a
17 changed files with 119 additions and 104 deletions
+2 -8
View File
@@ -309,19 +309,13 @@ where
/// Count, in units of 1/100 (a percent), the number of "secondary" (AR) blocks in the provided window of blocks.
pub fn ar_count(_height: u64, diff_data: &[HeaderInfo]) -> u64 {
100 * diff_data
.iter()
.filter(|n| n.is_secondary)
.count() as u64
100 * diff_data.iter().filter(|n| n.is_secondary).count() as u64
}
/// Factor by which the secondary proof of work difficulty will be adjusted
pub fn secondary_pow_scaling(height: u64, diff_data: &[HeaderInfo]) -> u32 {
// Get the scaling factor sum of the last DIFFICULTY_ADJUST_WINDOW elements
let scale_sum: u64 = diff_data
.iter()
.map(|dd| dd.secondary_scaling as u64)
.sum();
let scale_sum: u64 = diff_data.iter().map(|dd| dd.secondary_scaling as u64).sum();
// compute ideal 2nd_pow_fraction in pct and across window
let target_pct = secondary_pow_ratio(height);
+1 -4
View File
@@ -27,10 +27,7 @@ use crate::core::committed::{self, Committed};
use crate::core::compact_block::{CompactBlock, CompactBlockBody};
use crate::core::hash::{Hash, Hashed, ZERO_HASH};
use crate::core::verifier_cache::VerifierCache;
use crate::core::{
transaction, Commitment, Input, Output, Transaction,
TransactionBody, TxKernel,
};
use crate::core::{transaction, Commitment, Input, Output, Transaction, TransactionBody, TxKernel};
use crate::global;
use crate::keychain::{self, BlindingFactor};
use crate::pow::{Difficulty, Proof, ProofOfWork};
+2 -1
View File
@@ -17,6 +17,7 @@ use croaring::Bitmap;
use crate::core::hash::Hash;
use crate::core::BlockHeader;
use crate::ser::PMMRable;
use std::path::Path;
/// Storage backend for the MMR, just needs to be indexed by order of insertion.
/// The PMMR itself does not need the Backend to be accurate on the existence
@@ -59,7 +60,7 @@ pub trait Backend<T: PMMRable> {
/// Returns the data file path.. this is a bit of a hack now that doesn't
/// sit well with the design, but TxKernels have to be summed and the
/// fastest way to to be able to allow direct access to the file
fn get_data_file_path(&self) -> &str;
fn get_data_file_path(&self) -> &Path;
/// Also a bit of a hack...
/// Saves a snapshot of the rewound utxo file with the block hash as
+2 -1
View File
@@ -22,6 +22,7 @@ use crate::core::merkle_proof::MerkleProof;
use crate::core::pmmr::{Backend, ReadonlyPMMR};
use crate::core::BlockHeader;
use crate::ser::{PMMRIndexHashable, PMMRable};
use std::path::Path;
/// 64 bits all ones: 0b11111111...1
const ALL_ONES: u64 = u64::MAX;
@@ -323,7 +324,7 @@ where
}
/// Return the path of the data file (needed to sum kernels efficiently)
pub fn data_file_path(&self) -> &str {
pub fn data_file_path(&self) -> &Path {
self.backend.get_data_file_path()
}
+1 -5
View File
@@ -23,11 +23,7 @@ use crate::libtx::{aggsig, proof};
use crate::util::static_secp_instance;
/// output a reward output
pub fn output<K>(
keychain: &K,
key_id: &Identifier,
fees: u64,
) -> Result<(Output, TxKernel), Error>
pub fn output<K>(keychain: &K, key_id: &Identifier, fees: u64) -> Result<(Output, TxKernel), Error>
where
K: Keychain,
{