Backports to beta (#1919)
* RPC errors & logs (#1845) * Refactoring errors in RPC * Updating jsonrpc-core * Fixing code_at * Avoid mentioning obvious segments in proof [ci:skip] * fixed cache_manager lock order * Purging .derefs, fixing clippy warnings. (#1890) * Fixing clippy warnings * Purging derefs * Simplifying engine derefs * Simplifying more engine derefs * Adding more details to miner log * fixed #1889, .DS_Store is no longer treated as key file (#1892) * fixed #1889, .DS_Store is no longer treated as key file * ethstore filters directories, hidden files and common system files * fixed compiling * fix regression with geth dir * fix regression with geth dir * Fix ipc compilation and add ipc feature to test targets (#1902) * fix compilation and add it to the ci run * no separator? * use quotes and spaces * RocksDB version bump * Don't return deleted nodes that are not yet flushed (#1908) * polling & connection timeouts (#1910) * Peers RPC + UI displaying active/connected/max peers (#1915) * Peers API * Bumping Parity-UI * Fixing tests * Save nodes removed from backing_overlay until commit (#1917)
This commit is contained in:
@@ -133,8 +133,9 @@ enum CacheID {
|
||||
impl bc::group::BloomGroupDatabase for BlockChain {
|
||||
fn blooms_at(&self, position: &bc::group::GroupPosition) -> Option<bc::group::BloomGroup> {
|
||||
let position = LogGroupPosition::from(position.clone());
|
||||
self.note_used(CacheID::BlocksBlooms(position.clone()));
|
||||
self.db.read_with_cache(DB_COL_EXTRA, &self.blocks_blooms, &position).map(Into::into)
|
||||
let result = self.db.read_with_cache(DB_COL_EXTRA, &self.blocks_blooms, &position).map(Into::into);
|
||||
self.note_used(CacheID::BlocksBlooms(position));
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,9 +212,7 @@ impl BlockProvider for BlockChain {
|
||||
let opt = self.db.get(DB_COL_HEADERS, hash)
|
||||
.expect("Low level database error. Some issue with disk?");
|
||||
|
||||
self.note_used(CacheID::BlockHeader(hash.clone()));
|
||||
|
||||
match opt {
|
||||
let result = match opt {
|
||||
Some(b) => {
|
||||
let bytes: Bytes = UntrustedRlp::new(&b).decompress(RlpType::Blocks).to_vec();
|
||||
let mut write = self.block_headers.write();
|
||||
@@ -221,7 +220,10 @@ impl BlockProvider for BlockChain {
|
||||
Some(bytes)
|
||||
},
|
||||
None => None
|
||||
}
|
||||
};
|
||||
|
||||
self.note_used(CacheID::BlockHeader(hash.clone()));
|
||||
result
|
||||
}
|
||||
|
||||
/// Get block body data
|
||||
@@ -246,9 +248,7 @@ impl BlockProvider for BlockChain {
|
||||
let opt = self.db.get(DB_COL_BODIES, hash)
|
||||
.expect("Low level database error. Some issue with disk?");
|
||||
|
||||
self.note_used(CacheID::BlockBody(hash.clone()));
|
||||
|
||||
match opt {
|
||||
let result = match opt {
|
||||
Some(b) => {
|
||||
let bytes: Bytes = UntrustedRlp::new(&b).decompress(RlpType::Blocks).to_vec();
|
||||
let mut write = self.block_bodies.write();
|
||||
@@ -256,31 +256,39 @@ impl BlockProvider for BlockChain {
|
||||
Some(bytes)
|
||||
},
|
||||
None => None
|
||||
}
|
||||
};
|
||||
|
||||
self.note_used(CacheID::BlockBody(hash.clone()));
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
/// Get the familial details concerning a block.
|
||||
fn block_details(&self, hash: &H256) -> Option<BlockDetails> {
|
||||
let result = self.db.read_with_cache(DB_COL_EXTRA, &self.block_details, hash);
|
||||
self.note_used(CacheID::BlockDetails(hash.clone()));
|
||||
self.db.read_with_cache(DB_COL_EXTRA, &self.block_details, hash)
|
||||
result
|
||||
}
|
||||
|
||||
/// Get the hash of given block's number.
|
||||
fn block_hash(&self, index: BlockNumber) -> Option<H256> {
|
||||
let result = self.db.read_with_cache(DB_COL_EXTRA, &self.block_hashes, &index);
|
||||
self.note_used(CacheID::BlockHashes(index));
|
||||
self.db.read_with_cache(DB_COL_EXTRA, &self.block_hashes, &index)
|
||||
result
|
||||
}
|
||||
|
||||
/// Get the address of transaction with given hash.
|
||||
fn transaction_address(&self, hash: &H256) -> Option<TransactionAddress> {
|
||||
let result = self.db.read_with_cache(DB_COL_EXTRA, &self.transaction_addresses, hash);
|
||||
self.note_used(CacheID::TransactionAddresses(hash.clone()));
|
||||
self.db.read_with_cache(DB_COL_EXTRA, &self.transaction_addresses, hash)
|
||||
result
|
||||
}
|
||||
|
||||
/// Get receipts of block with given hash.
|
||||
fn block_receipts(&self, hash: &H256) -> Option<BlockReceipts> {
|
||||
let result = self.db.read_with_cache(DB_COL_EXTRA, &self.block_receipts, hash);
|
||||
self.note_used(CacheID::BlockReceipts(hash.clone()));
|
||||
self.db.read_with_cache(DB_COL_EXTRA, &self.block_receipts, hash)
|
||||
result
|
||||
}
|
||||
|
||||
/// Returns numbers of blocks containing given bloom.
|
||||
@@ -635,11 +643,12 @@ impl BlockChain {
|
||||
let mut update = HashMap::new();
|
||||
update.insert(block_hash, parent_details);
|
||||
|
||||
self.note_used(CacheID::BlockDetails(block_hash));
|
||||
|
||||
let mut write_details = self.block_details.write();
|
||||
batch.extend_with_cache(DB_COL_EXTRA, &mut *write_details, update, CacheUpdatePolicy::Overwrite);
|
||||
|
||||
self.note_used(CacheID::BlockDetails(block_hash));
|
||||
|
||||
self.db.write(batch).unwrap();
|
||||
}
|
||||
|
||||
@@ -730,12 +739,14 @@ impl BlockChain {
|
||||
/// Prepares extras update.
|
||||
fn prepare_update(&self, batch: &DBTransaction, update: ExtrasUpdate, is_best: bool) {
|
||||
{
|
||||
for hash in update.block_details.keys().cloned() {
|
||||
self.note_used(CacheID::BlockDetails(hash));
|
||||
}
|
||||
let block_hashes: Vec<_> = update.block_details.keys().cloned().collect();
|
||||
|
||||
let mut write_details = self.block_details.write();
|
||||
batch.extend_with_cache(DB_COL_EXTRA, &mut *write_details, update.block_details, CacheUpdatePolicy::Overwrite);
|
||||
|
||||
for hash in block_hashes.into_iter() {
|
||||
self.note_used(CacheID::BlockDetails(hash));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@@ -779,13 +790,6 @@ impl BlockChain {
|
||||
let mut pending_write_hashes = self.pending_block_hashes.write();
|
||||
let mut pending_write_txs = self.pending_transaction_addresses.write();
|
||||
|
||||
for n in pending_write_hashes.keys() {
|
||||
self.note_used(CacheID::BlockHashes(*n));
|
||||
}
|
||||
for hash in pending_write_txs.keys() {
|
||||
self.note_used(CacheID::TransactionAddresses(hash.clone()));
|
||||
}
|
||||
|
||||
let mut best_block = self.best_block.write();
|
||||
let mut write_hashes = self.block_hashes.write();
|
||||
let mut write_txs = self.transaction_addresses.write();
|
||||
@@ -794,8 +798,19 @@ impl BlockChain {
|
||||
*best_block = block;
|
||||
}
|
||||
|
||||
let pending_hashes_keys: Vec<_> = pending_write_hashes.keys().cloned().collect();
|
||||
let pending_txs_keys: Vec<_> = pending_write_txs.keys().cloned().collect();
|
||||
|
||||
write_hashes.extend(mem::replace(&mut *pending_write_hashes, HashMap::new()));
|
||||
write_txs.extend(mem::replace(&mut *pending_write_txs, HashMap::new()));
|
||||
|
||||
for n in pending_hashes_keys.into_iter() {
|
||||
self.note_used(CacheID::BlockHashes(n));
|
||||
}
|
||||
|
||||
for hash in pending_txs_keys.into_iter() {
|
||||
self.note_used(CacheID::TransactionAddresses(hash));
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterator that lists `first` and then all of `first`'s ancestors, by hash.
|
||||
@@ -1000,16 +1015,18 @@ impl BlockChain {
|
||||
|
||||
/// Ticks our cache system and throws out any old data.
|
||||
pub fn collect_garbage(&self) {
|
||||
let mut cache_man = self.cache_man.write();
|
||||
cache_man.collect_garbage(|| self.cache_size().total(), | ids | {
|
||||
let mut block_headers = self.block_headers.write();
|
||||
let mut block_bodies = self.block_bodies.write();
|
||||
let mut block_details = self.block_details.write();
|
||||
let mut block_hashes = self.block_hashes.write();
|
||||
let mut transaction_addresses = self.transaction_addresses.write();
|
||||
let mut blocks_blooms = self.blocks_blooms.write();
|
||||
let mut block_receipts = self.block_receipts.write();
|
||||
let current_size = self.cache_size().total();
|
||||
|
||||
let mut block_headers = self.block_headers.write();
|
||||
let mut block_bodies = self.block_bodies.write();
|
||||
let mut block_details = self.block_details.write();
|
||||
let mut block_hashes = self.block_hashes.write();
|
||||
let mut transaction_addresses = self.transaction_addresses.write();
|
||||
let mut blocks_blooms = self.blocks_blooms.write();
|
||||
let mut block_receipts = self.block_receipts.write();
|
||||
|
||||
let mut cache_man = self.cache_man.write();
|
||||
cache_man.collect_garbage(current_size, | ids | {
|
||||
for id in &ids {
|
||||
match *id {
|
||||
CacheID::BlockHeader(ref h) => { block_headers.remove(h); },
|
||||
@@ -1021,6 +1038,7 @@ impl BlockChain {
|
||||
CacheID::BlockReceipts(ref h) => { block_receipts.remove(h); }
|
||||
}
|
||||
}
|
||||
|
||||
block_headers.shrink_to_fit();
|
||||
block_bodies.shrink_to_fit();
|
||||
block_details.shrink_to_fit();
|
||||
@@ -1028,6 +1046,14 @@ impl BlockChain {
|
||||
transaction_addresses.shrink_to_fit();
|
||||
blocks_blooms.shrink_to_fit();
|
||||
block_receipts.shrink_to_fit();
|
||||
|
||||
block_headers.heap_size_of_children() +
|
||||
block_bodies.heap_size_of_children() +
|
||||
block_details.heap_size_of_children() +
|
||||
block_hashes.heap_size_of_children() +
|
||||
transaction_addresses.heap_size_of_children() +
|
||||
blocks_blooms.heap_size_of_children() +
|
||||
block_receipts.heap_size_of_children()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user