Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring the bad ER tracking and the fraud proof trigger #2329

Merged
merged 7 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the way we derive this is not stable. We should instead track the confirmed domain block number and then return the immediate uncornfirmed block's ER as oldest receipt number instead of using head_receipt number since, like you mentioned, is prone to FraudProof pruning

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we should explicitly track either the confirmed domain block number or the oldest receipt number (which does not make much difference IMO) instead of deriving from the head receipt number.

// 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 @@ -1908,6 +1910,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 @@ -1073,6 +1073,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
Loading