mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 09:57:56 +00:00
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:
committed by
GitHub
parent
7c4bfc9749
commit
1ed70004e7
@@ -215,13 +215,13 @@ pub trait BlockImportOperation<Block: BlockT> {
|
||||
/// Mark a block as finalized.
|
||||
fn mark_finalized(
|
||||
&mut self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
justification: Option<Justification>,
|
||||
) -> sp_blockchain::Result<()>;
|
||||
|
||||
/// Mark a block as new head. If both block import and set head are specified, set head
|
||||
/// overrides block import's best block rule.
|
||||
fn mark_head(&mut self, hash: &Block::Hash) -> sp_blockchain::Result<()>;
|
||||
fn mark_head(&mut self, hash: Block::Hash) -> sp_blockchain::Result<()>;
|
||||
|
||||
/// Add a transaction index operation.
|
||||
fn update_transaction_index(&mut self, index: Vec<IndexOperation>)
|
||||
@@ -251,7 +251,7 @@ pub trait Finalizer<Block: BlockT, B: Backend<Block>> {
|
||||
fn apply_finality(
|
||||
&self,
|
||||
operation: &mut ClientImportOperation<Block, B>,
|
||||
block: &Block::Hash,
|
||||
block: Block::Hash,
|
||||
justification: Option<Justification>,
|
||||
notify: bool,
|
||||
) -> sp_blockchain::Result<()>;
|
||||
@@ -271,7 +271,7 @@ pub trait Finalizer<Block: BlockT, B: Backend<Block>> {
|
||||
/// while performing major synchronization work.
|
||||
fn finalize_block(
|
||||
&self,
|
||||
block: &Block::Hash,
|
||||
block: Block::Hash,
|
||||
justification: Option<Justification>,
|
||||
notify: bool,
|
||||
) -> sp_blockchain::Result<()>;
|
||||
@@ -359,21 +359,21 @@ pub trait StorageProvider<Block: BlockT, B: Backend<Block>> {
|
||||
/// Given a block's `Hash` and a key, return the value under the key in that block.
|
||||
fn storage(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
key: &StorageKey,
|
||||
) -> sp_blockchain::Result<Option<StorageData>>;
|
||||
|
||||
/// Given a block's `Hash` and a key prefix, return the matching storage keys in that block.
|
||||
fn storage_keys(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
key_prefix: &StorageKey,
|
||||
) -> sp_blockchain::Result<Vec<StorageKey>>;
|
||||
|
||||
/// Given a block's `Hash` and a key, return the value under the hash in that block.
|
||||
fn storage_hash(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
key: &StorageKey,
|
||||
) -> sp_blockchain::Result<Option<Block::Hash>>;
|
||||
|
||||
@@ -381,7 +381,7 @@ pub trait StorageProvider<Block: BlockT, B: Backend<Block>> {
|
||||
/// in that block.
|
||||
fn storage_pairs(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
key_prefix: &StorageKey,
|
||||
) -> sp_blockchain::Result<Vec<(StorageKey, StorageData)>>;
|
||||
|
||||
@@ -389,7 +389,7 @@ pub trait StorageProvider<Block: BlockT, B: Backend<Block>> {
|
||||
/// keys in that block.
|
||||
fn storage_keys_iter<'a>(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
prefix: Option<&'a StorageKey>,
|
||||
start_key: Option<&StorageKey>,
|
||||
) -> sp_blockchain::Result<KeyIterator<'a, B::State, Block>>;
|
||||
@@ -398,7 +398,7 @@ pub trait StorageProvider<Block: BlockT, B: Backend<Block>> {
|
||||
/// that block.
|
||||
fn child_storage(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
child_info: &ChildInfo,
|
||||
key: &StorageKey,
|
||||
) -> sp_blockchain::Result<Option<StorageData>>;
|
||||
@@ -407,7 +407,7 @@ pub trait StorageProvider<Block: BlockT, B: Backend<Block>> {
|
||||
/// storage keys.
|
||||
fn child_storage_keys(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
child_info: &ChildInfo,
|
||||
key_prefix: &StorageKey,
|
||||
) -> sp_blockchain::Result<Vec<StorageKey>>;
|
||||
@@ -416,7 +416,7 @@ pub trait StorageProvider<Block: BlockT, B: Backend<Block>> {
|
||||
/// return a `KeyIterator` that iterates matching storage keys in that block.
|
||||
fn child_storage_keys_iter<'a>(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
child_info: ChildInfo,
|
||||
prefix: Option<&'a StorageKey>,
|
||||
start_key: Option<&StorageKey>,
|
||||
@@ -426,7 +426,7 @@ pub trait StorageProvider<Block: BlockT, B: Backend<Block>> {
|
||||
/// block.
|
||||
fn child_storage_hash(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
child_info: &ChildInfo,
|
||||
key: &StorageKey,
|
||||
) -> sp_blockchain::Result<Option<Block::Hash>>;
|
||||
@@ -466,7 +466,7 @@ pub trait Backend<Block: BlockT>: AuxStore + Send + Sync {
|
||||
fn begin_state_operation(
|
||||
&self,
|
||||
operation: &mut Self::BlockImportOperation,
|
||||
block: &Block::Hash,
|
||||
block: Block::Hash,
|
||||
) -> sp_blockchain::Result<()>;
|
||||
|
||||
/// Commit block insertion.
|
||||
@@ -480,7 +480,7 @@ pub trait Backend<Block: BlockT>: AuxStore + Send + Sync {
|
||||
/// This should only be called if the parent of the given block has been finalized.
|
||||
fn finalize_block(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
justification: Option<Justification>,
|
||||
) -> sp_blockchain::Result<()>;
|
||||
|
||||
@@ -489,7 +489,7 @@ pub trait Backend<Block: BlockT>: AuxStore + Send + Sync {
|
||||
/// This should only be called for blocks that are already finalized.
|
||||
fn append_justification(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
justification: Justification,
|
||||
) -> sp_blockchain::Result<()>;
|
||||
|
||||
@@ -503,12 +503,12 @@ pub trait Backend<Block: BlockT>: AuxStore + Send + Sync {
|
||||
fn offchain_storage(&self) -> Option<Self::OffchainStorage>;
|
||||
|
||||
/// Returns true if state for given block is available.
|
||||
fn have_state_at(&self, hash: &Block::Hash, _number: NumberFor<Block>) -> bool {
|
||||
fn have_state_at(&self, hash: Block::Hash, _number: NumberFor<Block>) -> bool {
|
||||
self.state_at(hash).is_ok()
|
||||
}
|
||||
|
||||
/// Returns state backend with post-state of given block.
|
||||
fn state_at(&self, hash: &Block::Hash) -> sp_blockchain::Result<Self::State>;
|
||||
fn state_at(&self, hash: Block::Hash) -> sp_blockchain::Result<Self::State>;
|
||||
|
||||
/// Attempts to revert the chain by `n` blocks. If `revert_finalized` is set it will attempt to
|
||||
/// revert past any finalized block, this is unsafe and can potentially leave the node in an
|
||||
@@ -524,7 +524,7 @@ pub trait Backend<Block: BlockT>: AuxStore + Send + Sync {
|
||||
) -> sp_blockchain::Result<(NumberFor<Block>, HashSet<Block::Hash>)>;
|
||||
|
||||
/// Discard non-best, unfinalized leaf block.
|
||||
fn remove_leaf_block(&self, hash: &Block::Hash) -> sp_blockchain::Result<()>;
|
||||
fn remove_leaf_block(&self, hash: Block::Hash) -> sp_blockchain::Result<()>;
|
||||
|
||||
/// Insert auxiliary data into key-value store.
|
||||
fn insert_aux<
|
||||
|
||||
@@ -110,7 +110,7 @@ pub trait BlockBackend<Block: BlockT> {
|
||||
/// Get block body by ID. Returns `None` if the body is not stored.
|
||||
fn block_body(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
) -> sp_blockchain::Result<Option<Vec<<Block as BlockT>::Extrinsic>>>;
|
||||
|
||||
/// Get all indexed transactions for a block,
|
||||
@@ -118,8 +118,7 @@ pub trait BlockBackend<Block: BlockT> {
|
||||
///
|
||||
/// Note that this will only fetch transactions
|
||||
/// that are indexed by the runtime with `storage_index_transaction`.
|
||||
fn block_indexed_body(&self, hash: &Block::Hash)
|
||||
-> sp_blockchain::Result<Option<Vec<Vec<u8>>>>;
|
||||
fn block_indexed_body(&self, hash: Block::Hash) -> sp_blockchain::Result<Option<Vec<Vec<u8>>>>;
|
||||
|
||||
/// Get full block by id.
|
||||
fn block(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Option<SignedBlock<Block>>>;
|
||||
@@ -129,7 +128,7 @@ pub trait BlockBackend<Block: BlockT> {
|
||||
-> sp_blockchain::Result<sp_consensus::BlockStatus>;
|
||||
|
||||
/// Get block justifications for the block with the given id.
|
||||
fn justifications(&self, hash: &Block::Hash) -> sp_blockchain::Result<Option<Justifications>>;
|
||||
fn justifications(&self, hash: Block::Hash) -> sp_blockchain::Result<Option<Justifications>>;
|
||||
|
||||
/// Get block hash by number.
|
||||
fn block_hash(&self, number: NumberFor<Block>) -> sp_blockchain::Result<Option<Block::Hash>>;
|
||||
@@ -138,10 +137,10 @@ pub trait BlockBackend<Block: BlockT> {
|
||||
///
|
||||
/// Note that this will only fetch transactions
|
||||
/// that are indexed by the runtime with `storage_index_transaction`.
|
||||
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>>>;
|
||||
|
||||
/// Check if transaction index exists.
|
||||
fn has_indexed_transaction(&self, hash: &Block::Hash) -> sp_blockchain::Result<bool> {
|
||||
fn has_indexed_transaction(&self, hash: Block::Hash) -> sp_blockchain::Result<bool> {
|
||||
Ok(self.indexed_transaction(hash)?.is_some())
|
||||
}
|
||||
|
||||
|
||||
@@ -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(_)),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ pub trait ProofProvider<Block: BlockT> {
|
||||
/// Reads storage value at a given block + key, returning read proof.
|
||||
fn read_proof(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
keys: &mut dyn Iterator<Item = &[u8]>,
|
||||
) -> sp_blockchain::Result<StorageProof>;
|
||||
|
||||
@@ -35,7 +35,7 @@ pub trait ProofProvider<Block: BlockT> {
|
||||
/// read proof.
|
||||
fn read_child_proof(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
child_info: &ChildInfo,
|
||||
keys: &mut dyn Iterator<Item = &[u8]>,
|
||||
) -> sp_blockchain::Result<StorageProof>;
|
||||
@@ -46,7 +46,7 @@ pub trait ProofProvider<Block: BlockT> {
|
||||
/// No changes are made.
|
||||
fn execution_proof(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
method: &str,
|
||||
call_data: &[u8],
|
||||
) -> sp_blockchain::Result<(Vec<u8>, StorageProof)>;
|
||||
@@ -61,7 +61,7 @@ pub trait ProofProvider<Block: BlockT> {
|
||||
/// Returns combined proof and the numbers of collected keys.
|
||||
fn read_proof_collection(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
start_keys: &[Vec<u8>],
|
||||
size_limit: usize,
|
||||
) -> sp_blockchain::Result<(CompactProof, u32)>;
|
||||
@@ -76,7 +76,7 @@ pub trait ProofProvider<Block: BlockT> {
|
||||
/// end.
|
||||
fn storage_collection(
|
||||
&self,
|
||||
hash: &Block::Hash,
|
||||
hash: Block::Hash,
|
||||
start_key: &[Vec<u8>],
|
||||
size_limit: usize,
|
||||
) -> sp_blockchain::Result<Vec<(KeyValueStorageLevel, bool)>>;
|
||||
|
||||
Reference in New Issue
Block a user