From a9cbb81eb471e6cedc407dde234335ebeace3688 Mon Sep 17 00:00:00 2001 From: vedhavyas Date: Wed, 18 Oct 2023 01:02:43 +0200 Subject: [PATCH] use correct error, update comment, and remove unneeded check in the tests --- crates/pallet-domains/src/lib.rs | 6 +++-- crates/pallet-domains/src/tests.rs | 30 +++++++-------------- domains/client/domain-operator/src/tests.rs | 3 --- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/crates/pallet-domains/src/lib.rs b/crates/pallet-domains/src/lib.rs index 9451e4da24..062822d3cb 100644 --- a/crates/pallet-domains/src/lib.rs +++ b/crates/pallet-domains/src/lib.rs @@ -589,7 +589,7 @@ mod pallet { DescendantsOfFraudulentERNotPruned, /// Invalid fraud proof since total rewards are not mismatched. InvalidTotalRewardsFraudProof(sp_domains::verification::VerificationError), - /// Invalid fraud proof since domain block hash is not mismatched. + /// Invalid domain block hash fraud proof. InvalidDomainBlockHashFraudProof(sp_domains::verification::VerificationError), /// Invalid domain extrinsic fraud proof InvalidExtrinsicRootFraudProof(sp_domains::verification::VerificationError), @@ -599,6 +599,8 @@ mod pallet { FailedToGetDomainTimestampExtrinsic, /// Received invalid Verification info from host function. ReceivedInvalidVerificationInfo, + /// Parent receipt not found. + ParentReceiptNotFound, } impl From for Error { @@ -1532,7 +1534,7 @@ impl Pallet { }) => { let parent_receipt = DomainBlocks::::get(bad_receipt.parent_domain_block_receipt_hash) - .ok_or(FraudProofError::BadReceiptNotFound)? + .ok_or(FraudProofError::ParentReceiptNotFound)? .execution_receipt; verify_invalid_domain_block_hash_fraud_proof::< T::Block, diff --git a/crates/pallet-domains/src/tests.rs b/crates/pallet-domains/src/tests.rs index b83a30d763..4fb2427879 100644 --- a/crates/pallet-domains/src/tests.rs +++ b/crates/pallet-domains/src/tests.rs @@ -945,25 +945,24 @@ fn test_invalid_domain_block_hash_fraud_proof() { let bad_receipt_at = 8; let mut domain_block = get_block_tree_node_at::(domain_id, bad_receipt_at).unwrap(); - - let bad_receipt_hash = domain_block.execution_receipt.hash(); - let (fraud_proof, root) = generate_invalid_domain_block_hash_fraud_proof::( - domain_id, - bad_receipt_hash, - Digest::default(), - ); + let (root, digest_storage_proof) = + generate_invalid_domain_block_hash_fraud_proof::(Digest::default()); domain_block.execution_receipt.final_state_root = root; domain_block.execution_receipt.domain_block_hash = H256::random(); + let bad_receipt_hash = domain_block.execution_receipt.hash(); DomainBlocks::::insert(bad_receipt_hash, domain_block); + let fraud_proof = FraudProof::InvalidDomainBlockHash(InvalidDomainBlockHashProof { + domain_id, + bad_receipt_hash, + digest_storage_proof, + }); assert_ok!(Domains::validate_fraud_proof(&fraud_proof),); }); } fn generate_invalid_domain_block_hash_fraud_proof( - domain_id: DomainId, - bad_receipt_hash: ReceiptHash, digest: Digest, -) -> (FraudProof, T::Hash>, T::Hash) { +) -> (T::Hash, StorageProof) { let digest_storage_key = sp_domains::fraud_proof::system_digest_final_key(); let mut root = T::Hash::default(); let mut mdb = PrefixedMemoryDB::::default(); @@ -973,16 +972,7 @@ fn generate_invalid_domain_block_hash_fraud_proof( }; let backend = TrieBackendBuilder::new(mdb, root).build(); - let (root, digest_storage_proof) = - storage_proof_for_key::(backend, StorageKey(digest_storage_key)); - ( - FraudProof::InvalidDomainBlockHash(InvalidDomainBlockHashProof { - domain_id, - bad_receipt_hash, - digest_storage_proof, - }), - root, - ) + storage_proof_for_key::(backend, StorageKey(digest_storage_key)) } #[test] diff --git a/domains/client/domain-operator/src/tests.rs b/domains/client/domain-operator/src/tests.rs index 5eed0ea339..063a6100b7 100644 --- a/domains/client/domain-operator/src/tests.rs +++ b/domains/client/domain-operator/src/tests.rs @@ -1061,7 +1061,6 @@ async fn test_invalid_domain_block_hash_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 @@ -1078,13 +1077,11 @@ async fn test_invalid_domain_block_hash_proof_creation() { if let FraudProof::InvalidDomainBlockHash(InvalidDomainBlockHashProof { .. }) = *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();