client report and heap size for header chain
This commit is contained in:
parent
d0194f3ad3
commit
bdf90df56f
@ -34,7 +34,7 @@ use ethcore::block_status::BlockStatus;
|
|||||||
use ethcore::error::BlockError;
|
use ethcore::error::BlockError;
|
||||||
use ethcore::ids::BlockId;
|
use ethcore::ids::BlockId;
|
||||||
use ethcore::views::HeaderView;
|
use ethcore::views::HeaderView;
|
||||||
use util::{Bytes, H256, U256, Mutex, RwLock};
|
use util::{Bytes, H256, U256, HeapSizeOf, Mutex, RwLock};
|
||||||
|
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
@ -66,6 +66,15 @@ struct Entry {
|
|||||||
canonical_hash: H256,
|
canonical_hash: H256,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HeapSizeOf for Entry {
|
||||||
|
fn heap_size_of_children(&self) -> usize {
|
||||||
|
match self.candidates.spilled() {
|
||||||
|
false => 0,
|
||||||
|
true => self.candidates.capacity() * ::std::mem::size_of::<Candidate>(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Header chain. See module docs for more details.
|
/// Header chain. See module docs for more details.
|
||||||
pub struct HeaderChain {
|
pub struct HeaderChain {
|
||||||
genesis_header: Bytes, // special-case the genesis.
|
genesis_header: Bytes, // special-case the genesis.
|
||||||
@ -255,6 +264,14 @@ impl HeaderChain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HeapSizeOf for HeaderChain {
|
||||||
|
fn heap_size_of_children(&self) -> usize {
|
||||||
|
self.candidates.read().heap_size_of_children() +
|
||||||
|
self.headers.read().heap_size_of_children() +
|
||||||
|
self.cht_roots.lock().heap_size_of_children()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::HeaderChain;
|
use super::HeaderChain;
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
use ethcore::block_import_error::BlockImportError;
|
use ethcore::block_import_error::BlockImportError;
|
||||||
use ethcore::block_status::BlockStatus;
|
use ethcore::block_status::BlockStatus;
|
||||||
|
use ethcore::client::ClientReport;
|
||||||
use ethcore::ids::BlockId;
|
use ethcore::ids::BlockId;
|
||||||
use ethcore::header::Header;
|
use ethcore::header::Header;
|
||||||
use ethcore::verification::queue::{self, HeaderQueue};
|
use ethcore::verification::queue::{self, HeaderQueue};
|
||||||
@ -28,7 +29,7 @@ use ethcore::service::ClientIoMessage;
|
|||||||
use io::IoChannel;
|
use io::IoChannel;
|
||||||
|
|
||||||
use util::hash::{H256, H256FastMap};
|
use util::hash::{H256, H256FastMap};
|
||||||
use util::{Bytes, Mutex};
|
use util::{Bytes, Mutex, RwLock};
|
||||||
|
|
||||||
use provider::Provider;
|
use provider::Provider;
|
||||||
use request;
|
use request;
|
||||||
@ -76,6 +77,7 @@ pub struct Client {
|
|||||||
queue: HeaderQueue,
|
queue: HeaderQueue,
|
||||||
chain: HeaderChain,
|
chain: HeaderChain,
|
||||||
tx_pool: Mutex<H256FastMap<PendingTransaction>>,
|
tx_pool: Mutex<H256FastMap<PendingTransaction>>,
|
||||||
|
report: RwLock<ClientReport>,
|
||||||
import_lock: Mutex<()>,
|
import_lock: Mutex<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,6 +88,7 @@ impl Client {
|
|||||||
queue: HeaderQueue::new(config.queue, spec.engine.clone(), io_channel, true),
|
queue: HeaderQueue::new(config.queue, spec.engine.clone(), io_channel, true),
|
||||||
chain: HeaderChain::new(&::rlp::encode(&spec.genesis_header())),
|
chain: HeaderChain::new(&::rlp::encode(&spec.genesis_header())),
|
||||||
tx_pool: Mutex::new(Default::default()),
|
tx_pool: Mutex::new(Default::default()),
|
||||||
|
report: RwLock::new(ClientReport::default()),
|
||||||
import_lock: Mutex::new(()),
|
import_lock: Mutex::new(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,7 +167,10 @@ impl Client {
|
|||||||
let (num, hash) = (verified_header.number(), verified_header.hash());
|
let (num, hash) = (verified_header.number(), verified_header.hash());
|
||||||
|
|
||||||
match self.chain.insert(::rlp::encode(&verified_header).to_vec()) {
|
match self.chain.insert(::rlp::encode(&verified_header).to_vec()) {
|
||||||
Ok(()) => good.push(hash),
|
Ok(()) => {
|
||||||
|
good.push(hash);
|
||||||
|
self.report.write().blocks_imported += 1;
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!(target: "client", "Error importing header {:?}: {}", (num, hash), e);
|
debug!(target: "client", "Error importing header {:?}: {}", (num, hash), e);
|
||||||
bad.push(hash);
|
bad.push(hash);
|
||||||
@ -175,6 +181,11 @@ impl Client {
|
|||||||
self.queue.mark_as_bad(&bad);
|
self.queue.mark_as_bad(&bad);
|
||||||
self.queue.mark_as_good(&good);
|
self.queue.mark_as_good(&good);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get a report about blocks imported.
|
||||||
|
pub fn report(&self) -> ClientReport {
|
||||||
|
::std::mem::replace(&mut *self.report.write(), ClientReport::default())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LightChainClient for Client {
|
impl LightChainClient for Client {
|
||||||
|
Loading…
Reference in New Issue
Block a user