Blockchain cache pruning strategy (#3395)

* blockchain cache pruning strategy

* added some internal docs to cache_pruning_strategy

* Update core/client/db/src/cache/mod.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>
This commit is contained in:
Svyatoslav Nikolsky
2019-09-20 09:49:15 +03:00
committed by GitHub
parent d105d3f3a1
commit eba6dd73c6
20 changed files with 161 additions and 104 deletions
+2 -1
View File
@@ -33,7 +33,7 @@ use std::{sync::Arc, time::Duration, thread, marker::PhantomData, hash::Hash, fm
use codec::{Encode, Decode, Codec};
use consensus_common::{self, BlockImport, Environment, Proposer,
ForkChoiceStrategy, BlockImportParams, BlockOrigin, Error as ConsensusError,
SelectChain, well_known_cache_keys::{self, Id as CacheKeyId}
SelectChain,
};
use consensus_common::import_queue::{
Verifier, BasicQueue, BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport,
@@ -41,6 +41,7 @@ use consensus_common::import_queue::{
use client::{
block_builder::api::BlockBuilder as BlockBuilderApi, blockchain::ProvideCache,
runtime_api::ApiExt, error::Result as CResult, backend::AuxStore, BlockOf,
well_known_cache_keys::{self, Id as CacheKeyId},
};
use sr_primitives::{generic::{BlockId, OpaqueDigestItemId}, Justification};
+2 -2
View File
@@ -65,7 +65,6 @@ use consensus_common::ImportResult;
use consensus_common::import_queue::{
BoxJustificationImport, BoxFinalityProofImport,
};
use consensus_common::well_known_cache_keys::Id as CacheKeyId;
use sr_primitives::{generic::{BlockId, OpaqueDigestItemId}, Justification};
use sr_primitives::traits::{
Block as BlockT, Header, DigestItemFor, NumberFor, ProvideRuntimeApi,
@@ -96,7 +95,7 @@ use srml_babe::{
BabeInherentData,
timestamp::{TimestampInherentData, InherentType as TimestampInherent}
};
use consensus_common::{SelectChain, well_known_cache_keys};
use consensus_common::SelectChain;
use consensus_common::import_queue::{Verifier, BasicQueue};
use client::{
block_builder::api::BlockBuilder as BlockBuilderApi,
@@ -104,6 +103,7 @@ use client::{
runtime_api::ApiExt, error::Result as ClientResult, backend::{AuxStore, Backend},
ProvideUncles,
utils::is_descendent_of,
well_known_cache_keys::{self, Id as CacheKeyId},
};
use fork_tree::ForkTree;
use slots::{CheckedHeader, check_equivocation};
@@ -21,9 +21,8 @@ use sr_primitives::Justification;
use std::borrow::Cow;
use std::collections::HashMap;
use std::sync::Arc;
use crate::well_known_cache_keys;
use crate::import_queue::Verifier;
use crate::import_queue::{Verifier, CacheKeyId};
/// Block import result.
#[derive(Debug, PartialEq, Eq)]
@@ -182,7 +181,7 @@ pub trait BlockImport<B: BlockT> {
fn import_block(
&mut self,
block: BlockImportParams<B>,
cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
cache: HashMap<CacheKeyId, Vec<u8>>,
) -> Result<ImportResult, Self::Error>;
}
@@ -202,7 +201,7 @@ where for<'r> &'r T: BlockImport<B, Error = E>
fn import_block(
&mut self,
block: BlockImportParams<B>,
cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
cache: HashMap<CacheKeyId, Vec<u8>>,
) -> Result<ImportResult, Self::Error> {
(&**self).import_block(block, cache)
}
@@ -27,7 +27,7 @@
use std::collections::HashMap;
use sr_primitives::{Justification, traits::{Block as BlockT, Header as _, NumberFor}};
use crate::{error::Error as ConsensusError, well_known_cache_keys::Id as CacheKeyId};
use crate::error::Error as ConsensusError;
use crate::block_import::{
BlockImport, BlockOrigin, BlockImportParams, ImportedAux, JustificationImport, ImportResult,
FinalityProofImport,
@@ -65,6 +65,9 @@ pub struct IncomingBlock<B: BlockT> {
pub origin: Option<Origin>,
}
/// Type of keys in the blockchain cache that consensus module could use for its needs.
pub type CacheKeyId = [u8; 4];
/// Verify a justification of a block
pub trait Verifier<B: BlockT>: Send + Sync {
/// Verify the given data and return the BlockImportParams and an optional
@@ -117,15 +117,3 @@ where T: ?Sized, for<'r> &'r T: SyncOracle
<&T>::is_offline(&mut &**self)
}
}
/// A list of all well known keys in the cache.
pub mod well_known_cache_keys {
/// The type representing cache keys.
pub type Id = [u8; 4];
/// A list of authorities.
pub const AUTHORITIES: Id = *b"auth";
/// Current Epoch data.
pub const EPOCH: Id = *b"epch";
}
+2 -1
View File
@@ -35,6 +35,7 @@ use std::collections::HashMap;
use client::{
BlockOf, blockchain::{HeaderBackend, ProvideCache},
block_builder::api::BlockBuilder as BlockBuilderApi, backend::AuxStore,
well_known_cache_keys::Id as CacheKeyId,
};
use sr_primitives::Justification;
use sr_primitives::generic::{BlockId, Digest, DigestItem};
@@ -45,7 +46,7 @@ use primitives::H256;
use inherents::{InherentDataProviders, InherentData};
use consensus_common::{
BlockImportParams, BlockOrigin, ForkChoiceStrategy,
well_known_cache_keys::Id as CacheKeyId, Environment, Proposer,
Environment, Proposer,
};
use consensus_common::import_queue::{BoxBlockImport, BasicQueue, Verifier};
use codec::{Encode, Decode};