-
Notifications
You must be signed in to change notification settings - Fork 241
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,14 +213,7 @@ mod pallet { | |
/// A variation of the Identifier used for holding the funds used for staking and domains. | ||
type HoldIdentifier: HoldIdentifier<Self>; | ||
|
||
/// The block tree pruning depth, its value should <= `BlockHashCount` because we | ||
/// need the consensus block hash to verify execution receipt, which is used to | ||
/// construct the node of the block tree. | ||
/// | ||
/// TODO: `BlockTreePruningDepth` <= `BlockHashCount` is not enough to guarantee the consensus block | ||
/// hash must exists while verifying receipt because the domain block is not mapping to the consensus | ||
/// block one by one, we need to either store the consensus block hash in runtime manually or store | ||
/// the consensus block hash in the client side and use host function to get them in runtime. | ||
/// The block tree pruning depth. | ||
#[pallet::constant] | ||
type BlockTreePruningDepth: Get<Self::DomainNumber>; | ||
|
||
|
@@ -468,6 +461,17 @@ mod pallet { | |
OptionQuery, | ||
>; | ||
|
||
/// The consensus block hash used to verify ER, only store the consensus block hash for a domain | ||
/// if that consensus block contains bundle of the domain, the hash will be pruned when the ER | ||
/// that point to the consensus block is pruned. | ||
/// | ||
/// TODO: this storage is unbounded in some cases, see https://github.com/subspace/subspace/issues/1673 | ||
/// 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> = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
StorageDoubleMap<_, Identity, DomainId, Identity, T::BlockNumber, T::Hash, OptionQuery>; | ||
|
||
/// A set of `BundleDigest` from all bundles that successfully submitted to the consensus block, | ||
/// these bundles will be used to construct the domain block and `ExecutionInbox` is used to: | ||
/// | ||
|
@@ -1067,7 +1071,13 @@ mod pallet { | |
|
||
do_upgrade_runtimes::<T>(block_number); | ||
|
||
let _ = SuccessfulBundles::<T>::clear(u32::MAX, None); | ||
// Store the hash of the parent consensus block for domain that have bundles submitted | ||
// in that consensus block | ||
let parent_number = block_number - One::one(); | ||
let parent_hash = frame_system::Pallet::<T>::block_hash(parent_number); | ||
for (domain_id, _) in SuccessfulBundles::<T>::drain() { | ||
ConsensusBlockHash::<T>::insert(domain_id, parent_number, parent_hash); | ||
} | ||
|
||
Weight::zero() | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,6 @@ use sp_std::prelude::*; | |
#[cfg(feature = "std")] | ||
use sp_version::NativeVersion; | ||
use sp_version::RuntimeVersion; | ||
use static_assertions::const_assert; | ||
use subspace_core_primitives::crypto::Scalar; | ||
use subspace_core_primitives::objects::BlockObjectMapping; | ||
use subspace_core_primitives::{ | ||
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. I noticed earlier that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the last use of |
||
|
||
impl pallet_domains::Config for Runtime { | ||
type RuntimeEvent = RuntimeEvent; | ||
type DomainNumber = DomainNumber; | ||
|
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.