duration_ns: u64 -> duration: Duration (#8457)

* duration_ns: u64 -> duration: Duration

* format on millis {:.2} -> {}
This commit is contained in:
Niklas Adolfsson
2018-04-27 15:04:27 +02:00
committed by Afri Schoedon
parent 01d399ad66
commit e36c4ecc98
13 changed files with 43 additions and 35 deletions

View File

@@ -17,6 +17,7 @@
use bytes::Bytes;
use ethereum_types::H256;
use transaction::UnverifiedTransaction;
use std::time::Duration;
/// Messages to broadcast via chain
pub enum ChainMessageType {
@@ -40,7 +41,7 @@ pub trait ChainNotify : Send + Sync {
_sealed: Vec<H256>,
// Block bytes.
_proposed: Vec<Bytes>,
_duration: u64,
_duration: Duration,
) {
// does nothing by default
}

View File

@@ -18,7 +18,7 @@ use std::collections::{HashSet, HashMap, BTreeMap, VecDeque};
use std::str::FromStr;
use std::sync::{Arc, Weak};
use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering};
use std::time::{Instant};
use std::time::{Instant, Duration};
use itertools::Itertools;
// util
@@ -32,7 +32,7 @@ use util_error::UtilError;
// other
use ethereum_types::{H256, Address, U256};
use block::{IsBlock, LockedBlock, Drain, ClosedBlock, OpenBlock, enact_verified, SealedBlock};
use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute, TransactionAddress};
use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute, TransactionAddress};
use client::ancient_import::AncientVerifier;
use client::Error as ClientError;
use client::{
@@ -120,7 +120,7 @@ impl<'a> ::std::ops::Sub<&'a ClientReport> for ClientReport {
self.blocks_imported -= other.blocks_imported;
self.transactions_applied -= other.transactions_applied;
self.gas_processed = self.gas_processed - other.gas_processed;
self.state_db_mem = higher_mem - lower_mem;
self.state_db_mem = higher_mem - lower_mem;
self
}
@@ -331,11 +331,7 @@ impl Importer {
self.block_queue.mark_as_bad(&invalid_blocks);
}
let is_empty = self.block_queue.mark_as_good(&imported_blocks);
let duration_ns = {
let elapsed = start.elapsed();
elapsed.as_secs() * 1_000_000_000 + elapsed.subsec_nanos() as u64
};
(imported_blocks, import_results, invalid_blocks, imported, proposed_blocks, duration_ns, is_empty)
(imported_blocks, import_results, invalid_blocks, imported, proposed_blocks, start.elapsed(), is_empty)
};
{
@@ -1434,7 +1430,7 @@ impl ImportBlock for Client {
bail!(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain));
}
let status = self.block_status(BlockId::Hash(header.parent_hash()));
if status == BlockStatus::Unknown || status == BlockStatus::Pending {
if status == BlockStatus::Unknown || status == BlockStatus::Pending {
bail!(BlockImportErrorKind::Block(BlockError::UnknownParent(header.parent_hash())));
}
}
@@ -1497,7 +1493,7 @@ impl Call for Client {
}
fn estimate_gas(&self, t: &SignedTransaction, state: &Self::State, header: &Header) -> Result<U256, CallError> {
let (mut upper, max_upper, env_info) = {
let (mut upper, max_upper, env_info) = {
let init = *header.gas_limit();
let max = init * U256::from(10);
@@ -2096,10 +2092,7 @@ impl ImportSealedBlock for Client {
retracted.clone(),
vec![h.clone()],
vec![],
{
let elapsed = start.elapsed();
elapsed.as_secs() * 1_000_000_000 + elapsed.subsec_nanos() as u64
},
start.elapsed(),
);
});
self.db.read().flush().expect("DB flush failed.");
@@ -2109,6 +2102,7 @@ impl ImportSealedBlock for Client {
impl BroadcastProposalBlock for Client {
fn broadcast_proposal_block(&self, block: SealedBlock) {
const DURATION_ZERO: Duration = Duration::from_millis(0);
self.notify(|notify| {
notify.new_blocks(
vec![],
@@ -2117,7 +2111,7 @@ impl BroadcastProposalBlock for Client {
vec![],
vec![],
vec![block.rlp_bytes()],
0,
DURATION_ZERO,
);
});
}

View File

@@ -24,7 +24,7 @@ use io::IoChannel;
use ethereum_types::H256;
use bytes::Bytes;
use std::sync::Arc;
use std::{sync::Arc, time::Duration};
// helper trait for transforming hashes to numbers and checking if syncing.
trait Oracle: Send + Sync {
@@ -107,7 +107,7 @@ impl ChainNotify for Watcher {
_: Vec<H256>,
_: Vec<H256>,
_: Vec<Bytes>,
_duration: u64)
_duration: Duration)
{
if self.oracle.is_major_importing() { return }
@@ -136,6 +136,7 @@ mod tests {
use ethereum_types::{H256, U256};
use std::collections::HashMap;
use std::time::Duration;
struct TestOracle(HashMap<H256, u64>);
@@ -158,6 +159,8 @@ mod tests {
// helper harness for tests which expect a notification.
fn harness(numbers: Vec<u64>, period: u64, history: u64, expected: Option<u64>) {
const DURATION_ZERO: Duration = Duration::from_millis(0);
let hashes: Vec<_> = numbers.clone().into_iter().map(|x| H256::from(U256::from(x))).collect();
let map = hashes.clone().into_iter().zip(numbers).collect();
@@ -175,7 +178,7 @@ mod tests {
vec![],
vec![],
vec![],
0,
DURATION_ZERO,
);
}