Skip to content

Commit

Permalink
test(runtime): configure lower time bounds behind a feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
th7nder committed Jul 18, 2024
1 parent 8d5c9fd commit 0a2c6cd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
12 changes: 8 additions & 4 deletions pallets/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ pub mod pallet {
#[pallet::constant]
type MaxDeals: Get<u32>;

/// How many blocks are created in a day (time unit used for calculation)
/// How many blocks are created in a time unit.
/// E.g. BlocksPerTimeUnit = Number of Blocks finalized in a Day = DAYS
/// [`MinDealDuration`] and [`MaxDealDuration`] are expressed in terms of [`BlocksPerTimeUnit`].
/// MinDealDuration = [`MinDealDuration`] * [`BlocksPerTimeUnit`] in Blocks.
/// MaxDealDuration = [`MaxDealDuration`] * [`BlocksPerTimeUnit`] in Blocks.
#[pallet::constant]
type BlocksPerDay: Get<BlockNumberFor<Self>>;
type BlocksPerTimeUnit: Get<BlockNumberFor<Self>>;

/// How many days should a deal last (activated). Minimum.
/// Filecoin uses 180 as default.
Expand Down Expand Up @@ -947,8 +951,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::BlocksPerTimeUnit::get() * T::MinDealDuration::get();
let max_dur = T::BlocksPerTimeUnit::get() * T::MaxDealDuration::get();
ensure!(
deal.proposal.duration() >= min_dur && deal.proposal.duration() <= max_dur,
ProposalError::DealDurationOutOfBounds
Expand Down
2 changes: 1 addition & 1 deletion pallets/market/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl crate::Config for Test {
type OffchainSignature = Signature;
type OffchainPublic = AccountPublic;
type MaxDeals = ConstU32<32>;
type BlocksPerDay = ConstU64<1>;
type BlocksPerTimeUnit = ConstU64<1>;
type MinDealDuration = ConstU64<2>;
type MaxDealDuration = ConstU64<30>;
type MaxDealsPerBlock = ConstU32<32>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/storage-provider/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 BlocksPerTimeUnit = ConstU64<1>;
type MinDealDuration = ConstU64<1>;
type MaxDealDuration = ConstU64<30>;
type MaxDealsPerBlock = ConstU32<32>;
Expand Down
3 changes: 2 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -141,6 +141,7 @@ std = [
"xcm-executor/std",
"xcm/std",
]
testnet = []

runtime-benchmarks = [
"cumulus-pallet-parachain-system/runtime-benchmarks",
Expand Down
43 changes: 37 additions & 6 deletions runtime/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down Expand Up @@ -306,6 +310,7 @@ impl pallet_collator_selection::Config for Runtime {
type WeightInfo = ();
}

#[cfg(not(feature = "testnet"))]
parameter_types! {
pub const WpostProvingPeriod: BlockNumber = DAYS;
// Half an hour (=48 per day)
Expand All @@ -318,6 +323,16 @@ parameter_types! {
pub const MaxProveCommitDuration: BlockNumber = (30 * DAYS) + 150;
}

#[cfg(feature = "testnet")]
parameter_types! {
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;
}

impl pallet_storage_provider::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type PeerId = BoundedVec<u8, ConstU32<256>>; // Arbitrary length
Expand All @@ -338,15 +353,31 @@ parameter_types! {

pub type AccountPublic = <MultiSignature as Verify>::Signer;

/// Deal duration values copied from FileCoin.
/// <https://github.com/filecoin-project/builtin-actors/blob/c32c97229931636e3097d92cf4c43ac36a7b4b47/actors/market/src/policy.rs#L28>
#[cfg(not(feature = "testnet"))]
parameter_types! {
pub const BlocksPerTimeUnit: u32 = DAYS;
pub const MinDealDuration: u32 = 20;
pub const MaxDealDuration: u32 = 1278;
}

#[cfg(feature = "testnet")]
parameter_types! {
pub const BlocksPerTimeUnit: u32 = MINUTES;
pub const MinDealDuration: u32 = 5;
pub const MaxDealDuration: u32 = 180;
}

impl pallet_market::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type PalletId = MarketPalletId;
type OffchainSignature = MultiSignature;
type OffchainPublic = AccountPublic;
type MaxDeals = ConstU32<128>;
type BlocksPerDay = ConstU32<DAYS>;
type MinDealDuration = ConstU32<{ DAYS * 180 }>;
type MaxDealDuration = ConstU32<{ DAYS * 1278 }>;
type MaxDealsPerBlock = ConstU32<128>;
type BlocksPerTimeUnit = BlocksPerTimeUnit;
type MinDealDuration = MinDealDuration;
type MaxDealDuration = MaxDealDuration;
}

0 comments on commit 0a2c6cd

Please sign in to comment.