Skip to content

Commit

Permalink
Merge pull request #145 from eigerco/fix/139/configure-time-units-for…
Browse files Browse the repository at this point in the history
…-testnet

test(runtime): configure lower time bounds behind a feature flag
  • Loading branch information
jmg-duarte authored Jul 22, 2024
2 parents 5f41a25 + b317101 commit 1e186c3
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
5 changes: 4 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 12 additions & 4 deletions pallets/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,27 @@ 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.
/// [`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<BlockNumberFor<Self>>;
type TimeUnitInBlocks: Get<BlockNumberFor<Self>>;

/// 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<BlockNumberFor<Self>>;

/// 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<BlockNumberFor<Self>>;

Expand Down Expand Up @@ -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
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 TimeUnitInBlocks = 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 TimeUnitInBlocks = ConstU64<1>;
type MinDealDuration = ConstU64<1>;
type MaxDealDuration = ConstU64<30>;
type MaxDealsPerBlock = ConstU32<32>;
Expand Down
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ std = [
"xcm-executor/std",
"xcm/std",
]
testnet = []

runtime-benchmarks = [
"cumulus-pallet-parachain-system/runtime-benchmarks",
Expand Down
41 changes: 35 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,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
Expand All @@ -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.
/// <https://github.com/filecoin-project/builtin-actors/blob/c32c97229931636e3097d92cf4c43ac36a7b4b47/actors/market/src/policy.rs#L28>
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 {
Expand Down Expand Up @@ -345,8 +374,8 @@ impl pallet_market::Config for Runtime {
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 TimeUnitInBlocks = TimeUnitInBlocks;
type MinDealDuration = MinDealDuration;
type MaxDealDuration = MaxDealDuration;
}

0 comments on commit 1e186c3

Please sign in to comment.