Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elastic scaling: introduce new candidate receipt primitive #5322

Merged
merged 43 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
793142e
WIP primitives
sandreim Jul 17, 2024
3a29fdf
WIP
sandreim Aug 5, 2024
4a53577
Working version.
sandreim Aug 7, 2024
8285ae7
Better version
sandreim Aug 8, 2024
2831c5e
Add missing primitives and fix things
sandreim Aug 8, 2024
c767d60
Implement v2 receipts in polkadot-runtime-parachains
sandreim Aug 8, 2024
96999e3
add missing stuff
sandreim Aug 12, 2024
c5f2dc3
Switch parachains runtime to use new primitives
sandreim Aug 12, 2024
dbb0160
use vstaging primitives
sandreim Aug 12, 2024
5efab68
update rococo and westend
sandreim Aug 12, 2024
c2232e4
client keeps using the old primitives
sandreim Aug 12, 2024
87b079f
no unsafe pls
sandreim Aug 12, 2024
00e8c13
move async backing primtiives to own file
sandreim Aug 12, 2024
cd4d02f
fix
sandreim Aug 12, 2024
5509e33
fix test build
sandreim Aug 12, 2024
f8b86d2
fix test-runtime
sandreim Aug 12, 2024
fe2fbfb
self review feedback
sandreim Aug 13, 2024
975e13b
review feedback
sandreim Aug 13, 2024
1c7ac55
feedback
sandreim Aug 13, 2024
653873b
feedback
sandreim Aug 13, 2024
dc98149
clippy
sandreim Aug 13, 2024
0a6bce3
chores
sandreim Aug 13, 2024
4296942
simplify check()
sandreim Aug 19, 2024
6fb7790
impl<H>
sandreim Aug 20, 2024
d0b3961
comment
sandreim Aug 20, 2024
66f7a96
add some tests
sandreim Aug 20, 2024
5c0c919
update
sandreim Aug 20, 2024
38ce589
prdoc
sandreim Aug 21, 2024
9f1d611
can't be happy if CI is sad
sandreim Aug 21, 2024
a6a7329
Merge branch 'master' of github.com:paritytech/polkadot-sdk into sand…
sandreim Aug 21, 2024
663817d
remove newlines
sandreim Aug 21, 2024
a1dacc1
match rfc 103 reserved field naming
sandreim Aug 21, 2024
33b80ea
remove default cq offset
sandreim Aug 21, 2024
1db5eb0
Para Inherent: filter v2 candidate descriptors (#5362)
sandreim Aug 22, 2024
984e8e1
add unknown version
sandreim Aug 29, 2024
fab215d
add check for unknown version and test
sandreim Aug 29, 2024
7300552
Merge branch 'sandreim/rfc103-primitives' of github.com:paritytech/po…
sandreim Aug 29, 2024
9bbe2cc
typo
sandreim Aug 29, 2024
cd3eb5f
Merge branch 'master' of github.com:paritytech/polkadot-sdk into sand…
sandreim Aug 30, 2024
f8ef4ce
fix merge damage
sandreim Aug 30, 2024
04e31a1
unused
sandreim Aug 30, 2024
5fd1279
fix
sandreim Aug 30, 2024
19d6f32
fix benchmark build
sandreim Sep 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions cumulus/client/relay-chain-inprocess-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ impl RelayChainInterface for RelayChainInProcessInterface {
hash: PHash,
para_id: ParaId,
) -> RelayChainResult<Option<CommittedCandidateReceipt>> {
Ok(self.full_client.runtime_api().candidate_pending_availability(hash, para_id)?)
Ok(self
.full_client
.runtime_api()
.candidate_pending_availability(hash, para_id)?
.map(|receipt| receipt.into()))
}

async fn session_index_for_child(&self, hash: PHash) -> RelayChainResult<SessionIndex> {
Expand Down Expand Up @@ -260,15 +264,27 @@ impl RelayChainInterface for RelayChainInProcessInterface {
&self,
relay_parent: PHash,
) -> RelayChainResult<Vec<CoreState<PHash, BlockNumber>>> {
Ok(self.full_client.runtime_api().availability_cores(relay_parent)?)
Ok(self
.full_client
.runtime_api()
.availability_cores(relay_parent)?
.into_iter()
.map(|core_state| core_state.into())
.collect::<Vec<_>>())
}

async fn candidates_pending_availability(
&self,
hash: PHash,
para_id: ParaId,
) -> RelayChainResult<Vec<CommittedCandidateReceipt>> {
Ok(self.full_client.runtime_api().candidates_pending_availability(hash, para_id)?)
Ok(self
.full_client
.runtime_api()
.candidates_pending_availability(hash, para_id)?
.into_iter()
.map(|receipt| receipt.into())
.collect::<Vec<_>>())
}
}

Expand Down
16 changes: 10 additions & 6 deletions polkadot/node/service/src/fake_runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@

use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
use polkadot_primitives::{
runtime_api, slashing, AccountId, AuthorityDiscoveryId, Balance, Block, BlockNumber,
CandidateCommitments, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState,
DisputeState, ExecutorParams, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage,
InboundHrmpMessage, Nonce, OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement,
ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash,
ValidatorId, ValidatorIndex, ValidatorSignature,
runtime_api, slashing,
vstaging::{
CandidateEvent, CommittedCandidateReceiptV2 as CommittedCandidateReceipt, CoreState,
ScrapedOnChainVotes,
},
AccountId, AuthorityDiscoveryId, Balance, Block, BlockNumber, CandidateCommitments,
CandidateHash, DisputeState, ExecutorParams, GroupRotationInfo, Hash, Id as ParaId,
InboundDownwardMessage, InboundHrmpMessage, Nonce, OccupiedCoreAssumption,
PersistedValidationData, PvfCheckStatement, SessionIndex, SessionInfo, ValidationCode,
ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature,
};
use sp_consensus_beefy::ecdsa_crypto::{AuthorityId as BeefyId, Signature as BeefySignature};
use sp_consensus_grandpa::AuthorityId as GrandpaId;
Expand Down
34 changes: 28 additions & 6 deletions polkadot/node/subsystem-types/src/runtime_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,10 @@ where
&self,
at: Hash,
) -> Result<Vec<CoreState<Hash, BlockNumber>>, ApiError> {
self.client.runtime_api().availability_cores(at)
self.client
.runtime_api()
.availability_cores(at)
.map(|cores| cores.into_iter().map(|core| core.into()).collect::<Vec<_>>())
}

