mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 20:31:13 +00:00
alter DB schema to fix lookup race (#1135)
This commit is contained in:
committed by
Gav Wood
parent
c74daa8afe
commit
969c81028c
+4
-4
@@ -86,7 +86,7 @@ pub struct DbColumns {
|
||||
/// Column holding cache meta.
|
||||
pub meta: Option<u32>,
|
||||
/// Column holding the mapping of { block number => block hash } for blocks of the best chain.
|
||||
pub hash_lookup: Option<u32>,
|
||||
pub key_lookup: Option<u32>,
|
||||
/// Column holding the mapping of { block hash => block header }.
|
||||
pub header: Option<u32>,
|
||||
/// Column holding cache entries.
|
||||
@@ -126,12 +126,12 @@ impl DbStorage {
|
||||
|
||||
impl<Block: BlockT, T: CacheItemT> Storage<Block, T> for DbStorage {
|
||||
fn read_id(&self, at: NumberFor<Block>) -> ClientResult<Option<Block::Hash>> {
|
||||
utils::read_header::<Block>(&*self.db, self.columns.hash_lookup, self.columns.header, BlockId::Number(at))
|
||||
utils::read_header::<Block>(&*self.db, self.columns.key_lookup, self.columns.header, BlockId::Number(at))
|
||||
.map(|maybe_header| maybe_header.map(|header| header.hash()))
|
||||
}
|
||||
|
||||
fn read_header(&self, at: &Block::Hash) -> ClientResult<Option<Block::Header>> {
|
||||
utils::read_header::<Block>(&*self.db, self.columns.hash_lookup, self.columns.header, BlockId::Hash(*at))
|
||||
utils::read_header::<Block>(&*self.db, self.columns.key_lookup, self.columns.header, BlockId::Hash(*at))
|
||||
}
|
||||
|
||||
fn read_meta(&self) -> ClientResult<Metadata<Block>> {
|
||||
@@ -197,7 +197,7 @@ impl<'a, Block: BlockT, T: CacheItemT> StorageTransaction<Block, T> for DbStorag
|
||||
mod meta {
|
||||
use super::*;
|
||||
|
||||
/// Convert cache name into cache metadata key.
|
||||
/// Convert cache name into cache metadata key.
|
||||
pub fn key(name: &[u8]) -> Vec<u8> {
|
||||
let mut key_name = meta_keys::CACHE_META_PREFIX.to_vec();
|
||||
key_name.extend_from_slice(name);
|
||||
|
||||
+4
-4
@@ -72,7 +72,7 @@ impl<Block: BlockT> DbCache<Block> {
|
||||
/// Create new cache.
|
||||
pub fn new(
|
||||
db: Arc<KeyValueDB>,
|
||||
hash_lookup_column: Option<u32>,
|
||||
key_lookup_column: Option<u32>,
|
||||
header_column: Option<u32>,
|
||||
authorities_column: Option<u32>,
|
||||
best_finalized_block: ComplexBlockId<Block>,
|
||||
@@ -82,7 +82,7 @@ impl<Block: BlockT> DbCache<Block> {
|
||||
self::list_storage::DbStorage::new(b"auth".to_vec(), db,
|
||||
self::list_storage::DbColumns {
|
||||
meta: COLUMN_META,
|
||||
hash_lookup: hash_lookup_column,
|
||||
key_lookup: key_lookup_column,
|
||||
header: header_column,
|
||||
cache: authorities_column,
|
||||
},
|
||||
@@ -188,7 +188,7 @@ impl<Block: BlockT> BlockchainCache<Block> for DbCacheSync<Block> {
|
||||
BlockId::Hash(hash) => {
|
||||
let header = utils::read_header::<Block>(
|
||||
&**db,
|
||||
columns.hash_lookup,
|
||||
columns.key_lookup,
|
||||
columns.header,
|
||||
BlockId::Hash(hash.clone())).ok()??;
|
||||
ComplexBlockId::new(hash, *header.number())
|
||||
@@ -196,7 +196,7 @@ impl<Block: BlockT> BlockchainCache<Block> for DbCacheSync<Block> {
|
||||
BlockId::Number(number) => {
|
||||
let hash = utils::read_header::<Block>(
|
||||
&**db,
|
||||
columns.hash_lookup,
|
||||
columns.key_lookup,
|
||||
columns.header,
|
||||
BlockId::Number(number.clone())).ok()??.hash();
|
||||
ComplexBlockId::new(hash, number)
|
||||
|
||||
Reference in New Issue
Block a user