From 69cc7f2090e169e736d9c998c29467040521881d Mon Sep 17 00:00:00 2001
From: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
Date: Thu, 11 Apr 2024 11:37:12 +0300
Subject: [PATCH] Fix ClaimQueue case of nothing scheduled on session boundary 
 (#4065)

Same issue but about av-cores was fixed in
https://github.com/paritytech/polkadot-sdk/pull/1403

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
---
 .../parachains/src/runtime_api_impl/vstaging.rs    | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs b/polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs
index 046f6041f0b..9ea29a2d374 100644
--- a/polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs
+++ b/polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs
@@ -18,10 +18,22 @@
 
 use crate::scheduler;
 use primitives::{CoreIndex, Id as ParaId};
-use sp_std::collections::{btree_map::BTreeMap, vec_deque::VecDeque};
+use sp_runtime::traits::One;
+use sp_std::{
+	collections::{btree_map::BTreeMap, vec_deque::VecDeque},
+	vec::Vec,
+};
 
 /// Returns the claimqueue from the scheduler
 pub fn claim_queue<T: scheduler::Config>() -> BTreeMap<CoreIndex, VecDeque<ParaId>> {
+	let now = <frame_system::Pallet<T>>::block_number() + One::one();
+
+	// This explicit update is only strictly required for session boundaries:
+	//
+	// At the end of a session we clear the claim queues: Without this update call, nothing would be
+	// scheduled to the client.
+	<scheduler::Pallet<T>>::free_cores_and_fill_claimqueue(Vec::new(), now);
+
 	scheduler::ClaimQueue::<T>::get()
 		.into_iter()
 		.map(|(core_index, entries)| {
-- 
GitLab