From 67683236ca7a358d8a1fce6459069ddb65995856 Mon Sep 17 00:00:00 2001 From: linning Date: Fri, 3 Nov 2023 18:19:32 +0800 Subject: [PATCH] Apply review suggestion Signed-off-by: linning --- crates/pallet-domains/src/block_tree.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/pallet-domains/src/block_tree.rs b/crates/pallet-domains/src/block_tree.rs index 894590cc6b..60507e188c 100644 --- a/crates/pallet-domains/src/block_tree.rs +++ b/crates/pallet-domains/src/block_tree.rs @@ -87,7 +87,7 @@ pub(crate) enum ReceiptType { Rejected(RejectedReceiptType), } -pub(crate) fn is_receipt_exist( +pub(crate) fn does_receipt_exists( domain_id: DomainId, domain_number: DomainBlockNumberFor, receipt_hash: ReceiptHashFor, @@ -104,8 +104,9 @@ pub(crate) fn execution_receipt_type( ) -> ReceiptType { let receipt_number = execution_receipt.domain_block_number; let head_receipt_number = HeadReceiptNumber::::get(domain_id); + let next_receipt_number = head_receipt_number.saturating_add(One::one()); - match receipt_number.cmp(&head_receipt_number.saturating_add(One::one())) { + match receipt_number.cmp(&next_receipt_number) { Ordering::Greater => ReceiptType::Rejected(RejectedReceiptType::InFuture), Ordering::Equal => ReceiptType::Accepted(AcceptedReceiptType::NewHead), Ordering::Less => { @@ -117,7 +118,7 @@ pub(crate) fn execution_receipt_type( } // Reject receipt that try to create new branch in the block tree - let already_exist = is_receipt_exist::( + let already_exist = does_receipt_exists::( domain_id, receipt_number, execution_receipt.hash::>(), @@ -161,7 +162,7 @@ pub(crate) fn verify_execution_receipt( // The genesis receipt is generated and added to the block tree by the runtime upon domain // instantiation, thus it is unchallengeable and must always be the same. ensure!( - is_receipt_exist::( + does_receipt_exists::( domain_id, *domain_block_number, execution_receipt.hash::>(), @@ -222,7 +223,7 @@ pub(crate) fn verify_execution_receipt( } if let Some(parent_block_number) = domain_block_number.checked_sub(&One::one()) { - let parent_block_exist = is_receipt_exist::( + let parent_block_exist = does_receipt_exists::( domain_id, parent_block_number, *parent_domain_block_receipt_hash,