Skip to content

Commit cbe218f

Browse files
committed
Replace incorrect derivation of oldest_receipt_number with LatestConfirmedDomainBlockNumber
This commit also remove the block_tree_pruning_depth runtime api, which is unused and also unnecessary Signed-off-by: linning <[email protected]>
1 parent fcf7cdf commit cbe218f

File tree

6 files changed

+10
-27
lines changed

6 files changed

+10
-27
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pallet-domains/src/block_tree.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::pallet::StateRoots;
44
use crate::{
55
BalanceOf, BlockTree, BlockTreeNodes, Config, ConsensusBlockHash, DomainBlockNumberFor,
66
DomainHashingFor, ExecutionInbox, ExecutionReceiptOf, HeadReceiptExtended, HeadReceiptNumber,
7-
InboxedBundleAuthor, ReceiptHashFor,
7+
InboxedBundleAuthor, LatestConfirmedDomainBlockNumber, ReceiptHashFor,
88
};
99
use codec::{Decode, Encode};
1010
use frame_support::{ensure, PalletError};
@@ -106,15 +106,15 @@ pub(crate) fn execution_receipt_type<T: Config>(
106106
let receipt_number = execution_receipt.domain_block_number;
107107
let head_receipt_number = HeadReceiptNumber::<T>::get(domain_id);
108108
let next_receipt_number = head_receipt_number.saturating_add(One::one());
109+
let latest_confirmed_domain_block_number =
110+
LatestConfirmedDomainBlockNumber::<T>::get(domain_id);
109111

110112
match receipt_number.cmp(&next_receipt_number) {
111113
Ordering::Greater => ReceiptType::Rejected(RejectedReceiptType::InFuture),
112114
Ordering::Equal => ReceiptType::Accepted(AcceptedReceiptType::NewHead),
113115
Ordering::Less => {
114-
// Reject receipt that already pruned/confirmed
115-
let oldest_receipt_number =
116-
head_receipt_number.saturating_sub(T::BlockTreePruningDepth::get());
117-
if receipt_number < oldest_receipt_number {
116+
// Reject receipt that already confirmed
117+
if receipt_number <= latest_confirmed_domain_block_number {
118118
return ReceiptType::Rejected(RejectedReceiptType::Pruned);
119119
}
120120

crates/pallet-domains/src/lib.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use sp_domains_fraud_proof::verification::{
5959
verify_invalid_domain_extrinsics_root_fraud_proof, verify_invalid_state_transition_fraud_proof,
6060
verify_valid_bundle_fraud_proof,
6161
};
62-
use sp_runtime::traits::{CheckedSub, Hash, Header, One, Zero};
62+
use sp_runtime::traits::{Hash, Header, One, Zero};
6363
use sp_runtime::{RuntimeAppPublic, SaturatedConversion, Saturating};
6464
use sp_std::boxed::Box;
6565
use sp_std::collections::btree_map::BTreeMap;
@@ -1877,11 +1877,6 @@ impl<T: Config> Pallet<T> {
18771877
}
18781878
}
18791879

1880-
/// Returns the block tree pruning depth.
1881-
pub fn block_tree_pruning_depth() -> DomainBlockNumberFor<T> {
1882-
T::BlockTreePruningDepth::get()
1883-
}
1884-
18851880
/// Returns the domain block limit of the given domain.
18861881
pub fn domain_block_limit(domain_id: DomainId) -> Option<DomainBlockLimit> {
18871882
DomainRegistry::<T>::get(domain_id).map(|domain_obj| DomainBlockLimit {
@@ -1897,10 +1892,10 @@ impl<T: Config> Pallet<T> {
18971892
return true;
18981893
}
18991894

1895+
// Start from the oldest non-confirmed ER to the head domain number
1896+
let mut to_check =
1897+
LatestConfirmedDomainBlockNumber::<T>::get(domain_id).saturating_add(One::one());
19001898
let head_number = HeadDomainNumber::<T>::get(domain_id);
1901-
let mut to_check = head_number
1902-
.checked_sub(&T::BlockTreePruningDepth::get())
1903-
.unwrap_or(Zero::zero());
19041899

19051900
while to_check <= head_number {
19061901
if !ExecutionInbox::<T>::iter_prefix_values((domain_id, to_check)).all(|digests| {

crates/sp-domains/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,6 @@ sp_api::decl_runtime_apis! {
997997
/// Returns the block number of oldest execution receipt.
998998
fn oldest_receipt_number(domain_id: DomainId) -> Option<HeaderNumberFor<DomainHeader>>;
999999

1000-
/// Returns the block tree pruning depth.
1001-
fn block_tree_pruning_depth() -> HeaderNumberFor<DomainHeader>;
1002-
10031000
/// Returns the domain block limit of the given domain.
10041001
fn domain_block_limit(domain_id: DomainId) -> Option<DomainBlockLimit>;
10051002

crates/subspace-runtime/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,10 +1036,6 @@ impl_runtime_apis! {
10361036
Domains::oldest_receipt_number(domain_id)
10371037
}
10381038

1039-
fn block_tree_pruning_depth() -> DomainNumber {
1040-
Domains::block_tree_pruning_depth()
1041-
}
1042-
10431039
fn domain_block_limit(domain_id: DomainId) -> Option<sp_domains::DomainBlockLimit> {
10441040
Domains::domain_block_limit(domain_id)
10451041
}

test/subspace-test-runtime/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,10 +1221,6 @@ impl_runtime_apis! {
12211221
Domains::oldest_receipt_number(domain_id)
12221222
}
12231223

1224-
fn block_tree_pruning_depth() -> DomainNumber {
1225-
Domains::block_tree_pruning_depth()
1226-
}
1227-
12281224
fn domain_block_limit(domain_id: DomainId) -> Option<sp_domains::DomainBlockLimit> {
12291225
Domains::domain_block_limit(domain_id)
12301226
}

0 commit comments

Comments
 (0)