Performance optimizations (#1642)
* Optimize ethash verification * disable WAL for puts * Clear account cache after commit * Commit only modified accounts * Optimize existing block check * Cache last hashes
This commit is contained in:
committed by
Gav Wood
parent
5dba43178b
commit
5ab18d1313
@@ -145,6 +145,7 @@ pub struct Client {
|
||||
notify: RwLock<Option<Weak<ChainNotify>>>,
|
||||
queue_transactions: AtomicUsize,
|
||||
previous_enode: Mutex<Option<String>>,
|
||||
last_hashes: RwLock<VecDeque<H256>>,
|
||||
}
|
||||
|
||||
const HISTORY: u64 = 1200;
|
||||
@@ -232,6 +233,7 @@ impl Client {
|
||||
notify: RwLock::new(None),
|
||||
queue_transactions: AtomicUsize::new(0),
|
||||
previous_enode: Mutex::new(None),
|
||||
last_hashes: RwLock::new(VecDeque::new()),
|
||||
};
|
||||
Ok(Arc::new(client))
|
||||
}
|
||||
@@ -253,6 +255,14 @@ impl Client {
|
||||
}
|
||||
|
||||
fn build_last_hashes(&self, parent_hash: H256) -> LastHashes {
|
||||
{
|
||||
let hashes = self.last_hashes.read();
|
||||
if hashes.front().map_or(false, |h| h == &parent_hash) {
|
||||
let mut res = Vec::from(hashes.clone());
|
||||
res.resize(256, H256::default());
|
||||
return res;
|
||||
}
|
||||
}
|
||||
let mut last_hashes = LastHashes::new();
|
||||
last_hashes.resize(256, H256::new());
|
||||
last_hashes[0] = parent_hash;
|
||||
@@ -264,6 +274,8 @@ impl Client {
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
let mut cached_hashes = self.last_hashes.write();
|
||||
*cached_hashes = VecDeque::from(last_hashes.clone());
|
||||
last_hashes
|
||||
}
|
||||
|
||||
@@ -418,6 +430,7 @@ impl Client {
|
||||
|
||||
fn commit_block<B>(&self, block: B, hash: &H256, block_data: &[u8]) -> ImportRoute where B: IsBlock + Drain {
|
||||
let number = block.header().number();
|
||||
let parent = block.header().parent_hash().clone();
|
||||
// Are we committing an era?
|
||||
let ancient = if number >= HISTORY {
|
||||
let n = number - HISTORY;
|
||||
@@ -445,9 +458,20 @@ impl Client {
|
||||
enacted: route.enacted.clone(),
|
||||
retracted: route.retracted.len()
|
||||
});
|
||||
self.update_last_hashes(&parent, hash);
|
||||
route
|
||||
}
|
||||
|
||||
fn update_last_hashes(&self, parent: &H256, hash: &H256) {
|
||||
let mut hashes = self.last_hashes.write();
|
||||
if hashes.front().map_or(false, |h| h == parent) {
|
||||
if hashes.len() > 255 {
|
||||
hashes.pop_back();
|
||||
}
|
||||
hashes.push_front(hash.clone());
|
||||
}
|
||||
}
|
||||
|
||||
/// Import transactions from the IO queue
|
||||
pub fn import_queued_transactions(&self, transactions: &[Bytes]) -> usize {
|
||||
let _timer = PerfTimer::new("import_queued_transactions");
|
||||
|
||||
Reference in New Issue
Block a user