inherent disputes: remove per block initializer and disputes timeout event (#6937)

* Limit disputes weight and remove initializer code

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* const

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* remove timeout test

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* review feedback #1

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Remove the new weight limiting for disputes

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* cargo lock

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Remove dispute_conclusion_by_time_out_period

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Enable migrations

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Update guide

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Fix comment

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* More guide fixes

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Also migrate pending configs

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fix build

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fix test

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

---------

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
This commit is contained in:
Andrei Sandu
2023-03-24 13:48:56 +02:00
committed by GitHub
parent 95f0ca271e
commit bd209c2d70
13 changed files with 116 additions and 266 deletions
@@ -8,7 +8,6 @@ stateDiagram-v2
[*] --> WaitForDisputeVote: backing Vote received
WaitForBackingVote --> Open: negative Vote received
WaitForDisputeVote --> Open: backing Vote received
Open --> Concluded: Timeout without supermajority
Open --> Concluded: Incoming Vote via Gossip
Open --> Open: No ⅔ supermajority
Open --> [*]
@@ -62,6 +62,6 @@ Validators are rewarded for providing statements to the chain as well as for par
## Dispute Conclusion
Disputes, roughly, are over when one side reaches a ⅔ supermajority. They may also conclude after a timeout, without either side witnessing supermajority, which will only happen if the majority of validators are unable to vote for some reason. Furthermore, disputes on-chain will stay open for some fixed amount of time even after concluding, to accept new votes.
Disputes, roughly, are over when one side reaches a ⅔ supermajority. They may also never conclude without either side witnessing supermajority, which will only happen if the majority of validators are unable to vote for some reason. Furthermore, disputes on-chain will stay open for some fixed amount of time even after concluding, to accept new votes.
Late votes, after the dispute already reached a ⅔ supermajority, must be rewarded (albeit a smaller amount) as well.
@@ -56,7 +56,7 @@ Frozen: Option<BlockNumber>,
## Block Initialization
1. Iterate through all disputes. If any have not concluded and started more than `config.dispute_conclusion_by_timeout_period` blocks ago, set them to `Concluded` and mildly punish all validators associated, as they have failed to distribute available data.
This is currently a `no op`.
## Routines
@@ -44,8 +44,6 @@ struct HostConfiguration {
pub dispute_post_conclusion_acceptance_period: BlockNumber,
/// The maximum number of dispute spam slots
pub dispute_max_spam_slots: u32,
/// How long it takes for a dispute to conclude by time-out, if no supermajority is reached.
pub dispute_conclusion_by_time_out_period: BlockNumber,
/// The amount of consensus slots that must pass between submitting an assignment and
/// submitting an approval vote before a validator is considered a no-show.
/// Must be at least 1.
+1
View File
@@ -1481,6 +1481,7 @@ pub type Migrations = (
Runtime,
NominationPoolsMigrationV4OldPallet,
>,
parachains_configuration::migration::v5::MigrateToV5<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
@@ -193,8 +193,6 @@ pub struct HostConfiguration<BlockNumber> {
pub dispute_period: SessionIndex,
/// How long after dispute conclusion to accept statements.
pub dispute_post_conclusion_acceptance_period: BlockNumber,
/// How long it takes for a dispute to conclude by time-out, if no supermajority is reached.
pub dispute_conclusion_by_time_out_period: BlockNumber,
/// The amount of consensus slots that must pass between submitting an assignment and
/// submitting an approval vote before a validator is considered a no-show.
///
@@ -262,7 +260,6 @@ impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber
max_validators: None,
dispute_period: 6,
dispute_post_conclusion_acceptance_period: 100.into(),
dispute_conclusion_by_time_out_period: 200.into(),
n_delay_tranches: Default::default(),
zeroth_delay_tranche_width: Default::default(),
needed_approvals: Default::default(),
@@ -765,22 +762,6 @@ pub mod pallet {
})
}
/// Set the dispute conclusion by time out period.
#[pallet::call_index(17)]
#[pallet::weight((
T::WeightInfo::set_config_with_block_number(),
DispatchClass::Operational,
))]
pub fn set_dispute_conclusion_by_time_out_period(
origin: OriginFor<T>,
new: T::BlockNumber,
) -> DispatchResult {
ensure_root(origin)?;
Self::schedule_config_update(|config| {
config.dispute_conclusion_by_time_out_period = new;
})
}
/// Set the no show slots, in number of number of consensus slots.
/// Must be at least 1.
#[pallet::call_index(18)]
@@ -16,9 +16,10 @@
//! A module that is responsible for migration of storage.
use crate::configuration::{self, ActiveConfig, Config, Pallet, MAX_POV_SIZE};
use crate::configuration::{self, ActiveConfig, Config, Pallet, PendingConfigs, MAX_POV_SIZE};
use frame_support::{pallet_prelude::*, traits::StorageVersion, weights::Weight};
use frame_system::pallet_prelude::BlockNumberFor;
use sp_std::vec::Vec;
/// The current storage version.
///
@@ -26,9 +27,10 @@ use frame_system::pallet_prelude::BlockNumberFor;
/// v1-v2: <https://github.com/paritytech/polkadot/pull/4420>
/// v2-v3: <https://github.com/paritytech/polkadot/pull/6091>
/// v3-v4: <https://github.com/paritytech/polkadot/pull/6345>
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);
/// v4-v5: <https://github.com/paritytech/polkadot/pull/6937>
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(5);
pub mod v4 {
pub mod v5 {
use super::*;
use frame_support::{traits::OnRuntimeUpgrade, weights::constants::WEIGHT_REF_TIME_PER_MILLIS};
use primitives::{Balance, SessionIndex};
@@ -37,7 +39,7 @@ pub mod v4 {
// Copied over from configuration.rs @ de9e147695b9f1be8bd44e07861a31e483c8343a and removed
// all the comments, and changed the Weight struct to OldWeight
#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug)]
#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, Clone)]
pub struct OldHostConfiguration<BlockNumber> {
pub max_code_size: u32,
pub max_head_data_size: u32,
@@ -71,7 +73,6 @@ pub mod v4 {
pub max_validators: Option<u32>,
pub dispute_period: SessionIndex,
pub dispute_post_conclusion_acceptance_period: BlockNumber,
pub dispute_max_spam_slots: u32,
pub dispute_conclusion_by_time_out_period: BlockNumber,
pub no_show_slots: u32,
pub n_delay_tranches: u32,
@@ -104,7 +105,6 @@ pub mod v4 {
max_validators: None,
dispute_period: 6,
dispute_post_conclusion_acceptance_period: 100.into(),
dispute_max_spam_slots: 2,
dispute_conclusion_by_time_out_period: 200.into(),
n_delay_tranches: Default::default(),
zeroth_delay_tranche_width: Default::default(),
@@ -137,8 +137,8 @@ pub mod v4 {
}
}
pub struct MigrateToV4<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV4<T> {
pub struct MigrateToV5<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV5<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()");
@@ -148,15 +148,15 @@ pub mod v4 {
}
fn on_runtime_upgrade() -> Weight {
if StorageVersion::get::<Pallet<T>>() == 3 {
let weight_consumed = migrate_to_v4::<T>();
if StorageVersion::get::<Pallet<T>>() == 4 {
let weight_consumed = migrate_to_v5::<T>();
log::info!(target: configuration::LOG_TARGET, "MigrateToV4 executed successfully");
log::info!(target: configuration::LOG_TARGET, "MigrateToV5 executed successfully");
STORAGE_VERSION.put::<Pallet<T>>();
weight_consumed
} else {
log::warn!(target: configuration::LOG_TARGET, "MigrateToV4 should be removed.");
log::warn!(target: configuration::LOG_TARGET, "MigrateToV5 should be removed.");
T::DbWeight::get().reads(1)
}
}
@@ -166,7 +166,7 @@ pub mod v4 {
log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()");
ensure!(
StorageVersion::get::<Pallet<T>>() == STORAGE_VERSION,
"Storage version should be 4 after the migration"
"Storage version should be 5 after the migration"
);
Ok(())
@@ -174,14 +174,14 @@ pub mod v4 {
}
}
fn migrate_to_v4<T: Config>() -> Weight {
fn migrate_to_v5<T: Config>() -> Weight {
// Unusual formatting is justified:
// - make it easier to verify that fields assign what they supposed to assign.
// - this code is transient and will be removed after all migrations are done.
// - this code is important enough to optimize for legibility sacrificing consistency.
#[rustfmt::skip]
let translate =
|pre: v4::OldHostConfiguration<BlockNumberFor<T>>| ->
|pre: v5::OldHostConfiguration<BlockNumberFor<T>>| ->
configuration::HostConfiguration<BlockNumberFor<T>>
{
super::HostConfiguration {
@@ -217,7 +217,6 @@ max_validators_per_core : pre.max_validators_per_core,
max_validators : pre.max_validators,
dispute_period : pre.dispute_period,
dispute_post_conclusion_acceptance_period: pre.dispute_post_conclusion_acceptance_period,
dispute_conclusion_by_time_out_period : pre.dispute_conclusion_by_time_out_period,
no_show_slots : pre.no_show_slots,
n_delay_tranches : pre.n_delay_tranches,
zeroth_delay_tranche_width : pre.zeroth_delay_tranche_width,
@@ -238,11 +237,27 @@ minimum_validation_upgrade_delay : pre.minimum_validation_upgrade_delay,
// to be unlikely to be caused by this. So we just log. Maybe it'll work out still?
log::error!(
target: configuration::LOG_TARGET,
"unexpected error when performing translation of the configuration type during storage upgrade to v4."
"unexpected error when performing translation of the active configuration during storage upgrade to v5."
);
}
T::DbWeight::get().reads_writes(1, 1)
if let Err(_) = PendingConfigs::<T>::translate(|pre| {
pre.map(
|v: Vec<(primitives::SessionIndex, v5::OldHostConfiguration<BlockNumberFor<T>>)>| {
v.into_iter()
.map(|(session, config)| (session, translate(config)))
.collect::<Vec<_>>()
},
)
}) {
log::error!(
target: configuration::LOG_TARGET,
"unexpected error when performing translation of the pending configuration during storage upgrade to v5."
);
}
let num_configs = (PendingConfigs::<T>::get().len() + 1) as u64;
T::DbWeight::get().reads_writes(num_configs, num_configs)
}
#[cfg(test)]
@@ -251,10 +266,9 @@ mod tests {
use crate::mock::{new_test_ext, Test};
#[test]
fn v3_deserialized_from_actual_data() {
fn v4_deserialized_from_actual_data() {
// Example how to get new `raw_config`:
// We'll obtain the raw_config hes for block
// 15,772,152 (0xf89d3ab5312c5f70d396dc59612f0aa65806c798346f9db4b35278baed2e0e53) on Kusama.
// We'll obtain the raw_config at a specified a block
// Steps:
// 1. Go to Polkadot.js -> Developer -> Chain state -> Storage: https://polkadot.js.org/apps/#/chainstate
// 2. Set these parameters:
@@ -265,37 +279,35 @@ mod tests {
// 3. Go to Polkadot.js -> Developer -> Chain state -> Raw storage
// 3.1 Enter the encoded storage key and you get the raw config.
// Fetched at Kusama 15,772,152 (0xf89d3ab5312c5f70d396dc59612f0aa65806c798346f9db4b35278baed2e0e53)
//
// This exceeds the maximal line width length, but that's fine, since this is not code and
// doesn't need to be read and also leaving it as one line allows to easily copy it.
let raw_config = hex_literal::hex!["0000a000005000000a00000000c8000000c800000a0000000a000000100e0000580200000000500000c800000700e8764817020040011e00000000000000005039278c0400000000000000000000005039278c0400000000000000000000e8030000009001001e00000000000000009001008070000000000000000000000a0000000a0000000a00000001000000010500000001c8000000060000005802000002000000580200000200000059000000000000001e000000280000000700c817a80402004001000200000014000000"];
let raw_config = hex_literal::hex!["0000a000005000000a00000000c8000000c800000a0000000a000000100e0000580200000000500000c800000700e8764817020040011e00000000000000005039278c0400000000000000000000005039278c0400000000000000000000e8030000009001001e00000000000000009001008070000000000000000000000a0000000a0000000a00000001000000010500000001c80000000600000058020000580200000200000059000000000000001e000000280000000700c817a80402004001010200000014000000"];
let v3 = v4::OldHostConfiguration::<primitives::BlockNumber>::decode(&mut &raw_config[..])
let v4 = v5::OldHostConfiguration::<primitives::BlockNumber>::decode(&mut &raw_config[..])
.unwrap();
// We check only a sample of the values here. If we missed any fields or messed up data types
// that would skew all the fields coming after.
assert_eq!(v3.max_code_size, 10_485_760);
assert_eq!(v3.validation_upgrade_cooldown, 3600);
assert_eq!(v3.max_pov_size, 5_242_880);
assert_eq!(v3.hrmp_channel_max_message_size, 102_400);
assert_eq!(v3.n_delay_tranches, 89);
assert_eq!(v3.ump_max_individual_weight, Weight::from_parts(20_000_000_000, 5_242_880));
assert_eq!(v3.minimum_validation_upgrade_delay, 20);
assert_eq!(v4.max_code_size, 10_485_760);
assert_eq!(v4.validation_upgrade_cooldown, 3600);
assert_eq!(v4.max_pov_size, 5_242_880);
assert_eq!(v4.hrmp_channel_max_message_size, 102_400);
assert_eq!(v4.n_delay_tranches, 89);
assert_eq!(v4.ump_max_individual_weight, Weight::from_parts(20_000_000_000, 5_242_880));
assert_eq!(v4.minimum_validation_upgrade_delay, 20);
}
#[test]
fn test_migrate_to_v4() {
// Host configuration has lots of fields. However, in this migration we add only a couple of
// fields. The most important part to check are a couple of the last fields. We also pick
fn test_migrate_to_v5() {
// Host configuration has lots of fields. However, in this migration we only remove one field.
// The most important part to check are a couple of the last fields. We also pick
// extra fields to check arbitrarily, e.g. depending on their position (i.e. the middle) and
// also their type.
//
// We specify only the picked fields and the rest should be provided by the `Default`
// implementation. That implementation is copied over between the two types and should work
// fine.
let v3 = v4::OldHostConfiguration::<primitives::BlockNumber> {
let v4 = v5::OldHostConfiguration::<primitives::BlockNumber> {
ump_max_individual_weight: Weight::from_parts(0x71616e6f6e0au64, 0x71616e6f6e0au64),
needed_approvals: 69,
thread_availability_period: 55,
@@ -306,63 +318,72 @@ mod tests {
..Default::default()
};
let mut pending_configs = Vec::new();
pending_configs.push((100, v4.clone()));
pending_configs.push((300, v4.clone()));
new_test_ext(Default::default()).execute_with(|| {
// Implant the v3 version in the state.
// Implant the v4 version in the state.
frame_support::storage::unhashed::put_raw(
&configuration::ActiveConfig::<Test>::hashed_key(),
&v3.encode(),
&v4.encode(),
);
frame_support::storage::unhashed::put_raw(
&configuration::PendingConfigs::<Test>::hashed_key(),
&pending_configs.encode(),
);
migrate_to_v4::<Test>();
migrate_to_v5::<Test>();
let v4 = configuration::ActiveConfig::<Test>::get();
let v5 = configuration::ActiveConfig::<Test>::get();
let mut configs_to_check = configuration::PendingConfigs::<Test>::get();
configs_to_check.push((0, v5.clone()));
#[rustfmt::skip]
{
assert_eq!(v3.max_code_size , v4.max_code_size);
assert_eq!(v3.max_head_data_size , v4.max_head_data_size);
assert_eq!(v3.max_upward_queue_count , v4.max_upward_queue_count);
assert_eq!(v3.max_upward_queue_size , v4.max_upward_queue_size);
assert_eq!(v3.max_upward_message_size , v4.max_upward_message_size);
assert_eq!(v3.max_upward_message_num_per_candidate , v4.max_upward_message_num_per_candidate);
assert_eq!(v3.hrmp_max_message_num_per_candidate , v4.hrmp_max_message_num_per_candidate);
assert_eq!(v3.validation_upgrade_cooldown , v4.validation_upgrade_cooldown);
assert_eq!(v3.validation_upgrade_delay , v4.validation_upgrade_delay);
assert_eq!(v3.max_pov_size , v4.max_pov_size);
assert_eq!(v3.max_downward_message_size , v4.max_downward_message_size);
assert_eq!(v3.ump_service_total_weight , v4.ump_service_total_weight);
assert_eq!(v3.hrmp_max_parachain_outbound_channels , v4.hrmp_max_parachain_outbound_channels);
assert_eq!(v3.hrmp_max_parathread_outbound_channels , v4.hrmp_max_parathread_outbound_channels);
assert_eq!(v3.hrmp_sender_deposit , v4.hrmp_sender_deposit);
assert_eq!(v3.hrmp_recipient_deposit , v4.hrmp_recipient_deposit);
assert_eq!(v3.hrmp_channel_max_capacity , v4.hrmp_channel_max_capacity);
assert_eq!(v3.hrmp_channel_max_total_size , v4.hrmp_channel_max_total_size);
assert_eq!(v3.hrmp_max_parachain_inbound_channels , v4.hrmp_max_parachain_inbound_channels);
assert_eq!(v3.hrmp_max_parathread_inbound_channels , v4.hrmp_max_parathread_inbound_channels);
assert_eq!(v3.hrmp_channel_max_message_size , v4.hrmp_channel_max_message_size);
assert_eq!(v3.code_retention_period , v4.code_retention_period);
assert_eq!(v3.parathread_cores , v4.parathread_cores);
assert_eq!(v3.parathread_retries , v4.parathread_retries);
assert_eq!(v3.group_rotation_frequency , v4.group_rotation_frequency);
assert_eq!(v3.chain_availability_period , v4.chain_availability_period);
assert_eq!(v3.thread_availability_period , v4.thread_availability_period);
assert_eq!(v3.scheduling_lookahead , v4.scheduling_lookahead);
assert_eq!(v3.max_validators_per_core , v4.max_validators_per_core);
assert_eq!(v3.max_validators , v4.max_validators);
assert_eq!(v3.dispute_period , v4.dispute_period);
assert_eq!(v3.dispute_post_conclusion_acceptance_period, v4.dispute_post_conclusion_acceptance_period);
assert_eq!(v3.dispute_conclusion_by_time_out_period , v4.dispute_conclusion_by_time_out_period);
assert_eq!(v3.no_show_slots , v4.no_show_slots);
assert_eq!(v3.n_delay_tranches , v4.n_delay_tranches);
assert_eq!(v3.zeroth_delay_tranche_width , v4.zeroth_delay_tranche_width);
assert_eq!(v3.needed_approvals , v4.needed_approvals);
assert_eq!(v3.relay_vrf_modulo_samples , v4.relay_vrf_modulo_samples);
assert_eq!(v3.ump_max_individual_weight , v4.ump_max_individual_weight);
assert_eq!(v3.pvf_checking_enabled , v4.pvf_checking_enabled);
assert_eq!(v3.pvf_voting_ttl , v4.pvf_voting_ttl);
assert_eq!(v3.minimum_validation_upgrade_delay , v4.minimum_validation_upgrade_delay);
}; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression.
for (_, v4) in configs_to_check {
#[rustfmt::skip]
{
assert_eq!(v4.max_code_size , v5.max_code_size);
assert_eq!(v4.max_head_data_size , v5.max_head_data_size);
assert_eq!(v4.max_upward_queue_count , v5.max_upward_queue_count);
assert_eq!(v4.max_upward_queue_size , v5.max_upward_queue_size);
assert_eq!(v4.max_upward_message_size , v5.max_upward_message_size);
assert_eq!(v4.max_upward_message_num_per_candidate , v5.max_upward_message_num_per_candidate);
assert_eq!(v4.hrmp_max_message_num_per_candidate , v5.hrmp_max_message_num_per_candidate);
assert_eq!(v4.validation_upgrade_cooldown , v5.validation_upgrade_cooldown);
assert_eq!(v4.validation_upgrade_delay , v5.validation_upgrade_delay);
assert_eq!(v4.max_pov_size , v5.max_pov_size);
assert_eq!(v4.max_downward_message_size , v5.max_downward_message_size);
assert_eq!(v4.ump_service_total_weight , v5.ump_service_total_weight);
assert_eq!(v4.hrmp_max_parachain_outbound_channels , v5.hrmp_max_parachain_outbound_channels);
assert_eq!(v4.hrmp_max_parathread_outbound_channels , v5.hrmp_max_parathread_outbound_channels);
assert_eq!(v4.hrmp_sender_deposit , v5.hrmp_sender_deposit);
assert_eq!(v4.hrmp_recipient_deposit , v5.hrmp_recipient_deposit);
assert_eq!(v4.hrmp_channel_max_capacity , v5.hrmp_channel_max_capacity);
assert_eq!(v4.hrmp_channel_max_total_size , v5.hrmp_channel_max_total_size);
assert_eq!(v4.hrmp_max_parachain_inbound_channels , v5.hrmp_max_parachain_inbound_channels);
assert_eq!(v4.hrmp_max_parathread_inbound_channels , v5.hrmp_max_parathread_inbound_channels);
assert_eq!(v4.hrmp_channel_max_message_size , v5.hrmp_channel_max_message_size);
assert_eq!(v4.code_retention_period , v5.code_retention_period);
assert_eq!(v4.parathread_cores , v5.parathread_cores);
assert_eq!(v4.parathread_retries , v5.parathread_retries);
assert_eq!(v4.group_rotation_frequency , v5.group_rotation_frequency);
assert_eq!(v4.chain_availability_period , v5.chain_availability_period);
assert_eq!(v4.thread_availability_period , v5.thread_availability_period);
assert_eq!(v4.scheduling_lookahead , v5.scheduling_lookahead);
assert_eq!(v4.max_validators_per_core , v5.max_validators_per_core);
assert_eq!(v4.max_validators , v5.max_validators);
assert_eq!(v4.dispute_period , v5.dispute_period);
assert_eq!(v4.no_show_slots , v5.no_show_slots);
assert_eq!(v4.n_delay_tranches , v5.n_delay_tranches);
assert_eq!(v4.zeroth_delay_tranche_width , v5.zeroth_delay_tranche_width);
assert_eq!(v4.needed_approvals , v5.needed_approvals);
assert_eq!(v4.relay_vrf_modulo_samples , v5.relay_vrf_modulo_samples);
assert_eq!(v4.ump_max_individual_weight , v5.ump_max_individual_weight);
assert_eq!(v4.pvf_checking_enabled , v5.pvf_checking_enabled);
assert_eq!(v4.pvf_voting_ttl , v5.pvf_voting_ttl);
assert_eq!(v4.minimum_validation_upgrade_delay , v5.minimum_validation_upgrade_delay);
}; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression.
}
});
}
}
@@ -297,7 +297,6 @@ fn setting_pending_config_members() {
max_validators: None,
dispute_period: 239,
dispute_post_conclusion_acceptance_period: 10,
dispute_conclusion_by_time_out_period: 512,
no_show_slots: 240,
n_delay_tranches: 241,
zeroth_delay_tranche_width: 242,
@@ -389,11 +388,6 @@ fn setting_pending_config_members() {
new_config.dispute_post_conclusion_acceptance_period,
)
.unwrap();
Configuration::set_dispute_conclusion_by_time_out_period(
RuntimeOrigin::root(),
new_config.dispute_conclusion_by_time_out_period,
)
.unwrap();
Configuration::set_no_show_slots(RuntimeOrigin::root(), new_config.no_show_slots).unwrap();
Configuration::set_n_delay_tranches(RuntimeOrigin::root(), new_config.n_delay_tranches)
.unwrap();
+3 -24
View File
@@ -18,7 +18,7 @@
use crate::{configuration, initializer::SessionChangeNotification, session_info};
use bitvec::{bitvec, order::Lsb0 as BitOrderLsb0};
use frame_support::{ensure, traits::Get, weights::Weight};
use frame_support::{ensure, weights::Weight};
use frame_system::pallet_prelude::*;
use parity_scale_codec::{Decode, Encode};
use primitives::{
@@ -503,9 +503,6 @@ pub mod pallet {
/// A dispute has concluded for or against a candidate.
/// `\[para id, candidate hash, dispute result\]`
DisputeConcluded(CandidateHash, DisputeResult),
/// A dispute has timed out due to insufficient participation.
/// `\[para id, candidate hash\]`
DisputeTimedOut(CandidateHash),
/// A dispute has concluded with supermajority against a candidate.
/// Block authors should no longer build on top of this head and should
/// instead revert the block at the given height. This should be the
@@ -911,26 +908,8 @@ impl StatementSetFilter {
impl<T: Config> Pallet<T> {
/// Called by the initializer to initialize the disputes module.
pub(crate) fn initializer_initialize(now: T::BlockNumber) -> Weight {
let config = <configuration::Pallet<T>>::config();
let mut weight = Weight::zero();
for (session_index, candidate_hash, mut dispute) in <Disputes<T>>::iter() {
weight += T::DbWeight::get().reads_writes(1, 0);
if dispute.concluded_at.is_none() &&
dispute.start + config.dispute_conclusion_by_time_out_period < now
{
Self::deposit_event(Event::DisputeTimedOut(candidate_hash));
dispute.concluded_at = Some(now);
<Disputes<T>>::insert(session_index, candidate_hash, &dispute);
weight += T::DbWeight::get().writes(1);
}
}
weight
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
Weight::zero()
}
/// Called by the initializer to finalize the disputes pallet.
@@ -329,131 +329,6 @@ fn test_import_backing_votes() {
);
}
// Test that dispute timeout is handled correctly.
#[test]
fn test_dispute_timeout() {
let dispute_conclusion_by_time_out_period = 3;
let start = 10;
let mock_genesis_config = MockGenesisConfig {
configuration: crate::configuration::GenesisConfig {
config: HostConfiguration {
dispute_conclusion_by_time_out_period,
..Default::default()
},
..Default::default()
},
..Default::default()
};
new_test_ext(mock_genesis_config).execute_with(|| {
// We need 7 validators for the byzantine threshold to be 2
let v0 = <ValidatorId as CryptoType>::Pair::generate().0;
let v1 = <ValidatorId as CryptoType>::Pair::generate().0;
let v2 = <ValidatorId as CryptoType>::Pair::generate().0;
let v3 = <ValidatorId as CryptoType>::Pair::generate().0;
let v4 = <ValidatorId as CryptoType>::Pair::generate().0;
let v5 = <ValidatorId as CryptoType>::Pair::generate().0;
let v6 = <ValidatorId as CryptoType>::Pair::generate().0;
run_to_block(start, |b| {
// a new session at each block
Some((
true,
b,
vec![
(&0, v0.public()),
(&1, v1.public()),
(&2, v2.public()),
(&3, v3.public()),
(&4, v4.public()),
(&5, v5.public()),
(&6, v6.public()),
],
Some(vec![
(&0, v0.public()),
(&1, v1.public()),
(&2, v2.public()),
(&3, v3.public()),
(&4, v4.public()),
(&5, v5.public()),
(&6, v6.public()),
]),
))
});
let candidate_hash = CandidateHash(sp_core::H256::repeat_byte(1));
let inclusion_parent = sp_core::H256::repeat_byte(0xff);
// v0 and v1 vote for 3, v2 against. We need f+1 votes (3) so that the dispute is
// confirmed. Otherwise It will be filtered out.
let session = start - 1;
let stmts = vec![DisputeStatementSet {
candidate_hash: candidate_hash.clone(),
session,
statements: vec![
(
DisputeStatement::Valid(ValidDisputeStatementKind::BackingValid(
inclusion_parent,
)),
ValidatorIndex(0),
v0.sign(&CompactStatement::Valid(candidate_hash).signing_payload(
&SigningContext { session_index: start - 1, parent_hash: inclusion_parent },
)),
),
(
DisputeStatement::Valid(ValidDisputeStatementKind::Explicit),
ValidatorIndex(1),
v1.sign(
&ExplicitDisputeStatement {
valid: true,
candidate_hash: candidate_hash.clone(),
session: start - 1,
}
.signing_payload(),
),
),
(
DisputeStatement::Invalid(InvalidDisputeStatementKind::Explicit),
ValidatorIndex(6),
v2.sign(
&ExplicitDisputeStatement {
valid: false,
candidate_hash: candidate_hash.clone(),
session: start - 1,
}
.signing_payload(),
),
),
],
}];
let stmts = filter_dispute_set(stmts);
assert_ok!(
Pallet::<Test>::process_checked_multi_dispute_data(&stmts),
vec![(9, candidate_hash.clone())],
);
// Run to timeout period
run_to_block(start + dispute_conclusion_by_time_out_period, |_| None);
assert!(<Disputes<Test>>::get(&session, &candidate_hash)
.expect("dispute should exist")
.concluded_at
.is_none());
// Run to timeout + 1 in order to executive on_finalize(timeout)
run_to_block(start + dispute_conclusion_by_time_out_period + 1, |_| None);
assert_eq!(
<Disputes<Test>>::get(&session, &candidate_hash)
.expect("dispute should exist")
.concluded_at
.expect("dispute should have concluded"),
start + dispute_conclusion_by_time_out_period + 1
);
});
}
// Test pruning works
#[test]
fn test_initializer_on_new_session() {
+1
View File
@@ -1418,6 +1418,7 @@ pub type Migrations = (
Runtime,
NominationPoolsMigrationV4OldPallet,
>,
parachains_configuration::migration::v5::MigrateToV5<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
+1 -1
View File
@@ -1494,7 +1494,7 @@ pub type UncheckedExtrinsic =
/// All migrations that will run on the next runtime upgrade.
///
/// Should be cleared after every release.
pub type Migrations = ();
pub type Migrations = parachains_configuration::migration::v5::MigrateToV5<Runtime>;
/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
+1
View File
@@ -1214,6 +1214,7 @@ pub type Migrations = (
Runtime,
NominationPoolsMigrationV4OldPallet,
>,
parachains_configuration::migration::v5::MigrateToV5<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.