Add small header cache (#7516)

* Remove header query

* Header cache

* Fix potential race issue

* Simplify status query
This commit is contained in:
Arkadiy Paronyan
2020-11-26 00:07:51 +01:00
committed by GitHub
parent f590b06fab
commit 769f1981cb
3 changed files with 46 additions and 19 deletions
@@ -53,7 +53,7 @@ pub trait HeaderBackend<Block: BlockT>: Send + Sync {
/// Convert an arbitrary block ID into a block hash.
fn block_number_from_id(&self, id: &BlockId<Block>) -> Result<Option<NumberFor<Block>>> {
match *id {
BlockId::Hash(_) => Ok(self.header(*id)?.map(|h| h.number().clone())),
BlockId::Hash(h) => self.number(h),
BlockId::Number(n) => Ok(Some(n)),
}
}