Skip to content

Commit

Permalink
Switch node side to v2 candidate receipts (paritytech#5679)
Browse files Browse the repository at this point in the history
on top of paritytech#5423

This PR implements the plumbing work required for
paritytech#5047 . I also added
additional helper methods gated by feature "test" in primitives.

TODO:
- [x] PRDoc

---------

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
2 people authored and mordamax committed Oct 29, 2024
1 parent 3719063 commit 239048d
Show file tree
Hide file tree
Showing 122 changed files with 1,136 additions and 721 deletions.
2 changes: 1 addition & 1 deletion cumulus/client/consensus/common/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use async_trait::async_trait;
use codec::Encode;
use cumulus_client_pov_recovery::RecoveryKind;
use cumulus_primitives_core::{
relay_chain::{BlockId, BlockNumber, CoreState},
relay_chain::{vstaging::CoreState, BlockId, BlockNumber},
CumulusDigestItem, InboundDownwardMessage, InboundHrmpMessage,
};
use cumulus_relay_chain_interface::{
Expand Down
12 changes: 6 additions & 6 deletions cumulus/client/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use polkadot_node_primitives::{CollationSecondedSignal, Statement};
use polkadot_node_subsystem::messages::RuntimeApiRequest;
use polkadot_parachain_primitives::primitives::HeadData;
use polkadot_primitives::{
CandidateReceipt, CompactStatement, Hash as PHash, Id as ParaId, OccupiedCoreAssumption,
SigningContext, UncheckedSigned,
vstaging::CandidateReceiptV2 as CandidateReceipt, CompactStatement, Hash as PHash,
Id as ParaId, OccupiedCoreAssumption, SigningContext, UncheckedSigned,
};

use codec::{Decode, DecodeAll, Encode};
Expand Down Expand Up @@ -79,7 +79,7 @@ impl Decode for BlockAnnounceData {
let relay_parent = match PHash::decode(input) {
Ok(p) => p,
// For being backwards compatible, we support missing relay-chain parent.
Err(_) => receipt.descriptor.relay_parent,
Err(_) => receipt.descriptor.relay_parent(),
};

Ok(Self { receipt, statement, relay_parent })
Expand Down Expand Up @@ -108,7 +108,7 @@ impl BlockAnnounceData {
return Err(Validation::Failure { disconnect: true })
}

if HeadData(encoded_header).hash() != self.receipt.descriptor.para_head {
if HeadData(encoded_header).hash() != self.receipt.descriptor.para_head() {
tracing::debug!(
target: LOG_TARGET,
"Receipt para head hash doesn't match the hash of the header in the block announcement",
Expand Down Expand Up @@ -302,7 +302,7 @@ where
}
.map_err(|e| Box::new(BlockAnnounceError(format!("{:?}", e))) as Box<_>)?;

Ok(candidate_receipts.into_iter().map(|cr| cr.descriptor.para_head))
Ok(candidate_receipts.into_iter().map(|cr| cr.descriptor.para_head()))
}

/// Handle a block announcement with empty data (no statement) attached to it.
Expand Down Expand Up @@ -399,7 +399,7 @@ where
return Ok(e)
}

let relay_parent = block_announce_data.receipt.descriptor.relay_parent;
let relay_parent = block_announce_data.receipt.descriptor.relay_parent();

relay_chain_interface
.wait_for_block(relay_parent)
Expand Down
22 changes: 12 additions & 10 deletions cumulus/client/network/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ use futures::{executor::block_on, poll, task::Poll, FutureExt, Stream, StreamExt
use parking_lot::Mutex;
use polkadot_node_primitives::{SignedFullStatement, Statement};
use polkadot_primitives::{
vstaging::{CommittedCandidateReceiptV2, CoreState},
BlockNumber, CandidateCommitments, CandidateDescriptor, CollatorPair,
CommittedCandidateReceipt, CoreState, Hash as PHash, HeadData, InboundDownwardMessage,
InboundHrmpMessage, OccupiedCoreAssumption, PersistedValidationData, SessionIndex,
SigningContext, ValidationCodeHash, ValidatorId,
CommittedCandidateReceipt, Hash as PHash, HeadData, InboundDownwardMessage, InboundHrmpMessage,
OccupiedCoreAssumption, PersistedValidationData, SessionIndex, SigningContext,
ValidationCodeHash, ValidatorId,
};
use polkadot_test_client::{
Client as PClient, ClientBlockImportExt, DefaultTestClientBuilderExt, FullBackend as PBackend,
Expand Down Expand Up @@ -166,15 +167,15 @@ impl RelayChainInterface for DummyRelayChainInterface {
&self,
_: PHash,
_: ParaId,
) -> RelayChainResult<Option<CommittedCandidateReceipt>> {
) -> RelayChainResult<Option<CommittedCandidateReceiptV2>> {
if self.data.lock().runtime_version >=
RuntimeApiRequest::CANDIDATES_PENDING_AVAILABILITY_RUNTIME_REQUIREMENT
{
panic!("Should have used candidates_pending_availability instead");
}

if self.data.lock().has_pending_availability {
Ok(Some(dummy_candidate()))
Ok(Some(dummy_candidate().into()))
} else {
Ok(None)
}
Expand All @@ -184,15 +185,15 @@ impl RelayChainInterface for DummyRelayChainInterface {
&self,
_: PHash,
_: ParaId,
) -> RelayChainResult<Vec<CommittedCandidateReceipt>> {
) -> RelayChainResult<Vec<CommittedCandidateReceiptV2>> {
if self.data.lock().runtime_version <
RuntimeApiRequest::CANDIDATES_PENDING_AVAILABILITY_RUNTIME_REQUIREMENT
{
panic!("Should have used candidate_pending_availability instead");
}

if self.data.lock().has_pending_availability {
Ok(vec![dummy_candidate()])
Ok(vec![dummy_candidate().into()])
} else {
Ok(vec![])
}
Expand Down Expand Up @@ -412,7 +413,7 @@ async fn make_gossip_message_and_header(
validation_code_hash: ValidationCodeHash::from(PHash::random()),
},
};
let statement = Statement::Seconded(candidate_receipt);
let statement = Statement::Seconded(candidate_receipt.into());
let signed = SignedFullStatement::sign(
&keystore,
statement,
Expand Down Expand Up @@ -525,7 +526,7 @@ fn legacy_block_announce_data_handling() {

let block_data =
BlockAnnounceData::decode(&mut &data[..]).expect("Decoding works from legacy works");
assert_eq!(receipt.descriptor.relay_parent, block_data.relay_parent);
assert_eq!(receipt.descriptor.relay_parent(), block_data.relay_parent);

let data = block_data.encode();
LegacyBlockAnnounceData::decode(&mut &data[..]).expect("Decoding works");
Expand Down Expand Up @@ -600,7 +601,8 @@ async fn check_statement_seconded() {
erasure_root: PHash::random(),
signature: sp_core::sr25519::Signature::default().into(),
validation_code_hash: ValidationCodeHash::from(PHash::random()),
},
}
.into(),
},
statement: signed_statement.convert_payload().into(),
relay_parent,
Expand Down
6 changes: 5 additions & 1 deletion cumulus/client/pov-recovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ use polkadot_node_primitives::{PoV, POV_BOMB_LIMIT};
use polkadot_node_subsystem::messages::{AvailabilityRecoveryMessage, RuntimeApiRequest};
use polkadot_overseer::Handle as OverseerHandle;
use polkadot_primitives::{
CandidateReceipt, CommittedCandidateReceipt, Id as ParaId, SessionIndex,
vstaging::{
CandidateReceiptV2 as CandidateReceipt,
CommittedCandidateReceiptV2 as CommittedCandidateReceipt,
},
Id as ParaId, SessionIndex,
};

use cumulus_primitives_core::ParachainBlockData;
Expand Down
5 changes: 3 additions & 2 deletions cumulus/client/pov-recovery/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::*;
use assert_matches::assert_matches;
use codec::{Decode, Encode};
use cumulus_primitives_core::relay_chain::{
BlockId, CandidateCommitments, CandidateDescriptor, CoreIndex, CoreState,
vstaging::CoreState, BlockId, CandidateCommitments, CandidateDescriptor, CoreIndex,
};
use cumulus_relay_chain_interface::{
InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption, PHash, PHeader,
Expand Down Expand Up @@ -532,7 +532,8 @@ fn make_candidate_chain(candidate_number_range: Range<u32>) -> Vec<CommittedCand
signature: collator.sign(&[0u8; 132]).into(),
para_head: PHash::zero(),
validation_code_hash: PHash::zero().into(),
},
}
.into(),
commitments: CandidateCommitments {
head_data: head_data.encode().into(),
upward_messages: vec![].try_into().expect("empty vec fits within bounds"),
Expand Down
5 changes: 3 additions & 2 deletions cumulus/client/relay-chain-inprocess-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ use std::{
use async_trait::async_trait;
use cumulus_primitives_core::{
relay_chain::{
runtime_api::ParachainHost, Block as PBlock, BlockId, BlockNumber,
CommittedCandidateReceipt, CoreIndex, CoreState, Hash as PHash, Header as PHeader,
runtime_api::ParachainHost,
vstaging::{CommittedCandidateReceiptV2 as CommittedCandidateReceipt, CoreState},
Block as PBlock, BlockId, BlockNumber, CoreIndex, Hash as PHash, Header as PHeader,
InboundHrmpMessage, OccupiedCoreAssumption, SessionIndex, ValidationCodeHash, ValidatorId,
},
InboundDownwardMessage, ParaId, PersistedValidationData,
Expand Down
6 changes: 3 additions & 3 deletions cumulus/client/relay-chain-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ use sp_api::ApiError;
use cumulus_primitives_core::relay_chain::{BlockId, Hash as RelayHash};
pub use cumulus_primitives_core::{
relay_chain::{
BlockNumber, CommittedCandidateReceipt, CoreIndex, CoreState, Hash as PHash,
Header as PHeader, InboundHrmpMessage, OccupiedCoreAssumption, SessionIndex,
ValidationCodeHash, ValidatorId,
vstaging::{CommittedCandidateReceiptV2 as CommittedCandidateReceipt, CoreState},
BlockNumber, CoreIndex, Hash as PHash, Header as PHeader, InboundHrmpMessage,
OccupiedCoreAssumption, SessionIndex, ValidationCodeHash, ValidatorId,
},
InboundDownwardMessage, ParaId, PersistedValidationData,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use futures::{Stream, StreamExt};
use polkadot_core_primitives::{Block, BlockNumber, Hash, Header};
use polkadot_overseer::{ChainApiBackend, RuntimeApiSubsystemClient};
use polkadot_primitives::{
async_backing::{AsyncBackingParams, BackingState},
slashing, ApprovalVotingParams, CoreIndex, NodeFeatures,
async_backing::AsyncBackingParams, slashing, vstaging::async_backing::BackingState,
ApprovalVotingParams, CoreIndex, NodeFeatures,
};
use sc_authority_discovery::{AuthorityDiscovery, Error as AuthorityDiscoveryError};
use sc_client_api::AuxStore;
Expand Down Expand Up @@ -143,7 +143,10 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient {
async fn availability_cores(
&self,
at: Hash,
) -> Result<Vec<polkadot_primitives::CoreState<Hash, BlockNumber>>, sp_api::ApiError> {
) -> Result<
Vec<polkadot_primitives::vstaging::CoreState<Hash, polkadot_core_primitives::BlockNumber>>,
sp_api::ApiError,
> {
Ok(self.rpc_client.parachain_host_availability_cores(at).await?)
}

Expand Down Expand Up @@ -212,8 +215,11 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient {
async fn candidate_pending_availability(
&self,
at: Hash,
para_id: ParaId,
) -> Result<Option<polkadot_primitives::CommittedCandidateReceipt<Hash>>, sp_api::ApiError> {
para_id: cumulus_primitives_core::ParaId,
) -> Result<
Option<polkadot_primitives::vstaging::CommittedCandidateReceiptV2<Hash>>,
sp_api::ApiError,
> {
Ok(self
.rpc_client
.parachain_host_candidate_pending_availability(at, para_id)
Expand All @@ -223,7 +229,7 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient {
async fn candidate_events(
&self,
at: Hash,
) -> Result<Vec<polkadot_primitives::CandidateEvent<Hash>>, sp_api::ApiError> {
) -> Result<Vec<polkadot_primitives::vstaging::CandidateEvent<Hash>>, sp_api::ApiError> {
Ok(self.rpc_client.parachain_host_candidate_events(at).await?)
}

Expand Down Expand Up @@ -266,7 +272,8 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient {
async fn on_chain_votes(
&self,
at: Hash,
) -> Result<Option<polkadot_primitives::ScrapedOnChainVotes<Hash>>, sp_api::ApiError> {
) -> Result<Option<polkadot_primitives::vstaging::ScrapedOnChainVotes<Hash>>, sp_api::ApiError>
{
Ok(self.rpc_client.parachain_host_on_chain_votes(at).await?)
}

Expand Down Expand Up @@ -437,8 +444,11 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient {
async fn candidates_pending_availability(
&self,
at: Hash,
para_id: ParaId,
) -> Result<Vec<polkadot_primitives::CommittedCandidateReceipt<Hash>>, sp_api::ApiError> {
para_id: cumulus_primitives_core::ParaId,
) -> Result<
Vec<polkadot_primitives::vstaging::CommittedCandidateReceiptV2<Hash>>,
sp_api::ApiError,
> {
Ok(self
.rpc_client
.parachain_host_candidates_pending_availability(at, para_id)
Expand Down
5 changes: 3 additions & 2 deletions cumulus/client/relay-chain-rpc-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ use async_trait::async_trait;
use core::time::Duration;
use cumulus_primitives_core::{
relay_chain::{
CommittedCandidateReceipt, Hash as RelayHash, Header as RelayHeader, InboundHrmpMessage,
OccupiedCoreAssumption, SessionIndex, ValidationCodeHash, ValidatorId,
vstaging::CommittedCandidateReceiptV2 as CommittedCandidateReceipt, Hash as RelayHash,
Header as RelayHeader, InboundHrmpMessage, OccupiedCoreAssumption, SessionIndex,
ValidationCodeHash, ValidatorId,
},
InboundDownwardMessage, ParaId, PersistedValidationData,
};
Expand Down
19 changes: 12 additions & 7 deletions cumulus/client/relay-chain-rpc-interface/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ use codec::{Decode, Encode};

use cumulus_primitives_core::{
relay_chain::{
async_backing::{AsyncBackingParams, BackingState},
slashing, ApprovalVotingParams, BlockNumber, CandidateCommitments, CandidateEvent,
CandidateHash, CommittedCandidateReceipt, CoreIndex, CoreState, DisputeState,
ExecutorParams, GroupRotationInfo, Hash as RelayHash, Header as RelayHeader,
InboundHrmpMessage, NodeFeatures, OccupiedCoreAssumption, PvfCheckStatement,
ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash,
ValidatorId, ValidatorIndex, ValidatorSignature,
async_backing::AsyncBackingParams,
slashing,
vstaging::{
async_backing::BackingState, CandidateEvent,
CommittedCandidateReceiptV2 as CommittedCandidateReceipt, CoreState,
ScrapedOnChainVotes,
},
ApprovalVotingParams, BlockNumber, CandidateCommitments, CandidateHash, CoreIndex,
DisputeState, ExecutorParams, GroupRotationInfo, Hash as RelayHash, Header as RelayHeader,
InboundHrmpMessage, NodeFeatures, OccupiedCoreAssumption, PvfCheckStatement, SessionIndex,
SessionInfo, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
ValidatorSignature,
},
InboundDownwardMessage, ParaId, PersistedValidationData,
};
Expand Down
1 change: 1 addition & 0 deletions polkadot/node/collation-generation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ polkadot-primitives-test-helpers = { workspace = true }
assert_matches = { workspace = true }
rstest = { workspace = true }
sp-keyring = { workspace = true, default-features = true }
polkadot-primitives = { workspace = true, features = ["test"] }
10 changes: 6 additions & 4 deletions polkadot/node/collation-generation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ use polkadot_node_subsystem_util::{
request_validators, runtime::fetch_claim_queue,
};
use polkadot_primitives::{
collator_signature_payload, CandidateCommitments, CandidateDescriptor, CandidateReceipt,
CollatorPair, CoreIndex, CoreState, Hash, Id as ParaId, OccupiedCoreAssumption,
PersistedValidationData, ScheduledCore, ValidationCodeHash,
collator_signature_payload,
vstaging::{CandidateReceiptV2 as CandidateReceipt, CoreState},
CandidateCommitments, CandidateDescriptor, CollatorPair, CoreIndex, Hash, Id as ParaId,
OccupiedCoreAssumption, PersistedValidationData, ScheduledCore, ValidationCodeHash,
};
use sp_core::crypto::Pair;
use std::sync::Arc;
Expand Down Expand Up @@ -607,7 +608,8 @@ async fn construct_and_distribute_receipt(
erasure_root,
para_head: commitments.head_data.hash(),
validation_code_hash,
},
}
.into(),
};

gum::debug!(
Expand Down
Loading

0 comments on commit 239048d

Please sign in to comment.