Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
implement get_availability_cores by adding a new runtime api request
Browse files Browse the repository at this point in the history
  • Loading branch information
coriolinus committed Jul 27, 2020
1 parent 4f2e9a0 commit 64d8e69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
23 changes: 14 additions & 9 deletions node/core/bitfield-signing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,22 @@ async fn get_core_availability(
}

// delegates to the v1 runtime API
async fn get_availability_cores(_relay_parent: Hash, _sender: &mut mpsc::Sender<FromJob>) -> Result<Vec<CoreState>, Error> {
// pending https://github.com/paritytech/polkadot/issues/1419
unimplemented!()
async fn get_availability_cores(relay_parent: Hash, sender: &mut mpsc::Sender<FromJob>) -> Result<Vec<CoreState>, Error> {
use FromJob::RuntimeApi;
use messages::{
RuntimeApiMessage::Request,
RuntimeApiRequest::AvailabilityCores,
};

let (tx, rx) = oneshot::channel();
sender.send(RuntimeApi(Request(relay_parent, AvailabilityCores(tx)))).await?;
rx.await.map_err(Into::into)
}

// the way this function works is not intuitive:
//
// - get the scheduler roster so we have a list of cores, in order.
// - for each occupied core, fetch `candidate_pending_availability` from runtime
// - from there, we can get the `CandidateDescriptor`
// - from there, we can send a `AvailabilityStore::QueryPoV` and set the indexed bit to 1 if it returns Some(_)
// - get the list of core states from the runtime
// - for each core, concurrently determine chunk availability (see `get_core_availability`)
// - return the bitfield if there were no errors at any point in this process
// (otherwise, it's prone to false negatives)
async fn construct_availability_bitfield(
relay_parent: Hash,
validator_idx: ValidatorIndex,
Expand Down
6 changes: 4 additions & 2 deletions node/subsystem/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use polkadot_primitives::v1::{
BlockNumber, Hash,
CandidateReceipt, CommittedCandidateReceipt, PoV, ErasureChunk, BackedCandidate, Id as ParaId,
SignedAvailabilityBitfield, SigningContext, ValidatorId, ValidationCode, ValidatorIndex,
CoreAssignment, CoreOccupied, HeadData, CandidateDescriptor,
CoreAssignment, CoreOccupied, CoreState, HeadData, CandidateDescriptor,
ValidatorSignature, OmittedValidationData, AvailableData, CandidateEvent,
};
use polkadot_node_primitives::{
Expand Down Expand Up @@ -311,8 +311,10 @@ pub enum RuntimeApiRequest {
HeadData(ParaId, oneshot::Sender<HeadData>),
/// Get all events concerning candidates in the last block.
CandidateEvents(oneshot::Sender<Vec<CandidateEvent>>),
/// Get a the candidate pending availability for a particular parachain by parachain / core index
/// Get the candidate pending availability for a particular parachain by parachain / core index
CandidatePendingAvailability(ParaId, oneshot::Sender<Option<CommittedCandidateReceipt>>),
/// Get the current availability cores
AvailabilityCores(oneshot::Sender<Vec<CoreState>>),
}

/// A message to the Runtime API subsystem.
Expand Down

0 comments on commit 64d8e69

Please sign in to comment.