Skip to content

Commit

Permalink
Apply review suggestion
Browse files Browse the repository at this point in the history
Signed-off-by: linning <[email protected]>
  • Loading branch information
NingLin-P committed Nov 3, 2023
1 parent 2cb70a3 commit 6768323
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions crates/pallet-domains/src/block_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub(crate) enum ReceiptType {
Rejected(RejectedReceiptType),
}

pub(crate) fn is_receipt_exist<T: Config>(
pub(crate) fn does_receipt_exists<T: Config>(
domain_id: DomainId,
domain_number: DomainBlockNumberFor<T>,
receipt_hash: ReceiptHashFor<T>,
Expand All @@ -104,8 +104,9 @@ pub(crate) fn execution_receipt_type<T: Config>(
) -> ReceiptType {
let receipt_number = execution_receipt.domain_block_number;
let head_receipt_number = HeadReceiptNumber::<T>::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 => {
Expand All @@ -117,7 +118,7 @@ pub(crate) fn execution_receipt_type<T: Config>(
}

// Reject receipt that try to create new branch in the block tree
let already_exist = is_receipt_exist::<T>(
let already_exist = does_receipt_exists::<T>(
domain_id,
receipt_number,
execution_receipt.hash::<DomainHashingFor<T>>(),
Expand Down Expand Up @@ -161,7 +162,7 @@ pub(crate) fn verify_execution_receipt<T: Config>(
// 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::<T>(
does_receipt_exists::<T>(
domain_id,
*domain_block_number,
execution_receipt.hash::<DomainHashingFor<T>>(),
Expand Down Expand Up @@ -222,7 +223,7 @@ pub(crate) fn verify_execution_receipt<T: Config>(
}

if let Some(parent_block_number) = domain_block_number.checked_sub(&One::one()) {
let parent_block_exist = is_receipt_exist::<T>(
let parent_block_exist = does_receipt_exists::<T>(
domain_id,
parent_block_number,
*parent_domain_block_receipt_hash,
Expand Down

0 comments on commit 6768323

Please sign in to comment.