From a7c7eed7a9c7f12a43cf9b377a57eee339e1b1ea Mon Sep 17 00:00:00 2001 From: Konrad Stepniak Date: Thu, 18 Jul 2024 08:47:34 +0000 Subject: [PATCH 1/2] test(runtime): configure lower time bounds behind a feature flag --- pallets/market/src/lib.rs | 16 ++++++--- pallets/market/src/mock.rs | 2 +- pallets/storage-provider/src/tests/mod.rs | 2 +- runtime/Cargo.toml | 3 +- runtime/src/configs/mod.rs | 41 +++++++++++++++++++---- 5 files changed, 51 insertions(+), 13 deletions(-) diff --git a/pallets/market/src/lib.rs b/pallets/market/src/lib.rs index c21749457..0884a6ea8 100644 --- a/pallets/market/src/lib.rs +++ b/pallets/market/src/lib.rs @@ -80,19 +80,27 @@ pub mod pallet { #[pallet::constant] type MaxDeals: Get; - /// How many blocks are created in a day (time unit used for calculation) + /// How many blocks are created in a time unit. + /// [`MinDealDuration`] and [`MaxDealDuration`] are expressed in terms of [`TimeUnitInBlocks`]. + /// + /// E.g. `TimeUnitInBlocks = DAYS` is the number of of blocks finalized in a day + /// #[pallet::constant] - type BlocksPerDay: Get>; + type TimeUnitInBlocks: Get>; /// How many days should a deal last (activated). Minimum. /// Filecoin uses 180 as default. /// https://github.com/filecoin-project/builtin-actors/blob/c32c97229931636e3097d92cf4c43ac36a7b4b47/actors/market/src/policy.rs#L29 + /// + /// MinDealDuration = [`MinDealDuration`] * [`TimeUnitInBlocks`] in Blocks. #[pallet::constant] type MinDealDuration: Get>; /// How many days should a deal last (activated). Maximum. /// Filecoin uses 1278 as default. /// https://github.com/filecoin-project/builtin-actors/blob/c32c97229931636e3097d92cf4c43ac36a7b4b47/actors/market/src/policy.rs#L29 + /// + /// MaxDealDuration = [`MaxDealDuration`] * [`TimeUnitInBlocks`] in Blocks. #[pallet::constant] type MaxDealDuration: Get>; @@ -960,8 +968,8 @@ pub mod pallet { ProposalError::DealNotPublished ); - let min_dur = T::BlocksPerDay::get() * T::MinDealDuration::get(); - let max_dur = T::BlocksPerDay::get() * T::MaxDealDuration::get(); + let min_dur = T::TimeUnitInBlocks::get() * T::MinDealDuration::get(); + let max_dur = T::TimeUnitInBlocks::get() * T::MaxDealDuration::get(); ensure!( deal.proposal.duration() >= min_dur && deal.proposal.duration() <= max_dur, ProposalError::DealDurationOutOfBounds diff --git a/pallets/market/src/mock.rs b/pallets/market/src/mock.rs index e8d16d4a0..5aebc3d6f 100644 --- a/pallets/market/src/mock.rs +++ b/pallets/market/src/mock.rs @@ -55,7 +55,7 @@ impl crate::Config for Test { type OffchainSignature = Signature; type OffchainPublic = AccountPublic; type MaxDeals = ConstU32<32>; - type BlocksPerDay = ConstU64<1>; + type TimeUnitInBlocks = ConstU64<1>; type MinDealDuration = ConstU64<2>; type MaxDealDuration = ConstU64<30>; type MaxDealsPerBlock = ConstU32<32>; diff --git a/pallets/storage-provider/src/tests/mod.rs b/pallets/storage-provider/src/tests/mod.rs index fe08208fa..b609be62c 100644 --- a/pallets/storage-provider/src/tests/mod.rs +++ b/pallets/storage-provider/src/tests/mod.rs @@ -70,7 +70,7 @@ impl pallet_market::Config for Test { type OffchainSignature = Signature; type OffchainPublic = AccountPublic; type MaxDeals = ConstU32<32>; - type BlocksPerDay = ConstU64<1>; + type TimeUnitInBlocks = ConstU64<1>; type MinDealDuration = ConstU64<1>; type MaxDealDuration = ConstU64<30>; type MaxDealsPerBlock = ConstU32<32>; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index b5ccf00b5..2d0373ff8 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -87,7 +87,7 @@ parachain-info = { workspace = true, default-features = false } parachains-common = { workspace = true, default-features = false } [features] -default = ["std"] +default = ["std", "testnet"] std = [ "codec/std", "cumulus-pallet-aura-ext/std", @@ -141,6 +141,7 @@ std = [ "xcm-executor/std", "xcm/std", ] +testnet = [] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", diff --git a/runtime/src/configs/mod.rs b/runtime/src/configs/mod.rs index 43a75efc5..98f45cad3 100644 --- a/runtime/src/configs/mod.rs +++ b/runtime/src/configs/mod.rs @@ -51,15 +51,19 @@ use sp_version::RuntimeVersion; use xcm::latest::prelude::BodyId; use xcm_config::{RelayLocation, XcmOriginToTransactDispatchOrigin}; +#[cfg(not(feature = "testnet"))] +use super::DAYS; +#[cfg(feature = "testnet")] +use super::MINUTES; // Local module imports use super::{ weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}, AccountId, Aura, Balance, Balances, Block, BlockNumber, CollatorSelection, Hash, MessageQueue, Nonce, PalletInfo, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, RuntimeTask, Session, SessionKeys, System, WeightToFee, - XcmpQueue, AVERAGE_ON_INITIALIZE_RATIO, BLOCK_PROCESSING_VELOCITY, DAYS, EXISTENTIAL_DEPOSIT, - HOURS, MAXIMUM_BLOCK_WEIGHT, MICROUNIT, NORMAL_DISPATCH_RATIO, - RELAY_CHAIN_SLOT_DURATION_MILLIS, SLOT_DURATION, UNINCLUDED_SEGMENT_CAPACITY, VERSION, + XcmpQueue, AVERAGE_ON_INITIALIZE_RATIO, BLOCK_PROCESSING_VELOCITY, EXISTENTIAL_DEPOSIT, HOURS, + MAXIMUM_BLOCK_WEIGHT, MICROUNIT, NORMAL_DISPATCH_RATIO, RELAY_CHAIN_SLOT_DURATION_MILLIS, + SLOT_DURATION, UNINCLUDED_SEGMENT_CAPACITY, VERSION, }; parameter_types! { @@ -306,7 +310,9 @@ impl pallet_collator_selection::Config for Runtime { type WeightInfo = (); } +#[cfg(not(feature = "testnet"))] parameter_types! { + // Storage Provider Pallet pub const WpostProvingPeriod: BlockNumber = DAYS; // Half an hour (=48 per day) // 30 * 60 = 30 minutes @@ -316,6 +322,29 @@ parameter_types! { pub const MaxSectorExpirationExtension: BlockNumber = 1278 * DAYS; pub const SectorMaximumLifetime: BlockNumber = (365 * DAYS) * 5; // 5 years pub const MaxProveCommitDuration: BlockNumber = (30 * DAYS) + 150; + + // Market Pallet + /// Deal duration values copied from FileCoin. + /// + pub const TimeUnitInBlocks: u32 = DAYS; + pub const MinDealDuration: u32 = 20; + pub const MaxDealDuration: u32 = 1278; +} + +#[cfg(feature = "testnet")] +parameter_types! { + // Storage Provider Pallet + pub const WpostProvingPeriod: BlockNumber = 5 * MINUTES; + pub const WpostChallengeWindow: BlockNumber = 2 * MINUTES; + pub const MinSectorExpiration: BlockNumber = 5 * MINUTES; + pub const MaxSectorExpirationExtension: BlockNumber = 60 * MINUTES; + pub const SectorMaximumLifetime: BlockNumber = 120 * MINUTES; + pub const MaxProveCommitDuration: BlockNumber = 5 * MINUTES; + + // Market Pallet + pub const TimeUnitInBlocks: u32 = MINUTES; + pub const MinDealDuration: u32 = 5; + pub const MaxDealDuration: u32 = 180; } impl pallet_storage_provider::Config for Runtime { @@ -345,8 +374,8 @@ impl pallet_market::Config for Runtime { type OffchainSignature = MultiSignature; type OffchainPublic = AccountPublic; type MaxDeals = ConstU32<128>; - type BlocksPerDay = ConstU32; - type MinDealDuration = ConstU32<{ DAYS * 180 }>; - type MaxDealDuration = ConstU32<{ DAYS * 1278 }>; type MaxDealsPerBlock = ConstU32<128>; + type TimeUnitInBlocks = TimeUnitInBlocks; + type MinDealDuration = MinDealDuration; + type MaxDealDuration = MaxDealDuration; } From b317101fcd2f056b0c5a81c1afdcc46fb2f3f51d Mon Sep 17 00:00:00 2001 From: Konrad Stepniak Date: Sun, 21 Jul 2024 18:11:21 +0000 Subject: [PATCH 2/2] build: add runtime feature flags for testnet --- Justfile | 5 ++++- runtime/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Justfile b/Justfile index 10c2415c4..f88f6e145 100644 --- a/Justfile +++ b/Justfile @@ -12,7 +12,10 @@ build: lint release: lint cargo build --release -testnet: release +release-testnet: lint + cargo build --release --features polka-storage-runtime/testnet + +testnet: release-testnet zombienet -p native spawn zombienet/local-testnet.toml build-parachain-docker: diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 2d0373ff8..12ded1cf1 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -87,7 +87,7 @@ parachain-info = { workspace = true, default-features = false } parachains-common = { workspace = true, default-features = false } [features] -default = ["std", "testnet"] +default = ["std"] std = [ "codec/std", "cumulus-pallet-aura-ext/std",