Skip to content

Commit

Permalink
Apply updated configuration to Zeitgeist runtime (#749)
Browse files Browse the repository at this point in the history
* Copy shared parameters into each runtime

* Document parameters

* Add mock constants

* Use constant pallet ids
  • Loading branch information
sea212 committed Aug 12, 2022
1 parent c37d2d5 commit 8788f42
Show file tree
Hide file tree
Showing 37 changed files with 640 additions and 229 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

14 changes: 9 additions & 5 deletions node/src/command_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sp_inherents::{InherentData, InherentDataProvider};
use sp_keyring::Sr25519Keyring;
use sp_runtime::{OpaqueExtrinsic, SaturatedConversion};
use std::{sync::Arc, time::Duration};
use zeitgeist_primitives::{constants::BlockHashCount, types::Signature};
use zeitgeist_primitives::types::Signature;

/// Generates extrinsics for the `benchmark overhead` command.
///
Expand Down Expand Up @@ -92,8 +92,10 @@ pub fn create_benchmark_extrinsic_zeitgeist<
let best_hash = client.chain_info().best_hash;
let best_block = client.chain_info().best_number;

let period =
BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64;
let period = zeitgeist_runtime::BlockHashCount::get()
.checked_next_power_of_two()
.map(|c| c / 2)
.unwrap_or(2) as u64;
let extra: zeitgeist_runtime::SignedExtra = (
zeitgeist_runtime::CheckNonZeroSender::<zeitgeist_runtime::Runtime>::new(),
zeitgeist_runtime::CheckSpecVersion::<zeitgeist_runtime::Runtime>::new(),
Expand Down Expand Up @@ -148,8 +150,10 @@ pub fn create_benchmark_extrinsic_battery_station<
let best_hash = client.chain_info().best_hash;
let best_block = client.chain_info().best_number;

let period =
BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64;
let period = battery_station_runtime::BlockHashCount::get()
.checked_next_power_of_two()
.map(|c| c / 2)
.unwrap_or(2) as u64;
let extra: battery_station_runtime::SignedExtra = (
battery_station_runtime::CheckNonZeroSender::<battery_station_runtime::Runtime>::new(),
battery_station_runtime::CheckSpecVersion::<battery_station_runtime::Runtime>::new(),
Expand Down
1 change: 1 addition & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test-case = "2.0.2"

[features]
default = ["std"]
mock = []
std = [
"frame-support/std",
"frame-system/std",
Expand Down
121 changes: 26 additions & 95 deletions primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
clippy::integer_arithmetic
)]

#[cfg(feature = "mock")]
pub mod mock;
pub mod ztg;

use crate::{
asset::Asset,
types::{Balance, BlockNumber, CurrencyId, Moment},
};
use crate::types::{Balance, BlockNumber};
use frame_support::{parameter_types, PalletId};
use orml_traits::parameter_type_with_key;

// Definitions for time
pub const BLOCKS_PER_DAY: BlockNumber = BLOCKS_PER_HOUR * 24;
Expand Down Expand Up @@ -62,95 +60,28 @@ parameter_types! {
}

// Authorized
parameter_types! {
pub const AuthorizedPalletId: PalletId = PalletId(*b"zge/atzd");
}
/// Pallet identifier, mainly used for named balance reserves.
pub const AUTHORIZED_PALLET_ID: PalletId = PalletId(*b"zge/atzd");

// Court
parameter_types! {
pub const CourtCaseDuration: u64 = BLOCKS_PER_DAY;
pub const CourtPalletId: PalletId = PalletId(*b"zge/cout");
pub const StakeWeight: u128 = 2 * BASE;
}

// Liquidity Mining parameters
parameter_types! {
pub const LiquidityMiningPalletId: PalletId = PalletId(*b"zge/lymg");
}

// Prediction Market parameters
parameter_types! {
pub const AdvisoryBond: Balance = 25 * CENT;
pub const DisputeBond: Balance = 5 * BASE;
pub const DisputeFactor: Balance = 2 * BASE;
pub const DisputePeriod: BlockNumber = BLOCKS_PER_DAY;
pub const MaxCategories: u16 = 10;
pub const MaxDisputes: u16 = 6;
pub const MinCategories: u16 = 2;
// 60_000 = 1 minute. Should be raised to something more reasonable in the future.
pub const MinSubsidyPeriod: Moment = 60_000;
// 2_678_400_000 = 31 days.
pub const MaxSubsidyPeriod: Moment = 2_678_400_000;
// Requirements: MaxPeriod + ReportingPeriod + MaxDisputes * DisputePeriod < u64::MAX.
pub const MaxMarketPeriod: Moment = u64::MAX / 2;
pub const OracleBond: Balance = 50 * CENT;
pub const PmPalletId: PalletId = PalletId(*b"zge/pred");
pub const ReportingPeriod: u32 = BLOCKS_PER_DAY as _;
pub const ValidityBond: Balance = 50 * CENT;
}

// Simple disputes parameters
parameter_types! {
pub const SimpleDisputesPalletId: PalletId = PalletId(*b"zge/sedp");
}

// Swaps parameters
parameter_types! {
pub const ExitFee: Balance = 3 * BASE / 1000; // 0.3%
pub const MinAssets: u16 = 2;
pub const MaxAssets: u16 = MaxCategories::get() + 1;
pub const MaxInRatio: Balance = (BASE / 3) + 1;
pub const MaxOutRatio: Balance = (BASE / 3) + 1;
pub const MaxSwapFee: Balance = BASE / 10; // 10%
pub const MaxTotalWeight: Balance = 50 * BASE;
pub const MaxWeight: Balance = 50 * BASE;
pub const MinLiquidity: Balance = 100 * BASE;
pub const MinSubsidy: Balance = MinLiquidity::get();
pub const MinSubsidyPerAccount: Balance = MinSubsidy::get();
pub const MinWeight: Balance = BASE;
pub const SwapsPalletId: PalletId = PalletId(*b"zge/swap");
}

// Shared within tests
// Balance
parameter_types! {
pub const ExistentialDeposit: u128 = CENT;
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = 50;
}

// ORML
parameter_types! {
// ORML
pub const GetNativeCurrencyId: CurrencyId = Asset::Ztg;
}

parameter_type_with_key! {
// Well, not every asset is a currency ¯\_(ツ)_/¯
pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
match currency_id {
Asset::Ztg => ExistentialDeposit::get(),
_ => 0
}
};
}

// System
parameter_types! {
pub const BlockHashCount: u64 = 250;
}

// Time
parameter_types! {
pub const MinimumPeriod: u64 = MILLISECS_PER_BLOCK as u64 / 2;
}
/// Pallet identifier, mainly used for named balance reserves.
pub const COURT_PALLET_ID: PalletId = PalletId(*b"zge/cout");

// Liqudity Mining
/// Pallet identifier, mainly used for named balance reserves.
pub const LM_PALLET_ID: PalletId = PalletId(*b"zge/lymg");

// Prediction Markets
/// Max. categories in a prediction market.
pub const MAX_CATEGORIES: u16 = 10;
/// Pallet identifier, mainly used for named balance reserves.
pub const PM_PALLET_ID: PalletId = PalletId(*b"zge/pred");

// Simple Disputes
pub const SD_PALLET_ID: PalletId = PalletId(*b"zge/sedp");

// Swaps
/// Max. assets in a swap pool.
pub const MAX_ASSETS: u16 = MAX_CATEGORIES + 1;
/// Pallet identifier, mainly used for named balance reserves.
pub const SWAPS_PALLET_ID: PalletId = PalletId(*b"zge/swap");
103 changes: 103 additions & 0 deletions primitives/src/constants/mock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#![cfg(feature = "mock")]

pub use super::*;
use crate::{
asset::Asset,
types::{Balance, BlockNumber, CurrencyId, Moment},
};
use frame_support::{parameter_types, PalletId};
use orml_traits::parameter_type_with_key;

// Authorized
parameter_types! {
pub const AuthorizedPalletId: PalletId = PalletId(*b"zge/atzd");
}

// Court
parameter_types! {
pub const CourtCaseDuration: u64 = BLOCKS_PER_DAY;
pub const CourtPalletId: PalletId = PalletId(*b"zge/cout");
pub const StakeWeight: u128 = 2 * BASE;
}

// Liquidity Mining parameters
parameter_types! {
pub const LiquidityMiningPalletId: PalletId = PalletId(*b"zge/lymg");
}

// Prediction Market parameters
parameter_types! {
pub const AdvisoryBond: Balance = 25 * CENT;
pub const DisputeBond: Balance = 5 * BASE;
pub const DisputeFactor: Balance = 2 * BASE;
pub const DisputePeriod: BlockNumber = BLOCKS_PER_DAY;
pub const MaxCategories: u16 = 10;
pub const MaxDisputes: u16 = 6;
pub const MinCategories: u16 = 2;
// 60_000 = 1 minute. Should be raised to something more reasonable in the future.
pub const MinSubsidyPeriod: Moment = 60_000;
// 2_678_400_000 = 31 days.
pub const MaxSubsidyPeriod: Moment = 2_678_400_000;
// Requirements: MaxPeriod + ReportingPeriod + MaxDisputes * DisputePeriod < u64::MAX.
pub const MaxMarketPeriod: Moment = u64::MAX / 2;
pub const OracleBond: Balance = 50 * CENT;
pub const PmPalletId: PalletId = PalletId(*b"zge/pred");
pub const ReportingPeriod: u32 = BLOCKS_PER_DAY as _;
pub const ValidityBond: Balance = 50 * CENT;
}

// Simple disputes parameters
parameter_types! {
pub const SimpleDisputesPalletId: PalletId = PalletId(*b"zge/sedp");
}

// Swaps parameters
parameter_types! {
pub const ExitFee: Balance = 3 * BASE / 1000; // 0.3%
pub const MinAssets: u16 = 2;
pub const MaxAssets: u16 = MaxCategories::get() + 1;
pub const MaxInRatio: Balance = (BASE / 3) + 1;
pub const MaxOutRatio: Balance = (BASE / 3) + 1;
pub const MaxSwapFee: Balance = BASE / 10; // 10%
pub const MaxTotalWeight: Balance = 50 * BASE;
pub const MaxWeight: Balance = 50 * BASE;
pub const MinLiquidity: Balance = 100 * BASE;
pub const MinSubsidy: Balance = MinLiquidity::get();
pub const MinSubsidyPerAccount: Balance = MinSubsidy::get();
pub const MinWeight: Balance = BASE;
pub const SwapsPalletId: PalletId = PalletId(*b"zge/swap");
}

// Shared within tests
// Balance
parameter_types! {
pub const ExistentialDeposit: u128 = CENT;
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = 50;
}

// ORML
parameter_types! {
// ORML
pub const GetNativeCurrencyId: CurrencyId = Asset::Ztg;
}

parameter_type_with_key! {
// Well, not every asset is a currency ¯\_(ツ)_/¯
pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
match currency_id {
Asset::Ztg => ExistentialDeposit::get(),
_ => 0
}
};
}

