mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 16:07:57 +00:00
Expose ClaimQueue via a runtime api and use it in collation-generation (#3580)
The PR adds two things: 1. Runtime API exposing the whole claim queue 2. Consumes the API in `collation-generation` to fetch the next scheduled `ParaEntry` for an occupied core. Related to https://github.com/paritytech/polkadot-sdk/issues/1797
This commit is contained in:
committed by
GitHub
parent
e659c4b3f7
commit
e58e854a32
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::collections::btree_map::BTreeMap;
|
||||
use std::collections::{btree_map::BTreeMap, VecDeque};
|
||||
|
||||
use schnellru::{ByLength, LruMap};
|
||||
use sp_consensus_babe::Epoch;
|
||||
@@ -23,10 +23,11 @@ use polkadot_primitives::{
|
||||
async_backing, slashing,
|
||||
vstaging::{self, ApprovalVotingParams},
|
||||
AuthorityDiscoveryId, BlockNumber, CandidateCommitments, CandidateEvent, CandidateHash,
|
||||
CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams, GroupRotationInfo, Hash,
|
||||
Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption,
|
||||
PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo,
|
||||
ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
|
||||
CommittedCandidateReceipt, CoreIndex, CoreState, DisputeState, ExecutorParams,
|
||||
GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage,
|
||||
OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes,
|
||||
SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
|
||||
ValidatorSignature,
|
||||
};
|
||||
|
||||
/// For consistency we have the same capacity for all caches. We use 128 as we'll only need that
|
||||
@@ -70,6 +71,7 @@ pub(crate) struct RequestResultCache {
|
||||
async_backing_params: LruMap<Hash, async_backing::AsyncBackingParams>,
|
||||
node_features: LruMap<SessionIndex, vstaging::NodeFeatures>,
|
||||
approval_voting_params: LruMap<SessionIndex, ApprovalVotingParams>,
|
||||
claim_queue: LruMap<Hash, BTreeMap<CoreIndex, VecDeque<ParaId>>>,
|
||||
}
|
||||
|
||||
impl Default for RequestResultCache {
|
||||
@@ -105,6 +107,7 @@ impl Default for RequestResultCache {
|
||||
para_backing_state: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
async_backing_params: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
node_features: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
claim_queue: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -525,6 +528,21 @@ impl RequestResultCache {
|
||||
) {
|
||||
self.approval_voting_params.insert(session_index, value);
|
||||
}
|
||||
|
||||
pub(crate) fn claim_queue(
|
||||
&mut self,
|
||||
relay_parent: &Hash,
|
||||
) -> Option<&BTreeMap<CoreIndex, VecDeque<ParaId>>> {
|
||||
self.claim_queue.get(relay_parent).map(|v| &*v)
|
||||
}
|
||||
|
||||
pub(crate) fn cache_claim_queue(
|
||||
&mut self,
|
||||
relay_parent: Hash,
|
||||
value: BTreeMap<CoreIndex, VecDeque<ParaId>>,
|
||||
) {
|
||||
self.claim_queue.insert(relay_parent, value);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) enum RequestResult {
|
||||
@@ -577,4 +595,5 @@ pub(crate) enum RequestResult {
|
||||
ParaBackingState(Hash, ParaId, Option<async_backing::BackingState>),
|
||||
AsyncBackingParams(Hash, async_backing::AsyncBackingParams),
|
||||
NodeFeatures(SessionIndex, vstaging::NodeFeatures),
|
||||
ClaimQueue(Hash, BTreeMap<CoreIndex, VecDeque<ParaId>>),
|
||||
}
|
||||
|
||||
@@ -177,6 +177,9 @@ where
|
||||
self.requests_cache.cache_async_backing_params(relay_parent, params),
|
||||
NodeFeatures(session_index, params) =>
|
||||
self.requests_cache.cache_node_features(session_index, params),
|
||||
ClaimQueue(relay_parent, sender) => {
|
||||
self.requests_cache.cache_claim_queue(relay_parent, sender);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,6 +332,8 @@ where
|
||||
Some(Request::NodeFeatures(index, sender))
|
||||
}
|
||||
},
|
||||
Request::ClaimQueue(sender) =>
|
||||
query!(claim_queue(), sender).map(|sender| Request::ClaimQueue(sender)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -626,5 +631,11 @@ where
|
||||
sender,
|
||||
result = (index)
|
||||
),
|
||||
Request::ClaimQueue(sender) => query!(
|
||||
ClaimQueue,
|
||||
claim_queue(),
|
||||
ver = Request::CLAIM_QUEUE_RUNTIME_REQUIREMENT,
|
||||
sender
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,15 +23,16 @@ use polkadot_primitives::{
|
||||
async_backing, slashing,
|
||||
vstaging::{ApprovalVotingParams, NodeFeatures},
|
||||
AuthorityDiscoveryId, BlockNumber, CandidateCommitments, CandidateEvent, CandidateHash,
|
||||
CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams, GroupRotationInfo,
|
||||
Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption,
|
||||
PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes, SessionIndex, SessionInfo,
|
||||
Slot, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
|
||||
CommittedCandidateReceipt, CoreIndex, CoreState, DisputeState, ExecutorParams,
|
||||
GroupRotationInfo, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage,
|
||||
OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes,
|
||||
SessionIndex, SessionInfo, Slot, ValidationCode, ValidationCodeHash, ValidatorId,
|
||||
ValidatorIndex, ValidatorSignature,
|
||||
};
|
||||
use sp_api::ApiError;
|
||||
use sp_core::testing::TaskExecutor;
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
collections::{BTreeMap, HashMap, VecDeque},
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use test_helpers::{dummy_committed_candidate_receipt, dummy_validation_code};
|
||||
@@ -286,6 +287,13 @@ impl RuntimeApiSubsystemClient for MockSubsystemClient {
|
||||
async fn disabled_validators(&self, _: Hash) -> Result<Vec<ValidatorIndex>, ApiError> {
|
||||
todo!("Not required for tests")
|
||||
}
|
||||
|
||||
async fn claim_queue(
|
||||
&self,
|
||||
_: Hash,
|
||||
) -> Result<BTreeMap<CoreIndex, VecDeque<ParaId>>, ApiError> {
|
||||
todo!("Not required for tests")
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user