Skip to content

Commit

Permalink
feat : add fast-runtime feature
Browse files Browse the repository at this point in the history
  • Loading branch information
1xstj committed Jan 10, 2024
1 parent c7fc287 commit c620b8a
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 2,091 deletions.
2,276 changes: 203 additions & 2,073 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ members = [
"precompiles/proxy",
"precompiles/preimage",
"precompiles/jobs",
"relayer-gadget",
"relayer-gadget/cli",
# "relayer-gadget",
# "relayer-gadget/cli",
]
resolver = "2"

Expand Down Expand Up @@ -74,8 +74,8 @@ paste = "1.0.6"
slices = "0.2.0"
schnorrkel = { version = "0.9.1", default-features = false }

tangle-relayer-gadget = { packge = "tangle-relayer-gadget", path = "relayer-gadget" }
tangle-relayer-gadget-cli = { packge = "tangle-relayer-gadget-cli", path = "relayer-gadget/cli" }
# tangle-relayer-gadget = { packge = "tangle-relayer-gadget", path = "relayer-gadget" }
# tangle-relayer-gadget-cli = { packge = "tangle-relayer-gadget-cli", path = "relayer-gadget/cli" }

tangle-testnet-runtime = { package = "tangle-testnet-runtime", path = "runtime/testnet" }
tangle-runtime = { package = "tangle-runtime", path = "runtime/mainnet" }
Expand Down
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,4 @@ rocksdb = [
sql = ["fc-db/sql", "fc-mapping-sync/sql"]
testnet = ["tangle-testnet-runtime"]
txpool = ["fc-rpc/txpool"]
fast-runtime = ["tangle-testnet-runtime/fast-runtime", "tangle-runtime/fast-runtime"]
3 changes: 3 additions & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ sp-consensus-babe = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
sp-staking = { workspace = true }

# Arkworks
ark-bn254 = { workspace = true, optional = true }
Expand Down Expand Up @@ -54,6 +55,7 @@ std = [
"ark-groth16?/std",
"ark-serialize?/std",
"ethabi?/std",
"sp-staking/std"
]
verifying = [
"ark-crypto-primitives",
Expand All @@ -66,3 +68,4 @@ verifying = [
"ethabi",
]
integration-tests = []
fast-runtime = []
34 changes: 34 additions & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ pub mod time {
// 1 in 4 blocks (on average, not counting collisions) will be primary BABE blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);

#[cfg(feature = "fast-runtime")]
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 10; // 10 blocks for fast tests

// NOTE: Currently it is not possible to change the epoch duration after the chain has started.
// Attempting to do so will brick block production.
#[cfg(not(feature = "fast-runtime"))]
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 4 * HOURS;
pub const EPOCH_DURATION_IN_SLOTS: u64 = {
const SLOT_FILL_RATE: f64 = MILLISECS_PER_BLOCK as f64 / SLOT_DURATION as f64;
Expand Down Expand Up @@ -266,6 +270,36 @@ pub mod treasury {
pub const MAX_APPROVALS: u32 = 100;
}

#[cfg(not(feature = "fast-runtime"))]
pub mod staking {
// Six sessions in an era (24 hours).
pub const SESSIONS_PER_ERA: sp_staking::SessionIndex = 6;
// 28 eras for unbonding (28 days).
pub const BONDING_DURATION: sp_staking::EraIndex = 28;
// 27 eras for slash defer duration (27 days).
pub const SLASH_DEFER_DURATION: sp_staking::EraIndex = 27;
pub const MAX_NOMINATOR_REWARDED_PER_VALIDATOR: u32 = 256;
pub const OFFENDING_VALIDATOR_THRESHOLD: sp_arithmetic::Perbill =
sp_arithmetic::Perbill::from_percent(17);
pub const OFFCHAIN_REPEAT: crate::BlockNumber = 5;
pub const HISTORY_DEPTH: u32 = 80;
}

#[cfg(feature = "fast-runtime")]
pub mod staking {
// 1 sessions in an era (10 blocks).
pub const SESSIONS_PER_ERA: sp_staking::SessionIndex = 1;
// 2 eras for unbonding (20 blocks).
pub const BONDING_DURATION: sp_staking::EraIndex = 2;
// 1 eras for slash defer (10 blocks).
pub const SLASH_DEFER_DURATION: sp_staking::EraIndex = 1;
pub const MAX_NOMINATOR_REWARDED_PER_VALIDATOR: u32 = 256;
pub const OFFENDING_VALIDATOR_THRESHOLD: sp_arithmetic::Perbill =
sp_arithmetic::Perbill::from_percent(17);
pub const OFFCHAIN_REPEAT: crate::BlockNumber = 5;
pub const HISTORY_DEPTH: u32 = 80;
}

/// We assume that ~10% of the block weight is consumed by `on_initialize` handlers. This is
/// used to limit the maximal weight of a single extrinsic.
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
Expand Down
1 change: 1 addition & 0 deletions runtime/mainnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,4 @@ integration-tests = ["tangle-primitives/integration-tests"]
with-rocksdb-weights = []
with-paritydb-weights = []
evm-tracing = []
fast-runtime = ["tangle-primitives/fast-runtime"]
18 changes: 11 additions & 7 deletions runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ use tangle_primitives::{
CANDIDACY_BOND, DESIRED_MEMBERS, DESIRED_RUNNERS_UP, ELECTIONS_PHRAGMEN_PALLET_ID,
MAX_CANDIDATES, MAX_VOTERS, TERM_DURATION,
},
staking::{
BONDING_DURATION, HISTORY_DEPTH, MAX_NOMINATOR_REWARDED_PER_VALIDATOR, OFFCHAIN_REPEAT,
OFFENDING_VALIDATOR_THRESHOLD, SESSIONS_PER_ERA, SLASH_DEFER_DURATION,
},
treasury::{
BURN, DATA_DEPOSIT_PER_BYTE, MAXIMUM_REASON_LENGTH, MAX_APPROVALS, PROPOSAL_BOND,
PROPOSAL_BOND_MINIMUM, SPEND_PERIOD, TIP_COUNTDOWN, TIP_FINDERS_FEE,
Expand Down Expand Up @@ -415,16 +419,16 @@ pallet_staking_reward_curve::build! {

parameter_types! {
// Six sessions in an era (24 hours).
pub const SessionsPerEra: sp_staking::SessionIndex = 6;
pub const SessionsPerEra: sp_staking::SessionIndex = SESSIONS_PER_ERA;
// 28 eras for unbonding (28 days).
pub const BondingDuration: sp_staking::EraIndex = 28;
pub const BondingDuration: sp_staking::EraIndex = BONDING_DURATION;
// 27 eras for slash defer duration (27 days).
pub const SlashDeferDuration: sp_staking::EraIndex = 27;
pub const SlashDeferDuration: sp_staking::EraIndex = SLASH_DEFER_DURATION;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 256;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub OffchainRepeat: BlockNumber = 5;
pub const HistoryDepth: u32 = 80;
pub const MaxNominatorRewardedPerValidator: u32 = MAX_NOMINATOR_REWARDED_PER_VALIDATOR;
pub const OffendingValidatorsThreshold: Perbill = OFFENDING_VALIDATOR_THRESHOLD;
pub OffchainRepeat: BlockNumber = OFFCHAIN_REPEAT;
pub const HistoryDepth: u32 = HISTORY_DEPTH;
}

pub struct StakingBenchmarkingConfig;
Expand Down
1 change: 1 addition & 0 deletions runtime/testnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,4 @@ integration-tests = ["tangle-primitives/integration-tests"]
with-rocksdb-weights = []
with-paritydb-weights = []
evm-tracing = []
fast-runtime = ["tangle-primitives/fast-runtime"]
18 changes: 11 additions & 7 deletions runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ use tangle_primitives::{
CANDIDACY_BOND, DESIRED_MEMBERS, DESIRED_RUNNERS_UP, ELECTIONS_PHRAGMEN_PALLET_ID,
MAX_CANDIDATES, MAX_VOTERS, TERM_DURATION,
},
staking::{
BONDING_DURATION, HISTORY_DEPTH, MAX_NOMINATOR_REWARDED_PER_VALIDATOR, OFFCHAIN_REPEAT,
OFFENDING_VALIDATOR_THRESHOLD, SESSIONS_PER_ERA, SLASH_DEFER_DURATION,
},
treasury::{
BURN, DATA_DEPOSIT_PER_BYTE, MAXIMUM_REASON_LENGTH, MAX_APPROVALS, PROPOSAL_BOND,
PROPOSAL_BOND_MINIMUM, SPEND_PERIOD, TIP_COUNTDOWN, TIP_FINDERS_FEE,
Expand Down Expand Up @@ -431,16 +435,16 @@ pallet_staking_reward_curve::build! {

parameter_types! {
// Six sessions in an era (24 hours).
pub const SessionsPerEra: sp_staking::SessionIndex = 6;
pub const SessionsPerEra: sp_staking::SessionIndex = SESSIONS_PER_ERA;
// 28 eras for unbonding (28 days).
pub const BondingDuration: sp_staking::EraIndex = 28;
pub const BondingDuration: sp_staking::EraIndex = BONDING_DURATION;
// 27 eras for slash defer duration (27 days).
pub const SlashDeferDuration: sp_staking::EraIndex = 27;
pub const SlashDeferDuration: sp_staking::EraIndex = SLASH_DEFER_DURATION;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 256;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub OffchainRepeat: BlockNumber = 5;
pub const HistoryDepth: u32 = 80;
pub const MaxNominatorRewardedPerValidator: u32 = MAX_NOMINATOR_REWARDED_PER_VALIDATOR;
pub const OffendingValidatorsThreshold: Perbill = OFFENDING_VALIDATOR_THRESHOLD;
pub OffchainRepeat: BlockNumber = OFFCHAIN_REPEAT;
pub const HistoryDepth: u32 = HISTORY_DEPTH;
}

pub struct StakingBenchmarkingConfig;
Expand Down

0 comments on commit c620b8a

Please sign in to comment.