Skip to content

Commit

Permalink
rename confusing variable and constant names
Browse files Browse the repository at this point in the history
  • Loading branch information
vedhavyas committed Sep 27, 2023
1 parent af30f80 commit b700e16
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
5 changes: 3 additions & 2 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ use sp_domains::verification::{
};
use sp_domains::{
DomainBlockLimit, DomainId, DomainInstanceData, ExecutionReceipt, OpaqueBundle, OperatorId,
OperatorPublicKey, ProofOfElection, RuntimeId, EMPTY_EXTRINSIC_ROOT, EXTRINSICS_SHUFFLING_SEED,
OperatorPublicKey, ProofOfElection, RuntimeId, DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT,
EMPTY_EXTRINSIC_ROOT,
};
use sp_runtime::traits::{BlakeTwo256, CheckedSub, Hash, One, Zero};
use sp_runtime::{RuntimeAppPublic, SaturatedConversion, Saturating};
Expand Down Expand Up @@ -1783,7 +1784,7 @@ impl<T: Config> Pallet<T> {
}

pub fn extrinsics_shuffling_seed() -> T::Hash {
let seed = EXTRINSICS_SHUFFLING_SEED;
let seed = DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT;
let (randomness, _) = T::Randomness::random(seed);
randomness
}
Expand Down
4 changes: 2 additions & 2 deletions crates/sp-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use subspace_runtime_primitives::{Balance, Moment};
const KEY_TYPE: KeyTypeId = KeyTypeId(*b"oper");

/// Extrinsics shuffling seed
pub const EXTRINSICS_SHUFFLING_SEED: &[u8] = b"extrinsics-shuffling-seed";
pub const DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT: &[u8] = b"extrinsics-shuffling-seed";

mod app {
use super::KEY_TYPE;
Expand Down Expand Up @@ -733,7 +733,7 @@ pub struct ValidBundle {
/// Index of this bundle in the original list of bundles in the consensus block.
pub bundle_index: u32,
/// Hash of `Vec<(tx_signer, tx_hash)>` of all domain extrinsic being included in the bundle.
pub bundle_digest: H256,
pub bundle_digest_hash: H256,
}

#[derive(Debug, Decode, Encode, TypeInfo, Clone, PartialEq, Eq)]
Expand Down
12 changes: 6 additions & 6 deletions crates/sp-domains/src/verification.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fraud_proof::{ExtrinsicDigest, InvalidExtrinsicsRootProof, StorageKeys};
use crate::valued_trie_root::valued_ordered_trie_root;
use crate::{ExecutionReceipt, EXTRINSICS_SHUFFLING_SEED};
use crate::{ExecutionReceipt, DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT};
use domain_runtime_primitives::opaque::AccountId;
use frame_support::PalletError;
use hash_db::Hasher;
Expand Down Expand Up @@ -126,18 +126,18 @@ where
..
} = fraud_proof;

let mut ext_values = Vec::new();
let mut bundle_extrinsics_digests = Vec::new();
for (valid_bundle, bundle_digest) in bad_receipt
.valid_bundles
.into_iter()
.zip(valid_bundle_digests)
{
let bundle_digest_hash = BlakeTwo256::hash_of(&bundle_digest.bundle_digest);
if bundle_digest_hash != valid_bundle.bundle_digest {
if bundle_digest_hash != valid_bundle.bundle_digest_hash {
return Err(VerificationError::InvalidBundleDigest);
}

ext_values.extend(bundle_digest.bundle_digest.clone());
bundle_extrinsics_digests.extend(bundle_digest.bundle_digest.clone());
}

let storage_key = SK::block_randomness_key();
Expand All @@ -153,7 +153,7 @@ where
H256::decode(&mut extrinsics_shuffling_seed::<Hashing>(block_randomness).as_ref())
.map_err(|_| VerificationError::FailedToDecode)?;
let ordered_extrinsics = deduplicate_and_shuffle_extrinsics(
ext_values,
bundle_extrinsics_digests,
Randomness::from(shuffling_seed.to_fixed_bytes()),
);
let ordered_trie_node_values = ordered_extrinsics
Expand All @@ -177,7 +177,7 @@ fn extrinsics_shuffling_seed<Hashing>(block_randomness: Randomness) -> Hashing::
where
Hashing: Hasher,
{
let mut subject = EXTRINSICS_SHUFFLING_SEED.to_vec();
let mut subject = DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT.to_vec();
subject.extend_from_slice(block_randomness.as_ref());
Hashing::hash(&subject)
}
Expand Down
2 changes: 1 addition & 1 deletion domains/client/block-preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ where
.collect();
valid_bundles.push(ValidBundle {
bundle_index: index as u32,
bundle_digest: BlakeTwo256::hash_of(&bundle_digest),
bundle_digest_hash: BlakeTwo256::hash_of(&bundle_digest),
});
valid_extrinsics.extend(extrinsics);
}
Expand Down
4 changes: 4 additions & 0 deletions domains/client/domain-operator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,7 @@ async fn test_invalid_domain_extrinsics_root_proof_creation() {

// When the domain node operator process the primary block that contains the `bad_submit_bundle_tx`,
// it will generate and submit a fraud proof
let mut fraud_proof_submitted = false;
while let Some(ready_tx_hash) = import_tx_stream.next().await {
let ready_tx = ferdie
.transaction_pool
Expand All @@ -1104,11 +1105,14 @@ async fn test_invalid_domain_extrinsics_root_proof_creation() {
if let FraudProof::InvalidExtrinsicsRoot(InvalidExtrinsicsRootProof { .. }) =
*fraud_proof
{
fraud_proof_submitted = true;
break;
}
}
}

assert!(fraud_proof_submitted, "Fraud proof must be submitted");

// Produce a consensus block that contains the fraud proof, the fraud proof wil be verified on
// on the runtime itself
ferdie.produce_blocks(1).await.unwrap();
Expand Down

0 comments on commit b700e16

Please sign in to comment.