Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions runtime/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
futures = "0.3.17"
bitvec = { version = "0.20.1", default-features = false, features = ["alloc"] }
parity-scale-codec = { version = "2.3.1", default-features = false, features = ["derive"] }
log = { version = "0.4.14", default-features = false }
Expand All @@ -13,6 +14,9 @@ scale-info = { version = "1.0", default-features = false, features = ["derive"]
serde = { version = "1.0.130", features = [ "derive" ], optional = true }
derive_more = "0.99.14"
bitflags = "1.3.2"
no-std-compat = "0.4.1"
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }

sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
inherents = { package = "sp-inherents", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
Expand Down Expand Up @@ -43,12 +47,8 @@ rand = { version = "0.8.3", default-features = false }
rand_chacha = { version = "0.3.1", default-features = false }

[dev-dependencies]
futures = "0.3.17"
hex-literal = "0.3.3"
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" }
frame-support-test = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }


[features]
default = ["std"]
Expand Down
24 changes: 24 additions & 0 deletions runtime/parachains/src/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ pub trait DisputesHandler<BlockNumber> {
included_in: BlockNumber,
);

/// Retrieve the included state of a given candidate in a particular session.
fn included_state(session: SessionIndex, candidate_hash: CandidateHash) -> Option<BlockNumber>;

/// Whether the given candidate concluded invalid in a dispute with supermajority.
fn concluded_invalid(session: SessionIndex, candidate_hash: CandidateHash) -> bool;

Expand Down Expand Up @@ -164,6 +167,13 @@ impl<BlockNumber> DisputesHandler<BlockNumber> for () {
) {
}

fn included_state(
_session: SessionIndex,
_candidate_hash: CandidateHash,
) -> Option<BlockNumber> {
None
}

fn concluded_invalid(_session: SessionIndex, _candidate_hash: CandidateHash) -> bool {
false
}
Expand Down Expand Up @@ -200,6 +210,13 @@ impl<T: Config> DisputesHandler<T::BlockNumber> for pallet::Pallet<T> {
pallet::Pallet::<T>::note_included(session, candidate_hash, included_in)
}

fn included_state(
session: SessionIndex,
candidate_hash: CandidateHash,
) -> Option<T::BlockNumber> {
pallet::Pallet::<T>::included_state(session, candidate_hash)
}

fn concluded_invalid(session: SessionIndex, candidate_hash: CandidateHash) -> bool {
pallet::Pallet::<T>::concluded_invalid(session, candidate_hash)
}
Expand Down Expand Up @@ -1116,6 +1133,13 @@ impl<T: Config> Pallet<T> {
}
}

pub(crate) fn included_state(
session: SessionIndex,
candidate_hash: CandidateHash,
) -> Option<T::BlockNumber> {
<Included<T>>::get(session, candidate_hash)
}

