Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ Grab `zombienet` utility used to start network from [releases](https://github.co

Start local testnet with 4 relay chain validators and HydraDX as a parachain with 2 collators.

```
```bash
cd launch-configs/zombienet/
zombienet spawn local.json

# Enable 2s block time
npm exec --yes --package=@polkadot/api --package=@polkadot/util-crypto -- node scripts/assign_cores.js
```

## Interaction with the node
Expand Down
6 changes: 5 additions & 1 deletion launch-configs/zombienet/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
"patch": {
"configuration": {
"config": {
"scheduler_params": {
"num_cores": 3
},
"async_backing_params": {
"max_candidate_depth": 3,
"max_candidate_depth": 6,
"allowed_ancestry_len": 2
}
}
Expand All @@ -31,6 +34,7 @@
"--pruning=archive"
],
"ws_port": 9944,
"rpc_port": 9945,
"invulnerable": true
},
{
Expand Down
36 changes: 27 additions & 9 deletions math/src/staking/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,40 @@ pub fn calculate_slashed_points(
/// Function calculates period number from block number and period size.
///
/// Parameters:
/// - `period_length`: length of the one period in blocks
/// - `period_length`: length of one period based on 12s blocks (this was the initial default)
/// - `block_number`: block number to calculate period for
/// - `six_sec_block_since`: block number when staking switched to 6 sec. blocks and period
/// - `period_length` should be doubled
/// - `six_sec_blocks_since`: block number when staking switched to 6s blocks
/// - `two_sec_blocks_since`: block number when staking switched to 2s blocks
pub fn calculate_period_number(
period_length: NonZeroU128,
block_number: u128,
six_sec_block_since: NonZeroU128,
six_sec_blocks_since: NonZeroU128,
two_sec_blocks_since: NonZeroU128,
) -> Period {
if block_number.le(&Into::<u128>::into(six_sec_block_since)) {
return block_number.saturating_div(period_length.get());
let period_length = period_length.get();
let six_sec_blocks_since = six_sec_blocks_since.get();
let two_sec_blocks_since = two_sec_blocks_since.get();

if block_number.le(&six_sec_blocks_since) {
return block_number.saturating_div(period_length);
}

if block_number.le(&two_sec_blocks_since) || two_sec_blocks_since <= six_sec_blocks_since {
return six_sec_blocks_since
.saturating_add(block_number)
.saturating_div(period_length.saturating_mul(2));
}

Into::<u128>::into(six_sec_block_since)
.saturating_add(block_number)
.saturating_div(period_length.get().saturating_mul(2))
let normalized_blocks = six_sec_blocks_since
.saturating_mul(6)
.saturating_add(
two_sec_blocks_since
.saturating_sub(six_sec_blocks_since)
.saturating_mul(3),
)
.saturating_add(block_number.saturating_sub(two_sec_blocks_since));

normalized_blocks.saturating_div(period_length.saturating_mul(6))
}

/// Function calculates total amount of `Points` user have accumulated until now.
Expand Down
74 changes: 68 additions & 6 deletions math/src/staking/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ fn calculate_period_number_should_work_when_period_length_is_not_zero() {
calculate_period_number(
NonZeroU128::try_from(1_u128).unwrap(),
12_341_u128,
NonZeroU128::try_from(12_341_u128).unwrap()
NonZeroU128::try_from(12_341_u128).unwrap(),
NonZeroU128::try_from(u32::MAX as u128).unwrap()
),
12_341_u128
);
Expand All @@ -97,7 +98,8 @@ fn calculate_period_number_should_work_when_period_length_is_not_zero() {
calculate_period_number(
NonZeroU128::try_from(1_000_u128).unwrap(),
12_341_u128,
NonZeroU128::try_from(12_342_u128).unwrap()
NonZeroU128::try_from(12_342_u128).unwrap(),
NonZeroU128::try_from(u32::MAX as u128).unwrap()
),
12_u128
);
Expand All @@ -106,7 +108,8 @@ fn calculate_period_number_should_work_when_period_length_is_not_zero() {
calculate_period_number(
NonZeroU128::try_from(1_000_u128).unwrap(),
1_u128,
NonZeroU128::try_from(1).unwrap()
NonZeroU128::try_from(1).unwrap(),
NonZeroU128::try_from(u32::MAX as u128).unwrap()
),
0_u128
);
Expand All @@ -115,7 +118,8 @@ fn calculate_period_number_should_work_when_period_length_is_not_zero() {
calculate_period_number(
NonZeroU128::try_from(82_u128).unwrap(),
12_341_u128,
NonZeroU128::try_from(12_341_u128).unwrap()
NonZeroU128::try_from(12_341_u128).unwrap(),
NonZeroU128::try_from(u32::MAX as u128).unwrap()
),
150_u128
);
Expand All @@ -126,7 +130,8 @@ fn calculate_period_number_should_work_when_period_length_is_not_zero() {
calculate_period_number(
NonZeroU128::try_from(41_u128).unwrap(),
12_341_u128,
NonZeroU128::try_from(5_001_u128).unwrap()
NonZeroU128::try_from(5_001_u128).unwrap(),
NonZeroU128::try_from(u32::MAX as u128).unwrap()
),
211_u128
);
Expand All @@ -138,12 +143,69 @@ fn calculate_period_number_should_work_when_period_length_is_not_zero() {
calculate_period_number(
NonZeroU128::try_from(2_617_u128).unwrap(),
678_789_789_u128,
NonZeroU128::try_from(89_789_124_u128).unwrap()
NonZeroU128::try_from(89_789_124_u128).unwrap(),
NonZeroU128::try_from(u32::MAX as u128).unwrap()
),
146_843_u128
);
}

#[test]
fn calculate_period_number_should_work_after_two_sec_transition() {
assert_eq!(
calculate_period_number(
NonZeroU128::try_from(10_u128).unwrap(),
100_u128,
NonZeroU128::try_from(100_u128).unwrap(),
NonZeroU128::try_from(200_u128).unwrap()
),
10_u128
);

assert_eq!(
calculate_period_number(
NonZeroU128::try_from(10_u128).unwrap(),
200_u128,
NonZeroU128::try_from(100_u128).unwrap(),
NonZeroU128::try_from(200_u128).unwrap()
),
15_u128
);

assert_eq!(
calculate_period_number(
NonZeroU128::try_from(10_u128).unwrap(),
259_u128,
NonZeroU128::try_from(100_u128).unwrap(),
NonZeroU128::try_from(200_u128).unwrap()
),
15_u128
);

assert_eq!(
calculate_period_number(
NonZeroU128::try_from(10_u128).unwrap(),
260_u128,
NonZeroU128::try_from(100_u128).unwrap(),
NonZeroU128::try_from(200_u128).unwrap()
),
16_u128
);
}

#[test]
fn calculate_period_number_should_fall_back_when_two_sec_transition_is_invalid() {
assert_eq!(
calculate_period_number(
NonZeroU128::try_from(10_u128).unwrap(),
200_u128,
NonZeroU128::try_from(100_u128).unwrap(),
NonZeroU128::try_from(50_u128).unwrap()
),
15_u128
);
}

#[test]
fn calculate_points_should_work() {
let time_points_per_period = 2_u8;
Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydradx"
version = "15.0.0"
version = "15.1.0"
description = "Hydration node"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ fn start_consensus(
para_id,
proposer,
collator_service,
authoring_duration: Duration::from_millis(1500),
authoring_duration: Duration::from_millis(2000),
reinitialize: false,
slot_offset: Duration::from_secs(1),
block_import_handle,
Expand Down
4 changes: 3 additions & 1 deletion node/src/service/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub fn spawn_frontier_tasks(
None,
MappingSyncWorker::new(
client.import_notification_stream(),
Duration::new(6, 0),
Duration::new(2, 0),
client.clone(),
backend,
overrides.clone(),
Expand All @@ -177,6 +177,7 @@ pub fn spawn_frontier_tasks(

// Spawn Frontier EthFilterApi maintenance task.
// Each filter is allowed to stay in the pool for 100 blocks.
// TODO: 2s increase?
const FILTER_RETAIN_THRESHOLD: u64 = 100;
task_manager.spawn_essential_handle().spawn(
"frontier-filter-pool",
Expand All @@ -185,6 +186,7 @@ pub fn spawn_frontier_tasks(
);

// Spawn Frontier FeeHistory cache maintenance task.
// TODO: 2s increase default from 2048?
task_manager.spawn_essential_handle().spawn(
"frontier-fee-history",
None,
Expand Down
2 changes: 1 addition & 1 deletion pallets/dca/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'pallet-dca'
version = "1.18.1"
version = "1.19.0"
description = 'A pallet to manage DCA scheduling'
authors = ['GalacticCouncil']
edition = '2021'
Expand Down
2 changes: 1 addition & 1 deletion pallets/dca/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub mod pallet {

use super::*;

const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);
const STORAGE_VERSION: StorageVersion = StorageVersion::new(3);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
Expand Down
Loading
Loading