duration_ns: u64 -> duration: Duration
(#8457)
* duration_ns: u64 -> duration: Duration * format on millis {:.2} -> {}
This commit is contained in:
parent
01d399ad66
commit
e36c4ecc98
@ -66,6 +66,7 @@ pub use error::{Error, ErrorKind};
|
|||||||
|
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::time::Duration;
|
||||||
use ethereum_types::{H128, H256, U256, Address};
|
use ethereum_types::{H128, H256, U256, Address};
|
||||||
use hash::keccak;
|
use hash::keccak;
|
||||||
use rlp::*;
|
use rlp::*;
|
||||||
@ -667,7 +668,7 @@ fn find_account_password(passwords: &Vec<String>, account_provider: &AccountProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ChainNotify for Provider {
|
impl ChainNotify for Provider {
|
||||||
fn new_blocks(&self, imported: Vec<H256>, _invalid: Vec<H256>, _enacted: Vec<H256>, _retracted: Vec<H256>, _sealed: Vec<H256>, _proposed: Vec<Bytes>, _duration: u64) {
|
fn new_blocks(&self, imported: Vec<H256>, _invalid: Vec<H256>, _enacted: Vec<H256>, _retracted: Vec<H256>, _sealed: Vec<H256>, _proposed: Vec<Bytes>, _duration: Duration) {
|
||||||
if !imported.is_empty() {
|
if !imported.is_empty() {
|
||||||
trace!("New blocks imported, try to prune the queue");
|
trace!("New blocks imported, try to prune the queue");
|
||||||
if let Err(err) = self.process_queue() {
|
if let Err(err) = self.process_queue() {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use transaction::UnverifiedTransaction;
|
use transaction::UnverifiedTransaction;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
/// Messages to broadcast via chain
|
/// Messages to broadcast via chain
|
||||||
pub enum ChainMessageType {
|
pub enum ChainMessageType {
|
||||||
@ -40,7 +41,7 @@ pub trait ChainNotify : Send + Sync {
|
|||||||
_sealed: Vec<H256>,
|
_sealed: Vec<H256>,
|
||||||
// Block bytes.
|
// Block bytes.
|
||||||
_proposed: Vec<Bytes>,
|
_proposed: Vec<Bytes>,
|
||||||
_duration: u64,
|
_duration: Duration,
|
||||||
) {
|
) {
|
||||||
// does nothing by default
|
// does nothing by default
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ use std::collections::{HashSet, HashMap, BTreeMap, VecDeque};
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering};
|
use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering};
|
||||||
use std::time::{Instant};
|
use std::time::{Instant, Duration};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
// util
|
// util
|
||||||
@ -32,7 +32,7 @@ use util_error::UtilError;
|
|||||||
// other
|
// other
|
||||||
use ethereum_types::{H256, Address, U256};
|
use ethereum_types::{H256, Address, U256};
|
||||||
use block::{IsBlock, LockedBlock, Drain, ClosedBlock, OpenBlock, enact_verified, SealedBlock};
|
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::ancient_import::AncientVerifier;
|
||||||
use client::Error as ClientError;
|
use client::Error as ClientError;
|
||||||
use client::{
|
use client::{
|
||||||
@ -120,7 +120,7 @@ impl<'a> ::std::ops::Sub<&'a ClientReport> for ClientReport {
|
|||||||
self.blocks_imported -= other.blocks_imported;
|
self.blocks_imported -= other.blocks_imported;
|
||||||
self.transactions_applied -= other.transactions_applied;
|
self.transactions_applied -= other.transactions_applied;
|
||||||
self.gas_processed = self.gas_processed - other.gas_processed;
|
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
|
self
|
||||||
}
|
}
|
||||||
@ -331,11 +331,7 @@ impl Importer {
|
|||||||
self.block_queue.mark_as_bad(&invalid_blocks);
|
self.block_queue.mark_as_bad(&invalid_blocks);
|
||||||
}
|
}
|
||||||
let is_empty = self.block_queue.mark_as_good(&imported_blocks);
|
let is_empty = self.block_queue.mark_as_good(&imported_blocks);
|
||||||
let duration_ns = {
|
(imported_blocks, import_results, invalid_blocks, imported, proposed_blocks, start.elapsed(), is_empty)
|
||||||
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)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -1434,7 +1430,7 @@ impl ImportBlock for Client {
|
|||||||
bail!(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain));
|
bail!(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain));
|
||||||
}
|
}
|
||||||
let status = self.block_status(BlockId::Hash(header.parent_hash()));
|
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())));
|
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> {
|
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 init = *header.gas_limit();
|
||||||
let max = init * U256::from(10);
|
let max = init * U256::from(10);
|
||||||
|
|
||||||
@ -2096,10 +2092,7 @@ impl ImportSealedBlock for Client {
|
|||||||
retracted.clone(),
|
retracted.clone(),
|
||||||
vec![h.clone()],
|
vec![h.clone()],
|
||||||
vec![],
|
vec![],
|
||||||
{
|
start.elapsed(),
|
||||||
let elapsed = start.elapsed();
|
|
||||||
elapsed.as_secs() * 1_000_000_000 + elapsed.subsec_nanos() as u64
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
self.db.read().flush().expect("DB flush failed.");
|
self.db.read().flush().expect("DB flush failed.");
|
||||||
@ -2109,6 +2102,7 @@ impl ImportSealedBlock for Client {
|
|||||||
|
|
||||||
impl BroadcastProposalBlock for Client {
|
impl BroadcastProposalBlock for Client {
|
||||||
fn broadcast_proposal_block(&self, block: SealedBlock) {
|
fn broadcast_proposal_block(&self, block: SealedBlock) {
|
||||||
|
const DURATION_ZERO: Duration = Duration::from_millis(0);
|
||||||
self.notify(|notify| {
|
self.notify(|notify| {
|
||||||
notify.new_blocks(
|
notify.new_blocks(
|
||||||
vec![],
|
vec![],
|
||||||
@ -2117,7 +2111,7 @@ impl BroadcastProposalBlock for Client {
|
|||||||
vec![],
|
vec![],
|
||||||
vec![],
|
vec![],
|
||||||
vec![block.rlp_bytes()],
|
vec![block.rlp_bytes()],
|
||||||
0,
|
DURATION_ZERO,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ use io::IoChannel;
|
|||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
// helper trait for transforming hashes to numbers and checking if syncing.
|
// helper trait for transforming hashes to numbers and checking if syncing.
|
||||||
trait Oracle: Send + Sync {
|
trait Oracle: Send + Sync {
|
||||||
@ -107,7 +107,7 @@ impl ChainNotify for Watcher {
|
|||||||
_: Vec<H256>,
|
_: Vec<H256>,
|
||||||
_: Vec<H256>,
|
_: Vec<H256>,
|
||||||
_: Vec<Bytes>,
|
_: Vec<Bytes>,
|
||||||
_duration: u64)
|
_duration: Duration)
|
||||||
{
|
{
|
||||||
if self.oracle.is_major_importing() { return }
|
if self.oracle.is_major_importing() { return }
|
||||||
|
|
||||||
@ -136,6 +136,7 @@ mod tests {
|
|||||||
use ethereum_types::{H256, U256};
|
use ethereum_types::{H256, U256};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
struct TestOracle(HashMap<H256, u64>);
|
struct TestOracle(HashMap<H256, u64>);
|
||||||
|
|
||||||
@ -158,6 +159,8 @@ mod tests {
|
|||||||
|
|
||||||
// helper harness for tests which expect a notification.
|
// helper harness for tests which expect a notification.
|
||||||
fn harness(numbers: Vec<u64>, period: u64, history: u64, expected: Option<u64>) {
|
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 hashes: Vec<_> = numbers.clone().into_iter().map(|x| H256::from(U256::from(x))).collect();
|
||||||
let map = hashes.clone().into_iter().zip(numbers).collect();
|
let map = hashes.clone().into_iter().zip(numbers).collect();
|
||||||
|
|
||||||
@ -175,7 +178,7 @@ mod tests {
|
|||||||
vec![],
|
vec![],
|
||||||
vec![],
|
vec![],
|
||||||
vec![],
|
vec![],
|
||||||
0,
|
DURATION_ZERO,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,7 +413,7 @@ impl ChainNotify for EthSync {
|
|||||||
retracted: Vec<H256>,
|
retracted: Vec<H256>,
|
||||||
sealed: Vec<H256>,
|
sealed: Vec<H256>,
|
||||||
proposed: Vec<Bytes>,
|
proposed: Vec<Bytes>,
|
||||||
_duration: u64)
|
_duration: Duration)
|
||||||
{
|
{
|
||||||
use light::net::Announcement;
|
use light::net::Announcement;
|
||||||
|
|
||||||
@ -452,7 +452,7 @@ impl ChainNotify for EthSync {
|
|||||||
|
|
||||||
fn start(&self) {
|
fn start(&self) {
|
||||||
match self.network.start().map_err(Into::into) {
|
match self.network.start().map_err(Into::into) {
|
||||||
Err(ErrorKind::Io(ref e)) if e.kind() == io::ErrorKind::AddrInUse => warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", self.network.config().listen_address.expect("Listen address is not set.")),
|
Err(ErrorKind::Io(ref e)) if e.kind() == io::ErrorKind::AddrInUse => warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", self.network.config().listen_address.expect("Listen address is not set.")),
|
||||||
Err(err) => warn!("Error starting network: {}", err),
|
Err(err) => warn!("Error starting network: {}", err),
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
@ -625,7 +625,7 @@ impl NetworkConfiguration {
|
|||||||
config_path: self.config_path,
|
config_path: self.config_path,
|
||||||
net_config_path: self.net_config_path,
|
net_config_path: self.net_config_path,
|
||||||
listen_address: match self.listen_address { None => None, Some(addr) => Some(SocketAddr::from_str(&addr)?) },
|
listen_address: match self.listen_address { None => None, Some(addr) => Some(SocketAddr::from_str(&addr)?) },
|
||||||
public_address: match self.public_address { None => None, Some(addr) => Some(SocketAddr::from_str(&addr)?) },
|
public_address: match self.public_address { None => None, Some(addr) => Some(SocketAddr::from_str(&addr)?) },
|
||||||
udp_port: self.udp_port,
|
udp_port: self.udp_port,
|
||||||
nat_enabled: self.nat_enabled,
|
nat_enabled: self.nat_enabled,
|
||||||
discovery_enabled: self.discovery_enabled,
|
discovery_enabled: self.discovery_enabled,
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
use std::collections::{VecDeque, HashSet, HashMap};
|
use std::collections::{VecDeque, HashSet, HashMap};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use parking_lot::{RwLock, Mutex};
|
use parking_lot::{RwLock, Mutex};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
@ -538,7 +539,7 @@ impl ChainNotify for EthPeer<EthcoreClient> {
|
|||||||
retracted: Vec<H256>,
|
retracted: Vec<H256>,
|
||||||
sealed: Vec<H256>,
|
sealed: Vec<H256>,
|
||||||
proposed: Vec<Bytes>,
|
proposed: Vec<Bytes>,
|
||||||
_duration: u64)
|
_duration: Duration)
|
||||||
{
|
{
|
||||||
self.new_blocks_queue.write().push_back(NewBlockMessage {
|
self.new_blocks_queue.write().push_back(NewBlockMessage {
|
||||||
imported,
|
imported,
|
||||||
|
@ -351,7 +351,7 @@ impl<T: InformantData> Informant<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ChainNotify for Informant<FullNodeInformantData> {
|
impl ChainNotify for Informant<FullNodeInformantData> {
|
||||||
fn new_blocks(&self, imported: Vec<H256>, _invalid: Vec<H256>, _enacted: Vec<H256>, _retracted: Vec<H256>, _sealed: Vec<H256>, _proposed: Vec<Bytes>, duration: u64) {
|
fn new_blocks(&self, imported: Vec<H256>, _invalid: Vec<H256>, _enacted: Vec<H256>, _retracted: Vec<H256>, _sealed: Vec<H256>, _proposed: Vec<Bytes>, duration: Duration) {
|
||||||
let mut last_import = self.last_import.lock();
|
let mut last_import = self.last_import.lock();
|
||||||
let client = &self.target.client;
|
let client = &self.target.client;
|
||||||
|
|
||||||
@ -373,7 +373,7 @@ impl ChainNotify for Informant<FullNodeInformantData> {
|
|||||||
Colour::White.bold().paint(format!("{}", header_view.hash())),
|
Colour::White.bold().paint(format!("{}", header_view.hash())),
|
||||||
Colour::Yellow.bold().paint(format!("{}", block.transactions_count())),
|
Colour::Yellow.bold().paint(format!("{}", block.transactions_count())),
|
||||||
Colour::Yellow.bold().paint(format!("{:.2}", header_view.gas_used().low_u64() as f32 / 1000000f32)),
|
Colour::Yellow.bold().paint(format!("{:.2}", header_view.gas_used().low_u64() as f32 / 1000000f32)),
|
||||||
Colour::Purple.bold().paint(format!("{:.2}", duration as f32 / 1000000f32)),
|
Colour::Purple.bold().paint(format!("{}", duration.as_milliseconds())),
|
||||||
Colour::Blue.bold().paint(format!("{:.2}", size as f32 / 1024f32)),
|
Colour::Blue.bold().paint(format!("{:.2}", size as f32 / 1024f32)),
|
||||||
if skipped > 0 {
|
if skipped > 0 {
|
||||||
format!(" + another {} block(s) containing {} tx(s)",
|
format!(" + another {} block(s) containing {} tx(s)",
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use jsonrpc_core::{BoxFuture, Result, Error};
|
use jsonrpc_core::{BoxFuture, Result, Error};
|
||||||
use jsonrpc_core::futures::{self, Future, IntoFuture};
|
use jsonrpc_core::futures::{self, Future, IntoFuture};
|
||||||
@ -227,7 +228,7 @@ impl<C: BlockChainClient> ChainNotify for ChainNotificationHandler<C> {
|
|||||||
_sealed: Vec<H256>,
|
_sealed: Vec<H256>,
|
||||||
// Block bytes.
|
// Block bytes.
|
||||||
_proposed: Vec<Bytes>,
|
_proposed: Vec<Bytes>,
|
||||||
_duration: u64,
|
_duration: Duration,
|
||||||
) {
|
) {
|
||||||
const EXTRA_INFO_PROOF: &'static str = "Object exists in in blockchain (fetched earlier), extra_info is always available if object exists; qed";
|
const EXTRA_INFO_PROOF: &'static str = "Object exists in in blockchain (fetched earlier), extra_info is always available if object exists; qed";
|
||||||
let headers = enacted
|
let headers = enacted
|
||||||
|
@ -20,11 +20,15 @@ use jsonrpc_core::MetaIoHandler;
|
|||||||
use jsonrpc_core::futures::{self, Stream, Future};
|
use jsonrpc_core::futures::{self, Stream, Future};
|
||||||
use jsonrpc_pubsub::Session;
|
use jsonrpc_pubsub::Session;
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use v1::{EthPubSub, EthPubSubClient, Metadata};
|
use v1::{EthPubSub, EthPubSubClient, Metadata};
|
||||||
|
|
||||||
use ethcore::client::{TestBlockChainClient, EachBlockWith, ChainNotify};
|
use ethcore::client::{TestBlockChainClient, EachBlockWith, ChainNotify};
|
||||||
use parity_reactor::EventLoop;
|
use parity_reactor::EventLoop;
|
||||||
|
|
||||||
|
const DURATION_ZERO: Duration = Duration::from_millis(0);
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_subscribe_to_new_heads() {
|
fn should_subscribe_to_new_heads() {
|
||||||
// given
|
// given
|
||||||
@ -53,13 +57,13 @@ fn should_subscribe_to_new_heads() {
|
|||||||
assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned()));
|
assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned()));
|
||||||
|
|
||||||
// Check notifications
|
// Check notifications
|
||||||
handler.new_blocks(vec![], vec![], vec![h1], vec![], vec![], vec![], 0);
|
handler.new_blocks(vec![], vec![], vec![h1], vec![], vec![], vec![], DURATION_ZERO);
|
||||||
let (res, receiver) = receiver.into_future().wait().unwrap();
|
let (res, receiver) = receiver.into_future().wait().unwrap();
|
||||||
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x1","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x1","parentHash":"0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x416d77337e24399d"}}"#;
|
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x1","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x1","parentHash":"0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x416d77337e24399d"}}"#;
|
||||||
assert_eq!(res, Some(response.into()));
|
assert_eq!(res, Some(response.into()));
|
||||||
|
|
||||||
// Notify about two blocks
|
// Notify about two blocks
|
||||||
handler.new_blocks(vec![], vec![], vec![h2, h3], vec![], vec![], vec![], 0);
|
handler.new_blocks(vec![], vec![], vec![h2, h3], vec![], vec![], vec![], DURATION_ZERO);
|
||||||
|
|
||||||
// Receive both
|
// Receive both
|
||||||
let (res, receiver) = receiver.into_future().wait().unwrap();
|
let (res, receiver) = receiver.into_future().wait().unwrap();
|
||||||
@ -125,7 +129,7 @@ fn should_subscribe_to_logs() {
|
|||||||
assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned()));
|
assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned()));
|
||||||
|
|
||||||
// Check notifications (enacted)
|
// Check notifications (enacted)
|
||||||
handler.new_blocks(vec![], vec![], vec![h1], vec![], vec![], vec![], 0);
|
handler.new_blocks(vec![], vec![], vec![h1], vec![], vec![], vec![], DURATION_ZERO);
|
||||||
let (res, receiver) = receiver.into_future().wait().unwrap();
|
let (res, receiver) = receiver.into_future().wait().unwrap();
|
||||||
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"address":"0x0000000000000000000000000000000000000005","blockHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","blockNumber":"0x1","data":"0x","logIndex":"0x0","topics":["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"],"transactionHash":""#.to_owned()
|
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"address":"0x0000000000000000000000000000000000000005","blockHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","blockNumber":"0x1","data":"0x","logIndex":"0x0","topics":["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"],"transactionHash":""#.to_owned()
|
||||||
+ &format!("0x{:x}", tx_hash)
|
+ &format!("0x{:x}", tx_hash)
|
||||||
@ -133,7 +137,7 @@ fn should_subscribe_to_logs() {
|
|||||||
assert_eq!(res, Some(response.into()));
|
assert_eq!(res, Some(response.into()));
|
||||||
|
|
||||||
// Check notifications (retracted)
|
// Check notifications (retracted)
|
||||||
handler.new_blocks(vec![], vec![], vec![], vec![h1], vec![], vec![], 0);
|
handler.new_blocks(vec![], vec![], vec![], vec![h1], vec![], vec![], DURATION_ZERO);
|
||||||
let (res, receiver) = receiver.into_future().wait().unwrap();
|
let (res, receiver) = receiver.into_future().wait().unwrap();
|
||||||
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"address":"0x0000000000000000000000000000000000000005","blockHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","blockNumber":"0x1","data":"0x","logIndex":"0x0","topics":["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"],"transactionHash":""#.to_owned()
|
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"address":"0x0000000000000000000000000000000000000005","blockHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","blockNumber":"0x1","data":"0x","logIndex":"0x0","topics":["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"],"transactionHash":""#.to_owned()
|
||||||
+ &format!("0x{:x}", tx_hash)
|
+ &format!("0x{:x}", tx_hash)
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::time::Duration;
|
||||||
use parking_lot::{Mutex, RwLock};
|
use parking_lot::{Mutex, RwLock};
|
||||||
use ethcore::client::{BlockId, ChainNotify, CallContract, RegistryInfo};
|
use ethcore::client::{BlockId, ChainNotify, CallContract, RegistryInfo};
|
||||||
use ethereum_types::{H256, Address};
|
use ethereum_types::{H256, Address};
|
||||||
@ -75,7 +76,7 @@ impl AclStorage for OnChainAclStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ChainNotify for OnChainAclStorage {
|
impl ChainNotify for OnChainAclStorage {
|
||||||
fn new_blocks(&self, _imported: Vec<H256>, _invalid: Vec<H256>, enacted: Vec<H256>, retracted: Vec<H256>, _sealed: Vec<H256>, _proposed: Vec<Bytes>, _duration: u64) {
|
fn new_blocks(&self, _imported: Vec<H256>, _invalid: Vec<H256>, enacted: Vec<H256>, retracted: Vec<H256>, _sealed: Vec<H256>, _proposed: Vec<Bytes>, _duration: Duration) {
|
||||||
if !enacted.is_empty() || !retracted.is_empty() {
|
if !enacted.is_empty() || !retracted.is_empty() {
|
||||||
self.contract.lock().update()
|
self.contract.lock().update()
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::collections::{BTreeMap, HashSet};
|
use std::collections::{BTreeMap, HashSet};
|
||||||
|
use std::time::Duration;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use ethcore::client::{Client, BlockChainClient, BlockId, ChainNotify, CallContract, RegistryInfo};
|
use ethcore::client::{Client, BlockChainClient, BlockId, ChainNotify, CallContract, RegistryInfo};
|
||||||
use ethcore::filter::Filter;
|
use ethcore::filter::Filter;
|
||||||
@ -162,7 +163,7 @@ impl KeyServerSet for OnChainKeyServerSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ChainNotify for OnChainKeyServerSet {
|
impl ChainNotify for OnChainKeyServerSet {
|
||||||
fn new_blocks(&self, _imported: Vec<H256>, _invalid: Vec<H256>, enacted: Vec<H256>, retracted: Vec<H256>, _sealed: Vec<H256>, _proposed: Vec<Bytes>, _duration: u64) {
|
fn new_blocks(&self, _imported: Vec<H256>, _invalid: Vec<H256>, enacted: Vec<H256>, retracted: Vec<H256>, _sealed: Vec<H256>, _proposed: Vec<Bytes>, _duration: Duration) {
|
||||||
if !enacted.is_empty() || !retracted.is_empty() {
|
if !enacted.is_empty() || !retracted.is_empty() {
|
||||||
self.contract.lock().update(enacted, retracted)
|
self.contract.lock().update(enacted, retracted)
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
use std::time::Duration;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use ethcore::client::ChainNotify;
|
use ethcore::client::ChainNotify;
|
||||||
@ -428,7 +429,7 @@ impl Drop for ServiceContractListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ChainNotify for ServiceContractListener {
|
impl ChainNotify for ServiceContractListener {
|
||||||
fn new_blocks(&self, _imported: Vec<H256>, _invalid: Vec<H256>, enacted: Vec<H256>, _retracted: Vec<H256>, _sealed: Vec<H256>, _proposed: Vec<Bytes>, _duration: u64) {
|
fn new_blocks(&self, _imported: Vec<H256>, _invalid: Vec<H256>, enacted: Vec<H256>, _retracted: Vec<H256>, _sealed: Vec<H256>, _proposed: Vec<Bytes>, _duration: Duration) {
|
||||||
let enacted_len = enacted.len();
|
let enacted_len = enacted.len();
|
||||||
if enacted_len == 0 {
|
if enacted_len == 0 {
|
||||||
return;
|
return;
|
||||||
|
@ -660,7 +660,7 @@ impl<O: OperationsClient, F: HashFetch, T: TimeProvider, R: GenRange> Updater<O,
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ChainNotify for Updater {
|
impl ChainNotify for Updater {
|
||||||
fn new_blocks(&self, _imported: Vec<H256>, _invalid: Vec<H256>, _enacted: Vec<H256>, _retracted: Vec<H256>, _sealed: Vec<H256>, _proposed: Vec<Bytes>, _duration: u64) {
|
fn new_blocks(&self, _imported: Vec<H256>, _invalid: Vec<H256>, _enacted: Vec<H256>, _retracted: Vec<H256>, _sealed: Vec<H256>, _proposed: Vec<Bytes>, _duration: Duration) {
|
||||||
match (self.client.upgrade(), self.sync.as_ref().and_then(Weak::upgrade)) {
|
match (self.client.upgrade(), self.sync.as_ref().and_then(Weak::upgrade)) {
|
||||||
(Some(ref c), Some(ref s)) if !s.status().is_syncing(c.queue_info()) => self.poll(),
|
(Some(ref c), Some(ref s)) if !s.status().is_syncing(c.queue_info()) => self.poll(),
|
||||||
_ => {},
|
_ => {},
|
||||||
|
Loading…
Reference in New Issue
Block a user