disputes pallet: Remove spam slots (#6345)

* disputes pallet: Filter disputes with votes less than supermajority threshold

* Remove `max_spam_slots` usages

* Remove `SpamSlots`

* Remove `SpamSlotChange`

* Remove `Error<T>::PotentialSpam` and stale comments

* `create_disputes_with_no_spam` -> `create_disputes`

* Make tests compile - wip commit

* Rework `test_dispute_timeout`. Rename `update_spam_slots` to `filter_dispute_set`

* Remove `dispute_statement_becoming_onesided_due_to_spamslots_is_accepted` and `filter_correctly_accounts_spam_slots` -> they bring no value with removed spam slots

* Fix `test_provide_multi_dispute_success_and_other`

* Remove an old comment

* Remove spam slots from tests - clean todo comments

* Remove test - `test_decrement_spam`

* todo comments

* Update TODO comments

* Extract `test_unconfirmed_are_ignored` as separate test case

* Remove dead code

* Fix `test_unconfirmed_are_ignored`

* Remove dead code in `filter_dispute_data`

* Fix weights (related to commit "Remove `SpamSlots`")

* Disputes migration - first try

* Remove `dispute_max_spam_slots` + storage migration

* Fix `HostConfig` migration tests

* Deprecate `SpamSlots`

* Code review feedback

* add weight for storage version update
* fix bound for clear()

* Fix weights in disputes migration

* Revert "Deprecate `SpamSlots`"

This reverts commit 8c4d967c7b061abd76ba8b551223918c0b9e6370.

* Make mod migration public

* Remove `SpamSlots` from disputes pallet and use `storage_alias` in the migration

* Fix call to `clear()` for `SpamSlots` in migration

* Update migration and add a `try-runtime` test

* Add `pre_upgrade` `try-runtime` test

* Fix some test names in `HostConfiguration` migration

* Link spamslots migration in all runtimes

* Add `test_unconfirmed_disputes_cause_block_import_error`

* Update guide

- Remove `SpamSlots` related information from roadmap/implementers-guide/src/runtime/disputes.md
- Add 'Disputes filtering' to Runtime section of the Implementor's guide

* Update runtime/parachains/src/configuration/migration.rs

Co-authored-by: Marcin S. <marcin@bytedude.com>

* Code review feedback - update logs

* Code review feedback: fix weights

* Update runtime/parachains/src/disputes.rs

Co-authored-by: s0me0ne-unkn0wn <48632512+s0me0ne-unkn0wn@users.noreply.github.com>

* Additional logs in disputes migration

* Fix merge conflicts

* Add version checks in try-runtime tests

* Fix a compilation warning`

Co-authored-by: Marcin S. <marcin@bytedude.com>
Co-authored-by: s0me0ne-unkn0wn <48632512+s0me0ne-unkn0wn@users.noreply.github.com>
This commit is contained in:
Tsvetomir Dimitrov
2023-01-07 15:56:14 +02:00
committed by GitHub
parent 715e98268a
commit ed9a1a400e
13 changed files with 492 additions and 927 deletions
@@ -17,11 +17,7 @@
//! A module that is responsible for migration of storage.
use crate::configuration::{self, Config, Pallet, Store, MAX_POV_SIZE};
use frame_support::{
pallet_prelude::*,
traits::StorageVersion,
weights::{OldWeight, Weight},
};
use frame_support::{pallet_prelude::*, traits::StorageVersion, weights::Weight};
use frame_system::pallet_prelude::BlockNumberFor;
/// The current storage version.
@@ -29,12 +25,15 @@ use frame_system::pallet_prelude::BlockNumberFor;
/// v0-v1: <https://github.com/paritytech/polkadot/pull/3575>
/// v1-v2: <https://github.com/paritytech/polkadot/pull/4420>
/// v2-v3: <https://github.com/paritytech/polkadot/pull/6091>
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(3);
/// v3-v4: <https://github.com/paritytech/polkadot/pull/6345>
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);
pub mod v3 {
pub mod v4 {
use super::*;
use frame_support::traits::OnRuntimeUpgrade;
use frame_support::{traits::OnRuntimeUpgrade, weights::constants::WEIGHT_REF_TIME_PER_MILLIS};
use primitives::v2::{Balance, SessionIndex};
#[cfg(feature = "try-runtime")]
use sp_std::prelude::*;
// Copied over from configuration.rs @ de9e147695b9f1be8bd44e07861a31e483c8343a and removed
// all the comments, and changed the Weight struct to OldWeight
@@ -51,7 +50,7 @@ pub mod v3 {
pub validation_upgrade_delay: BlockNumber,
pub max_pov_size: u32,
pub max_downward_message_size: u32,
pub ump_service_total_weight: OldWeight,
pub ump_service_total_weight: Weight,
pub hrmp_max_parachain_outbound_channels: u32,
pub hrmp_max_parathread_outbound_channels: u32,
pub hrmp_sender_deposit: Balance,
@@ -79,7 +78,7 @@ pub mod v3 {
pub zeroth_delay_tranche_width: u32,
pub needed_approvals: u32,
pub relay_vrf_modulo_samples: u32,
pub ump_max_individual_weight: OldWeight,
pub ump_max_individual_weight: Weight,
pub pvf_checking_enabled: bool,
pub pvf_voting_ttl: SessionIndex,
pub minimum_validation_upgrade_delay: BlockNumber,
@@ -114,7 +113,7 @@ pub mod v3 {
max_upward_queue_count: Default::default(),
max_upward_queue_size: Default::default(),
max_downward_message_size: Default::default(),
ump_service_total_weight: OldWeight(Default::default()),
ump_service_total_weight: Default::default(),
max_upward_message_size: Default::default(),
max_upward_message_num_per_candidate: Default::default(),
hrmp_sender_deposit: Default::default(),
@@ -127,8 +126,9 @@ pub mod v3 {
hrmp_max_parachain_outbound_channels: Default::default(),
hrmp_max_parathread_outbound_channels: Default::default(),
hrmp_max_message_num_per_candidate: Default::default(),
ump_max_individual_weight: OldWeight(
frame_support::weights::constants::WEIGHT_REF_TIME_PER_MILLIS * 20,
ump_max_individual_weight: Weight::from_parts(
20u64 * WEIGHT_REF_TIME_PER_MILLIS,
MAX_POV_SIZE as u64,
),
pvf_checking_enabled: false,
pvf_voting_ttl: 2u32.into(),
@@ -137,32 +137,51 @@ pub mod v3 {
}
}
pub struct MigrateToV3<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV3<T> {
fn on_runtime_upgrade() -> Weight {
if StorageVersion::get::<Pallet<T>>() == 2 {
let weight_consumed = migrate_to_v3::<T>();
pub struct MigrateToV4<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV4<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()");
log::info!(target: configuration::LOG_TARGET, "MigrateToV3 executed successfully");
ensure!(StorageVersion::get::<Pallet<T>>() == 3, "The migration requires version 3");
Ok(Vec::new())
}
fn on_runtime_upgrade() -> Weight {
if StorageVersion::get::<Pallet<T>>() == 3 {
let weight_consumed = migrate_to_v4::<T>();
log::info!(target: configuration::LOG_TARGET, "MigrateToV4 executed successfully");
STORAGE_VERSION.put::<Pallet<T>>();
weight_consumed
} else {
log::warn!(target: configuration::LOG_TARGET, "MigrateToV3 should be removed.");
log::warn!(target: configuration::LOG_TARGET, "MigrateToV4 should be removed.");
T::DbWeight::get().reads(1)
}
}
#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
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"
);
Ok(())
}
}
}
fn migrate_to_v3<T: Config>() -> Weight {
fn migrate_to_v4<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: v3::OldHostConfiguration<BlockNumberFor<T>>| ->
|pre: v4::OldHostConfiguration<BlockNumberFor<T>>| ->
configuration::HostConfiguration<BlockNumberFor<T>>
{
super::HostConfiguration {
@@ -177,6 +196,7 @@ validation_upgrade_cooldown : pre.validation_upgrade_cooldown,
validation_upgrade_delay : pre.validation_upgrade_delay,
max_pov_size : pre.max_pov_size,
max_downward_message_size : pre.max_downward_message_size,
ump_service_total_weight : pre.ump_service_total_weight,
hrmp_max_parachain_outbound_channels : pre.hrmp_max_parachain_outbound_channels,
hrmp_max_parathread_outbound_channels : pre.hrmp_max_parathread_outbound_channels,
hrmp_sender_deposit : pre.hrmp_sender_deposit,
@@ -197,19 +217,17 @@ 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_max_spam_slots : pre.dispute_max_spam_slots,
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,
needed_approvals : pre.needed_approvals,
relay_vrf_modulo_samples : pre.relay_vrf_modulo_samples,
ump_max_individual_weight : pre.ump_max_individual_weight,
pvf_checking_enabled : pre.pvf_checking_enabled,
pvf_voting_ttl : pre.pvf_voting_ttl,
minimum_validation_upgrade_delay : pre.minimum_validation_upgrade_delay,
ump_service_total_weight: Weight::from_ref_time(pre.ump_service_total_weight.0).set_proof_size(MAX_POV_SIZE as u64),
ump_max_individual_weight: Weight::from_ref_time(pre.ump_max_individual_weight.0).set_proof_size(MAX_POV_SIZE as u64),
}
};
@@ -221,7 +239,7 @@ ump_max_individual_weight: Weight::from_ref_time(pre.ump_max_individual_weight.0
// 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 v2."
"unexpected error when performing translation of the configuration type during storage upgrade to v4."
);
}
@@ -234,31 +252,43 @@ mod tests {
use crate::mock::{new_test_ext, Test};
#[test]
fn v2_deserialized_from_actual_data() {
// Fetched at Kusama 14,703,780 (0x3b2c305d01bd4adf1973d32a2d55ca1260a55eea8dfb3168e317c57f2841fdf1)
fn v3_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.
// Steps:
// 1. Go to Polkadot.js -> Developer -> Chain state -> Storage: https://polkadot.js.org/apps/#/chainstate
// 2. Set these parameters:
// 2.1. selected state query: configuration; activeConfig(): PolkadotRuntimeParachainsConfigurationHostConfiguration
// 2.2. blockhash to query at: 0xf89d3ab5312c5f70d396dc59612f0aa65806c798346f9db4b35278baed2e0e53 (the hash of the block)
// 2.3. Note the value of encoded storage key -> 0x06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385 for the referenced block.
// 2.4. You'll also need the decoded values to update the test.
// 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!["0000a000005000000a00000000c8000000c800000a0000000a000000100e0000580200000000500000c8000000e87648170000001e00000000000000005039278c0400000000000000000000005039278c0400000000000000000000e8030000009001001e00000000000000009001008070000000000000000000000a0000000a0000000a00000001000000010500000001c8000000060000005802000002000000580200000200000059000000000000001e0000002800000000c817a804000000000200000014000000"];
let raw_config = hex_literal::hex!["0000a000005000000a00000000c8000000c800000a0000000a000000100e0000580200000000500000c800000700e8764817020040011e00000000000000005039278c0400000000000000000000005039278c0400000000000000000000e8030000009001001e00000000000000009001008070000000000000000000000a0000000a0000000a00000001000000010500000001c8000000060000005802000002000000580200000200000059000000000000001e000000280000000700c817a80402004001000200000014000000"];
let v2 =
v3::OldHostConfiguration::<primitives::v2::BlockNumber>::decode(&mut &raw_config[..])
let v3 =
v4::OldHostConfiguration::<primitives::v2::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!(v2.max_code_size, 10_485_760);
assert_eq!(v2.validation_upgrade_cooldown, 3600);
assert_eq!(v2.max_pov_size, 5_242_880);
assert_eq!(v2.hrmp_channel_max_message_size, 102_400);
assert_eq!(v2.dispute_max_spam_slots, 2);
assert_eq!(v2.n_delay_tranches, 89);
assert_eq!(v2.ump_max_individual_weight, OldWeight(20_000_000_000));
assert_eq!(v2.minimum_validation_upgrade_delay, 20);
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);
}
#[test]
fn test_migrate_to_v3() {
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
// extra fields to check arbitrarily, e.g. depending on their position (i.e. the middle) and
@@ -267,8 +297,8 @@ mod tests {
// 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 v2 = v3::OldHostConfiguration::<primitives::v2::BlockNumber> {
ump_max_individual_weight: OldWeight(0x71616e6f6e0au64),
let v3 = v4::OldHostConfiguration::<primitives::v2::BlockNumber> {
ump_max_individual_weight: Weight::from_parts(0x71616e6f6e0au64, 0x71616e6f6e0au64),
needed_approvals: 69,
thread_availability_period: 55,
hrmp_recipient_deposit: 1337,
@@ -279,64 +309,61 @@ mod tests {
};
new_test_ext(Default::default()).execute_with(|| {
// Implant the v2 version in the state.
// Implant the v3 version in the state.
frame_support::storage::unhashed::put_raw(
&configuration::ActiveConfig::<Test>::hashed_key(),
&v2.encode(),
&v3.encode(),
);
migrate_to_v3::<Test>();
migrate_to_v4::<Test>();
let v3 = configuration::ActiveConfig::<Test>::get();
let v4 = configuration::ActiveConfig::<Test>::get();
#[rustfmt::skip]
{
assert_eq!(v2.max_code_size , v3.max_code_size);
assert_eq!(v2.max_head_data_size , v3.max_head_data_size);
assert_eq!(v2.max_upward_queue_count , v3.max_upward_queue_count);
assert_eq!(v2.max_upward_queue_size , v3.max_upward_queue_size);
assert_eq!(v2.max_upward_message_size , v3.max_upward_message_size);
assert_eq!(v2.max_upward_message_num_per_candidate , v3.max_upward_message_num_per_candidate);
assert_eq!(v2.hrmp_max_message_num_per_candidate , v3.hrmp_max_message_num_per_candidate);
assert_eq!(v2.validation_upgrade_cooldown , v3.validation_upgrade_cooldown);
assert_eq!(v2.validation_upgrade_delay , v3.validation_upgrade_delay);
assert_eq!(v2.max_pov_size , v3.max_pov_size);
assert_eq!(v2.max_downward_message_size , v3.max_downward_message_size);
assert_eq!(v2.hrmp_max_parachain_outbound_channels , v3.hrmp_max_parachain_outbound_channels);
assert_eq!(v2.hrmp_max_parathread_outbound_channels , v3.hrmp_max_parathread_outbound_channels);
assert_eq!(v2.hrmp_sender_deposit , v3.hrmp_sender_deposit);
assert_eq!(v2.hrmp_recipient_deposit , v3.hrmp_recipient_deposit);
assert_eq!(v2.hrmp_channel_max_capacity , v3.hrmp_channel_max_capacity);
assert_eq!(v2.hrmp_channel_max_total_size , v3.hrmp_channel_max_total_size);
assert_eq!(v2.hrmp_max_parachain_inbound_channels , v3.hrmp_max_parachain_inbound_channels);
assert_eq!(v2.hrmp_max_parathread_inbound_channels , v3.hrmp_max_parathread_inbound_channels);
assert_eq!(v2.hrmp_channel_max_message_size , v3.hrmp_channel_max_message_size);
assert_eq!(v2.code_retention_period , v3.code_retention_period);
assert_eq!(v2.parathread_cores , v3.parathread_cores);
assert_eq!(v2.parathread_retries , v3.parathread_retries);
assert_eq!(v2.group_rotation_frequency , v3.group_rotation_frequency);
assert_eq!(v2.chain_availability_period , v3.chain_availability_period);
assert_eq!(v2.thread_availability_period , v3.thread_availability_period);
assert_eq!(v2.scheduling_lookahead , v3.scheduling_lookahead);
assert_eq!(v2.max_validators_per_core , v3.max_validators_per_core);
assert_eq!(v2.max_validators , v3.max_validators);
assert_eq!(v2.dispute_period , v3.dispute_period);
assert_eq!(v2.dispute_post_conclusion_acceptance_period, v3.dispute_post_conclusion_acceptance_period);
assert_eq!(v2.dispute_max_spam_slots , v3.dispute_max_spam_slots);
assert_eq!(v2.dispute_conclusion_by_time_out_period , v3.dispute_conclusion_by_time_out_period);
assert_eq!(v2.no_show_slots , v3.no_show_slots);
assert_eq!(v2.n_delay_tranches , v3.n_delay_tranches);
assert_eq!(v2.zeroth_delay_tranche_width , v3.zeroth_delay_tranche_width);
assert_eq!(v2.needed_approvals , v3.needed_approvals);
assert_eq!(v2.relay_vrf_modulo_samples , v3.relay_vrf_modulo_samples);
assert_eq!(v2.pvf_checking_enabled , v3.pvf_checking_enabled);
assert_eq!(v2.pvf_voting_ttl , v3.pvf_voting_ttl);
assert_eq!(v2.minimum_validation_upgrade_delay , v3.minimum_validation_upgrade_delay);
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);
assert_eq!(v2.ump_service_total_weight, OldWeight(v3.ump_service_total_weight.ref_time()));
assert_eq!(v2.ump_max_individual_weight, OldWeight(v3.ump_max_individual_weight.ref_time()));
assert_eq!(v3.ump_service_total_weight.proof_size(), MAX_POV_SIZE as u64);
assert_eq!(v3.ump_max_individual_weight.proof_size(), MAX_POV_SIZE as u64);
}; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression.
});
}