BlockId removal: &Hash to Hash (#12626)

It changes &Block::Hash argument to Block::Hash.

This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)
This commit is contained in:
Michal Kucharczyk
2022-11-07 22:42:16 +01:00
committed by GitHub
parent 7c4bfc9749
commit 1ed70004e7
49 changed files with 428 additions and 441 deletions
+26 -26
View File
@@ -271,16 +271,16 @@ impl<Block: BlockT> Blockchain<Block> {
fn finalize_header(
&self,
block: &Block::Hash,
block: Block::Hash,
justification: Option<Justification>,
) -> sp_blockchain::Result<()> {
let mut storage = self.storage.write();
storage.finalized_hash = *block;
storage.finalized_hash = block;
if justification.is_some() {
let block = storage
.blocks
.get_mut(block)
.get_mut(&block)
.expect("hash was fetched from a block in the db; qed");
let block_justifications = match block {
@@ -295,7 +295,7 @@ impl<Block: BlockT> Blockchain<Block> {
fn append_justification(
&self,
hash: &Block::Hash,
hash: Block::Hash,
justification: Justification,
) -> sp_blockchain::Result<()> {
let mut storage = self.storage.write();
@@ -405,17 +405,17 @@ impl<Block: BlockT> HeaderMetadata<Block> for Blockchain<Block> {
impl<Block: BlockT> blockchain::Backend<Block> for Blockchain<Block> {
fn body(
&self,
hash: &Block::Hash,
hash: Block::Hash,
) -> sp_blockchain::Result<Option<Vec<<Block as BlockT>::Extrinsic>>> {
Ok(self
.storage
.read()
.blocks
.get(hash)
.get(&hash)
.and_then(|b| b.extrinsics().map(|x| x.to_vec())))
}
fn justifications(&self, hash: &Block::Hash) -> sp_blockchain::Result<Option<Justifications>> {
fn justifications(&self, hash: Block::Hash) -> sp_blockchain::Result<Option<Justifications>> {
Ok(self.storage.read().blocks.get(&hash).and_then(|b| b.justifications().cloned()))
}
@@ -445,13 +445,13 @@ impl<Block: BlockT> blockchain::Backend<Block> for Blockchain<Block> {
unimplemented!()
}
fn indexed_transaction(&self, _hash: &Block::Hash) -> sp_blockchain::Result<Option<Vec<u8>>> {
fn indexed_transaction(&self, _hash: Block::Hash) -> sp_blockchain::Result<Option<Vec<u8>>> {
unimplemented!("Not supported by the in-mem backend.")
}
fn block_indexed_body(
&self,
_hash: &Block::Hash,
_hash: Block::Hash,
) -> sp_blockchain::Result<Option<Vec<Vec<u8>>>> {
unimplemented!("Not supported by the in-mem backend.")
}
@@ -596,16 +596,16 @@ where
fn mark_finalized(
&mut self,
hash: &Block::Hash,
hash: Block::Hash,
justification: Option<Justification>,
) -> sp_blockchain::Result<()> {
self.finalized_blocks.push((*hash, justification));
self.finalized_blocks.push((hash, justification));
Ok(())
}
fn mark_head(&mut self, hash: &Block::Hash) -> sp_blockchain::Result<()> {
fn mark_head(&mut self, hash: Block::Hash) -> sp_blockchain::Result<()> {
assert!(self.pending_block.is_none(), "Only one set block per operation is allowed");
self.set_head = Some(*hash);
self.set_head = Some(hash);
Ok(())
}
@@ -677,7 +677,7 @@ where
type OffchainStorage = OffchainStorage;
fn begin_operation(&self) -> sp_blockchain::Result<Self::BlockImportOperation> {
let old_state = self.state_at(&Default::default())?;
let old_state = self.state_at(Default::default())?;
Ok(BlockImportOperation {
pending_block: None,
old_state,
@@ -691,7 +691,7 @@ where
fn begin_state_operation(
&self,
operation: &mut Self::BlockImportOperation,
block: &Block::Hash,
block: Block::Hash,
) -> sp_blockchain::Result<()> {
operation.old_state = self.state_at(block)?;
Ok(())
@@ -700,7 +700,7 @@ where
fn commit_operation(&self, operation: Self::BlockImportOperation) -> sp_blockchain::Result<()> {
if !operation.finalized_blocks.is_empty() {
for (block, justification) in operation.finalized_blocks {
self.blockchain.finalize_header(&block, justification)?;
self.blockchain.finalize_header(block, justification)?;
}
}
@@ -733,7 +733,7 @@ where
fn finalize_block(
&self,
hash: &Block::Hash,
hash: Block::Hash,
justification: Option<Justification>,
) -> sp_blockchain::Result<()> {
self.blockchain.finalize_header(hash, justification)
@@ -741,7 +741,7 @@ where
fn append_justification(
&self,
hash: &Block::Hash,
hash: Block::Hash,
justification: Justification,
) -> sp_blockchain::Result<()> {
self.blockchain.append_justification(hash, justification)
@@ -759,14 +759,14 @@ where
None
}
fn state_at(&self, hash: &Block::Hash) -> sp_blockchain::Result<Self::State> {
if *hash == Default::default() {
fn state_at(&self, hash: Block::Hash) -> sp_blockchain::Result<Self::State> {
if hash == Default::default() {
return Ok(Self::State::default())
}
self.states
.read()
.get(hash)
.get(&hash)
.cloned()
.ok_or_else(|| sp_blockchain::Error::UnknownBlock(format!("{}", hash)))
}
@@ -779,7 +779,7 @@ where
Ok((Zero::zero(), HashSet::new()))
}
fn remove_leaf_block(&self, _hash: &Block::Hash) -> sp_blockchain::Result<()> {
fn remove_leaf_block(&self, _hash: Block::Hash) -> sp_blockchain::Result<()> {
Ok(())
}
@@ -862,13 +862,13 @@ mod tests {
let blockchain = test_blockchain();
let last_finalized = blockchain.last_finalized().unwrap();
blockchain.append_justification(&last_finalized, (ID2, vec![4])).unwrap();
blockchain.append_justification(last_finalized, (ID2, vec![4])).unwrap();
let justifications = {
let mut just = Justifications::from((ID1, vec![3]));
just.append((ID2, vec![4]));
just
};
assert_eq!(blockchain.justifications(&last_finalized).unwrap(), Some(justifications));
assert_eq!(blockchain.justifications(last_finalized).unwrap(), Some(justifications));
}
#[test]
@@ -876,9 +876,9 @@ mod tests {
let blockchain = test_blockchain();
let last_finalized = blockchain.last_finalized().unwrap();
blockchain.append_justification(&last_finalized, (ID2, vec![0])).unwrap();
blockchain.append_justification(last_finalized, (ID2, vec![0])).unwrap();
assert!(matches!(
blockchain.append_justification(&last_finalized, (ID2, vec![1])),
blockchain.append_justification(last_finalized, (ID2, vec![1])),
Err(sp_blockchain::Error::BadJustification(_)),
));
}