backing: move the min votes threshold to the runtime (#1200)

* move min backing votes const to runtime

also cache it per-session in the backing subsystem

Signed-off-by: alindima <alin@parity.io>

* add runtime migration

* introduce api versioning for min_backing votes

also enable it for rococo/versi for testing

* also add min_backing_votes runtime calls to statement-distribution

this dependency has been recently introduced by async backing

* remove explicit version runtime API call

this is not needed, as the RuntimeAPISubsystem already takes care
of versioning and will return NotSupported if the version is not
right.

* address review comments

- parametrise backing votes runtime API with session index
- remove RuntimeInfo usage in backing subsystem, as runtime API
caches the min backing votes by session index anyway.
- move the logic for adjusting the configured needed backing votes with the size of the backing group
to a primitives helper.
- move the legacy min backing votes value to a primitives helper.
- mark JoinMultiple error as fatal, since the Canceled (non-multiple) counterpart is also fatal.
- make backing subsystem handle fatal errors for new leaves update.
- add HostConfiguration consistency check for zeroed backing votes threshold
- add cumulus accompanying change

* fix cumulus test compilation

* fix tests

* more small fixes

* fix merge

* bump runtime api version for westend and rollback version for rococo

---------

Signed-off-by: alindima <alin@parity.io>
Co-authored-by: Javier Viola <javier@parity.io>
This commit is contained in:
Alin Dima
2023-08-31 14:01:36 +03:00
committed by GitHub
parent f1845f725d
commit d6af073aa5
37 changed files with 920 additions and 255 deletions
@@ -24,8 +24,8 @@ use frame_system::pallet_prelude::*;
use parity_scale_codec::{Decode, Encode};
use polkadot_parachain::primitives::{MAX_HORIZONTAL_MESSAGE_NUM, MAX_UPWARD_MESSAGE_NUM};
use primitives::{
vstaging::AsyncBackingParams, Balance, ExecutorParams, SessionIndex, MAX_CODE_SIZE,
MAX_HEAD_DATA_SIZE, MAX_POV_SIZE, ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE,
vstaging::AsyncBackingParams, Balance, ExecutorParams, SessionIndex, LEGACY_MIN_BACKING_VOTES,
MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE, MAX_POV_SIZE, ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE,
};
use sp_runtime::{traits::Zero, Perbill};
use sp_std::prelude::*;
@@ -245,6 +245,9 @@ pub struct HostConfiguration<BlockNumber> {
/// This value should be greater than
/// [`paras_availability_period`](Self::paras_availability_period).
pub minimum_validation_upgrade_delay: BlockNumber,
/// The minimum number of valid backing statements required to consider a parachain candidate
/// backable.
pub minimum_backing_votes: u32,
}
impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber> {
@@ -295,6 +298,7 @@ impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber
on_demand_fee_variability: Perbill::from_percent(3),
on_demand_target_queue_utilization: Perbill::from_percent(25),
on_demand_ttl: 5u32.into(),
minimum_backing_votes: LEGACY_MIN_BACKING_VOTES,
}
}
}
@@ -331,6 +335,8 @@ pub enum InconsistentError<BlockNumber> {
MaxHrmpOutboundChannelsExceeded,
/// Maximum number of HRMP inbound channels exceeded.
MaxHrmpInboundChannelsExceeded,
/// `minimum_backing_votes` is set to zero.
ZeroMinimumBackingVotes,
}
impl<BlockNumber> HostConfiguration<BlockNumber>
@@ -411,6 +417,10 @@ where
return Err(MaxHrmpInboundChannelsExceeded)
}
if self.minimum_backing_votes.is_zero() {
return Err(ZeroMinimumBackingVotes)
}
Ok(())
}
@@ -477,7 +487,8 @@ pub mod pallet {
/// v5-v6: <https://github.com/paritytech/polkadot/pull/6271> (remove UMP dispatch queue)
/// v6-v7: <https://github.com/paritytech/polkadot/pull/7396>
/// v7-v8: <https://github.com/paritytech/polkadot/pull/6969>
const STORAGE_VERSION: StorageVersion = StorageVersion::new(8);
/// v8-v9: <https://github.com/paritytech/polkadot/pull/7577>
const STORAGE_VERSION: StorageVersion = StorageVersion::new(9);
#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
@@ -1153,6 +1164,18 @@ pub mod pallet {
config.on_demand_ttl = new;
})
}
/// Set the minimum backing votes threshold.
#[pallet::call_index(52)]
#[pallet::weight((
T::WeightInfo::set_config_with_u32(),
DispatchClass::Operational
))]
pub fn set_minimum_backing_votes(origin: OriginFor<T>, new: u32) -> DispatchResult {
ensure_root(origin)?;
Self::schedule_config_update(|config| {
config.minimum_backing_votes = new;
})
}
}
#[pallet::hooks]