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

change HashFor to HashingFor #14483

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/node/inspect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ use sp_blockchain::HeaderBackend;
use sp_core::hexdisplay::HexDisplay;
use sp_runtime::{
generic::BlockId,
traits::{Block, Hash, HashFor, NumberFor},
traits::{Block, Hash, HashingFor, NumberFor},
};
use std::{fmt, fmt::Debug, marker::PhantomData, str::FromStr};

/// A helper type for a generic block input.
pub type BlockAddressFor<TBlock> =
BlockAddress<<HashFor<TBlock> as Hash>::Output, NumberFor<TBlock>>;
BlockAddress<<HashingFor<TBlock> as Hash>::Output, NumberFor<TBlock>>;

/// A Pretty formatter implementation.
pub trait PrettyPrinter<TBlock: Block> {
Expand Down Expand Up @@ -166,7 +166,7 @@ impl<TBlock: Block, TPrinter: PrettyPrinter<TBlock>> Inspector<TBlock, TPrinter>
/// Get a pretty-printed extrinsic.
pub fn extrinsic(
&self,
input: ExtrinsicAddress<<HashFor<TBlock> as Hash>::Output, NumberFor<TBlock>>,
input: ExtrinsicAddress<<HashingFor<TBlock> as Hash>::Output, NumberFor<TBlock>>,
) -> Result<String, Error> {
struct ExtrinsicPrinter<'a, A: Block, B>(A::Extrinsic, &'a B);
impl<'a, A: Block, B: PrettyPrinter<A>> fmt::Display for ExtrinsicPrinter<'a, A, B> {
Expand Down
2 changes: 1 addition & 1 deletion bin/node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ where
P: TransactionPool + 'static,
SC: SelectChain<Block> + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashingFor<Block>>,
{
use mmr_rpc::{Mmr, MmrApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
Expand Down
28 changes: 14 additions & 14 deletions client/api/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use parking_lot::RwLock;
use sp_consensus::BlockOrigin;
use sp_core::offchain::OffchainStorage;
use sp_runtime::{
traits::{Block as BlockT, HashFor, NumberFor},
traits::{Block as BlockT, HashingFor, NumberFor},
Justification, Justifications, StateVersion, Storage,
};
use sp_state_machine::{
Expand All @@ -42,7 +42,7 @@ pub use sp_state_machine::{Backend as StateBackend, KeyValueStates};
pub type StateBackendFor<B, Block> = <B as Backend<Block>>::State;

/// Extracts the transaction for the given state backend.
pub type TransactionForSB<B, Block> = <B as StateBackend<HashFor<Block>>>::Transaction;
pub type TransactionForSB<B, Block> = <B as StateBackend<HashingFor<Block>>>::Transaction;

/// Extracts the transaction for the given backend.
pub type TransactionFor<B, Block> = TransactionForSB<StateBackendFor<B, Block>, Block>;
Expand Down Expand Up @@ -161,7 +161,7 @@ impl NewBlockState {
/// Keeps hold if the inserted block state and data.
pub trait BlockImportOperation<Block: BlockT> {
/// Associated state backend type.
type State: StateBackend<HashFor<Block>>;
type State: StateBackend<HashingFor<Block>>;

/// Returns pending state.
///
Expand Down Expand Up @@ -315,16 +315,16 @@ pub trait AuxStore {
/// An `Iterator` that iterates keys in a given block under a prefix.
pub struct KeysIter<State, Block>
where
State: StateBackend<HashFor<Block>>,
State: StateBackend<HashingFor<Block>>,
Block: BlockT,
{
inner: <State as StateBackend<HashFor<Block>>>::RawIter,
inner: <State as StateBackend<HashingFor<Block>>>::RawIter,
state: State,
}

impl<State, Block> KeysIter<State, Block>
where
State: StateBackend<HashFor<Block>>,
State: StateBackend<HashingFor<Block>>,
Block: BlockT,
{
/// Create a new iterator over storage keys.
Expand Down Expand Up @@ -361,7 +361,7 @@ where
impl<State, Block> Iterator for KeysIter<State, Block>
where
Block: BlockT,
State: StateBackend<HashFor<Block>>,
State: StateBackend<HashingFor<Block>>,
{
type Item = StorageKey;

Expand All @@ -373,17 +373,17 @@ where
/// An `Iterator` that iterates keys and values in a given block under a prefix.
pub struct PairsIter<State, Block>
where
State: StateBackend<HashFor<Block>>,
State: StateBackend<HashingFor<Block>>,
Block: BlockT,
{
inner: <State as StateBackend<HashFor<Block>>>::RawIter,
inner: <State as StateBackend<HashingFor<Block>>>::RawIter,
state: State,
}

impl<State, Block> Iterator for PairsIter<State, Block>
where
Block: BlockT,
State: StateBackend<HashFor<Block>>,
State: StateBackend<HashingFor<Block>>,
{
type Item = (StorageKey, StorageData);

Expand All @@ -397,7 +397,7 @@ where

impl<State, Block> PairsIter<State, Block>
where
State: StateBackend<HashFor<Block>>,
State: StateBackend<HashingFor<Block>>,
Block: BlockT,
{
/// Create a new iterator over storage key and value pairs.
Expand Down Expand Up @@ -506,11 +506,11 @@ pub trait Backend<Block: BlockT>: AuxStore + Send + Sync {
/// Associated blockchain backend type.
type Blockchain: BlockchainBackend<Block>;
/// Associated state backend type.
type State: StateBackend<HashFor<Block>>
type State: StateBackend<HashingFor<Block>>
+ Send
+ AsTrieBackend<
HashFor<Block>,
TrieBackendStorage = <Self::State as StateBackend<HashFor<Block>>>::TrieBackendStorage,
HashingFor<Block>,
TrieBackendStorage = <Self::State as StateBackend<HashingFor<Block>>>::TrieBackendStorage,
>;
/// Offchain workers local storage.
type OffchainStorage: OffchainStorage;
Expand Down
17 changes: 9 additions & 8 deletions client/api/src/in_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sp_core::{
};
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, HashFor, Header as HeaderT, NumberFor, Zero},
traits::{Block as BlockT, HashingFor, Header as HeaderT, NumberFor, Zero},
Justification, Justifications, StateVersion, Storage,
};
use sp_state_machine::{
Expand Down Expand Up @@ -479,9 +479,10 @@ impl<Block: BlockT> backend::AuxStore for Blockchain<Block> {
/// In-memory operation.
pub struct BlockImportOperation<Block: BlockT> {
pending_block: Option<PendingBlock<Block>>,
old_state: InMemoryBackend<HashFor<Block>>,
new_state:
Option<<InMemoryBackend<HashFor<Block>> as StateBackend<HashFor<Block>>>::Transaction>,
old_state: InMemoryBackend<HashingFor<Block>>,
new_state: Option<
<InMemoryBackend<HashingFor<Block>> as StateBackend<HashingFor<Block>>>::Transaction,
>,
aux: Vec<(Vec<u8>, Option<Vec<u8>>)>,
finalized_blocks: Vec<(Block::Hash, Option<Justification>)>,
set_head: Option<Block::Hash>,
Expand Down Expand Up @@ -517,7 +518,7 @@ impl<Block: BlockT> BlockImportOperation<Block> {
}

impl<Block: BlockT> backend::BlockImportOperation<Block> for BlockImportOperation<Block> {
type State = InMemoryBackend<HashFor<Block>>;
type State = InMemoryBackend<HashingFor<Block>>;

fn state(&self) -> sp_blockchain::Result<Option<&Self::State>> {
Ok(Some(&self.old_state))
Expand All @@ -539,7 +540,7 @@ impl<Block: BlockT> backend::BlockImportOperation<Block> for BlockImportOperatio

fn update_db_storage(
&mut self,
update: <InMemoryBackend<HashFor<Block>> as StateBackend<HashFor<Block>>>::Transaction,
update: <InMemoryBackend<HashingFor<Block>> as StateBackend<HashingFor<Block>>>::Transaction,
) -> sp_blockchain::Result<()> {
self.new_state = Some(update);
Ok(())
Expand Down Expand Up @@ -606,7 +607,7 @@ impl<Block: BlockT> backend::BlockImportOperation<Block> for BlockImportOperatio
/// > **Warning**: Doesn't support all the features necessary for a proper database. Only use this
/// > struct for testing purposes. Do **NOT** use in production.
pub struct Backend<Block: BlockT> {
states: RwLock<HashMap<Block::Hash, InMemoryBackend<HashFor<Block>>>>,
states: RwLock<HashMap<Block::Hash, InMemoryBackend<HashingFor<Block>>>>,
blockchain: Blockchain<Block>,
import_lock: RwLock<()>,
pinned_blocks: RwLock<HashMap<Block::Hash, i64>>,
Expand Down Expand Up @@ -661,7 +662,7 @@ impl<Block: BlockT> backend::AuxStore for Backend<Block> {
impl<Block: BlockT> backend::Backend<Block> for Backend<Block> {
type BlockImportOperation = BlockImportOperation<Block>;
type Blockchain = Blockchain<Block>;
type State = InMemoryBackend<HashFor<Block>>;
type State = InMemoryBackend<HashingFor<Block>>;
type OffchainStorage = OffchainStorage;

fn begin_operation(&self) -> sp_blockchain::Result<Self::BlockImportOperation> {
Expand Down
53 changes: 37 additions & 16 deletions client/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ where
.propose_with(inherent_data, inherent_digests, deadline, block_size_limit)
.await;
if tx.send(res).is_err() {
trace!(target: LOG_TARGET, "Could not send block production result to proposer!");
trace!(
target: LOG_TARGET,
"Could not send block production result to proposer!"
);
}
}),
);
Expand Down Expand Up @@ -384,7 +387,10 @@ where
for inherent in inherents {
match block_builder.push(inherent) {
Err(ApplyExtrinsicFailed(Validity(e))) if e.exhausted_resources() => {
warn!(target: LOG_TARGET, "⚠️ Dropping non-mandatory inherent from overweight block.")
warn!(
target: LOG_TARGET,
"⚠️ Dropping non-mandatory inherent from overweight block."
)
},
Err(ApplyExtrinsicFailed(Validity(e))) if e.was_mandatory() => {
error!(
Expand All @@ -393,7 +399,10 @@ where
return Err(ApplyExtrinsicFailed(Validity(e)))
},
Err(e) => {
warn!(target: LOG_TARGET, "❗️ Inherent extrinsic returned unexpected error: {}. Dropping.", e);
warn!(
target: LOG_TARGET,
"❗️ Inherent extrinsic returned unexpected error: {}. Dropping.", e
);
},
Ok(_) => {},
}
Expand Down Expand Up @@ -449,9 +458,10 @@ where

let now = (self.now)();
if now > deadline {
debug!(target: LOG_TARGET,
debug!(
target: LOG_TARGET,
"Consensus deadline reached when pushing block transactions, \
proceeding with proposing."
proceeding with proposing."
);
break EndProposingReason::HitDeadline
}
Expand All @@ -465,21 +475,26 @@ where
pending_iterator.report_invalid(&pending_tx);
if skipped < MAX_SKIPPED_TRANSACTIONS {
skipped += 1;
debug!(target: LOG_TARGET,
debug!(
target: LOG_TARGET,
"Transaction would overflow the block size limit, \
but will try {} more transactions before quitting.",
but will try {} more transactions before quitting.",
MAX_SKIPPED_TRANSACTIONS - skipped,
);
continue
} else if now < soft_deadline {
debug!(target: LOG_TARGET,
debug!(
target: LOG_TARGET,
"Transaction would overflow the block size limit, \
but we still have time before the soft deadline, so \
we will try a bit more."
but we still have time before the soft deadline, so \
we will try a bit more."
);
continue
} else {
debug!(target: LOG_TARGET, "Reached block size limit, proceeding with proposing.");
debug!(
target: LOG_TARGET,
"Reached block size limit, proceeding with proposing."
);
break EndProposingReason::HitBlockSizeLimit
}
}
Expand All @@ -504,22 +519,28 @@ where
so we will try a bit more before quitting."
);
} else {
debug!(target: LOG_TARGET, "Reached block weight limit, proceeding with proposing.");
debug!(
target: LOG_TARGET,
"Reached block weight limit, proceeding with proposing."
);
break EndProposingReason::HitBlockWeightLimit
}
},
Err(e) => {
pending_iterator.report_invalid(&pending_tx);
debug!(target: LOG_TARGET, "[{:?}] Invalid transaction: {}", pending_tx_hash, e);
debug!(
target: LOG_TARGET,
"[{:?}] Invalid transaction: {}", pending_tx_hash, e
);
unqueue_invalid.push(pending_tx_hash);
},
}
};

if matches!(end_reason, EndProposingReason::HitBlockSizeLimit) && !transaction_pushed {
warn!(target: LOG_TARGET,
"Hit block size limit of `{}` without including any transaction!",
block_size_limit,
warn!(
target: LOG_TARGET,
"Hit block size limit of `{}` without including any transaction!", block_size_limit,
);
}

Expand Down
8 changes: 4 additions & 4 deletions client/block-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use sp_blockchain::{ApplyExtrinsicFailed, Error};
use sp_core::traits::CallContext;
use sp_runtime::{
legacy,
traits::{Block as BlockT, Hash, HashFor, Header as HeaderT, NumberFor, One},
traits::{Block as BlockT, Hash, HashingFor, Header as HeaderT, NumberFor, One},
Digest,
};

Expand Down Expand Up @@ -85,7 +85,7 @@ impl From<bool> for RecordProof {
/// backend to get the state of the block. Furthermore an optional `proof` is included which
/// can be used to proof that the build block contains the expected data. The `proof` will
/// only be set when proof recording was activated.
pub struct BuiltBlock<Block: BlockT, StateBackend: backend::StateBackend<HashFor<Block>>> {
pub struct BuiltBlock<Block: BlockT, StateBackend: backend::StateBackend<HashingFor<Block>>> {
/// The actual block that was build.
pub block: Block,
/// The changes that need to be applied to the backend to get the state of the build block.
Expand All @@ -94,7 +94,7 @@ pub struct BuiltBlock<Block: BlockT, StateBackend: backend::StateBackend<HashFor
pub proof: Option<StorageProof>,
}

impl<Block: BlockT, StateBackend: backend::StateBackend<HashFor<Block>>>
impl<Block: BlockT, StateBackend: backend::StateBackend<HashingFor<Block>>>
BuiltBlock<Block, StateBackend>
{
/// Convert into the inner values.
Expand Down Expand Up @@ -236,7 +236,7 @@ where

debug_assert_eq!(
header.extrinsics_root().clone(),
HashFor::<Block>::ordered_trie_root(
HashingFor::<Block>::ordered_trie_root(
self.extrinsics.iter().map(Encode::encode).collect(),
sp_runtime::StateVersion::V0,
),
Expand Down
4 changes: 2 additions & 2 deletions client/consensus/common/src/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use serde::{Deserialize, Serialize};
use sp_runtime::{
traits::{Block as BlockT, HashFor, Header as HeaderT, NumberFor},
traits::{Block as BlockT, HashingFor, Header as HeaderT, NumberFor},
DigestItem, Justification, Justifications,
};
use std::{any::Any, borrow::Cow, collections::HashMap, sync::Arc};
Expand Down Expand Up @@ -121,7 +121,7 @@ pub struct BlockCheckParams<Block: BlockT> {
/// Precomputed storage.
pub enum StorageChanges<Block: BlockT, Transaction> {
/// Changes coming from block execution.
Changes(sp_state_machine::StorageChanges<Transaction, HashFor<Block>>),
Changes(sp_state_machine::StorageChanges<Transaction, HashingFor<Block>>),
/// Whole new state.
Import(ImportedState<Block>),
}
Expand Down
4 changes: 2 additions & 2 deletions client/consensus/slots/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use sp_arithmetic::traits::BaseArithmetic;
use sp_consensus::{Proposal, Proposer, SelectChain, SyncOracle};
use sp_consensus_slots::{Slot, SlotDuration};
use sp_inherents::CreateInherentDataProviders;
use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT};
use sp_runtime::traits::{Block as BlockT, HashingFor, Header as HeaderT};
use std::{
fmt::Debug,
ops::Deref,
Expand All @@ -54,7 +54,7 @@ const LOG_TARGET: &str = "slots";
///
/// See [`sp_state_machine::StorageChanges`] for more information.
pub type StorageChanges<Transaction, Block> =
sp_state_machine::StorageChanges<Transaction, HashFor<Block>>;
sp_state_machine::StorageChanges<Transaction, HashingFor<Block>>;

/// The result of [`SlotWorker::on_slot`].
#[derive(Debug, Clone)]
Expand Down
Loading