Skip to content

Commit

Permalink
Merge pull request #2329 from subspace/refactoring-bad-er-tracking
Browse files Browse the repository at this point in the history
Refactoring the bad ER tracking and the fraud proof trigger
  • Loading branch information
NingLin-P authored Dec 20, 2023
2 parents 65317f4 + 36bbb17 commit b787130
Show file tree
Hide file tree
Showing 13 changed files with 534 additions and 1,114 deletions.
9 changes: 9 additions & 0 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,8 @@ impl<T: Config> Pallet<T> {
}

/// Returns the block number of oldest execution receipt.
// FIXME: the `oldest_receipt_number` may not be correct if fraud proof is submitted
// and bad ER were pruned, see https://github.com/subspace/subspace/issues/2354
pub fn oldest_receipt_number(domain_id: DomainId) -> DomainBlockNumberFor<T> {
Self::head_receipt_number(domain_id).saturating_sub(Self::block_tree_pruning_depth())
}
Expand Down Expand Up @@ -1929,6 +1931,13 @@ impl<T: Config> Pallet<T> {
pub fn execution_receipt(receipt_hash: ReceiptHashFor<T>) -> Option<ExecutionReceiptOf<T>> {
BlockTreeNodes::<T>::get(receipt_hash).map(|db| db.execution_receipt)
}

pub fn receipt_hash(
domain_id: DomainId,
domain_number: DomainBlockNumberFor<T>,
) -> Option<ReceiptHashFor<T>> {
BlockTree::<T>::get(domain_id, domain_number)
}
}

impl<T> Pallet<T>
Expand Down
3 changes: 3 additions & 0 deletions crates/sp-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,9 @@ sp_api::decl_runtime_apis! {

/// Get the consensus chain sudo account id, currently only used in the intentional malicious operator
fn sudo_account_id() -> subspace_runtime_primitives::AccountId;

/// Returns the execution receipt hash of the given domain and domain block number
fn receipt_hash(domain_id: DomainId, domain_number: HeaderNumberFor<DomainHeader>) -> Option<HeaderHashFor<DomainHeader>>;
}

pub trait BundleProducerElectionApi<Balance: Encode + Decode> {
Expand Down
4 changes: 4 additions & 0 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,10 @@ impl_runtime_apis! {
fn sudo_account_id() -> AccountId {
SudoId::get()
}

fn receipt_hash(domain_id: DomainId, domain_number: DomainNumber) -> Option<DomainHash> {
Domains::receipt_hash(domain_id, domain_number)
}
}

impl sp_domains::BundleProducerElectionApi<Block, Balance> for Runtime {
Expand Down
1 change: 1 addition & 0 deletions domains/client/domain-operator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ sc-cli = { version = "0.10.0-dev", git = "https://github.com/subspace/polkadot-s
sc-service = { version = "0.10.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "0831dfc3c54b10ab46e82acf98603b4af1a47bd5", default-features = false }
sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "0831dfc3c54b10ab46e82acf98603b4af1a47bd5" }
sp-state-machine = { version = "0.28.0", git = "https://github.com/subspace/polkadot-sdk", rev = "0831dfc3c54b10ab46e82acf98603b4af1a47bd5" }
subspace-core-primitives = { version = "0.1.0", default-features = false, path = "../../../crates/subspace-core-primitives" }
subspace-test-runtime = { version = "0.1.0", path = "../../../test/subspace-test-runtime" }
subspace-test-service = { version = "0.1.0", path = "../../../test/subspace-test-service" }
substrate-test-runtime-client = { version = "2.0.0", git = "https://github.com/subspace/polkadot-sdk", rev = "0831dfc3c54b10ab46e82acf98603b4af1a47bd5" }
Expand Down
Loading

0 comments on commit b787130

Please sign in to comment.