Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
BlockId removal: &Hash to Hash (#12626)
Browse files Browse the repository at this point in the history
It changes &Block::Hash argument to Block::Hash.

This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)
  • Loading branch information
michalkucharczyk authored Nov 7, 2022
1 parent ee9c385 commit 3a450ff
Show file tree
Hide file tree
Showing 49 changed files with 428 additions and 441 deletions.
2 changes: 1 addition & 1 deletion bin/node/bench/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl core::Benchmark for ImportBenchmark {
// Sanity checks.
context
.client
.state_at(&hash)
.state_at(hash)
.expect("state_at failed for block#1")
.inspect_state(|| {
match self.block_type {
Expand Down
4 changes: 2 additions & 2 deletions bin/node/inspect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl<TBlock: Block, TPrinter: PrettyPrinter<TBlock>> Inspector<TBlock, TPrinter>
let not_found = format!("Could not find block {:?}", id);
let body = self
.chain
.block_body(&hash)?
.block_body(hash)?
.ok_or_else(|| Error::NotFound(not_found.clone()))?;
let header =
self.chain.header(id)?.ok_or_else(|| Error::NotFound(not_found.clone()))?;
Expand All @@ -155,7 +155,7 @@ impl<TBlock: Block, TPrinter: PrettyPrinter<TBlock>> Inspector<TBlock, TPrinter>
let not_found = format!("Could not find block {:?}", id);
let body = self
.chain
.block_body(&hash)?
.block_body(hash)?
.ok_or_else(|| Error::NotFound(not_found.clone()))?;
let header =
self.chain.header(id)?.ok_or_else(|| Error::NotFound(not_found.clone()))?;
Expand Down
38 changes: 19 additions & 19 deletions client/api/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>)
Expand Down Expand Up @@ -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<()>;
Expand All @@ -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<()>;
Expand Down Expand Up @@ -359,37 +359,37 @@ 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>>;

/// Given a block's `Hash` and a key prefix, return the matching child storage keys and values
/// in that block.
fn storage_pairs(
&self,
hash: &Block::Hash,
hash: Block::Hash,
key_prefix: &StorageKey,
) -> sp_blockchain::Result<Vec<(StorageKey, StorageData)>>;

/// Given a block's `Hash` and a key prefix, return a `KeyIterator` iterates matching storage
/// 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>>;
Expand All @@ -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>>;
Expand All @@ -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>>;
Expand All @@ -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>,
Expand All @@ -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>>;
Expand Down Expand Up @@ -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.
Expand All @@ -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<()>;

Expand All @@ -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<()>;

Expand All @@ -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
Expand All @@ -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<
Expand Down
11 changes: 5 additions & 6 deletions client/api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,15 @@ 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,
/// including renewed transactions.
///
/// 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>>>;
Expand All @@ -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>>;
Expand All @@ -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())
}

Expand Down
Loading

0 comments on commit 3a450ff

Please sign in to comment.