Skip to content

Commit

Permalink
Move timestamp into shared data
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Dec 19, 2024
1 parent 5675113 commit ff07a65
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 36 deletions.
5 changes: 4 additions & 1 deletion crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod pallet {
use sp_std::fmt::Debug;
use sp_subspace_mmr::MmrProofVerifier;
use subspace_core_primitives::{Randomness, U256};
use subspace_runtime_primitives::StorageFee;
use subspace_runtime_primitives::{Moment, StorageFee};

#[pallet::config]
pub trait Config: frame_system::Config<Hash: Into<H256>> {
Expand Down Expand Up @@ -1913,8 +1913,11 @@ mod pallet {
Into::<H256>::into(Self::extrinsics_shuffling_seed()).to_fixed_bytes(),
);

let timestamp = Moment::default();

let invalid_inherent_extrinsic_data = InvalidInherentExtrinsicData {
extrinsics_shuffling_seed,
timestamp,
};

BlockInvalidInherentExtrinsicData::<T>::set(Some(invalid_inherent_extrinsic_data));
Expand Down
31 changes: 3 additions & 28 deletions crates/sp-domains-fraud-proof/src/storage_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ pub enum VerificationError {
RuntimeCodeNotFound,
UnexpectedDomainRuntimeUpgrade,
InvalidInherentExtrinsicStorageProof(StorageProofVerificationError),
TimestampStorageProof(StorageProofVerificationError),
SuccessfulBundlesStorageProof(StorageProofVerificationError),
TransactionByteFeeStorageProof(StorageProofVerificationError),
DomainAllowlistUpdatesStorageProof(StorageProofVerificationError),
Expand All @@ -56,7 +55,6 @@ pub enum VerificationError {
#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
pub enum FraudProofStorageKeyRequest<Number> {
InvalidInherentExtrinsicData,
Timestamp,
SuccessfulBundles(DomainId),
TransactionByteFee,
DomainAllowlistUpdates(DomainId),
Expand All @@ -73,7 +71,6 @@ impl<Number> FraudProofStorageKeyRequest<Number> {
Self::InvalidInherentExtrinsicData => {
VerificationError::InvalidInherentExtrinsicStorageProof(err)
}
Self::Timestamp => VerificationError::TimestampStorageProof(err),
Self::SuccessfulBundles(_) => VerificationError::SuccessfulBundlesStorageProof(err),
Self::TransactionByteFee => VerificationError::TransactionByteFeeStorageProof(err),
Self::DomainAllowlistUpdates(_) => {
Expand Down Expand Up @@ -188,17 +185,6 @@ impl<Block: BlockT> BasicStorageProof<Block> for DomainChainsAllowlistUpdateStor
}
}

#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
pub struct TimestampStorageProof(StorageProof);

impl_storage_proof!(TimestampStorageProof);
impl<Block: BlockT> BasicStorageProof<Block> for TimestampStorageProof {
type StorageValue = Moment;
fn storage_key_request(_key: Self::Key) -> FraudProofStorageKeyRequest<NumberFor<Block>> {
FraudProofStorageKeyRequest::Timestamp
}
}

#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
pub struct DynamicCostOfStorageProof(StorageProof);

Expand Down Expand Up @@ -409,6 +395,9 @@ impl MaybeDomainRuntimeUpgradedProof {
pub struct InvalidInherentExtrinsicData {
/// Extrinsics shuffling seed, derived from block randomness
pub extrinsics_shuffling_seed: Randomness,

/// Block timestamp
pub timestamp: Moment,
}

impl PassBy for InvalidInherentExtrinsicData {
Expand All @@ -428,9 +417,6 @@ impl<Block: BlockT> BasicStorageProof<Block> for InvalidInherentExtrinsicDataPro

#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
pub struct InvalidInherentExtrinsicProof {
/// Block timestamp storage proof
pub timestamp_proof: TimestampStorageProof,

/// Optional domain runtime code upgrade storage proof
pub maybe_domain_runtime_upgrade_proof: MaybeDomainRuntimeUpgradedProof,

Expand All @@ -447,7 +433,6 @@ pub struct InvalidInherentExtrinsicProof {
/// The verified data from an `InvalidInherentExtrinsicProof`
#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
pub struct InvalidInherentExtrinsicVerified {
pub timestamp: Moment,
pub maybe_domain_runtime_upgrade: Option<Vec<u8>>,
pub consensus_transaction_byte_fee: Balance,
pub domain_chain_allowlist: DomainAllowlistUpdates,
Expand All @@ -467,8 +452,6 @@ impl InvalidInherentExtrinsicProof {
block_hash: Block::Hash,
maybe_runtime_id: Option<RuntimeId>,
) -> Result<Self, GenerationError> {
let timestamp_proof =
TimestampStorageProof::generate(proof_provider, block_hash, (), storage_key_provider)?;
let maybe_domain_runtime_upgrade_proof = MaybeDomainRuntimeUpgradedProof::generate(
storage_key_provider,
proof_provider,
Expand All @@ -495,7 +478,6 @@ impl InvalidInherentExtrinsicProof {
)?;

Ok(Self {
timestamp_proof,
maybe_domain_runtime_upgrade_proof,
dynamic_cost_of_storage_proof,
consensus_chain_byte_fee_proof,
Expand All @@ -509,12 +491,6 @@ impl InvalidInherentExtrinsicProof {
runtime_id: RuntimeId,
state_root: &Block::Hash,
) -> Result<InvalidInherentExtrinsicVerified, VerificationError> {
let timestamp = <TimestampStorageProof as BasicStorageProof<Block>>::verify::<SKP>(
self.timestamp_proof.clone(),
(),
state_root,
)?;

let maybe_domain_runtime_upgrade = self
.maybe_domain_runtime_upgrade_proof
.verify::<Block, SKP>(runtime_id, state_root)?;
Expand Down Expand Up @@ -546,7 +522,6 @@ impl InvalidInherentExtrinsicProof {
)?;

Ok(InvalidInherentExtrinsicVerified {
timestamp,
maybe_domain_runtime_upgrade,
consensus_transaction_byte_fee,
domain_chain_allowlist,
Expand Down
2 changes: 1 addition & 1 deletion crates/sp-domains-fraud-proof/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ where
let shuffling_seed = invalid_inherent_extrinsic_data.extrinsics_shuffling_seed;

let domain_inherent_extrinsic_data = DomainInherentExtrinsicData {
timestamp: inherent_extrinsic_verified.timestamp,
timestamp: invalid_inherent_extrinsic_data.timestamp,
maybe_domain_runtime_upgrade: inherent_extrinsic_verified.maybe_domain_runtime_upgrade,
consensus_transaction_byte_fee: inherent_extrinsic_verified.consensus_transaction_byte_fee,
domain_chain_allowlist: inherent_extrinsic_verified.domain_chain_allowlist,
Expand Down
3 changes: 0 additions & 3 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,9 +1041,6 @@ impl FraudProofStorageKeyProvider<NumberFor<Block>> for StorageKeyProvider {
FraudProofStorageKeyRequest::InvalidInherentExtrinsicData => {
pallet_domains::BlockInvalidInherentExtrinsicData::<Runtime>::hashed_key().to_vec()
}
FraudProofStorageKeyRequest::Timestamp => {
pallet_timestamp::Now::<Runtime>::hashed_key().to_vec()
}
FraudProofStorageKeyRequest::SuccessfulBundles(domain_id) => {
pallet_domains::SuccessfulBundles::<Runtime>::hashed_key_for(domain_id)
}
Expand Down
3 changes: 0 additions & 3 deletions test/subspace-test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,9 +1118,6 @@ impl FraudProofStorageKeyProvider<NumberFor<Block>> for StorageKeyProvider {
FraudProofStorageKeyRequest::InvalidInherentExtrinsicData => {
pallet_domains::BlockInvalidInherentExtrinsicData::<Runtime>::hashed_key().to_vec()
}
FraudProofStorageKeyRequest::Timestamp => {
pallet_timestamp::Now::<Runtime>::hashed_key().to_vec()
}
FraudProofStorageKeyRequest::SuccessfulBundles(domain_id) => {
pallet_domains::SuccessfulBundles::<Runtime>::hashed_key_for(domain_id)
}
Expand Down

0 comments on commit ff07a65

Please sign in to comment.