mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-29 14:57:25 +00:00
Use [u8; 4] for well known cache keys (#2152)
* Use [u8; 4] for well known cache keys * Use type alias
This commit is contained in:
committed by
DemiMarie-parity
parent
3dfda381d5
commit
fbbd79e778
@@ -23,6 +23,7 @@ use runtime_primitives::{generic::BlockId, Justification, StorageOverlay, Childr
|
||||
use runtime_primitives::traits::{Block as BlockT, NumberFor};
|
||||
use state_machine::backend::Backend as StateBackend;
|
||||
use state_machine::ChangesTrieStorage as StateChangesTrieStorage;
|
||||
use consensus::well_known_cache_keys;
|
||||
use hash_db::Hasher;
|
||||
use trie::MemoryDB;
|
||||
|
||||
@@ -75,7 +76,7 @@ pub trait BlockImportOperation<Block, H> where
|
||||
) -> error::Result<()>;
|
||||
|
||||
/// Update cached data.
|
||||
fn update_cache(&mut self, cache: HashMap<Vec<u8>, Vec<u8>>);
|
||||
fn update_cache(&mut self, cache: HashMap<well_known_cache_keys::Id, Vec<u8>>);
|
||||
/// Inject storage data into the database.
|
||||
fn update_db_storage(&mut self, update: <Self::State as StateBackend<H>>::Transaction) -> error::Result<()>;
|
||||
/// Inject storage data into the database replacing any existing data.
|
||||
|
||||
@@ -21,6 +21,7 @@ use std::sync::Arc;
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::Justification;
|
||||
use consensus::well_known_cache_keys;
|
||||
|
||||
use crate::error::{ErrorKind, Result};
|
||||
|
||||
@@ -100,7 +101,7 @@ pub trait ProvideCache<Block: BlockT> {
|
||||
/// Blockchain optional data cache.
|
||||
pub trait Cache<Block: BlockT>: Send + Sync {
|
||||
/// Returns cached value by the given key.
|
||||
fn get_at(&self, key: &[u8], block: &BlockId<Block>) -> Option<Vec<u8>>;
|
||||
fn get_at(&self, key: &well_known_cache_keys::Id, block: &BlockId<Block>) -> Option<Vec<u8>>;
|
||||
}
|
||||
|
||||
/// Blockchain info
|
||||
|
||||
@@ -27,7 +27,7 @@ use runtime_primitives::{
|
||||
};
|
||||
use consensus::{
|
||||
Error as ConsensusError, ErrorKind as ConsensusErrorKind, ImportBlock, ImportResult,
|
||||
BlockOrigin, ForkChoiceStrategy,
|
||||
BlockOrigin, ForkChoiceStrategy, well_known_cache_keys::Id as CacheKeyId,
|
||||
};
|
||||
use runtime_primitives::traits::{
|
||||
Block as BlockT, Header as HeaderT, Zero, As, NumberFor, CurrentHeight, BlockNumberToHash,
|
||||
@@ -672,7 +672,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
&self,
|
||||
operation: &mut ClientImportOperation<Block, Blake2Hasher, B>,
|
||||
import_block: ImportBlock<Block>,
|
||||
new_cache: HashMap<Vec<u8>, Vec<u8>>,
|
||||
new_cache: HashMap<CacheKeyId, Vec<u8>>,
|
||||
) -> error::Result<ImportResult> where
|
||||
E: CallExecutor<Block, Blake2Hasher> + Send + Sync + Clone,
|
||||
{
|
||||
@@ -743,7 +743,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
import_headers: PrePostHeader<Block::Header>,
|
||||
justification: Option<Justification>,
|
||||
body: Option<Vec<Block::Extrinsic>>,
|
||||
new_cache: HashMap<Vec<u8>, Vec<u8>>,
|
||||
new_cache: HashMap<CacheKeyId, Vec<u8>>,
|
||||
finalized: bool,
|
||||
aux: Vec<(Vec<u8>, Option<Vec<u8>>)>,
|
||||
fork_choice: ForkChoiceStrategy,
|
||||
@@ -1396,7 +1396,7 @@ impl<B, E, Block, RA> consensus::BlockImport<Block> for Client<B, E, Block, RA>
|
||||
fn import_block(
|
||||
&self,
|
||||
import_block: ImportBlock<Block>,
|
||||
new_cache: HashMap<Vec<u8>, Vec<u8>>,
|
||||
new_cache: HashMap<CacheKeyId, Vec<u8>>,
|
||||
) -> Result<ImportResult, Self::Error> {
|
||||
self.lock_import_and_run(|operation| {
|
||||
self.apply_block(operation, import_block, new_cache)
|
||||
|
||||
@@ -29,6 +29,7 @@ use state_machine::{self, InMemoryChangesTrieStorage, ChangesTrieAnchorBlockId};
|
||||
use hash_db::Hasher;
|
||||
use heapsize::HeapSizeOf;
|
||||
use trie::MemoryDB;
|
||||
use consensus::well_known_cache_keys::Id as CacheKeyId;
|
||||
|
||||
use crate::error;
|
||||
use crate::backend::{self, NewBlockState};
|
||||
@@ -390,7 +391,7 @@ impl<Block: BlockT> light::blockchain::Storage<Block> for Blockchain<Block>
|
||||
fn import_header(
|
||||
&self,
|
||||
header: Block::Header,
|
||||
_cache: HashMap<Vec<u8>, Vec<u8>>,
|
||||
_cache: HashMap<CacheKeyId, Vec<u8>>,
|
||||
state: NewBlockState,
|
||||
aux_ops: Vec<(Vec<u8>, Option<Vec<u8>>)>,
|
||||
) -> error::Result<()> {
|
||||
@@ -431,7 +432,7 @@ impl<Block: BlockT> light::blockchain::Storage<Block> for Blockchain<Block>
|
||||
/// In-memory operation.
|
||||
pub struct BlockImportOperation<Block: BlockT, H: Hasher> {
|
||||
pending_block: Option<PendingBlock<Block>>,
|
||||
pending_cache: HashMap<Vec<u8>, Vec<u8>>,
|
||||
pending_cache: HashMap<CacheKeyId, Vec<u8>>,
|
||||
old_state: InMemory<H>,
|
||||
new_state: Option<InMemory<H>>,
|
||||
changes_trie_update: Option<MemoryDB<H>>,
|
||||
@@ -468,7 +469,7 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_cache(&mut self, cache: HashMap<Vec<u8>, Vec<u8>>) {
|
||||
fn update_cache(&mut self, cache: HashMap<CacheKeyId, Vec<u8>>) {
|
||||
self.pending_cache = cache;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ use crate::light::fetcher::{Fetcher, RemoteReadRequest};
|
||||
use hash_db::Hasher;
|
||||
use trie::MemoryDB;
|
||||
use heapsize::HeapSizeOf;
|
||||
use consensus::well_known_cache_keys;
|
||||
|
||||
const IN_MEMORY_EXPECT_PROOF: &str = "InMemory state backend has Void error type and always suceeds; qed";
|
||||
|
||||
@@ -46,7 +47,7 @@ pub struct Backend<S, F, H> {
|
||||
/// Light block (header and justification) import operation.
|
||||
pub struct ImportOperation<Block: BlockT, S, F, H> {
|
||||
header: Option<Block::Header>,
|
||||
cache: HashMap<Vec<u8>, Vec<u8>>,
|
||||
cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
|
||||
leaf_state: NewBlockState,
|
||||
aux_ops: Vec<(Vec<u8>, Option<Vec<u8>>)>,
|
||||
finalized_blocks: Vec<BlockId<Block>>,
|
||||
@@ -254,7 +255,7 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_cache(&mut self, cache: HashMap<Vec<u8>, Vec<u8>>) {
|
||||
fn update_cache(&mut self, cache: HashMap<well_known_cache_keys::Id, Vec<u8>>) {
|
||||
self.cache = cache;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ use parking_lot::Mutex;
|
||||
|
||||
use runtime_primitives::{Justification, generic::BlockId};
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero};
|
||||
use consensus::well_known_cache_keys;
|
||||
|
||||
use crate::backend::{AuxStore, NewBlockState};
|
||||
use crate::blockchain::{Backend as BlockchainBackend, BlockStatus, Cache as BlockchainCache,
|
||||
@@ -40,7 +41,7 @@ pub trait Storage<Block: BlockT>: AuxStore + BlockchainHeaderBackend<Block> {
|
||||
fn import_header(
|
||||
&self,
|
||||
header: Block::Header,
|
||||
cache: HashMap<Vec<u8>, Vec<u8>>,
|
||||
cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
|
||||
state: NewBlockState,
|
||||
aux_ops: Vec<(Vec<u8>, Option<Vec<u8>>)>,
|
||||
) -> ClientResult<()>;
|
||||
@@ -252,7 +253,7 @@ pub mod tests {
|
||||
fn import_header(
|
||||
&self,
|
||||
_header: Header,
|
||||
_cache: HashMap<Vec<u8>, Vec<u8>>,
|
||||
_cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
|
||||
_state: NewBlockState,
|
||||
_aux_ops: Vec<(Vec<u8>, Option<Vec<u8>>)>,
|
||||
) -> ClientResult<()> {
|
||||
|
||||
Reference in New Issue
Block a user