// System
parameter_types! {
pub const BlockHashCount: u64 = 250;
}

// Time
parameter_types! {
pub const MinimumPeriod: u64 = MILLISECS_PER_BLOCK as u64 / 2;
}
6 changes: 3 additions & 3 deletions primitives/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.

use crate::{
constants::MaxAssets,
constants::MAX_ASSETS,
types::{Asset, PoolStatus},
};
use alloc::{collections::BTreeMap, vec::Vec};
Expand Down Expand Up @@ -61,13 +61,13 @@ where
fn max_encoded_len() -> usize {
let max_encoded_length_bytes = <Compact<u64>>::max_encoded_len();
let b_tree_map_size = 1usize
.saturating_add(MaxAssets::get().saturated_into::<usize>().saturating_mul(
.saturating_add(MAX_ASSETS.saturated_into::<usize>().saturating_mul(
<Asset<MarketId>>::max_encoded_len().saturating_add(u128::max_encoded_len()),
))
.saturating_add(max_encoded_length_bytes);

<Asset<MarketId>>::max_encoded_len()
.saturating_mul(MaxAssets::get().saturated_into::<usize>())
.saturating_mul(MAX_ASSETS.saturated_into::<usize>())
.saturating_add(max_encoded_length_bytes)
.saturating_add(<Option<Asset<MarketId>>>::max_encoded_len())
.saturating_add(MarketId::max_encoded_len())
Expand Down
Loading

0 comments on commit 8788f42

Please sign in to comment.