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

Ensure data size of identity pallet is bounded #9168

Merged
19 commits merged into from
Jul 8, 2021
Merged

Conversation

KiChjang
Copy link
Contributor

@KiChjang KiChjang added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Jun 22, 2021
frame/identity/src/lib.rs Outdated Show resolved Hide resolved
frame/identity/src/lib.rs Outdated Show resolved Hide resolved
frame/identity/src/lib.rs Outdated Show resolved Hide resolved
display: Data::Raw(b"ten".to_vec()),
legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec()),
display: Data::Raw(b"ten".to_vec().try_into().unwrap()),
legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec().try_into().unwrap()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣

@@ -339,31 +336,31 @@ fn killing_slashing_should_work() {
#[test]
fn setting_subaccounts_should_work() {
new_test_ext().execute_with(|| {
let mut subs = vec![(20, Data::Raw(vec![40; 1]))];
let mut subs = vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing a lot of changes with this pattern. Maybe a test-scoped function like

fn one_raw_data<S>(n: u8) -> Data {
  Data::Raw(vec![n; 1].try_into().unwrap())
}

would be convenient?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other alternative is to turn the other side into vec, or by creating an implementation of PartialEq of boundedvec and vec?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementing PartialEq actually makes a lot more sense, I'll do that instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this actually doesn't work, because the problem isn't so much that PartialEq wasn't implemented between Vec and BoundedVec, it's that Data::Raw accepts a BoundedVec instead of a Vec as its inner struct.

@@ -122,6 +122,14 @@ impl<T, S> BoundedVec<T, S> {
pub fn retain<F: FnMut(&T) -> bool>(&mut self, f: F) {
self.0.retain(f)
}

/// Exactly the same semantics as [`Vec::get_mut`].
pub fn get_mut<I: SliceIndex<[T]>>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should also be the same addition to the weakly_bounded_vec definition

@KiChjang KiChjang force-pushed the kckyeung/bounded-identity branch from e309366 to be9954b Compare July 6, 2021 05:03
Copy link
Member

@shawntabrizi shawntabrizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs change below

@shawntabrizi shawntabrizi self-requested a review July 7, 2021 01:23
Copy link
Member

@shawntabrizi shawntabrizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify first, write last rule is not enforced

@shawntabrizi
Copy link
Member

bot merge

@ghost
Copy link

ghost commented Jul 8, 2021

Trying merge.

@ghost ghost merged commit 9235309 into master Jul 8, 2021
@ghost ghost deleted the kckyeung/bounded-identity branch July 8, 2021 02:57
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants