Skip to content

Commit

Permalink
Rename to InherentExtrinsicData when used for block production
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Jan 9, 2025
1 parent dce2c8d commit 27f3bb6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
28 changes: 14 additions & 14 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ mod pallet {
#[cfg(not(feature = "runtime-benchmarks"))]
use crate::staking_epoch::do_slash_operator;
use crate::staking_epoch::{do_finalize_domain_current_epoch, Error as StakingEpochError};
use crate::storage_proof::InvalidInherentExtrinsicData;
use crate::storage_proof::InherentExtrinsicData;
use crate::weights::WeightInfo;
#[cfg(not(feature = "runtime-benchmarks"))]
use crate::DomainHashingFor;
Expand Down Expand Up @@ -1857,7 +1857,7 @@ mod pallet {

/// Combined fraud proof data for the InvalidInherentExtrinsic fraud proof
#[pallet::storage]
pub type BlockInvalidInherentExtrinsicData<T> = StorageValue<_, InvalidInherentExtrinsicData>;
pub type BlockInherentExtrinsicData<T> = StorageValue<_, InherentExtrinsicData>;

#[pallet::hooks]
// TODO: proper benchmark
Expand Down Expand Up @@ -1908,7 +1908,7 @@ mod pallet {
}
}

BlockInvalidInherentExtrinsicData::<T>::kill();
BlockInherentExtrinsicData::<T>::kill();

Weight::zero()
}
Expand All @@ -1930,13 +1930,13 @@ mod pallet {
// The value returned by the consensus_chain_byte_fee() runtime API
let consensus_transaction_byte_fee = Self::consensus_transaction_byte_fee_value();

let invalid_inherent_extrinsic_data = InvalidInherentExtrinsicData {
let inherent_extrinsic_data = InherentExtrinsicData {
extrinsics_shuffling_seed,
timestamp,
consensus_transaction_byte_fee,
};

BlockInvalidInherentExtrinsicData::<T>::set(Some(invalid_inherent_extrinsic_data));
BlockInherentExtrinsicData::<T>::set(Some(inherent_extrinsic_data));
}

let _ = LastEpochStakingDistribution::<T>::clear(u32::MAX, None);
Expand Down Expand Up @@ -2764,33 +2764,33 @@ impl<T: Config> Pallet<T> {
}

/// The external function used to access the extrinsics shuffling seed stored in
/// `BlockInvalidInherentExtrinsicData`.
/// `BlockInherentExtrinsicData`.
pub fn extrinsics_shuffling_seed() -> T::Hash {
// Fall back to recalculating if it hasn't been stored yet.
BlockInvalidInherentExtrinsicData::<T>::get()
BlockInherentExtrinsicData::<T>::get()
.map(|data| H256::from(*data.extrinsics_shuffling_seed).into())
.unwrap_or_else(|| Self::extrinsics_shuffling_seed_value())
}

/// The internal function used to calculate the extrinsics shuffling seed for storage into
/// `BlockInvalidInherentExtrinsicData`.
/// `BlockInherentExtrinsicData`.
fn extrinsics_shuffling_seed_value() -> T::Hash {
let subject = DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT;
let (randomness, _) = T::Randomness::random(subject);
randomness
}

/// The external function used to access the timestamp stored in
/// `BlockInvalidInherentExtrinsicData`.
/// `BlockInherentExtrinsicData`.
pub fn timestamp() -> Moment {
// Fall back to recalculating if it hasn't been stored yet.
BlockInvalidInherentExtrinsicData::<T>::get()
BlockInherentExtrinsicData::<T>::get()
.map(|data| data.timestamp)
.unwrap_or_else(|| Self::timestamp_value())
}

/// The internal function used to access the timestamp for storage into
/// `BlockInvalidInherentExtrinsicData`.
/// `BlockInherentExtrinsicData`.
fn timestamp_value() -> Moment {
// There are no actual conversions here, but the trait bounds required to prove that
// (and debug-print the error in expect()) are very verbose.
Expand All @@ -2801,17 +2801,17 @@ impl<T: Config> Pallet<T> {
}

/// The external function used to access the consensus transaction byte fee stored in
/// `BlockInvalidInherentExtrinsicData`.
/// `BlockInherentExtrinsicData`.
/// This value is returned by the consensus_chain_byte_fee() runtime API
pub fn consensus_transaction_byte_fee() -> Balance {
// Fall back to recalculating if it hasn't been stored yet.
BlockInvalidInherentExtrinsicData::<T>::get()
BlockInherentExtrinsicData::<T>::get()
.map(|data| data.consensus_transaction_byte_fee)
.unwrap_or_else(|| Self::consensus_transaction_byte_fee_value())
}

/// The internal function used to calculate the consensus transaction byte fee for storage into
/// `BlockInvalidInherentExtrinsicData`.
/// `BlockInherentExtrinsicData`.
fn consensus_transaction_byte_fee_value() -> Balance {
// There are no actual conversions here, but the trait bounds required to prove that
// (and debug-print the error in expect()) are very verbose.
Expand Down
6 changes: 3 additions & 3 deletions crates/sp-domains-fraud-proof/src/storage_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ impl MaybeDomainRuntimeUpgradedProof {
}

#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
pub struct InvalidInherentExtrinsicData {
pub struct InherentExtrinsicData {
/// Extrinsics shuffling seed, derived from block randomness
pub extrinsics_shuffling_seed: Randomness,

Expand All @@ -380,7 +380,7 @@ pub struct InvalidInherentExtrinsicData {
pub consensus_transaction_byte_fee: Balance,
}

impl PassBy for InvalidInherentExtrinsicData {
impl PassBy for InherentExtrinsicData {
type PassBy = pass_by::Codec<Self>;
}

Expand All @@ -389,7 +389,7 @@ pub struct InvalidInherentExtrinsicDataProof(StorageProof);

impl_storage_proof!(InvalidInherentExtrinsicDataProof);
impl<Block: BlockT> BasicStorageProof<Block> for InvalidInherentExtrinsicDataProof {
type StorageValue = InvalidInherentExtrinsicData;
type StorageValue = InherentExtrinsicData;
fn storage_key_request(_key: Self::Key) -> FraudProofStorageKeyRequest<NumberFor<Block>> {
FraudProofStorageKeyRequest::InvalidInherentExtrinsicData
}
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ impl FraudProofStorageKeyProvider<NumberFor<Block>> for StorageKeyProvider {
fn storage_key(req: FraudProofStorageKeyRequest<NumberFor<Block>>) -> Vec<u8> {
match req {
FraudProofStorageKeyRequest::InvalidInherentExtrinsicData => {
pallet_domains::BlockInvalidInherentExtrinsicData::<Runtime>::hashed_key().to_vec()
pallet_domains::BlockInherentExtrinsicData::<Runtime>::hashed_key().to_vec()
}
FraudProofStorageKeyRequest::SuccessfulBundles(domain_id) => {
pallet_domains::SuccessfulBundles::<Runtime>::hashed_key_for(domain_id)
Expand Down
2 changes: 1 addition & 1 deletion test/subspace-test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ impl FraudProofStorageKeyProvider<NumberFor<Block>> for StorageKeyProvider {
fn storage_key(req: FraudProofStorageKeyRequest<NumberFor<Block>>) -> Vec<u8> {
match req {
FraudProofStorageKeyRequest::InvalidInherentExtrinsicData => {
pallet_domains::BlockInvalidInherentExtrinsicData::<Runtime>::hashed_key().to_vec()
pallet_domains::BlockInherentExtrinsicData::<Runtime>::hashed_key().to_vec()
}
FraudProofStorageKeyRequest::SuccessfulBundles(domain_id) => {
pallet_domains::SuccessfulBundles::<Runtime>::hashed_key_for(domain_id)
Expand Down

0 comments on commit 27f3bb6

Please sign in to comment.