Skip to content

Commit

Permalink
Store the extrinsics shuffling seed rather than block randomness
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Dec 16, 2024
1 parent f69de4e commit c974cfc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
14 changes: 14 additions & 0 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,20 @@ mod pallet {
}

fn on_finalize(_: BlockNumberFor<T>) {
// If this consensus block will derive any domain block, gather the necessary storage for potential fraud proof usage
if SuccessfulBundles::<T>::iter_keys().count() > 0
|| DomainRuntimeUpgrades::<T>::exists()
{
let extrinsics_shuffling_seed =
H256::from_slice(Self::extrinsics_shuffling_seed().as_ref());

let invalid_inherent_extrinsic_data = InvalidInherentExtrinsicData {
extrinsics_shuffling_seed,
};

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

let _ = LastEpochStakingDistribution::<T>::clear(u32::MAX, None);
let _ = NewAddedHeadReceipt::<T>::clear(u32::MAX, None);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/sp-domains-fraud-proof/src/host_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ where
) -> Option<DomainInherentExtrinsic> {
let InvalidInherentExtrinsicData {
// Used by caller
block_randomness: _,
extrinsics_shuffling_seed: _,
} = invalid_inherent_extrinsic_data;
let DomainInherentExtrinsicData {
timestamp,
Expand Down
5 changes: 2 additions & 3 deletions crates/sp-domains-fraud-proof/src/storage_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use sp_runtime_interface::pass_by::PassBy;
use sp_std::marker::PhantomData;
use sp_std::vec::Vec;
use sp_trie::StorageProof;
use subspace_core_primitives::Randomness;
use subspace_runtime_primitives::{Balance, BlockTransactionByteFee, Moment};

#[cfg(feature = "std")]
Expand Down Expand Up @@ -408,8 +407,8 @@ impl MaybeDomainRuntimeUpgradedProof {

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

impl PassBy for InvalidInherentExtrinsicData {
Expand Down
7 changes: 2 additions & 5 deletions crates/sp-domains-fraud-proof/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use domain_runtime_primitives::BlockNumber;
use hash_db::Hasher;
use sp_core::storage::StorageKey;
use sp_core::H256;
use sp_domains::extrinsics::{deduplicate_and_shuffle_extrinsics, extrinsics_shuffling_seed};
use sp_domains::extrinsics::deduplicate_and_shuffle_extrinsics;
use sp_domains::proof_provider_and_verifier::StorageProofVerifier;
use sp_domains::valued_trie::valued_ordered_trie_root;
use sp_domains::{
Expand Down Expand Up @@ -87,10 +87,7 @@ where
)?;
domain_inherent_extrinsic_data.maybe_sudo_runtime_call = domain_sudo_call.maybe_call;

let shuffling_seed = H256::from_slice(
extrinsics_shuffling_seed::<Hashing>(invalid_inherent_extrinsic_data.block_randomness)
.as_ref(),
);
let shuffling_seed = invalid_inherent_extrinsic_data.extrinsics_shuffling_seed;

let DomainInherentExtrinsic {
domain_timestamp_extrinsic,
Expand Down

0 comments on commit c974cfc

Please sign in to comment.