async fn persisted_validation_data(
Expand Down Expand Up @@ -433,19 +436,30 @@ where
at: Hash,
para_id: Id,
) -> Result<Option<CommittedCandidateReceipt<Hash>>, ApiError> {
self.client.runtime_api().candidate_pending_availability(at, para_id)
self.client
.runtime_api()
.candidate_pending_availability(at, para_id)
.map(|maybe_candidate| maybe_candidate.map(|candidate| candidate.into()))
}

async fn candidates_pending_availability(
&self,
at: Hash,
para_id: Id,
) -> Result<Vec<CommittedCandidateReceipt<Hash>>, ApiError> {
self.client.runtime_api().candidates_pending_availability(at, para_id)
self.client
.runtime_api()
.candidates_pending_availability(at, para_id)
.map(|candidates| {
candidates.into_iter().map(|candidate| candidate.into()).collect::<Vec<_>>()
})
}

async fn candidate_events(&self, at: Hash) -> Result<Vec<CandidateEvent<Hash>>, ApiError> {
self.client.runtime_api().candidate_events(at)
self.client
.runtime_api()
.candidate_events(at)
.map(|events| events.into_iter().map(|event| event.into()).collect::<Vec<_>>())
}

async fn dmq_contents(
Expand Down Expand Up @@ -476,7 +490,10 @@ where
&self,
at: Hash,
) -> Result<Option<ScrapedOnChainVotes<Hash>>, ApiError> {
self.client.runtime_api().on_chain_votes(at)
self.client
.runtime_api()
.on_chain_votes(at)
.map(|maybe_votes| maybe_votes.map(|votes| votes.into()))
}

async fn session_executor_params(
Expand Down Expand Up @@ -588,7 +605,12 @@ where
at: Hash,
para_id: Id,
) -> Result<Option<async_backing::BackingState>, ApiError> {
self.client.runtime_api().para_backing_state(at, para_id)
self.client
.runtime_api()
.para_backing_state(at, para_id)
.map(|maybe_backing_state| {
maybe_backing_state.map(|backing_state| backing_state.into())
})
}

