make max commit deviation to be 1/8 of EpochDuration
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
06618069e2
commit
24b08a87b1
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ghost-slow-clap"
|
name = "ghost-slow-clap"
|
||||||
version = "0.4.20"
|
version = "0.4.21"
|
||||||
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
|
||||||
|
|||||||
@ -79,9 +79,7 @@ const FETCH_TIMEOUT_PERIOD: u64 = 3_000;
|
|||||||
const LOCK_BLOCK_EXPIRATION: u64 = 20;
|
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 BLOCK_CHECK_CYCLES: u64 = 8;
|
||||||
const CHECK_BLOCK_INTERVAL: u64 = 300;
|
|
||||||
const BLOCK_COMMITMENT_DELAY: u64 = 100;
|
const BLOCK_COMMITMENT_DELAY: u64 = 100;
|
||||||
|
|
||||||
pub type AuthIndex = u32;
|
pub type AuthIndex = u32;
|
||||||
@ -488,11 +486,15 @@ pub mod pallet {
|
|||||||
let current_block_number: u64 = current_block.unique_saturated_into();
|
let current_block_number: u64 = current_block.unique_saturated_into();
|
||||||
|
|
||||||
let check_block_interval = T::EpochDuration::get().saturating_div(BLOCK_CHECK_CYCLES);
|
let check_block_interval = T::EpochDuration::get().saturating_div(BLOCK_CHECK_CYCLES);
|
||||||
|
if check_block_interval == 0 {
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
let cycle_offset = current_block_number % check_block_interval;
|
let cycle_offset = current_block_number % check_block_interval;
|
||||||
let block_in_epoch = current_block_number % T::EpochDuration::get();
|
let block_in_epoch = current_block_number % T::EpochDuration::get();
|
||||||
|
|
||||||
if cycle_offset >= networks_count.into() || block_in_epoch < check_block_interval {
|
if cycle_offset >= networks_count.into() || block_in_epoch < check_block_interval {
|
||||||
return Default::default();
|
return weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
let converted_block: usize = current_block_number.unique_saturated_into();
|
let converted_block: usize = current_block_number.unique_saturated_into();
|
||||||
@ -517,9 +519,11 @@ pub mod pallet {
|
|||||||
.unwrap_or(BitMap::new(validators.len() as u32));
|
.unwrap_or(BitMap::new(validators.len() as u32));
|
||||||
|
|
||||||
let max_external_block_deviation = ONE_HOUR_MILLIS
|
let max_external_block_deviation = ONE_HOUR_MILLIS
|
||||||
.saturating_mul(6) // TODO: make it constant or calculate
|
.saturating_mul(6)
|
||||||
.saturating_div(network_data.avg_block_speed);
|
.saturating_div(network_data.avg_block_speed);
|
||||||
|
|
||||||
|
let max_internal_block_deviation = check_block_interval.unique_saturated_into();
|
||||||
|
|
||||||
let mut stored_blocks: Vec<(AuthIndex, ExternalBlockNumber)> = Vec::new();
|
let mut stored_blocks: Vec<(AuthIndex, ExternalBlockNumber)> = Vec::new();
|
||||||
let mut block_updates: Vec<(AuthIndex, BlockNumberFor<T>)> = Vec::new();
|
let mut block_updates: Vec<(AuthIndex, BlockNumberFor<T>)> = Vec::new();
|
||||||
|
|
||||||
@ -543,7 +547,7 @@ pub mod pallet {
|
|||||||
&disabled_bitmap,
|
&disabled_bitmap,
|
||||||
&mut block_updates,
|
&mut block_updates,
|
||||||
validators_len,
|
validators_len,
|
||||||
CHECK_BLOCK_INTERVAL.unique_saturated_into(), // TODO: revisit
|
max_internal_block_deviation,
|
||||||
);
|
);
|
||||||
|
|
||||||
let offence_bitmap =
|
let offence_bitmap =
|
||||||
|
|||||||
@ -1105,10 +1105,8 @@ fn should_disable_on_commitment_inactivity() {
|
|||||||
prepare_evm_network(None, None);
|
prepare_evm_network(None, None);
|
||||||
|
|
||||||
assert_eq!(BlockCommitments::<Runtime>::get(network_id).len(), 0);
|
assert_eq!(BlockCommitments::<Runtime>::get(network_id).len(), 0);
|
||||||
System::set_block_number(420);
|
System::set_block_number(5 * EpochDuration::get() / 2);
|
||||||
|
let last_stored_block = 69;
|
||||||
let last_stored_block = 1337;
|
|
||||||
let current_block = SlowClap::current_block_number();
|
|
||||||
|
|
||||||
for i in 0..3 {
|
for i in 0..3 {
|
||||||
assert_ok!(do_block_commitment(
|
assert_ok!(do_block_commitment(
|
||||||
@ -1119,10 +1117,8 @@ fn should_disable_on_commitment_inactivity() {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let delay = ONE_HOUR_MILLIS.saturating_mul(6);
|
let current_block = System::current_block_number();
|
||||||
System::set_block_number(current_block + delay + 1);
|
SlowClap::on_initialize(current_block);
|
||||||
|
|
||||||
SlowClap::on_initialize(CHECK_BLOCK_INTERVAL);
|
|
||||||
System::assert_has_event(RuntimeEvent::SlowClap(
|
System::assert_has_event(RuntimeEvent::SlowClap(
|
||||||
crate::Event::SomeAuthoritiesDelayed {
|
crate::Event::SomeAuthoritiesDelayed {
|
||||||
delayed: vec![(3, 3)],
|
delayed: vec![(3, 3)],
|
||||||
@ -1205,7 +1201,11 @@ fn should_disable_on_commitment_block_deviation() {
|
|||||||
bad_last_stored_block,
|
bad_last_stored_block,
|
||||||
));
|
));
|
||||||
|
|
||||||
SlowClap::on_initialize(CHECK_BLOCK_INTERVAL);
|
let to_initialize = EpochDuration::get()
|
||||||
|
.saturating_div(BLOCK_CHECK_CYCLES)
|
||||||
|
.saturating_mul(2);
|
||||||
|
|
||||||
|
SlowClap::on_initialize(to_initialize);
|
||||||
System::assert_has_event(RuntimeEvent::SlowClap(
|
System::assert_has_event(RuntimeEvent::SlowClap(
|
||||||
crate::Event::SomeAuthoritiesDelayed {
|
crate::Event::SomeAuthoritiesDelayed {
|
||||||
delayed: vec![(3, 3)],
|
delayed: vec![(3, 3)],
|
||||||
@ -1292,6 +1292,7 @@ fn should_not_slash_by_applause_if_disabled_by_commitment() {
|
|||||||
prepare_evm_network(None, None);
|
prepare_evm_network(None, None);
|
||||||
|
|
||||||
assert_eq!(BlockCommitments::<Runtime>::get(network_id).len(), 0);
|
assert_eq!(BlockCommitments::<Runtime>::get(network_id).len(), 0);
|
||||||
|
System::set_block_number(5 * EpochDuration::get() / 2);
|
||||||
|
|
||||||
let last_stored_block = 9_500_000;
|
let last_stored_block = 9_500_000;
|
||||||
let current_block = SlowClap::current_block_number();
|
let current_block = SlowClap::current_block_number();
|
||||||
@ -1317,7 +1318,7 @@ fn should_not_slash_by_applause_if_disabled_by_commitment() {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
SlowClap::on_initialize(CHECK_BLOCK_INTERVAL);
|
SlowClap::on_initialize(current_block);
|
||||||
System::assert_has_event(RuntimeEvent::SlowClap(
|
System::assert_has_event(RuntimeEvent::SlowClap(
|
||||||
crate::Event::AuthoritiesCommitmentEquilibrium,
|
crate::Event::AuthoritiesCommitmentEquilibrium,
|
||||||
));
|
));
|
||||||
@ -1387,9 +1388,8 @@ fn should_split_commit_slash_between_active_validators() {
|
|||||||
prepare_evm_network(None, None);
|
prepare_evm_network(None, None);
|
||||||
|
|
||||||
assert_eq!(BlockCommitments::<Runtime>::get(network_id).len(), 0);
|
assert_eq!(BlockCommitments::<Runtime>::get(network_id).len(), 0);
|
||||||
|
System::set_block_number(5 * EpochDuration::get() / 2);
|
||||||
let last_stored_block = 9_500_000;
|
let last_stored_block = 69;
|
||||||
let current_block = SlowClap::current_block_number();
|
|
||||||
|
|
||||||
for i in 0..3 {
|
for i in 0..3 {
|
||||||
assert_ok!(do_block_commitment(
|
assert_ok!(do_block_commitment(
|
||||||
@ -1399,10 +1399,12 @@ fn should_split_commit_slash_between_active_validators() {
|
|||||||
last_stored_block,
|
last_stored_block,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let current_block = SlowClap::current_block_number();
|
||||||
let offences = Offences::get();
|
let offences = Offences::get();
|
||||||
assert_eq!(offences.len(), 0);
|
assert_eq!(offences.len(), 0);
|
||||||
|
|
||||||
SlowClap::on_initialize(CHECK_BLOCK_INTERVAL);
|
SlowClap::on_initialize(current_block);
|
||||||
System::assert_has_event(RuntimeEvent::SlowClap(
|
System::assert_has_event(RuntimeEvent::SlowClap(
|
||||||
crate::Event::SomeAuthoritiesDelayed {
|
crate::Event::SomeAuthoritiesDelayed {
|
||||||
delayed: vec![(3, 3)],
|
delayed: vec![(3, 3)],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user