Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Use a more typesafe approach for managing indexed data #6150

Merged
merged 46 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b5c02e8
Fix for issue #2403
tifecool Oct 13, 2022
954d392
Merge branch 'paritytech:master' into fix2403
tifecool Oct 13, 2022
ce8aba9
Nightly fmt
tifecool Oct 13, 2022
b5a7bfc
Quick documentation fixes
tifecool Oct 14, 2022
5da6693
Default Implementation
tifecool Oct 14, 2022
b90fc1e
iter() function integrated
tifecool Oct 14, 2022
557eebb
Implemented iter functionalities
tifecool Oct 15, 2022
09cc765
Fmt
tifecool Oct 15, 2022
3a6e327
small change
tifecool Oct 15, 2022
aba5837
updates node-network
tifecool Oct 15, 2022
dbac388
updates in dispute-coordinator
tifecool Oct 16, 2022
f1b8b4f
Updates
tifecool Oct 18, 2022
8696f93
benchmarking fix
tifecool Oct 18, 2022
4d10ca1
minor fix
tifecool Oct 18, 2022
95a3881
test fixes in runtime api
tifecool Oct 18, 2022
71fc436
Merge branch 'paritytech:master' into fix2403
tifecool Oct 18, 2022
4951b54
Update primitives/src/v2/mod.rs
tifecool Oct 19, 2022
35c1304
Update primitives/src/v2/mod.rs
tifecool Oct 19, 2022
a0edab4
Update primitives/src/v2/mod.rs
tifecool Oct 19, 2022
3823be1
Update primitives/src/v2/mod.rs
tifecool Oct 19, 2022
5714ad4
Update primitives/src/v2/mod.rs
tifecool Oct 19, 2022
7a8be34
Removal of [index], shorting of FromIterator, Renaming of GroupValida…
tifecool Oct 19, 2022
c3a1e72
Merge remote-tracking branch 'origin/fix2403' into fix2403
tifecool Oct 19, 2022
56b3904
Removal of ops import
tifecool Oct 19, 2022
a0bb41b
documentation fixes for spell check
tifecool Oct 19, 2022
ef5438c
implementation of generic type
tifecool Oct 20, 2022
4e825d0
Refactoring
tifecool Oct 21, 2022
f127cb4
Test and documentation fixes
tifecool Oct 21, 2022
06ecd6a
minor test fix
tifecool Oct 21, 2022
efa2278
minor test fix
tifecool Oct 21, 2022
cfca9b4
minor test fix
tifecool Oct 21, 2022
e6f685f
Update node/network/statement-distribution/src/lib.rs
tifecool Oct 21, 2022
33e3102
Update primitives/src/v2/mod.rs
tifecool Oct 21, 2022
e4d548b
Update primitives/src/v2/mod.rs
tifecool Oct 21, 2022
dee6396
removed IterMut
tifecool Oct 21, 2022
956a62e
Update node/core/dispute-coordinator/src/import.rs
tifecool Oct 21, 2022
1aba477
Update node/core/dispute-coordinator/src/initialized.rs
tifecool Oct 21, 2022
9025b12
Merge remote-tracking branch 'origin/fix2403' into fix2403
tifecool Oct 21, 2022
37cccf6
Update primitives/src/v2/mod.rs
tifecool Oct 21, 2022
f03adc0
fmt
tifecool Oct 21, 2022
bdc316c
IterMut
tifecool Oct 21, 2022
5ca768f
documentation update
tifecool Oct 21, 2022
2ee57d4
minor adjustments and new TypeIndex trait
tifecool Oct 21, 2022
be785f9
Merge remote-tracking branch 'origin/fix2403' into fix2403
tifecool Oct 21, 2022
6d87954
spelling fix
tifecool Oct 21, 2022
a2ae881
TypeIndex fix
tifecool Oct 21, 2022
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
Prev Previous commit
Next Next commit
Nightly fmt
  • Loading branch information
