Skip to content

Commit 1e2a2f0

Browse files
eskimoreskimor
andauthored
Fix nothing scheduled on session boundary (#1403)
* Fix scheduled state at session boundaries. * Cleanup + better docs. * More cleanup and fixes. * Remove 12s hack. * Add dep. * Make clippy happy --------- Co-authored-by: eskimor <[email protected]>
1 parent eeb368e commit 1e2a2f0

File tree

19 files changed

+492
-646
lines changed

19 files changed

+492
-646
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

polkadot/primitives/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ pub use v5::{
4141
BackedCandidate, Balance, BlakeTwo256, Block, BlockId, BlockNumber, CandidateCommitments,
4242
CandidateDescriptor, CandidateEvent, CandidateHash, CandidateIndex, CandidateReceipt,
4343
CheckedDisputeStatementSet, CheckedMultiDisputeStatementSet, CollatorId, CollatorSignature,
44-
CommittedCandidateReceipt, CompactStatement, ConsensusLog, CoreIndex, CoreOccupied, CoreState,
45-
DisputeState, DisputeStatement, DisputeStatementSet, DownwardMessage, EncodeAs, ExecutorParam,
44+
CommittedCandidateReceipt, CompactStatement, ConsensusLog, CoreIndex, CoreState, DisputeState,
45+
DisputeStatement, DisputeStatementSet, DownwardMessage, EncodeAs, ExecutorParam,
4646
ExecutorParams, ExecutorParamsHash, ExplicitDisputeStatement, GroupIndex, GroupRotationInfo,
4747
Hash, HashT, HeadData, Header, HrmpChannelId, Id, InboundDownwardMessage, InboundHrmpMessage,
4848
IndexedVec, InherentData, InvalidDisputeStatementKind, Moment, MultiDisputeStatementSet, Nonce,

polkadot/primitives/src/v5/mod.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -830,60 +830,6 @@ pub struct ParathreadEntry {
830830
pub retries: u32,
831831
}
832832

833-
/// An assignment for a parachain scheduled to be backed and included in a relay chain block.
834-
#[derive(Clone, Encode, Decode, PartialEq, TypeInfo, RuntimeDebug)]
835-
pub struct Assignment {
836-
/// Assignment's ParaId
837-
pub para_id: Id,
838-
}
839-
840-
impl Assignment {
841-
/// Create a new `Assignment`.
842-
pub fn new(para_id: Id) -> Self {
843-
Self { para_id }
844-
}
845-
}
846-
847-
/// An entry tracking a paras
848-
#[derive(Clone, Encode, Decode, TypeInfo, PartialEq, RuntimeDebug)]
849-
pub struct ParasEntry<N = BlockNumber> {
850-
/// The `Assignment`
851-
pub assignment: Assignment,
852-
/// The number of times the entry has timed out in availability.
853-
pub availability_timeouts: u32,
854-
/// The block height where this entry becomes invalid.
855-
pub ttl: N,
856-
}
857-
858-
impl<N> ParasEntry<N> {
859-
/// Return `Id` from the underlying `Assignment`.
860-
pub fn para_id(&self) -> Id {
861-
self.assignment.para_id
862-
}
863-
864-
/// Create a new `ParasEntry`.
865-
pub fn new(assignment: Assignment, now: N) -> Self {
866-
ParasEntry { assignment, availability_timeouts: 0, ttl: now }
867-
}
868-
}
869-
870-
/// What is occupying a specific availability core.
871-
#[derive(Clone, Encode, Decode, TypeInfo, RuntimeDebug)]
872-
#[cfg_attr(feature = "std", derive(PartialEq))]
873-
pub enum CoreOccupied<N> {
874-
/// The core is not occupied.
875-
Free,
876-
/// A paras.
877-
Paras(ParasEntry<N>),
878-
}
879-
880-
impl<N> CoreOccupied<N> {
881-
/// Is core free?
882-
pub fn is_free(&self) -> bool {
883-
matches!(self, Self::Free)
884-
}
885-
}
886-
887833
/// A helper data-type for tracking validator-group rotations.
888834
#[derive(Clone, Encode, Decode, TypeInfo, RuntimeDebug)]
889835
#[cfg_attr(feature = "std", derive(PartialEq))]

polkadot/runtime/parachains/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ rand_chacha = { version = "0.3.1", default-features = false }
5050
static_assertions = { version = "1.1.0", optional = true }
5151
polkadot-parachain-primitives = { path = "../../parachain", default-features = false }
5252
polkadot-runtime-metrics = { path = "../metrics", default-features = false}
53+
polkadot-core-primitives = { path = "../../core-primitives", default-features = false }
5354

5455
[dev-dependencies]
5556
futures = "0.3.21"

polkadot/runtime/parachains/src/assigner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
//! The Polkadot multiplexing assignment provider.
1818
//! Provides blockspace assignments for both bulk and on demand parachains.
1919
use frame_system::pallet_prelude::BlockNumberFor;
20-
use primitives::{v5::Assignment, CoreIndex, Id as ParaId};
20+
use primitives::{CoreIndex, Id as ParaId};
2121

2222
use crate::{
2323
configuration, paras,
24-
scheduler::common::{AssignmentProvider, AssignmentProviderConfig},
24+
scheduler::common::{Assignment, AssignmentProvider, AssignmentProviderConfig},
2525
};
2626

2727
pub use pallet::*;

polkadot/runtime/parachains/src/assigner_on_demand/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mod tests;
3434

3535
use crate::{
3636
configuration, paras,
37-
scheduler::common::{AssignmentProvider, AssignmentProviderConfig},
37+
scheduler::common::{Assignment, AssignmentProvider, AssignmentProviderConfig},
3838
};
3939

4040
use frame_support::{
@@ -46,7 +46,7 @@ use frame_support::{
4646
},
4747
};
4848
use frame_system::pallet_prelude::*;
49-
use primitives::{v5::Assignment, CoreIndex, Id as ParaId};
49+
use primitives::{CoreIndex, Id as ParaId};
5050
use sp_runtime::{
5151
traits::{One, SaturatedConversion},
5252
FixedPointNumber, FixedPointOperand, FixedU128, Perbill, Saturating,
@@ -606,7 +606,6 @@ impl<T: Config> AssignmentProvider<BlockNumberFor<T>> for Pallet<T> {
606606
fn get_provider_config(_core_idx: CoreIndex) -> AssignmentProviderConfig<BlockNumberFor<T>> {
607607
let config = <configuration::Pallet<T>>::config();
608608
AssignmentProviderConfig {
609-
availability_period: config.paras_availability_period,
610609
max_availability_timeouts: config.on_demand_retries,
611610
ttl: config.on_demand_ttl,
612611
}

polkadot/runtime/parachains/src/assigner_on_demand/tests.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ use crate::{
2424
System, Test,
2525
},
2626
paras::{ParaGenesisArgs, ParaKind},
27+
scheduler::common::Assignment,
2728
};
2829
use frame_support::{assert_noop, assert_ok, error::BadOrigin};
2930
use pallet_balances::Error as BalancesError;
30-
use primitives::{
31-
v5::{Assignment, ValidationCode},
32-
BlockNumber, SessionIndex,
33-
};
31+
use primitives::{v5::ValidationCode, BlockNumber, SessionIndex};
3432
use sp_std::collections::btree_map::BTreeMap;
3533

3634
fn schedule_blank_para(id: ParaId, parakind: ParaKind) {

polkadot/runtime/parachains/src/assigner_parachains.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
2020
use crate::{
2121
configuration, paras,
22-
scheduler::common::{AssignmentProvider, AssignmentProviderConfig},
22+
scheduler::common::{Assignment, AssignmentProvider, AssignmentProviderConfig},
2323
};
2424
use frame_system::pallet_prelude::BlockNumberFor;
2525
pub use pallet::*;
26-
use primitives::{v5::Assignment, CoreIndex, Id as ParaId};
26+
use primitives::{CoreIndex, Id as ParaId};
2727

2828
#[frame_support::pallet]
2929
pub mod pallet {
@@ -57,9 +57,7 @@ impl<T: Config> AssignmentProvider<BlockNumberFor<T>> for Pallet<T> {
5757
fn push_assignment_for_core(_: CoreIndex, _: Assignment) {}
5858

5959
fn get_provider_config(_core_idx: CoreIndex) -> AssignmentProviderConfig<BlockNumberFor<T>> {
60-
let config = <configuration::Pallet<T>>::config();
6160
AssignmentProviderConfig {
62-
availability_period: config.paras_availability_period,
6361
// The next assignment already goes to the same [`ParaId`], no timeout tracking needed.
6462
max_availability_timeouts: 0,
6563
// The next assignment already goes to the same [`ParaId`], this can be any number

polkadot/runtime/parachains/src/builder.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@ use crate::{
1818
configuration, inclusion, initializer, paras,
1919
paras::ParaKind,
2020
paras_inherent,
21-
scheduler::{self, common::AssignmentProviderConfig},
21+
scheduler::{
22+
self,
23+
common::{Assignment, AssignmentProviderConfig},
24+
CoreOccupied, ParasEntry,
25+
},
2226
session_info, shared,
2327
};
2428
use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec};
2529
use frame_support::pallet_prelude::*;
2630
use frame_system::pallet_prelude::*;
2731
use primitives::{
28-
collator_signature_payload,
29-
v5::{Assignment, ParasEntry},
30-
AvailabilityBitfield, BackedCandidate, CandidateCommitments, CandidateDescriptor,
31-
CandidateHash, CollatorId, CollatorSignature, CommittedCandidateReceipt, CompactStatement,
32-
CoreIndex, CoreOccupied, DisputeStatement, DisputeStatementSet, GroupIndex, HeadData,
32+
collator_signature_payload, AvailabilityBitfield, BackedCandidate, CandidateCommitments,
33+
CandidateDescriptor, CandidateHash, CollatorId, CollatorSignature, CommittedCandidateReceipt,
34+
CompactStatement, CoreIndex, DisputeStatement, DisputeStatementSet, GroupIndex, HeadData,
3335
Id as ParaId, IndexedVec, InherentData as ParachainsInherentData, InvalidDisputeStatementKind,
3436
PersistedValidationData, SessionIndex, SigningContext, UncheckedSigned,
3537
ValidDisputeStatementKind, ValidationCode, ValidatorId, ValidatorIndex, ValidityAttestation,

polkadot/runtime/parachains/src/configuration.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,20 @@ pub struct HostConfiguration<BlockNumber> {
190190
///
191191
/// Must be non-zero.
192192
pub group_rotation_frequency: BlockNumber,
193-
/// The availability period, in blocks. This is the amount of blocks
194-
/// after inclusion that validators have to make the block available and signal its
195-
/// availability to the chain.
193+
/// The minimum availability period, in blocks.
196194
///
197-
/// Must be at least 1.
195+
/// This is the minimum amount of blocks after a core became occupied that validators have time
196+
/// to make the block available.
197+
///
198+
/// This value only has effect on group rotations. If backers backed something at the end of
199+
/// their rotation, the occupied core affects the backing group that comes afterwards. We limit
200+
/// the effect one backing group can have on the next to `paras_availability_period` blocks.
201+
///
202+
/// Within a group rotation there is no timeout as backers are only affecting themselves.
203+
///
204+
/// Must be at least 1. With a value of 1, the previous group will not be able to negatively
205+
/// affect the following group at the expense of a tight availability timeline at group
206+
/// rotation boundaries.
198207
pub paras_availability_period: BlockNumber,
199208
/// The amount of blocks ahead to schedule paras.
200209
pub scheduling_lookahead: u32,

0 commit comments

Comments
 (0)