pub(crate) fn concluded_invalid(session: SessionIndex, candidate_hash: CandidateHash) -> bool {
<Disputes<T>>::get(&session, &candidate_hash).map_or(false, |dispute| {
// A dispute that has concluded with supermajority-against.
Expand Down
3 changes: 3 additions & 0 deletions runtime/parachains/src/inclusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ use crate::{configuration, disputes, dmp, hrmp, paras, scheduler::CoreAssignment

pub use pallet::*;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

/// A bitfield signed by a validator indicating that it is keeping its piece of the erasure-coding
/// for any backed candidates referred to by a `1` bit available.
///
Expand Down
143 changes: 143 additions & 0 deletions runtime/parachains/src/inclusion/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
use super::*;

use frame_benchmarking::benchmarks;
use futures::executor::block_on;
use keyring::Sr25519Keyring;
use sc_keystore::LocalKeystore;
use sp_keystore::SyncCryptoStorePtr;
use std::sync::Arc;

use primitives::v1::{
BlockNumber, CoreIndex, Id as ParaId, SignedAvailabilityBitfield, SigningContext,
UncheckedSignedAvailabilityBitfield, ValidationCode, ValidatorId, ValidatorIndex,
};

use super::mock::{Configuration, Paras, System};

#[derive(Default)]
struct TestCandidateBuilder {
para_id: ParaId,
head_data: HeadData,
para_head_hash: Option<Hash>,
pov_hash: Hash,
relay_parent: Hash,
persisted_validation_data_hash: Hash,
new_validation_code: Option<ValidationCode>,
validation_code: ValidationCode,
hrmp_watermark: BlockNumber,
}

impl TestCandidateBuilder {
fn build(self) -> CommittedCandidateReceipt {
CommittedCandidateReceipt {
descriptor: CandidateDescriptor {
para_id: self.para_id,
pov_hash: self.pov_hash,
relay_parent: self.relay_parent,
persisted_validation_data_hash: self.persisted_validation_data_hash,
validation_code_hash: self.validation_code.hash(),
para_head: self.para_head_hash.unwrap_or_else(|| self.head_data.hash()),
..Default::default()
},
commitments: CandidateCommitments {
head_data: self.head_data,
new_validation_code: self.new_validation_code,
hrmp_watermark: self.hrmp_watermark,
..Default::default()
},
}
}
}

fn expected_bits() -> usize {
Paras::parachains().len() + Configuration::config().parathread_cores as usize
}

fn default_backing_bitfield() -> BitVec<BitOrderLsb0, u8> {
bitvec::bitvec![BitOrderLsb0, u8; 0; ParasShared::active_validator_keys().len()]
}

fn default_bitfield() -> AvailabilityBitfield {
AvailabilityBitfield(bitvec::bitvec![BitOrderLsb0, u8; 8; expected_bits()])
}

async fn sign_bitfield(
keystore: &SyncCryptoStorePtr,
key: &Sr25519Keyring,
validator_index: ValidatorIndex,
bitfield: AvailabilityBitfield,
signing_context: &SigningContext,
) -> SignedAvailabilityBitfield {
SignedAvailabilityBitfield::sign(
keystore,
bitfield,
signing_context,
validator_index,
&key.public().into(),
)
.await
.unwrap()
.unwrap()
}

fn validator_pubkeys(validators: &[Sr25519Keyring]) -> Vec<ValidatorId> {
validators.iter().map(|v| v.public().into()).collect()
}

benchmarks! {
process_bitfields {
let chain_a = ParaId::from(1);
let chain_b = ParaId::from(2);
let thread_a = ParaId::from(3);

let validators = vec![
Sr25519Keyring::Alice,
Sr25519Keyring::Bob,
Sr25519Keyring::Charlie,
Sr25519Keyring::Dave,
Sr25519Keyring::Ferdie,
];
let keystore: SyncCryptoStorePtr = Arc::new(LocalKeystore::in_memory());
let validator_publics = validator_pubkeys(&validators);

let signing_context = SigningContext { parent_hash: System::parent_hash(), session_index: 5 };

let core_lookup = move |core| match core {
core if core == CoreIndex::from(0) => Some(chain_a),
core if core == CoreIndex::from(1) => Some(chain_b),
core if core == CoreIndex::from(2) => Some(thread_a),
core if core == CoreIndex::from(3) => None,
_ => panic!("out of bounds for testing"),
};

let signed = block_on(sign_bitfield(
&keystore,
&validators[0],
ValidatorIndex(0),
default_bitfield(),
&signing_context,
));

let candidate = TestCandidateBuilder::default().build();
}: {
<PendingAvailability<T>>::insert(
&chain_b,
CandidatePendingAvailability {
core: CoreIndex::from(1),
hash: candidate.hash(),
descriptor: candidate.descriptor,
availability_votes: default_availability_votes(),
relay_parent_number: 6,
backed_in_number: 7,
backers: default_backing_bitfield(),
backing_group: GroupIndex::from(1),
},
);
Pallet::<T>::process_bitfields(expected_bits(), vec![signed.into()], core_lookup).unwrap() }

impl_benchmark_test_suite!(
Pallet,
super::mock::new_test_ext(Default::default()),
super::mock::Test
);
}
Loading