avoid commitments check on the beginning of the epoch
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
028afc089f
commit
06618069e2
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ghost-slow-clap"
|
name = "ghost-slow-clap"
|
||||||
version = "0.4.19"
|
version = "0.4.20"
|
||||||
description = "Applause protocol for the EVM bridge"
|
description = "Applause protocol for the EVM bridge"
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|||||||
@ -80,6 +80,7 @@ const LOCK_BLOCK_EXPIRATION: u64 = 20;
|
|||||||
|
|
||||||
const ONE_HOUR_MILLIS: u64 = 3_600_000;
|
const ONE_HOUR_MILLIS: u64 = 3_600_000;
|
||||||
|
|
||||||
|
const BLOCK_CHECK_CYCLES: u64 = 8;
|
||||||
const CHECK_BLOCK_INTERVAL: u64 = 300;
|
const CHECK_BLOCK_INTERVAL: u64 = 300;
|
||||||
const BLOCK_COMMITMENT_DELAY: u64 = 100;
|
const BLOCK_COMMITMENT_DELAY: u64 = 100;
|
||||||
|
|
||||||
@ -317,6 +318,9 @@ pub mod pallet {
|
|||||||
#[pallet::constant]
|
#[pallet::constant]
|
||||||
type MinAuthoritiesNumber: Get<u32>;
|
type MinAuthoritiesNumber: Get<u32>;
|
||||||
|
|
||||||
|
#[pallet::constant]
|
||||||
|
type EpochDuration: Get<u64>;
|
||||||
|
|
||||||
type WeightInfo: WeightInfo;
|
type WeightInfo: WeightInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,15 +483,15 @@ pub mod pallet {
|
|||||||
#[pallet::hooks]
|
#[pallet::hooks]
|
||||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||||
fn on_initialize(current_block: BlockNumberFor<T>) -> Weight {
|
fn on_initialize(current_block: BlockNumberFor<T>) -> Weight {
|
||||||
// TODO: what about start of the session???
|
|
||||||
let mut weight = T::DbWeight::get().reads(1);
|
let mut weight = T::DbWeight::get().reads(1);
|
||||||
|
|
||||||
let networks_count = T::NetworkDataHandler::count();
|
let networks_count = T::NetworkDataHandler::count();
|
||||||
let current_block_number: u64 = current_block.unique_saturated_into();
|
let current_block_number: u64 = current_block.unique_saturated_into();
|
||||||
//let cycle_start = (current_block_number / CHECK_BLOCK_INTERVAL) * CHECK_BLOCK_INTERVAL;
|
|
||||||
let cycle_offset = current_block_number % CHECK_BLOCK_INTERVAL;
|
|
||||||
|
|
||||||
if cycle_offset >= networks_count.into() {
|
let check_block_interval = T::EpochDuration::get().saturating_div(BLOCK_CHECK_CYCLES);
|
||||||
|
let cycle_offset = current_block_number % check_block_interval;
|
||||||
|
let block_in_epoch = current_block_number % T::EpochDuration::get();
|
||||||
|
|
||||||
|
if cycle_offset >= networks_count.into() || block_in_epoch < check_block_interval {
|
||||||
return Default::default();
|
return Default::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -159,6 +159,7 @@ parameter_types! {
|
|||||||
pub static ExistentialDeposit: u64 = 2;
|
pub static ExistentialDeposit: u64 = 2;
|
||||||
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
|
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
|
||||||
pub const HistoryDepth: u32 = 10;
|
pub const HistoryDepth: u32 = 10;
|
||||||
|
pub const EpochDuration: u64 = 80;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
|
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
|
||||||
@ -213,6 +214,7 @@ impl Config for Runtime {
|
|||||||
type UnsignedPriority = ConstU64<{ 1 << 20 }>;
|
type UnsignedPriority = ConstU64<{ 1 << 20 }>;
|
||||||
type HistoryDepth = HistoryDepth;
|
type HistoryDepth = HistoryDepth;
|
||||||
type MinAuthoritiesNumber = ConstU32<1>;
|
type MinAuthoritiesNumber = ConstU32<1>;
|
||||||
|
type EpochDuration = EpochDuration;
|
||||||
|
|
||||||
type WeightInfo = ();
|
type WeightInfo = ();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1442,8 +1442,15 @@ fn should_check_different_networks_during_on_initialize() {
|
|||||||
prepare_evm_network(Some(network_id), None);
|
prepare_evm_network(Some(network_id), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let check_interval = times * CHECK_BLOCK_INTERVAL;
|
let expected_events_count: u64 = BLOCK_CHECK_CYCLES
|
||||||
for check_block in 0..check_interval {
|
.saturating_sub(1)
|
||||||
|
.saturating_mul(networks_count as u64)
|
||||||
|
.saturating_mul(times);
|
||||||
|
|
||||||
|
let expected_events_count: usize = expected_events_count.try_into().unwrap();
|
||||||
|
|
||||||
|
let epochs_passed = times * EpochDuration::get();
|
||||||
|
for check_block in 0..epochs_passed {
|
||||||
SlowClap::on_initialize(check_block);
|
SlowClap::on_initialize(check_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1468,12 +1475,13 @@ fn should_check_different_networks_during_on_initialize() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let expected_events = networks_count * (times as u32);
|
assert_eq!(total_number_of_events, expected_events_count);
|
||||||
assert_eq!(total_number_of_events, expected_events as usize);
|
|
||||||
assert_eq!(check_commitment_events.len() as u32, networks_count);
|
assert_eq!(check_commitment_events.len() as u32, networks_count);
|
||||||
for network_id in 0..networks_count {
|
for network_id in 0..networks_count {
|
||||||
let network_id_count = check_commitment_events.get(&network_id).unwrap();
|
let network_id_count = check_commitment_events.get(&network_id).unwrap();
|
||||||
assert_eq!(*network_id_count, times);
|
let expected_events_count =
|
||||||
|
expected_events_count.saturating_div(networks_count as usize);
|
||||||
|
assert_eq!(*network_id_count, expected_events_count);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user