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

Manually track consensus block hash for ER verification #1847

Merged
merged 3 commits into from
Aug 21, 2023
Merged

Conversation

NingLin-P
Copy link
Member

Currently, we use the consensus block hash from the frame-system to verify ER, even though we have the assumption of BlockTreePruningDepth <= BlockHashCount, which is not enough to guarantee the consensus block hash must exist when verifying ER because the domain block is not mapping to the consensus block one by one, if there are too many empty consensus blocks, the older hash will be pruned.

This PR fixes the issue by manually tracking the consensus block hash in pallet-domains, the storage is still unbounded in some cases see #1673 but the situation is better than in domain v1 because now we only need to store the consensus hash if the consensus block contains bundle, the unbounded storage issue should be fixed once #1731 is implemented.

Code contributor checklist:

The consensus block hash is only tracked if the block contains bundle and it
is pruned when the corresponding ER is pruned. This commit also adjust the
test correspondingly.

Signed-off-by: linning <linningde25@gmail.com>
…kHashCount

Signed-off-by: linning <linningde25@gmail.com>
Copy link
Contributor

@vedhavyas vedhavyas left a comment

Choose a reason for hiding this comment

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

I left questions but over all the approach make sense

@@ -491,10 +490,6 @@ parameter_types! {
pub const MaxPendingStakingOperation: u32 = 100;
}

// `BlockTreePruningDepth` should <= `BlockHashCount` because we need the consensus block hash to verify
// execution receipt, which is used to construct the node of the block tree.
const_assert!(BlockTreePruningDepth::get() <= BlockHashCount::get());
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. I noticed earlier that BlockHashCount was unused so removing the assertion make sense

Copy link
Member

Choose a reason for hiding this comment

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

This is the last use of static_assertions, dependency should have been removed as well

/// for more details, this will be fixed once https://github.com/subspace/subspace/issues/1731 is implemented.
#[pallet::storage]
#[pallet::getter(fn consensus_hash)]
pub type ConsensusBlockHash<T: Config> =
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is a another optimization that can done here using reference counting for all the domains rather than storing the same hash for each domain.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have considered this but it seems more complected because each domain may submit bundle in different consensus blocks so the consensus hash needed to store is different from domain to domain, and when should a consensus hash be pruned is also different from domain to domain, the complexity come when we need to track these difference.

@@ -267,6 +282,11 @@ pub(crate) fn process_execution_receipt<T: Config>(
}
let _ = ExecutionInbox::<T>::clear_prefix((domain_id, to_prune), u32::MAX, None);

ConsensusBlockHash::<T>::remove(
Copy link
Contributor

Choose a reason for hiding this comment

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

why not prune it when we see the first ER instead of waiting until challenge period is over since we do not require this for the same ERs which comes from other operators ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well the ER that is still in the challenge period can be pruned by fraud proof and resubmitted by other operators thus we need the consensus hash for the verification.

Copy link
Contributor

@vedhavyas vedhavyas left a comment

Choose a reason for hiding this comment

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

Looks fine to me for now. I think we can revisit this later

@NingLin-P NingLin-P merged commit 086664e into main Aug 21, 2023
9 checks passed
@NingLin-P NingLin-P deleted the consensus-hash branch August 21, 2023 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants