mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +00:00
Use a more typesafe approach for managing indexed data (#6150)
* Fix for issue #2403 * Nightly fmt * Quick documentation fixes * Default Implementation * iter() function integrated * Implemented iter functionalities * Fmt * small change * updates node-network * updates in dispute-coordinator * Updates * benchmarking fix * minor fix * test fixes in runtime api * Update primitives/src/v2/mod.rs Co-authored-by: Andronik <write@reusable.software> * Update primitives/src/v2/mod.rs Co-authored-by: Andronik <write@reusable.software> * Update primitives/src/v2/mod.rs Co-authored-by: Andronik <write@reusable.software> * Update primitives/src/v2/mod.rs Co-authored-by: Andronik <write@reusable.software> * Update primitives/src/v2/mod.rs Co-authored-by: Andronik <write@reusable.software> * Removal of [index], shorting of FromIterator, Renaming of GroupValidators to ValidatorGroups * Removal of ops import * documentation fixes for spell check * implementation of generic type * Refactoring * Test and documentation fixes * minor test fix * minor test fix * minor test fix * Update node/network/statement-distribution/src/lib.rs Co-authored-by: Andronik <write@reusable.software> * Update primitives/src/v2/mod.rs Co-authored-by: Andronik <write@reusable.software> * Update primitives/src/v2/mod.rs Co-authored-by: Andronik <write@reusable.software> * removed IterMut * Update node/core/dispute-coordinator/src/import.rs Co-authored-by: Andronik <write@reusable.software> * Update node/core/dispute-coordinator/src/initialized.rs Co-authored-by: Andronik <write@reusable.software> * Update primitives/src/v2/mod.rs Co-authored-by: Andronik <write@reusable.software> * fmt * IterMut * documentation update Co-authored-by: Andronik <write@reusable.software> * minor adjustments and new TypeIndex trait * spelling fix * TypeIndex fix Co-authored-by: Andronik <write@reusable.software>
This commit is contained in:
@@ -25,9 +25,10 @@ use primitives::v2::{
|
||||
collator_signature_payload, AvailabilityBitfield, BackedCandidate, CandidateCommitments,
|
||||
CandidateDescriptor, CandidateHash, CollatorId, CollatorSignature, CommittedCandidateReceipt,
|
||||
CompactStatement, CoreIndex, CoreOccupied, DisputeStatement, DisputeStatementSet, GroupIndex,
|
||||
HeadData, Id as ParaId, InherentData as ParachainsInherentData, InvalidDisputeStatementKind,
|
||||
PersistedValidationData, SessionIndex, SigningContext, UncheckedSigned,
|
||||
ValidDisputeStatementKind, ValidationCode, ValidatorId, ValidatorIndex, ValidityAttestation,
|
||||
HeadData, Id as ParaId, IndexedVec, InherentData as ParachainsInherentData,
|
||||
InvalidDisputeStatementKind, PersistedValidationData, SessionIndex, SigningContext,
|
||||
UncheckedSigned, ValidDisputeStatementKind, ValidationCode, ValidatorId, ValidatorIndex,
|
||||
ValidityAttestation,
|
||||
};
|
||||
use sp_core::{sr25519, H256};
|
||||
use sp_runtime::{
|
||||
@@ -65,7 +66,7 @@ fn byte32_slice_from(n: u32) -> [u8; 32] {
|
||||
/// Paras inherent `enter` benchmark scenario builder.
|
||||
pub(crate) struct BenchBuilder<T: paras_inherent::Config> {
|
||||
/// Active validators. Validators should be declared prior to all other setup.
|
||||
validators: Option<Vec<ValidatorId>>,
|
||||
validators: Option<IndexedVec<ValidatorIndex, ValidatorId>>,
|
||||
/// Starting block number; we expect it to get incremented on session setup.
|
||||
block_number: T::BlockNumber,
|
||||
/// Starting session; we expect it to get incremented on session setup.
|
||||
@@ -410,7 +411,7 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
|
||||
assert_eq!(<shared::Pallet<T>>::session_index(), target_session);
|
||||
|
||||
// We need to refetch validators since they have been shuffled.
|
||||
let validators_shuffled: Vec<_> = session_info::Pallet::<T>::session_info(target_session)
|
||||
let validators_shuffled = session_info::Pallet::<T>::session_info(target_session)
|
||||
.unwrap()
|
||||
.validators
|
||||
.clone();
|
||||
@@ -549,7 +550,7 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
|
||||
.iter()
|
||||
.take(*num_votes as usize)
|
||||
.map(|val_idx| {
|
||||
let public = validators.get(val_idx.0 as usize).unwrap();
|
||||
let public = validators.get(*val_idx).unwrap();
|
||||
let sig = UncheckedSigned::<CompactStatement>::benchmark_sign(
|
||||
public,
|
||||
CompactStatement::Valid(candidate_hash.clone()),
|
||||
@@ -606,7 +607,7 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
|
||||
self.dispute_statements.get(&seed).cloned().unwrap_or(validators.len() as u32);
|
||||
let statements = (0..statements_len)
|
||||
.map(|validator_index| {
|
||||
let validator_public = &validators.get(validator_index as usize).expect("Test case is not borked. `ValidatorIndex` out of bounds of `ValidatorId`s.");
|
||||
let validator_public = &validators.get(ValidatorIndex::from(validator_index)).expect("Test case is not borked. `ValidatorIndex` out of bounds of `ValidatorId`s.");
|
||||
|
||||
// We need dispute statements on each side. And we don't want a revert log
|
||||
// so we make sure that we have a super majority with valid statements.
|
||||
|
||||
@@ -985,8 +985,7 @@ impl<T: Config> Pallet<T> {
|
||||
let mut importer = DisputeStateImporter::new(dispute_state, now);
|
||||
for (i, (statement, validator_index, signature)) in set.statements.iter().enumerate() {
|
||||
// assure the validator index and is present in the session info
|
||||
let validator_public = match session_info.validators.get(validator_index.0 as usize)
|
||||
{
|
||||
let validator_public = match session_info.validators.get(*validator_index) {
|
||||
None => {
|
||||
filter.remove_index(i);
|
||||
continue
|
||||
|
||||
@@ -257,7 +257,7 @@ where
|
||||
|
||||
let keys = losers
|
||||
.into_iter()
|
||||
.filter_map(|i| session_info.validators.get(i.0 as usize).cloned().map(|id| (i, id)))
|
||||
.filter_map(|i| session_info.validators.get(i).cloned().map(|id| (i, id)))
|
||||
.collect();
|
||||
let unapplied = PendingSlashes { keys, kind };
|
||||
<UnappliedSlashes<T>>::insert(session_index, candidate_hash, unapplied);
|
||||
|
||||
@@ -80,7 +80,7 @@ where
|
||||
let session_index = crate::shared::Pallet::<T>::session_index();
|
||||
let session_info = crate::session_info::Pallet::<T>::session_info(session_index);
|
||||
let session_info = session_info.unwrap();
|
||||
let validator_id = session_info.validators[0].clone();
|
||||
let validator_id = session_info.validators.get(ValidatorIndex::from(0)).unwrap().clone();
|
||||
let key = (PARACHAIN_KEY_TYPE_ID, validator_id.clone());
|
||||
let key_owner_proof = pallet_session::historical::Pallet::<T>::prove(key).unwrap();
|
||||
|
||||
|
||||
@@ -126,12 +126,12 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
let dispute_period = config.dispute_period;
|
||||
|
||||
let validators = notification.validators.clone();
|
||||
let validators = notification.validators.clone().into();
|
||||
let discovery_keys = <T as AuthorityDiscoveryConfig>::authorities();
|
||||
let assignment_keys = AssignmentKeysUnsafe::<T>::get();
|
||||
let active_set = <shared::Pallet<T>>::active_validator_indices();
|
||||
|
||||
let validator_groups = <scheduler::Pallet<T>>::validator_groups();
|
||||
let validator_groups = <scheduler::Pallet<T>>::validator_groups().into();
|
||||
let n_cores = <scheduler::Pallet<T>>::availability_cores().len() as u32;
|
||||
let zeroth_delay_tranche_width = config.zeroth_delay_tranche_width;
|
||||
let relay_vrf_modulo_samples = config.relay_vrf_modulo_samples;
|
||||
|
||||
@@ -201,7 +201,7 @@ fn session_info_active_subsets() {
|
||||
});
|
||||
let session = Sessions::<Test>::get(&1).unwrap();
|
||||
|
||||
assert_eq!(session.validators, validators);
|
||||
assert_eq!(session.validators.to_vec(), validators);
|
||||
assert_eq!(
|
||||
session.discovery_keys,
|
||||
take_active_subset_and_inactive(&active_set, &unscrambled_discovery),
|
||||
|
||||
Reference in New Issue
Block a user