async fn async_backing_params(
Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/test/client/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use crate::Client;
use codec::{Decode, Encode};
use polkadot_primitives::{Block, InherentData as ParachainsInherentData};
use polkadot_primitives::{vstaging::InherentData as ParachainsInherentData, Block};
use polkadot_test_runtime::UncheckedExtrinsic;
use polkadot_test_service::GetLastTimestamp;
use sc_block_builder::{BlockBuilder, BlockBuilderBuilder};
Expand Down
6 changes: 6 additions & 0 deletions polkadot/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ sp-consensus-slots = { features = ["serde"], workspace = true }
sp-io = { workspace = true }
sp-keystore = { optional = true, workspace = true }
sp-staking = { features = ["serde"], workspace = true }
sp-std = { workspace = true, optional = true }

polkadot-core-primitives = { workspace = true }
polkadot-parachain-primitives = { workspace = true }

[dev-dependencies]
polkadot-primitives-test-helpers = { workspace = true }

[features]
default = ["std"]
std = [
Expand All @@ -54,9 +58,11 @@ std = [
"sp-keystore?/std",
"sp-runtime/std",
"sp-staking/std",
"sp-std/std",
]
runtime-benchmarks = [
"polkadot-parachain-primitives/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
]
test = []
16 changes: 10 additions & 6 deletions polkadot/primitives/src/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,15 @@
//! separated from the stable primitives.

use crate::{
async_backing, slashing, ApprovalVotingParams, AsyncBackingParams, BlockNumber,
CandidateCommitments, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreIndex,
CoreState, DisputeState, ExecutorParams, GroupRotationInfo, Hash, NodeFeatures,
OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes,
SessionIndex, SessionInfo, ValidatorId, ValidatorIndex, ValidatorSignature,
slashing,
vstaging::{
self, CandidateEvent, CommittedCandidateReceiptV2 as CommittedCandidateReceipt, CoreState,
ScrapedOnChainVotes,
},
ApprovalVotingParams, AsyncBackingParams, BlockNumber, CandidateCommitments, CandidateHash,
CoreIndex, DisputeState, ExecutorParams, GroupRotationInfo, Hash, NodeFeatures,
OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, SessionIndex, SessionInfo,
ValidatorId, ValidatorIndex, ValidatorSignature,
};

use alloc::{
Expand Down Expand Up @@ -260,7 +264,7 @@ sp_api::decl_runtime_apis! {

/// Returns the state of parachain backing for a given para.
#[api_version(7)]
fn para_backing_state(_: ppp::Id) -> Option<async_backing::BackingState<Hash, BlockNumber>>;
fn para_backing_state(_: ppp::Id) -> Option<vstaging::async_backing::BackingState<Hash, BlockNumber>>;

/// Returns candidate's acceptance limitations for asynchronous backing for a relay parent.
#[api_version(7)]
Expand Down
5 changes: 2 additions & 3 deletions polkadot/primitives/src/v8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! `V7` Primitives.

use alloc::{
vec,
vec::{IntoIter, Vec},
Expand Down Expand Up @@ -1157,7 +1156,7 @@ pub enum OccupiedCoreAssumption {
Free,
}

/// An even concerning a candidate.
/// An event concerning a candidate.
#[derive(Clone, Encode, Decode, TypeInfo, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(PartialEq))]
pub enum CandidateEvent<H = Hash> {
Expand Down Expand Up @@ -2130,7 +2129,7 @@ impl<BlockNumber: Default + From<u32>> Default for SchedulerParams<BlockNumber>
}

#[cfg(test)]
mod tests {
pub mod tests {
use super::*;
use bitvec::bitvec;
use sp_core::sr25519;
Expand Down
76 changes: 76 additions & 0 deletions polkadot/primitives/src/vstaging/async_backing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use super::*;

use alloc::vec::Vec;
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_core::RuntimeDebug;

/// A candidate pending availability.
#[derive(RuntimeDebug, Clone, PartialEq, Encode, Decode, TypeInfo)]
pub struct CandidatePendingAvailability<H = Hash, N = BlockNumber> {
/// The hash of the candidate.
pub candidate_hash: CandidateHash,
/// The candidate's descriptor.
pub descriptor: CandidateDescriptorV2<H>,
/// The commitments of the candidate.
pub commitments: CandidateCommitments,
/// The candidate's relay parent's number.
pub relay_parent_number: N,
/// The maximum Proof-of-Validity size allowed, in bytes.
pub max_pov_size: u32,
}

impl<H: Copy> From<CandidatePendingAvailability<H>>
for crate::v8::async_backing::CandidatePendingAvailability<H>
{
fn from(value: CandidatePendingAvailability<H>) -> Self {
Self {
candidate_hash: value.candidate_hash,
descriptor: value.descriptor.into(),
commitments: value.commitments,
relay_parent_number: value.relay_parent_number,
max_pov_size: value.max_pov_size,
}
}
}

/// The per-parachain state of the backing system, including
/// state-machine constraints and candidates pending availability.
#[derive(RuntimeDebug, Clone, PartialEq, Encode, Decode, TypeInfo)]
pub struct BackingState<H = Hash, N = BlockNumber> {
/// The state-machine constraints of the parachain.
pub constraints: Constraints<N>,
/// The candidates pending availability. These should be ordered, i.e. they should form
/// a sub-chain, where the first candidate builds on top of the required parent of the
/// constraints and each subsequent builds on top of the previous head-data.
pub pending_availability: Vec<CandidatePendingAvailability<H, N>>,
}

impl<H: Copy> From<BackingState<H>> for crate::v8::async_backing::BackingState<H> {
fn from(value: BackingState<H>) -> Self {
Self {
constraints: value.constraints,
pending_availability: value
.pending_availability
.into_iter()
.map(|candidate| candidate.into())
.collect::<Vec<_>>(),
}
}
}
Loading
Loading