Identity pallet improvements (#2048)

This PR is a follow up to #1661 

- [x] rename the `simple` module to `legacy`
- [x] fix benchmarks to disregard the number of additional fields
- [x] change the storage deposits to charge per encoded byte of the
identity information instance, removing the need for `fn
additional(&self) -> usize` in `IdentityInformationProvider`
- [x] ~add an extrinsic to rejig deposits to account for the change
above~
- [ ] ~ensure through proper configuration that the new byte-based
deposit is always lower than whatever is reserved now~
- [x] remove `IdentityFields` from the `set_fields` extrinsic signature,
as per [this
discussion](https://github.com/paritytech/polkadot-sdk/pull/1661#discussion_r1371703403)

> ensure through proper configuration that the new byte-based deposit is
always lower than whatever is reserved now

Not sure this is needed anymore. If the new deposits are higher than
what is currently on chain and users don't have enough funds to reserve
what is needed, the extrinisc fails and they're basically grandfathered
and frozen until they add more funds and/or make a change to their
identity. This behavior seems fine to me. Original idea
[here](https://github.com/paritytech/polkadot-sdk/pull/1661#issuecomment-1779606319).

> add an extrinsic to rejig deposits to account for the change above

This was initially implemented but now removed from this PR in favor of
the implementation detailed
[here](https://github.com/paritytech/polkadot-sdk/pull/2088).

---------

Signed-off-by: georgepisaltu <george.pisaltu@parity.io>
Co-authored-by: joepetrowski <joe@parity.io>
This commit is contained in:
georgepisaltu
2023-11-03 21:38:26 +02:00
committed by GitHub
parent ca5f10567a
commit 21fbc00d04
15 changed files with 353 additions and 459 deletions
+40 -28
View File
@@ -31,7 +31,10 @@ pub use frame_support::{
BoundedVec,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
use pallet_identity::{simple::IdentityInfo, Data, Judgement};
use pallet_identity::{
legacy::{IdentityField, IdentityInfo},
Data, Judgement,
};
pub use crate as pallet_alliance;
@@ -96,9 +99,9 @@ impl pallet_collective::Config<AllianceCollective> for Test {
}
parameter_types! {
pub const BasicDeposit: u64 = 10;
pub const FieldDeposit: u64 = 10;
pub const SubAccountDeposit: u64 = 10;
pub const BasicDeposit: u64 = 100;
pub const ByteDeposit: u64 = 10;
pub const SubAccountDeposit: u64 = 100;
pub const MaxSubAccounts: u32 = 2;
pub const MaxAdditionalFields: u32 = 2;
pub const MaxRegistrars: u32 = 20;
@@ -117,10 +120,9 @@ impl pallet_identity::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type BasicDeposit = BasicDeposit;
type FieldDeposit = FieldDeposit;
type ByteDeposit = ByteDeposit;
type SubAccountDeposit = SubAccountDeposit;
type MaxSubAccounts = MaxSubAccounts;
type MaxAdditionalFields = MaxAdditionalFields;
type IdentityInformation = IdentityInfo<MaxAdditionalFields>;
type MaxRegistrars = MaxRegistrars;
type Slashed = ();
@@ -131,8 +133,8 @@ impl pallet_identity::Config for Test {
pub struct AllianceIdentityVerifier;
impl IdentityVerifier<AccountId> for AllianceIdentityVerifier {
fn has_identity(who: &AccountId, fields: u64) -> bool {
Identity::has_identity(who, fields)
fn has_required_identities(who: &AccountId) -> bool {
Identity::has_identity(who, (IdentityField::Display | IdentityField::Web).bits())
}
fn has_good_judgement(who: &AccountId) -> bool {
@@ -232,20 +234,40 @@ frame_support::construct_runtime!(
}
);
fn test_identity_info() -> IdentityInfo<MaxAdditionalFields> {
IdentityInfo {
additional: BoundedVec::default(),
display: Data::Raw(b"name".to_vec().try_into().unwrap()),
legal: Data::default(),
web: Data::Raw(b"website".to_vec().try_into().unwrap()),
riot: Data::default(),
email: Data::default(),
pgp_fingerprint: None,
image: Data::default(),
twitter: Data::default(),
}
}
pub(super) fn test_identity_info_deposit() -> <Test as pallet_balances::Config>::Balance {
let basic_deposit: u64 = <Test as pallet_identity::Config>::BasicDeposit::get();
let byte_deposit: u64 = <Test as pallet_identity::Config>::ByteDeposit::get();
byte_deposit * test_identity_info().encoded_size() as u64 + basic_deposit
}
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pallet_balances::GenesisConfig::<Test> {
balances: vec![
(1, 50),
(2, 50),
(3, 50),
(4, 50),
(5, 30),
(6, 50),
(7, 50),
(8, 50),
(9, 50),
(1, 1000),
(2, 1000),
(3, 1000),
(4, 1000),
(5, test_identity_info_deposit() + 10),
(6, 1000),
(7, 1000),
(8, 1000),
(9, 1000),
],
}
.assimilate_storage(&mut t)
@@ -263,17 +285,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
ext.execute_with(|| {
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 1));
let info = IdentityInfo {
additional: BoundedVec::default(),
display: Data::Raw(b"name".to_vec().try_into().unwrap()),
legal: Data::default(),
web: Data::Raw(b"website".to_vec().try_into().unwrap()),
riot: Data::default(),
email: Data::default(),
pgp_fingerprint: None,
image: Data::default(),
twitter: Data::default(),
};
let info = test_identity_info();
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(1), Box::new(info.clone())));
assert_ok!(Identity::provide_judgement(
RuntimeOrigin::signed(1),