tifecool committed Oct 13, 2022
commit ce8aba9da63b52288eb2c252e1e63fc3e7a2240d
6 changes: 2 additions & 4 deletions node/primitives/src/disputes/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ impl UncheckedDisputeMessage {

let vote_valid = {
let ValidDisputeVote { validator_index, signature, kind } = valid_vote;
let validator_public =
session_info.validators.get(validator_index).ok_or(())?.clone();
let validator_public = session_info.validators.get(validator_index).ok_or(())?.clone();

(
SignedDisputeStatement::new_checked(
Expand All @@ -240,8 +239,7 @@ impl UncheckedDisputeMessage {

let vote_invalid = {
let InvalidDisputeVote { validator_index, signature, kind } = invalid_vote;
let validator_public =
session_info.validators.get(validator_index).ok_or(())?.clone();
let validator_public = session_info.validators.get(validator_index).ok_or(())?.clone();

(
SignedDisputeStatement::new_checked(
Expand Down
2 changes: 1 addition & 1 deletion node/subsystem-util/src/rolling_session_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ mod tests {
SubsystemContext,
};
use polkadot_node_subsystem_test_helpers::make_subsystem_context;
use polkadot_primitives::v2::{Header, Validators, GroupValidators};
use polkadot_primitives::v2::{GroupValidators, Header, Validators};
use sp_core::testing::TaskExecutor;

pub const TEST_WINDOW_SIZE: SessionWindowSize = new_session_window_size!(6);
Expand Down
23 changes: 11 additions & 12 deletions primitives/src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
use bitvec::vec::BitVec;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_std::prelude::*;
use sp_std::ops::Index;
use sp_std::{ops::Index, prelude::*};

use application_crypto::KeyTypeId;
use inherents::InherentIdentifier;
Expand Down Expand Up @@ -1573,30 +1572,30 @@ impl CompactStatement {
/// Validators struct indexed by ValidatorIndex.
#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
#[cfg_attr(feature = "std", derive(PartialEq, MallocSizeOf))]
pub struct Validators (Vec<ValidatorId>);
pub struct Validators(Vec<ValidatorId>);

impl Index<ValidatorIndex> for Validators{
impl Index<ValidatorIndex> for Validators {
type Output = ValidatorId;

fn index(&self, index: ValidatorIndex) -> &Self::Output {
&self.0.get(index.0 as usize).unwrap()
tifecool marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl From<Vec<ValidatorId>> for Validators{
impl From<Vec<ValidatorId>> for Validators {
fn from(validators: Vec<ValidatorId>) -> Self {
Validators(validators)
}
}

impl Validators {
tifecool marked this conversation as resolved.
Show resolved Hide resolved
/// Returns a reference to an element indexed using ValidatorIndex.
pub fn get(&self, index: ValidatorIndex) -> Option<&ValidatorId>{
pub fn get(&self, index: ValidatorIndex) -> Option<&ValidatorId> {
self.0.get(index.0 as usize)
}

///Returns number of elements in vector.
tifecool marked this conversation as resolved.
Show resolved Hide resolved
pub fn len(&self) -> usize{
pub fn len(&self) -> usize {
self.0.len()
}

Expand All @@ -1609,30 +1608,30 @@ impl Validators {
/// GroupValidators struct indexed by GroupIndex.
#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
#[cfg_attr(feature = "std", derive(PartialEq, MallocSizeOf))]
pub struct GroupValidators (Vec<Vec<ValidatorIndex>>);
pub struct GroupValidators(Vec<Vec<ValidatorIndex>>);
tifecool marked this conversation as resolved.
Show resolved Hide resolved

impl Index<GroupIndex> for GroupValidators{
impl Index<GroupIndex> for GroupValidators {
type Output = Vec<ValidatorIndex>;

fn index(&self, index: GroupIndex) -> &Self::Output {
self.0.get(index.0 as usize).unwrap()
}
}

impl From<Vec<Vec<ValidatorIndex>>> for GroupValidators{
impl From<Vec<Vec<ValidatorIndex>>> for GroupValidators {
fn from(group_validators: Vec<Vec<ValidatorIndex>>) -> Self {
GroupValidators(group_validators)
}
}

impl GroupValidators {
/// Returns a reference to an element indexed using GroupIndex.
tifecool marked this conversation as resolved.
Show resolved Hide resolved
pub fn get(&self, index: GroupIndex) -> Option<&Vec<ValidatorIndex>>{
pub fn get(&self, index: GroupIndex) -> Option<&Vec<ValidatorIndex>> {
self.0.get(index.0 as usize)
}

///Returns number of elements in vector.
tifecool marked this conversation as resolved.
Show resolved Hide resolved
pub fn len(&self) -> usize{
pub fn len(&self) -> usize {
self.0.len()
}

Expand Down
10 changes: 9 additions & 1 deletion runtime/parachains/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ use crate::{
};
use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec};
use frame_support::pallet_prelude::*;
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, Validators};
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, Validators,
ValidityAttestation,
};
use sp_core::{sr25519, H256};
use sp_runtime::{
generic::Digest,
Expand Down
3 changes: 1 addition & 2 deletions runtime/parachains/src/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
let validator_public = match session_info.validators.get(*validator_index) {
None => {
filter.remove_index(i);
continue
Expand Down