use futures::channel::oneshot;
use pezsc_network::{Multiaddr, ReputationChange};
use thiserror::Error;
pub use pezsc_network::IfDisconnected;
use pezkuwi_node_network_protocol::{
self as net_protocol, peer_set::PeerSet, request_response::Requests, PeerId,
};
use pezkuwi_pez_node_primitives::{
approval::{
v1::{BlockApprovalMeta, DelayTranche},
v2::{CandidateBitfield, IndirectAssignmentCertV2, IndirectSignedApprovalVoteV2},
},
AvailableData, BabeEpoch, BlockWeight, CandidateVotes, CollationGenerationConfig,
CollationSecondedSignal, DisputeMessage, DisputeStatus, ErasureChunk, PoV,
SignedDisputeStatement, SignedFullStatement, SignedFullStatementWithPVD, SubmitCollationParams,
ValidationResult,
};
use pezkuwi_primitives::{
self,
async_backing::{self, Constraints},
slashing, ApprovalVotingParams, AuthorityDiscoveryId, BackedCandidate, BlockNumber,
CandidateCommitments, CandidateEvent, CandidateHash, CandidateIndex,
CandidateReceiptV2 as CandidateReceipt,
CommittedCandidateReceiptV2 as CommittedCandidateReceipt, CoreIndex, CoreState, DisputeState,
ExecutorParams, GroupIndex, GroupRotationInfo, Hash, HeadData, Header as BlockHeader,
Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, MultiDisputeStatementSet,
NodeFeatures, OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement,
PvfExecKind as RuntimePvfExecKind, SessionIndex, SessionInfo, SignedAvailabilityBitfield,
SignedAvailabilityBitfields, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
ValidatorSignature,
};
use pezkuwi_statement_table::v2::Misbehavior;
use std::{
collections::{BTreeMap, HashMap, HashSet, VecDeque},
sync::Arc,
};
pub mod network_bridge_event;
pub use network_bridge_event::NetworkBridgeEvent;
#[derive(Debug, Copy, Clone)]
pub struct CanSecondRequest {
pub candidate_para_id: ParaId,
pub candidate_relay_parent: Hash,
pub candidate_hash: CandidateHash,
pub parent_head_data_hash: Hash,
}
#[derive(Debug)]
pub enum CandidateBackingMessage {
GetBackableCandidates(
HashMap<ParaId, Vec<(CandidateHash, Hash)>>,
oneshot::Sender<HashMap<ParaId, Vec<BackedCandidate>>>,
),
CanSecond(CanSecondRequest, oneshot::Sender<bool>),
Second(Hash, CandidateReceipt, PersistedValidationData, PoV),
Statement(Hash, SignedFullStatementWithPVD),
}
#[derive(Debug, Error)]
#[error("Validation failed with {0:?}")]
pub struct ValidationFailed(pub String);
#[derive(Debug, PartialEq)]
pub enum PreCheckOutcome {
Valid,
Invalid,
Failed,
}
#[derive(Debug)]
pub enum CandidateValidationMessage {
ValidateFromExhaustive {
validation_data: PersistedValidationData,
validation_code: ValidationCode,
candidate_receipt: CandidateReceipt,
pov: Arc<PoV>,
executor_params: ExecutorParams,
exec_kind: PvfExecKind,
response_sender: oneshot::Sender<Result<ValidationResult, ValidationFailed>>,
},
PreCheck {
relay_parent: Hash,
validation_code_hash: ValidationCodeHash,
response_sender: oneshot::Sender<PreCheckOutcome>,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PvfExecKind {
Dispute,
Approval,
BackingSystemParas(Hash),
Backing(Hash),
}
impl PvfExecKind {
pub fn as_str(&self) -> &str {
match *self {
Self::Dispute => "dispute",
Self::Approval => "approval",
Self::BackingSystemParas(_) => "backing_system_paras",
Self::Backing(_) => "backing",
}
}
}
impl From<PvfExecKind> for RuntimePvfExecKind {
fn from(exec: PvfExecKind) -> Self {
match exec {
PvfExecKind::Dispute => RuntimePvfExecKind::Approval,
PvfExecKind::Approval => RuntimePvfExecKind::Approval,
PvfExecKind::BackingSystemParas(_) => RuntimePvfExecKind::Backing,
PvfExecKind::Backing(_) => RuntimePvfExecKind::Backing,
}
}
}
#[derive(Debug, derive_more::From)]
pub enum CollatorProtocolMessage {
CollateOn(ParaId),
DistributeCollation {
candidate_receipt: CandidateReceipt,
parent_head_data_hash: Hash,
pov: PoV,
parent_head_data: HeadData,
result_sender: Option<oneshot::Sender<CollationSecondedSignal>>,
core_index: CoreIndex,
},
#[from]
NetworkBridgeUpdate(NetworkBridgeEvent<net_protocol::CollatorProtocolMessage>),
Invalid(Hash, CandidateReceipt),
Seconded(Hash, SignedFullStatement),
ConnectToBackingGroups,
DisconnectFromBackingGroups,
}
impl Default for CollatorProtocolMessage {
fn default() -> Self {
Self::CollateOn(Default::default())
}
}
#[derive(Debug)]
pub enum DisputeCoordinatorMessage {
ImportStatements {
candidate_receipt: CandidateReceipt,
session: SessionIndex,
statements: Vec<(SignedDisputeStatement, ValidatorIndex)>,
pending_confirmation: Option<oneshot::Sender<ImportStatementsResult>>,
},
RecentDisputes(oneshot::Sender<BTreeMap<(SessionIndex, CandidateHash), DisputeStatus>>),
ActiveDisputes(oneshot::Sender<BTreeMap<(SessionIndex, CandidateHash), DisputeStatus>>),
QueryCandidateVotes(
Vec<(SessionIndex, CandidateHash)>,
oneshot::Sender<Vec<(SessionIndex, CandidateHash, CandidateVotes)>>,
),
IssueLocalStatement(SessionIndex, CandidateHash, CandidateReceipt, bool),
DetermineUndisputedChain {
base: (BlockNumber, Hash),
block_descriptions: Vec<BlockDescription>,
tx: oneshot::Sender<(BlockNumber, Hash)>,
},
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ImportStatementsResult {
InvalidImport,
ValidImport,
}
#[derive(Debug)]
pub enum DisputeDistributionMessage {
SendDispute(DisputeMessage),
}
#[derive(Debug)]
pub enum NetworkBridgeRxMessage {
NewGossipTopology {
session: SessionIndex,
local_index: Option<ValidatorIndex>,
canonical_shuffling: Vec<(AuthorityDiscoveryId, ValidatorIndex)>,
shuffled_indices: Vec<usize>,
},
UpdatedAuthorityIds {
peer_id: PeerId,
authority_ids: HashSet<AuthorityDiscoveryId>,
},
}
#[derive(Debug)]
pub enum ReportPeerMessage {
Single(PeerId, ReputationChange),
Batch(HashMap<PeerId, i32>),
}
#[derive(Debug)]
pub enum NetworkBridgeTxMessage {
ReportPeer(ReportPeerMessage),
DisconnectPeers(Vec<PeerId>, PeerSet),
SendValidationMessage(Vec<PeerId>, net_protocol::VersionedValidationProtocol),
SendCollationMessage(Vec<PeerId>, net_protocol::VersionedCollationProtocol),
SendValidationMessages(Vec<(Vec<PeerId>, net_protocol::VersionedValidationProtocol)>),
SendCollationMessages(Vec<(Vec<PeerId>, net_protocol::VersionedCollationProtocol)>),
SendRequests(Vec<Requests>, IfDisconnected),
ConnectToValidators {
validator_ids: Vec<AuthorityDiscoveryId>,
peer_set: PeerSet,
failed: oneshot::Sender<usize>,
},
ConnectToResolvedValidators {
validator_addrs: Vec<HashSet<Multiaddr>>,
peer_set: PeerSet,
},
AddToResolvedValidators {
validator_addrs: Vec<HashSet<Multiaddr>>,
peer_set: PeerSet,
},
}
#[derive(Debug)]
pub enum AvailabilityDistributionMessage {
FetchPoV {
relay_parent: Hash,
from_validator: ValidatorIndex,
para_id: ParaId,
candidate_hash: CandidateHash,
pov_hash: Hash,
tx: oneshot::Sender<PoV>,
},
}
#[derive(Debug, derive_more::From)]
pub enum AvailabilityRecoveryMessage {
RecoverAvailableData(
CandidateReceipt,
SessionIndex,
Option<GroupIndex>, Option<CoreIndex>,
oneshot::Sender<Result<AvailableData, crate::errors::RecoveryError>>,
),
}
#[derive(Debug, derive_more::From)]
pub enum BitfieldDistributionMessage {
DistributeBitfield(Hash, SignedAvailabilityBitfield),
#[from]
NetworkBridgeUpdate(NetworkBridgeEvent<net_protocol::BitfieldDistributionMessage>),
}
#[derive(Debug)]
pub enum AvailabilityStoreMessage {
QueryAvailableData(CandidateHash, oneshot::Sender<Option<AvailableData>>),
QueryDataAvailability(CandidateHash, oneshot::Sender<bool>),
QueryChunk(CandidateHash, ValidatorIndex, oneshot::Sender<Option<ErasureChunk>>),
QueryChunkSize(CandidateHash, oneshot::Sender<Option<usize>>),
QueryAllChunks(CandidateHash, oneshot::Sender<Vec<(ValidatorIndex, ErasureChunk)>>),
QueryChunkAvailability(CandidateHash, ValidatorIndex, oneshot::Sender<bool>),
StoreChunk {
candidate_hash: CandidateHash,
validator_index: ValidatorIndex,
chunk: ErasureChunk,
tx: oneshot::Sender<Result<(), ()>>,
},
StoreAvailableData {
candidate_hash: CandidateHash,
n_validators: u32,
available_data: AvailableData,
expected_erasure_root: Hash,
core_index: CoreIndex,
node_features: NodeFeatures,
tx: oneshot::Sender<Result<(), StoreAvailableDataError>>,
},
}
#[derive(Error, Debug, Clone, PartialEq, Eq)]
#[allow(missing_docs)]
pub enum StoreAvailableDataError {
#[error("The computed erasure root did not match expected one")]
InvalidErasureRoot,
}
pub type ChainApiResponseChannel<T> = oneshot::Sender<Result<T, crate::errors::ChainApiError>>;
#[derive(Debug)]
pub enum ChainApiMessage {
BlockNumber(Hash, ChainApiResponseChannel<Option<BlockNumber>>),
BlockHeader(Hash, ChainApiResponseChannel<Option<BlockHeader>>),
BlockWeight(Hash, ChainApiResponseChannel<Option<BlockWeight>>),
FinalizedBlockHash(BlockNumber, ChainApiResponseChannel<Option<Hash>>),
FinalizedBlockNumber(ChainApiResponseChannel<BlockNumber>),
Ancestors {
hash: Hash,
k: usize,
response_channel: ChainApiResponseChannel<Vec<Hash>>,
},
}
#[derive(Debug)]
pub enum ChainSelectionMessage {
Approved(Hash),
Leaves(oneshot::Sender<Vec<Hash>>),
BestLeafContaining(Hash, oneshot::Sender<Option<Hash>>),
RevertBlocks(Vec<(BlockNumber, Hash)>),
}
pub type RuntimeApiSender<T> = oneshot::Sender<Result<T, crate::errors::RuntimeApiError>>;
#[derive(Debug)]
pub enum RuntimeApiRequest {
Version(RuntimeApiSender<u32>),
Authorities(RuntimeApiSender<Vec<AuthorityDiscoveryId>>),
Validators(RuntimeApiSender<Vec<ValidatorId>>),
ValidatorGroups(RuntimeApiSender<(Vec<Vec<ValidatorIndex>>, GroupRotationInfo)>),
AvailabilityCores(RuntimeApiSender<Vec<CoreState>>),
PersistedValidationData(
ParaId,
OccupiedCoreAssumption,
RuntimeApiSender<Option<PersistedValidationData>>,
),
AssumedValidationData(
ParaId,
Hash,
RuntimeApiSender<Option<(PersistedValidationData, ValidationCodeHash)>>,
),
CheckValidationOutputs(
ParaId,
pezkuwi_primitives::CandidateCommitments,
RuntimeApiSender<bool>,
),
SessionIndexForChild(RuntimeApiSender<SessionIndex>),
ValidationCode(ParaId, OccupiedCoreAssumption, RuntimeApiSender<Option<ValidationCode>>),
ValidationCodeByHash(ValidationCodeHash, RuntimeApiSender<Option<ValidationCode>>),
CandidatePendingAvailability(ParaId, RuntimeApiSender<Option<CommittedCandidateReceipt>>),
CandidateEvents(RuntimeApiSender<Vec<CandidateEvent>>),
SessionExecutorParams(SessionIndex, RuntimeApiSender<Option<ExecutorParams>>),
SessionInfo(SessionIndex, RuntimeApiSender<Option<SessionInfo>>),
DmqContents(ParaId, RuntimeApiSender<Vec<InboundDownwardMessage<BlockNumber>>>),
InboundHrmpChannelsContents(
ParaId,
RuntimeApiSender<BTreeMap<ParaId, Vec<InboundHrmpMessage<BlockNumber>>>>,
),
CurrentBabeEpoch(RuntimeApiSender<BabeEpoch>),
FetchOnChainVotes(RuntimeApiSender<Option<pezkuwi_primitives::ScrapedOnChainVotes>>),
SubmitPvfCheckStatement(PvfCheckStatement, ValidatorSignature, RuntimeApiSender<()>),
PvfsRequirePrecheck(RuntimeApiSender<Vec<ValidationCodeHash>>),
ValidationCodeHash(
ParaId,
OccupiedCoreAssumption,
RuntimeApiSender<Option<ValidationCodeHash>>,
),
Disputes(RuntimeApiSender<Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>>),
UnappliedSlashes(
RuntimeApiSender<Vec<(SessionIndex, CandidateHash, slashing::LegacyPendingSlashes)>>,
),
KeyOwnershipProof(ValidatorId, RuntimeApiSender<Option<slashing::OpaqueKeyOwnershipProof>>),
SubmitReportDisputeLost(
slashing::DisputeProof,
slashing::OpaqueKeyOwnershipProof,
RuntimeApiSender<Option<()>>,
),
MinimumBackingVotes(SessionIndex, RuntimeApiSender<u32>),
DisabledValidators(RuntimeApiSender<Vec<ValidatorIndex>>),
ParaBackingState(ParaId, RuntimeApiSender<Option<async_backing::BackingState>>),
AsyncBackingParams(RuntimeApiSender<async_backing::AsyncBackingParams>),
NodeFeatures(SessionIndex, RuntimeApiSender<NodeFeatures>),
ApprovalVotingParams(SessionIndex, RuntimeApiSender<ApprovalVotingParams>),
ClaimQueue(RuntimeApiSender<BTreeMap<CoreIndex, VecDeque<ParaId>>>),
CandidatesPendingAvailability(ParaId, RuntimeApiSender<Vec<CommittedCandidateReceipt>>),
BackingConstraints(ParaId, RuntimeApiSender<Option<Constraints>>),
SchedulingLookahead(SessionIndex, RuntimeApiSender<u32>),
ValidationCodeBombLimit(SessionIndex, RuntimeApiSender<u32>),
ParaIds(SessionIndex, RuntimeApiSender<Vec<ParaId>>),
UnappliedSlashesV2(
RuntimeApiSender<Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>>,
),
}
impl RuntimeApiRequest {
pub const DISPUTES_RUNTIME_REQUIREMENT: u32 = 3;
pub const EXECUTOR_PARAMS_RUNTIME_REQUIREMENT: u32 = 4;
pub const UNAPPLIED_SLASHES_RUNTIME_REQUIREMENT: u32 = 5;
pub const KEY_OWNERSHIP_PROOF_RUNTIME_REQUIREMENT: u32 = 5;
pub const SUBMIT_REPORT_DISPUTE_LOST_RUNTIME_REQUIREMENT: u32 = 5;
pub const MINIMUM_BACKING_VOTES_RUNTIME_REQUIREMENT: u32 = 6;
pub const ASYNC_BACKING_STATE_RUNTIME_REQUIREMENT: u32 = 7;
pub const DISABLED_VALIDATORS_RUNTIME_REQUIREMENT: u32 = 8;
pub const NODE_FEATURES_RUNTIME_REQUIREMENT: u32 = 9;
pub const APPROVAL_VOTING_PARAMS_REQUIREMENT: u32 = 10;
pub const CLAIM_QUEUE_RUNTIME_REQUIREMENT: u32 = 11;
pub const CANDIDATES_PENDING_AVAILABILITY_RUNTIME_REQUIREMENT: u32 = 11;
pub const VALIDATION_CODE_BOMB_LIMIT_RUNTIME_REQUIREMENT: u32 = 12;
pub const CONSTRAINTS_RUNTIME_REQUIREMENT: u32 = 13;
pub const SCHEDULING_LOOKAHEAD_RUNTIME_REQUIREMENT: u32 = 13;
pub const PARAIDS_RUNTIME_REQUIREMENT: u32 = 14;
pub const UNAPPLIED_SLASHES_V2_RUNTIME_REQUIREMENT: u32 = 15;
}
#[derive(Debug)]
pub enum RuntimeApiMessage {
Request(Hash, RuntimeApiRequest),
}
#[derive(Debug, derive_more::From)]
pub enum StatementDistributionMessage {
Share(Hash, SignedFullStatementWithPVD),
Backed(CandidateHash),
#[from]
NetworkBridgeUpdate(NetworkBridgeEvent<net_protocol::StatementDistributionMessage>),
}
#[derive(Debug, Clone)]
pub enum ProvisionableData {
Bitfield(Hash, SignedAvailabilityBitfield),
MisbehaviorReport(Hash, ValidatorIndex, Misbehavior),
Dispute(Hash, ValidatorSignature),
}
#[derive(Debug, Clone)]
pub struct ProvisionerInherentData {
pub bitfields: SignedAvailabilityBitfields,
pub backed_candidates: Vec<BackedCandidate>,
pub disputes: MultiDisputeStatementSet,
}
#[derive(Debug)]
pub enum ProvisionerMessage {
RequestInherentData(Hash, oneshot::Sender<ProvisionerInherentData>),
ProvisionableData(Hash, ProvisionableData),
}
#[derive(Debug)]
pub enum CollationGenerationMessage {
Initialize(CollationGenerationConfig),
Reinitialize(CollationGenerationConfig),
SubmitCollation(SubmitCollationParams),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AssignmentCheckResult {
Accepted,
AcceptedDuplicate,
TooFarInFuture,
Bad(AssignmentCheckError),
}
#[derive(Error, Debug, Clone, PartialEq, Eq)]
#[allow(missing_docs)]
pub enum AssignmentCheckError {
#[error("Unknown block: {0:?}")]
UnknownBlock(Hash),
#[error("Unknown session index: {0}")]
UnknownSessionIndex(SessionIndex),
#[error("Invalid candidate index: {0}")]
InvalidCandidateIndex(CandidateIndex),
#[error("Invalid candidate {0}: {1:?}")]
InvalidCandidate(CandidateIndex, CandidateHash),
#[error("Invalid cert: {0:?}, reason: {1}")]
InvalidCert(ValidatorIndex, String),
#[error("Internal state mismatch: {0:?}, {1:?}")]
Internal(Hash, CandidateHash),
#[error("Oversized candidate or core bitfield >= {0}")]
InvalidBitfield(usize),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ApprovalCheckResult {
Accepted,
Bad(ApprovalCheckError),
}
#[derive(Error, Debug, Clone, PartialEq, Eq)]
#[allow(missing_docs)]
pub enum ApprovalCheckError {
#[error("Unknown block: {0:?}")]
UnknownBlock(Hash),
#[error("Unknown session index: {0}")]
UnknownSessionIndex(SessionIndex),
#[error("Invalid candidate index: {0}")]
InvalidCandidateIndex(CandidateIndex),
#[error("Invalid validator index: {0:?}")]
InvalidValidatorIndex(ValidatorIndex),
#[error("Invalid candidate {0}: {1:?}")]
InvalidCandidate(CandidateIndex, CandidateHash),
#[error("Invalid signature: {0:?}")]
InvalidSignature(ValidatorIndex),
#[error("No assignment for {0:?}")]
NoAssignment(ValidatorIndex),
#[error("Internal state mismatch: {0:?}, {1:?}")]
Internal(Hash, CandidateHash),
}
#[derive(Clone, Debug)]
pub struct BlockDescription {
pub block_hash: Hash,
pub session: SessionIndex,
pub candidates: Vec<CandidateHash>,
}
#[derive(Debug, derive_more::From)]
pub enum ApprovalVotingParallelMessage {
ApprovedAncestor(Hash, BlockNumber, oneshot::Sender<Option<HighestApprovedAncestorBlock>>),
GetApprovalSignaturesForCandidate(
CandidateHash,
oneshot::Sender<HashMap<ValidatorIndex, (Vec<CandidateHash>, ValidatorSignature)>>,
),
NewBlocks(Vec<BlockApprovalMeta>),
DistributeAssignment(IndirectAssignmentCertV2, CandidateBitfield),
DistributeApproval(IndirectSignedApprovalVoteV2),
#[from]
NetworkBridgeUpdate(NetworkBridgeEvent<net_protocol::ApprovalDistributionMessage>),
GetApprovalSignatures(
HashSet<(Hash, CandidateIndex)>,
oneshot::Sender<HashMap<ValidatorIndex, (Hash, Vec<CandidateIndex>, ValidatorSignature)>>,
),
ApprovalCheckingLagUpdate(BlockNumber),
}
impl TryFrom<ApprovalVotingParallelMessage> for ApprovalVotingMessage {
type Error = ();
fn try_from(msg: ApprovalVotingParallelMessage) -> Result<Self, Self::Error> {
match msg {
ApprovalVotingParallelMessage::ApprovedAncestor(hash, number, tx) => {
Ok(ApprovalVotingMessage::ApprovedAncestor(hash, number, tx))
},
ApprovalVotingParallelMessage::GetApprovalSignaturesForCandidate(candidate, tx) => {
Ok(ApprovalVotingMessage::GetApprovalSignaturesForCandidate(candidate, tx))
},
_ => Err(()),
}
}
}
impl TryFrom<ApprovalVotingParallelMessage> for ApprovalDistributionMessage {
type Error = ();
fn try_from(msg: ApprovalVotingParallelMessage) -> Result<Self, Self::Error> {
match msg {
ApprovalVotingParallelMessage::NewBlocks(blocks) => {
Ok(ApprovalDistributionMessage::NewBlocks(blocks))
},
ApprovalVotingParallelMessage::DistributeAssignment(assignment, claimed_cores) => {
Ok(ApprovalDistributionMessage::DistributeAssignment(assignment, claimed_cores))
},
ApprovalVotingParallelMessage::DistributeApproval(vote) => {
Ok(ApprovalDistributionMessage::DistributeApproval(vote))
},
ApprovalVotingParallelMessage::NetworkBridgeUpdate(msg) => {
Ok(ApprovalDistributionMessage::NetworkBridgeUpdate(msg))
},
ApprovalVotingParallelMessage::GetApprovalSignatures(candidate_indicies, tx) => {
Ok(ApprovalDistributionMessage::GetApprovalSignatures(candidate_indicies, tx))
},
ApprovalVotingParallelMessage::ApprovalCheckingLagUpdate(lag) => {
Ok(ApprovalDistributionMessage::ApprovalCheckingLagUpdate(lag))
},
_ => Err(()),
}
}
}
impl From<ApprovalDistributionMessage> for ApprovalVotingParallelMessage {
fn from(msg: ApprovalDistributionMessage) -> Self {
match msg {
ApprovalDistributionMessage::NewBlocks(blocks) => {
ApprovalVotingParallelMessage::NewBlocks(blocks)
},
ApprovalDistributionMessage::DistributeAssignment(cert, bitfield) => {
ApprovalVotingParallelMessage::DistributeAssignment(cert, bitfield)
},
ApprovalDistributionMessage::DistributeApproval(vote) => {
ApprovalVotingParallelMessage::DistributeApproval(vote)
},
ApprovalDistributionMessage::NetworkBridgeUpdate(msg) => {
ApprovalVotingParallelMessage::NetworkBridgeUpdate(msg)
},
ApprovalDistributionMessage::GetApprovalSignatures(candidate_indicies, tx) => {
ApprovalVotingParallelMessage::GetApprovalSignatures(candidate_indicies, tx)
},
ApprovalDistributionMessage::ApprovalCheckingLagUpdate(lag) => {
ApprovalVotingParallelMessage::ApprovalCheckingLagUpdate(lag)
},
}
}
}
#[derive(Clone, Debug)]
pub struct HighestApprovedAncestorBlock {
pub hash: Hash,
pub number: BlockNumber,
pub descriptions: Vec<BlockDescription>,
}
#[derive(Debug)]
pub struct CheckedIndirectAssignment {
assignment: IndirectAssignmentCertV2,
candidate_indices: CandidateBitfield,
tranche: DelayTranche,
}
impl CheckedIndirectAssignment {
pub fn from_checked(
assignment: IndirectAssignmentCertV2,
claimed_candidate_indices: CandidateBitfield,
tranche: DelayTranche,
) -> Self {
Self { assignment, candidate_indices: claimed_candidate_indices, tranche }
}
pub fn assignment(&self) -> &IndirectAssignmentCertV2 {
&self.assignment
}
pub fn candidate_indices(&self) -> &CandidateBitfield {
&self.candidate_indices
}
pub fn tranche(&self) -> DelayTranche {
self.tranche
}
}
#[derive(Debug, derive_more::Deref, derive_more::Into)]
pub struct CheckedIndirectSignedApprovalVote(IndirectSignedApprovalVoteV2);
impl CheckedIndirectSignedApprovalVote {
pub fn from_checked(vote: IndirectSignedApprovalVoteV2) -> Self {
Self(vote)
}
}
#[derive(Debug)]
pub enum ApprovalVotingMessage {
ImportAssignment(CheckedIndirectAssignment, Option<oneshot::Sender<AssignmentCheckResult>>),
ImportApproval(CheckedIndirectSignedApprovalVote, Option<oneshot::Sender<ApprovalCheckResult>>),
ApprovedAncestor(Hash, BlockNumber, oneshot::Sender<Option<HighestApprovedAncestorBlock>>),
GetApprovalSignaturesForCandidate(
CandidateHash,
oneshot::Sender<HashMap<ValidatorIndex, (Vec<CandidateHash>, ValidatorSignature)>>,
),
}
#[derive(Debug, derive_more::From)]
pub enum ApprovalDistributionMessage {
NewBlocks(Vec<BlockApprovalMeta>),
DistributeAssignment(IndirectAssignmentCertV2, CandidateBitfield),
DistributeApproval(IndirectSignedApprovalVoteV2),
#[from]
NetworkBridgeUpdate(NetworkBridgeEvent<net_protocol::ApprovalDistributionMessage>),
GetApprovalSignatures(
HashSet<(Hash, CandidateIndex)>,
oneshot::Sender<HashMap<ValidatorIndex, (Hash, Vec<CandidateIndex>, ValidatorSignature)>>,
),
ApprovalCheckingLagUpdate(BlockNumber),
}
#[derive(Debug, derive_more::From)]
pub enum GossipSupportMessage {
#[from]
NetworkBridgeUpdate(NetworkBridgeEvent<net_protocol::GossipSupportNetworkMessage>),
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct IntroduceSecondedCandidateRequest {
pub candidate_para: ParaId,
pub candidate_receipt: CommittedCandidateReceipt,
pub persisted_validation_data: PersistedValidationData,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum HypotheticalCandidate {
Complete {
candidate_hash: CandidateHash,
receipt: Arc<CommittedCandidateReceipt>,
persisted_validation_data: PersistedValidationData,
},
Incomplete {
candidate_hash: CandidateHash,
candidate_para: ParaId,
parent_head_data_hash: Hash,
candidate_relay_parent: Hash,
},
}
impl HypotheticalCandidate {
pub fn candidate_hash(&self) -> CandidateHash {
match *self {
HypotheticalCandidate::Complete { candidate_hash, .. } => candidate_hash,
HypotheticalCandidate::Incomplete { candidate_hash, .. } => candidate_hash,
}
}
pub fn candidate_para(&self) -> ParaId {
match *self {
HypotheticalCandidate::Complete { ref receipt, .. } => receipt.descriptor.para_id(),
HypotheticalCandidate::Incomplete { candidate_para, .. } => candidate_para,
}
}
pub fn parent_head_data_hash(&self) -> Hash {
match *self {
HypotheticalCandidate::Complete { ref persisted_validation_data, .. } => {
persisted_validation_data.parent_head.hash()
},
HypotheticalCandidate::Incomplete { parent_head_data_hash, .. } => {
parent_head_data_hash
},
}
}
pub fn relay_parent(&self) -> Hash {
match *self {
HypotheticalCandidate::Complete { ref receipt, .. } => {
receipt.descriptor.relay_parent()
},
HypotheticalCandidate::Incomplete { candidate_relay_parent, .. } => {
candidate_relay_parent
},
}
}
pub fn output_head_data_hash(&self) -> Option<Hash> {
match *self {
HypotheticalCandidate::Complete { ref receipt, .. } => {
Some(receipt.descriptor.para_head())
},
HypotheticalCandidate::Incomplete { .. } => None,
}
}
pub fn commitments(&self) -> Option<&CandidateCommitments> {
match *self {
HypotheticalCandidate::Complete { ref receipt, .. } => Some(&receipt.commitments),
HypotheticalCandidate::Incomplete { .. } => None,
}
}
pub fn persisted_validation_data(&self) -> Option<&PersistedValidationData> {
match *self {
HypotheticalCandidate::Complete { ref persisted_validation_data, .. } => {
Some(persisted_validation_data)
},
HypotheticalCandidate::Incomplete { .. } => None,
}
}
pub fn validation_code_hash(&self) -> Option<ValidationCodeHash> {
match *self {
HypotheticalCandidate::Complete { ref receipt, .. } => {
Some(receipt.descriptor.validation_code_hash())
},
HypotheticalCandidate::Incomplete { .. } => None,
}
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct HypotheticalMembershipRequest {
pub candidates: Vec<HypotheticalCandidate>,
pub fragment_chain_relay_parent: Option<Hash>,
}
#[derive(Debug)]
pub struct ProspectiveValidationDataRequest {
pub para_id: ParaId,
pub candidate_relay_parent: Hash,
pub parent_head_data: ParentHeadData,
}
#[derive(Debug, Clone)]
pub enum ParentHeadData {
OnlyHash(Hash),
WithData {
head_data: HeadData,
hash: Hash,
},
}
impl ParentHeadData {
pub fn hash(&self) -> Hash {
match self {
ParentHeadData::OnlyHash(hash) => *hash,
ParentHeadData::WithData { hash, .. } => *hash,
}
}
}
pub type HypotheticalMembership = Vec<Hash>;
pub type Ancestors = HashSet<CandidateHash>;
#[derive(Debug)]
pub enum ProspectiveTeyrchainsMessage {
IntroduceSecondedCandidate(IntroduceSecondedCandidateRequest, oneshot::Sender<bool>),
CandidateBacked(ParaId, CandidateHash),
GetBackableCandidates(
Hash,
ParaId,
u32,
Ancestors,
oneshot::Sender<Vec<(CandidateHash, Hash)>>,
),
GetHypotheticalMembership(
HypotheticalMembershipRequest,
oneshot::Sender<Vec<(HypotheticalCandidate, HypotheticalMembership)>>,
),
GetMinimumRelayParents(Hash, oneshot::Sender<Vec<(ParaId, BlockNumber)>>),
GetProspectiveValidationData(
ProspectiveValidationDataRequest,
oneshot::Sender<Option<PersistedValidationData>>,
),
}