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

Implement block tree for the domain v2 #1650

Merged
merged 15 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions crates/pallet-domains/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ mod benchmarks {
/// - The receipts will prune a expired receipt
#[benchmark]
fn submit_system_bundle() {
let receipts_pruning_depth = T::ReceiptsPruningDepth::get().saturated_into::<u32>();
let receipts_pruning_depth = T::BlockTreePruningDepth::get().saturated_into::<u32>();

// Import `ReceiptsPruningDepth` number of receipts which will be pruned later
// Import `BlockTreePruningDepth` number of receipts which will be pruned later
run_to_block::<T>(1, receipts_pruning_depth);
for i in 0..receipts_pruning_depth {
let receipt = ExecutionReceipt::dummy(i.into(), block_hash_n::<T>(i));
Expand Down Expand Up @@ -82,9 +82,9 @@ mod benchmarks {
/// - The fraud proof will revert the maximal possible number of receipts
#[benchmark]
fn submit_system_domain_invalid_state_transition_proof() {
let receipts_pruning_depth = T::ReceiptsPruningDepth::get().saturated_into::<u32>();
let receipts_pruning_depth = T::BlockTreePruningDepth::get().saturated_into::<u32>();
NingLin-P marked this conversation as resolved.
Show resolved Hide resolved

// Import `ReceiptsPruningDepth` number of receipts which will be revert later
// Import `BlockTreePruningDepth` number of receipts which will be revert later
run_to_block::<T>(1, receipts_pruning_depth);
for i in 0..receipts_pruning_depth {
let receipt = ExecutionReceipt::dummy(i.into(), block_hash_n::<T>(i));
Expand All @@ -101,7 +101,7 @@ mod benchmarks {
(receipts_pruning_depth - 1).into()
);

// Construct a fraud proof that will revert `ReceiptsPruningDepth` number of receipts
// Construct a fraud proof that will revert `BlockTreePruningDepth` number of receipts
let proof: FraudProof<T::BlockNumber, T::Hash> =
FraudProof::InvalidStateTransition(dummy_invalid_state_transition_proof(DOMAIN_ID, 0));

Expand Down
10 changes: 10 additions & 0 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ mod pallet {
/// Identifier used for Freezing the funds used for staking.
type FreezeIdentifier: FreezeIdentifier<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.
#[pallet::constant]
type BlockTreePruningDepth: Get<Self::DomainNumber>;

/// The maximum fork at the same height allowed in the block tree.
#[pallet::constant]
type MaxBlockTreeFork: Get<u32>;

/// The maximum block size limit for all domain.
#[pallet::constant]
type MaxDomainBlockSize: Get<u32>;
Expand Down
5 changes: 4 additions & 1 deletion crates/pallet-domains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl frame_system::Config for Test {
}

parameter_types! {
pub const ReceiptsPruningDepth: BlockNumber = 256;
pub const MaximumReceiptDrift: BlockNumber = 128;
pub const InitialDomainTxRange: u64 = 10;
pub const DomainTxRangeAdjustmentInterval: u64 = 100;
Expand All @@ -79,6 +78,8 @@ parameter_types! {
pub const MaxDomainBlockWeight: Weight = Weight::from_parts(1024 * 1024, 0);
pub const DomainInstantiationDeposit: Balance = 100;
pub const MaxDomainNameLength: u32 = 16;
pub const BlockTreePruningDepth: u32 = 256;
pub const MaxBlockTreeFork: u32 = 32;
}

static CONFIRMATION_DEPTH_K: AtomicU64 = AtomicU64::new(10);
Expand Down Expand Up @@ -162,6 +163,8 @@ impl pallet_domains::Config for Test {
type DomainInstantiationDeposit = DomainInstantiationDeposit;
type MaxDomainNameLength = MaxDomainNameLength;
type Share = Balance;
type BlockTreePruningDepth = BlockTreePruningDepth;
type MaxBlockTreeFork = MaxBlockTreeFork;
}

pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ sp-session = { version = "4.0.0-dev", default-features = false, git = "https://g
sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
sp-version = { version = "22.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
static_assertions = "1.1.0"
subspace-core-primitives = { version = "0.1.0", default-features = false, path = "../subspace-core-primitives" }
subspace-runtime-primitives = { version = "0.1.0", default-features = false, path = "../subspace-runtime-primitives" }
subspace-verification = { version = "0.1.0", default-features = false, path = "../subspace-verification" }
Expand Down
10 changes: 9 additions & 1 deletion crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ 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::{
Expand Down Expand Up @@ -456,7 +457,6 @@ impl pallet_offences_subspace::Config for Runtime {
}

parameter_types! {
pub const ReceiptsPruningDepth: BlockNumber = 256;
pub const MaximumReceiptDrift: BlockNumber = 128;
pub const InitialDomainTxRange: u64 = INITIAL_DOMAIN_TX_RANGE;
pub const DomainTxRangeAdjustmentInterval: u64 = TX_RANGE_ADJUSTMENT_INTERVAL_BLOCKS;
Expand All @@ -472,8 +472,14 @@ parameter_types! {
pub const MaxBundlesPerBlock: u32 = 10;
pub const DomainInstantiationDeposit: Balance = 100 * SSC;
pub const MaxDomainNameLength: u32 = 32;
pub const BlockTreePruningDepth: u32 = 256;
pub const MaxBlockTreeFork: u32 = 32;
NingLin-P marked this conversation as resolved.
Show resolved Hide resolved
}

// `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());

impl pallet_domains::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type DomainNumber = DomainNumber;
Expand All @@ -493,6 +499,8 @@ impl pallet_domains::Config for Runtime {
type DomainInstantiationDeposit = DomainInstantiationDeposit;
type MaxDomainNameLength = MaxDomainNameLength;
type Share = Balance;
type BlockTreePruningDepth = BlockTreePruningDepth;
type MaxBlockTreeFork = MaxBlockTreeFork;
}

parameter_types! {
Expand Down
5 changes: 4 additions & 1 deletion test/subspace-test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ impl pallet_offences_subspace::Config for Runtime {
}

parameter_types! {
pub const ReceiptsPruningDepth: BlockNumber = 256;
pub const MaximumReceiptDrift: BlockNumber = 2;
pub const InitialDomainTxRange: u64 = 10;
pub const DomainTxRangeAdjustmentInterval: u64 = 100;
Expand All @@ -521,6 +520,8 @@ parameter_types! {
pub const MaxBundlesPerBlock: u32 = 10;
pub const DomainInstantiationDeposit: Balance = 100 * SSC;
pub const MaxDomainNameLength: u32 = 32;
pub const BlockTreePruningDepth: u32 = 256;
pub const MaxBlockTreeFork: u32 = 32;
}

impl pallet_domains::Config for Runtime {
Expand All @@ -542,6 +543,8 @@ impl pallet_domains::Config for Runtime {
type DomainInstantiationDeposit = DomainInstantiationDeposit;
type MaxDomainNameLength = MaxDomainNameLength;
type Share = Balance;
type BlockTreePruningDepth = BlockTreePruningDepth;
type MaxBlockTreeFork = MaxBlockTreeFork;
}

parameter_types! {
Expand Down