mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Index blocks by number in the DB (#890)
* resolve #780 * in import tx insert after retracting so blocks don't disappear * adapt db/cache to changes to db/utils * db/light: remove old hash lookup insertion * renames * improve naming * improve naming * db/utils: improve docs for block lookup key stuff * db/light/note_finalized: adapt to changes for issue #780 * db/light/cht/tests: add assertions for HASH_LOOKUP * simplify addresses https://github.com/paritytech/substrate/pull/890#discussion_r226009746 * break long line addresses https://github.com/paritytech/substrate/pull/890#discussion_r226002211 * Whitespace
This commit is contained in:
+3
-3
@@ -23,7 +23,7 @@ use kvdb::{KeyValueDB, DBTransaction};
|
||||
use client::error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as ClientResult};
|
||||
use codec::{Encode, Decode};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::traits::{Block as BlockT, NumberFor};
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor};
|
||||
use utils::{self, db_err, meta_keys};
|
||||
|
||||
use cache::{CacheItemT, ComplexBlockId};
|
||||
@@ -126,7 +126,8 @@ 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_id::<Block>(&*self.db, self.columns.hash_lookup, BlockId::Number(at))
|
||||
utils::read_header::<Block>(&*self.db, self.columns.hash_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>> {
|
||||
@@ -246,7 +247,6 @@ mod meta {
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use runtime_primitives::traits::Header as HeaderT;
|
||||
use super::*;
|
||||
|
||||
pub struct FaultyStorage;
|
||||
|
||||
+3
-2
@@ -194,10 +194,11 @@ impl<Block: BlockT> BlockchainCache<Block> for DbCacheSync<Block> {
|
||||
ComplexBlockId::new(hash, *header.number())
|
||||
},
|
||||
BlockId::Number(number) => {
|
||||
let hash = utils::read_id::<Block>(
|
||||
let hash = utils::read_header::<Block>(
|
||||
&**db,
|
||||
columns.hash_lookup,
|
||||
BlockId::Number(number.clone())).ok()??;
|
||||
columns.header,
|
||||
BlockId::Number(number.clone())).ok()??.hash();
|
||||
ComplexBlockId::new(hash, number)
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user