Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter v2S
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
a16039d3
Commit
a16039d3
authored
1 year ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
feat(smith-members): remove CertsByReceiver (all in Smiths)
parent
39ab7b77
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
pallets/smith-members/src/lib.rs
+24
-23
24 additions, 23 deletions
pallets/smith-members/src/lib.rs
pallets/smith-members/src/tests.rs
+64
-37
64 additions, 37 deletions
pallets/smith-members/src/tests.rs
pallets/smith-members/src/types.rs
+5
-2
5 additions, 2 deletions
pallets/smith-members/src/types.rs
with
93 additions
and
62 deletions
pallets/smith-members/src/lib.rs
+
24
−
23
View file @
a16039d3
...
@@ -173,7 +173,6 @@ pub mod pallet {
...
@@ -173,7 +173,6 @@ pub mod pallet {
// Write CertsByReceiver
// Write CertsByReceiver
issuers_
.sort
();
issuers_
.sort
();
let
issuers_count
=
issuers_
.len
();
let
issuers_count
=
issuers_
.len
();
CertsByReceiver
::
<
T
>
::
insert
(
receiver
,
issuers_
);
let
smith_status
=
if
issuers_count
as
u32
>=
T
::
MinCertForMembership
::
get
()
{
let
smith_status
=
if
issuers_count
as
u32
>=
T
::
MinCertForMembership
::
get
()
{
SmithStatus
::
Smith
SmithStatus
::
Smith
}
else
{
}
else
{
...
@@ -186,6 +185,7 @@ pub mod pallet {
...
@@ -186,6 +185,7 @@ pub mod pallet {
expires_on
:
Some
(
expires_on
:
Some
(
CurrentSession
::
<
T
>
::
get
()
+
T
::
InactivityMaxDuration
::
get
(),
CurrentSession
::
<
T
>
::
get
()
+
T
::
InactivityMaxDuration
::
get
(),
),
),
received_certs
:
issuers_
,
},
},
);
);
ExpiresOn
::
<
T
>
::
append
(
ExpiresOn
::
<
T
>
::
append
(
...
@@ -196,14 +196,10 @@ pub mod pallet {
...
@@ -196,14 +196,10 @@ pub mod pallet {
}
}
}
}
/// maps identity index to smith value
#[pallet::storage]
pub
type
CertsByReceiver
<
T
:
Config
>
=
StorageMap
<
_
,
Twox64Concat
,
T
::
IdtyIndex
,
Vec
<
T
::
IdtyIndex
>
,
OptionQuery
>
;
/// maps identity index to smith status
/// maps identity index to smith status
#[pallet::storage]
#[pallet::storage]
pub
type
Smiths
<
T
:
Config
>
=
StorageMap
<
_
,
Twox64Concat
,
T
::
IdtyIndex
,
SmithMeta
,
OptionQuery
>
;
pub
type
Smiths
<
T
:
Config
>
=
StorageMap
<
_
,
Twox64Concat
,
T
::
IdtyIndex
,
SmithMeta
<
T
::
IdtyIndex
>
,
OptionQuery
>
;
/// maps session index to possible smith removals
/// maps session index to possible smith removals
#[pallet::storage]
#[pallet::storage]
...
@@ -242,6 +238,8 @@ pub mod pallet {
...
@@ -242,6 +238,8 @@ pub mod pallet {
NotAMember
,
NotAMember
,
}
}
// TODO: refactor with check_* and do_* functions
#[pallet::call]
#[pallet::call]
impl
<
T
:
Config
>
Pallet
<
T
>
{
impl
<
T
:
Config
>
Pallet
<
T
>
{
#[pallet::call_index(
0
)]
#[pallet::call_index(
0
)]
...
@@ -270,6 +268,7 @@ pub mod pallet {
...
@@ -270,6 +268,7 @@ pub mod pallet {
SmithMeta
{
SmithMeta
{
status
:
SmithStatus
::
Invited
,
status
:
SmithStatus
::
Invited
,
expires_on
:
Some
(
new_expires_on
),
expires_on
:
Some
(
new_expires_on
),
received_certs
:
vec!
[],
},
},
);
);
ExpiresOn
::
<
T
>
::
append
(
new_expires_on
,
receiver
);
ExpiresOn
::
<
T
>
::
append
(
new_expires_on
,
receiver
);
...
@@ -322,20 +321,22 @@ pub mod pallet {
...
@@ -322,20 +321,22 @@ pub mod pallet {
Error
::
<
T
>
::
ReceveirMustAcceptInvitation
Error
::
<
T
>
::
ReceveirMustAcceptInvitation
);
);
CertsByReceiver
::
<
T
>
::
mutate
(
receiver
,
|
certs
|
{
let
certs
=
certs
.get_or_insert
(
vec!
[]);
certs
.push
(
issuer
);
Smiths
::
<
T
>
::
mutate
(
receiver
,
|
maybe_smith_meta
|
{
Smiths
::
<
T
>
::
mutate
(
receiver
,
|
maybe_smith_meta
|
{
let
maybe_smith_meta
=
let
maybe_smith_meta
=
maybe_smith_meta
.as_mut
()
.expect
(
"status checked earlier"
);
maybe_smith_meta
.as_mut
()
.expect
(
"status checked earlier"
);
maybe_smith_meta
.received_certs
.push
(
issuer
);
maybe_smith_meta
.received_certs
.sort
();
// TODO: "as u32" allowed?
// TODO: "as u32" allowed?
maybe_smith_meta
.status
=
maybe_smith_meta
.status
=
if
maybe_smith_meta
.received_certs
.len
()
as
u32
if
certs
.len
()
as
u32
>=
T
::
MinCertForMembership
::
get
()
{
>=
T
::
MinCertForMembership
::
get
()
{
SmithStatus
::
Smith
SmithStatus
::
Smith
}
else
{
}
else
{
SmithStatus
::
Pending
SmithStatus
::
Pending
};
};
});
// expiry postponed
let
new_expires_on
=
CurrentSession
::
<
T
>
::
get
()
+
T
::
InactivityMaxDuration
::
get
();
maybe_smith_meta
.expires_on
=
Some
(
new_expires_on
);
// TODO: unschedule old expiry
});
});
Ok
(()
.into
())
Ok
(()
.into
())
...
@@ -405,11 +406,11 @@ impl<T: Config> Pallet<T> {
...
@@ -405,11 +406,11 @@ impl<T: Config> Pallet<T> {
impl
<
T
:
Config
>
Pallet
<
T
>
{
impl
<
T
:
Config
>
Pallet
<
T
>
{
fn
do_is_member
(
idty_id
:
&
T
::
IdtyIndex
)
->
bool
{
fn
do_is_member
(
idty_id
:
&
T
::
IdtyIndex
)
->
bool
{
let
Some
(
certifications
)
=
CertsByReceiver
::
<
T
>
::
get
(
idty_id
)
else
{
let
Some
(
smith
)
=
Smiths
::
<
T
>
::
get
(
idty_id
)
else
{
return
false
;
return
false
;
};
};
let
mut
count
=
0u32
;
let
mut
count
=
0u32
;
for
_
in
certification
s
{
for
_
in
smith
.received_cert
s
{
count
+=
1
;
count
+=
1
;
}
}
return
count
>=
T
::
MinCertForMembership
::
get
();
return
count
>=
T
::
MinCertForMembership
::
get
();
...
...
This diff is collapsed.
Click to expand it.
pallets/smith-members/src/tests.rs
+
64
−
37
View file @
a16039d3
...
@@ -42,7 +42,6 @@ fn process_to_become_a_smith_and_lose_it() {
...
@@ -42,7 +42,6 @@ fn process_to_become_a_smith_and_lose_it() {
})
})
.execute_with
(||
{
.execute_with
(||
{
// State before
// State before
assert_eq!
(
CertsByReceiver
::
<
Runtime
>
::
get
(
5
),
None
);
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
5
),
None
);
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
5
),
None
);
// Try to invite
// Try to invite
assert_ok!
(
Pallet
::
<
Runtime
>
::
invite_smith
(
RuntimeOrigin
::
signed
(
1
),
5
));
assert_ok!
(
Pallet
::
<
Runtime
>
::
invite_smith
(
RuntimeOrigin
::
signed
(
1
),
5
));
...
@@ -51,30 +50,39 @@ fn process_to_become_a_smith_and_lose_it() {
...
@@ -51,30 +50,39 @@ fn process_to_become_a_smith_and_lose_it() {
5
5
)));
)));
// State after
// State after
assert_eq!
(
CertsByReceiver
::
<
Runtime
>
::
get
(
5
),
None
);
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
5
)
.unwrap
()
.status
,
Smiths
::
<
Runtime
>
::
get
(
5
)
.unwrap
(),
SmithStatus
::
Pending
SmithMeta
{
status
:
SmithStatus
::
Pending
,
expires_on
:
Some
(
5
),
received_certs
:
vec!
[],
}
);
);
// Then certification 1/2
// Then certification 1/2
assert_ok!
(
Pallet
::
<
Runtime
>
::
certify_smith
(
assert_ok!
(
Pallet
::
<
Runtime
>
::
certify_smith
(
RuntimeOrigin
::
signed
(
1
),
RuntimeOrigin
::
signed
(
1
),
5
5
));
));
assert_eq!
(
CertsByReceiver
::
<
Runtime
>
::
get
(
5
)
.unwrap
()
.len
(),
1
);
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
5
)
.unwrap
()
.status
,
Smiths
::
<
Runtime
>
::
get
(
5
)
.unwrap
(),
SmithStatus
::
Pending
SmithMeta
{
status
:
SmithStatus
::
Pending
,
expires_on
:
Some
(
5
),
received_certs
:
vec!
[
1
],
}
);
);
// Then certification 2/2
// Then certification 2/2
assert_ok!
(
Pallet
::
<
Runtime
>
::
certify_smith
(
assert_ok!
(
Pallet
::
<
Runtime
>
::
certify_smith
(
RuntimeOrigin
::
signed
(
2
),
RuntimeOrigin
::
signed
(
2
),
5
5
));
));
assert_eq!
(
CertsByReceiver
::
<
Runtime
>
::
get
(
5
)
.unwrap
()
.len
(),
2
);
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
5
)
.unwrap
()
.status
,
Smiths
::
<
Runtime
>
::
get
(
5
)
.unwrap
(),
SmithStatus
::
Smith
SmithMeta
{
status
:
SmithStatus
::
Smith
,
expires_on
:
Some
(
5
),
received_certs
:
vec!
[
1
,
2
],
}
);
);
// On session 4 everything if fine
// On session 4 everything if fine
...
@@ -84,9 +92,9 @@ fn process_to_become_a_smith_and_lose_it() {
...
@@ -84,9 +92,9 @@ fn process_to_become_a_smith_and_lose_it() {
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
5
)
.is_some
(),
true
);
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
5
)
.is_some
(),
true
);
// On session 5 no more smiths because of lack of activity
// On session 5 no more smiths because of lack of activity
Pallet
::
<
Runtime
>
::
on_new_session
(
5
);
Pallet
::
<
Runtime
>
::
on_new_session
(
5
);
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
1
),
None
);
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
1
),
None
);
// TODO: noautoremove (remaining certs)
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
2
),
None
);
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
2
),
None
);
// TODO: noautoremove (remaining certs)
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
5
),
None
);
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
5
),
None
);
// TODO: noautoremove (remaining certs)
});
});
}
}
...
@@ -114,27 +122,38 @@ fn should_have_checks_on_certify() {
...
@@ -114,27 +122,38 @@ fn should_have_checks_on_certify() {
})
})
.execute_with
(||
{
.execute_with
(||
{
// Initially
// Initially
assert_eq!
(
CertsByReceiver
::
<
Runtime
>
::
iter
()
.count
(),
4
);
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
1
)
.unwrap
()
.status
,
Smiths
::
<
Runtime
>
::
get
(
1
)
.unwrap
(),
SmithStatus
::
Smith
SmithMeta
{
status
:
SmithStatus
::
Smith
,
expires_on
:
Some
(
5
),
received_certs
:
vec!
[
2
,
3
,
4
],
}
);
);
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
2
)
.unwrap
()
.status
,
Smiths
::
<
Runtime
>
::
get
(
2
)
.unwrap
(),
SmithStatus
::
Smith
SmithMeta
{
status
:
SmithStatus
::
Smith
,
expires_on
:
Some
(
5
),
received_certs
:
vec!
[
3
,
4
],
}
);
);
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
3
)
.unwrap
()
.status
,
Smiths
::
<
Runtime
>
::
get
(
3
)
.unwrap
(),
SmithStatus
::
Pending
SmithMeta
{
status
:
SmithStatus
::
Pending
,
expires_on
:
Some
(
5
),
received_certs
:
vec!
[
4
],
}
);
);
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
4
)
.unwrap
()
.status
,
Smiths
::
<
Runtime
>
::
get
(
4
)
.unwrap
(),
SmithStatus
::
Smith
SmithMeta
{
status
:
SmithStatus
::
Smith
,
expires_on
:
Some
(
5
),
received_certs
:
vec!
[
1
,
2
],
}
);
);
assert_eq!
(
CertsByReceiver
::
<
Runtime
>
::
get
(
1
)
.unwrap
()
.len
(),
3
);
assert_eq!
(
CertsByReceiver
::
<
Runtime
>
::
get
(
2
)
.unwrap
()
.len
(),
2
);
assert_eq!
(
CertsByReceiver
::
<
Runtime
>
::
get
(
3
)
.unwrap
()
.len
(),
1
);
assert_eq!
(
CertsByReceiver
::
<
Runtime
>
::
get
(
4
)
.unwrap
()
.len
(),
2
);
// Tries all possible errors
// Tries all possible errors
assert_err!
(
assert_err!
(
...
@@ -155,10 +174,13 @@ fn should_have_checks_on_certify() {
...
@@ -155,10 +174,13 @@ fn should_have_checks_on_certify() {
);
);
// #3: state before
// #3: state before
assert_eq!
(
CertsByReceiver
::
<
Runtime
>
::
get
(
3
)
.unwrap
()
.len
(),
1
);
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
3
)
.unwrap
()
.status
,
Smiths
::
<
Runtime
>
::
get
(
3
)
.unwrap
(),
SmithStatus
::
Pending
SmithMeta
{
status
:
SmithStatus
::
Pending
,
expires_on
:
Some
(
5
),
received_certs
:
vec!
[
4
],
}
);
);
// Try to certify #3
// Try to certify #3
assert_ok!
(
Pallet
::
<
Runtime
>
::
certify_smith
(
assert_ok!
(
Pallet
::
<
Runtime
>
::
certify_smith
(
...
@@ -166,10 +188,13 @@ fn should_have_checks_on_certify() {
...
@@ -166,10 +188,13 @@ fn should_have_checks_on_certify() {
3
3
));
));
// #3: state after
// #3: state after
assert_eq!
(
CertsByReceiver
::
<
Runtime
>
::
get
(
3
)
.unwrap
()
.len
(),
2
);
assert_eq!
(
assert_eq!
(
Smiths
::
<
Runtime
>
::
get
(
3
)
.unwrap
()
.status
,
Smiths
::
<
Runtime
>
::
get
(
3
)
.unwrap
(),
SmithStatus
::
Smith
SmithMeta
{
status
:
SmithStatus
::
Smith
,
expires_on
:
Some
(
5
),
received_certs
:
vec!
[
1
,
4
],
}
);
);
});
});
}
}
...
@@ -184,9 +209,8 @@ fn smith_activity_postpones_expiration() {
...
@@ -184,9 +209,8 @@ fn smith_activity_postpones_expiration() {
4
=>
None
,
4
=>
None
,
],
],
2
=>
btreemap!
[
2
=>
btreemap!
[
3
=>
None
,
4
=>
None
,
4
=>
None
,
4
=>
None
,
5
=>
None
,
]
]
],
],
})
})
...
@@ -206,7 +230,8 @@ fn smith_activity_postpones_expiration() {
...
@@ -206,7 +230,8 @@ fn smith_activity_postpones_expiration() {
Smiths
::
<
Runtime
>
::
get
(
2
),
Smiths
::
<
Runtime
>
::
get
(
2
),
Some
(
SmithMeta
{
Some
(
SmithMeta
{
status
:
SmithStatus
::
Smith
,
status
:
SmithStatus
::
Smith
,
expires_on
:
None
expires_on
:
None
,
received_certs
:
vec!
[
3
,
4
],
})
})
);
);
...
@@ -218,7 +243,8 @@ fn smith_activity_postpones_expiration() {
...
@@ -218,7 +243,8 @@ fn smith_activity_postpones_expiration() {
Smiths
::
<
Runtime
>
::
get
(
2
),
Smiths
::
<
Runtime
>
::
get
(
2
),
Some
(
SmithMeta
{
Some
(
SmithMeta
{
status
:
SmithStatus
::
Smith
,
status
:
SmithStatus
::
Smith
,
expires_on
:
Some
(
11
)
expires_on
:
Some
(
11
),
received_certs
:
vec!
[
3
,
4
],
})
})
);
);
// Still not expired on session 10
// Still not expired on session 10
...
@@ -228,7 +254,8 @@ fn smith_activity_postpones_expiration() {
...
@@ -228,7 +254,8 @@ fn smith_activity_postpones_expiration() {
Smiths
::
<
Runtime
>
::
get
(
2
),
Smiths
::
<
Runtime
>
::
get
(
2
),
Some
(
SmithMeta
{
Some
(
SmithMeta
{
status
:
SmithStatus
::
Smith
,
status
:
SmithStatus
::
Smith
,
expires_on
:
Some
(
11
)
expires_on
:
Some
(
11
),
received_certs
:
vec!
[
3
,
4
],
})
})
);
);
// Finally expired on session 11
// Finally expired on session 11
...
...
This diff is collapsed.
Click to expand it.
pallets/smith-members/src/types.rs
+
5
−
2
View file @
a16039d3
...
@@ -24,14 +24,17 @@ use pallet_authority_members::SessionIndex;
...
@@ -24,14 +24,17 @@ use pallet_authority_members::SessionIndex;
use
scale_info
::
TypeInfo
;
use
scale_info
::
TypeInfo
;
/// certification metadata attached to an identity
/// certification metadata attached to an identity
#[derive(Encode,
Decode,
Clone,
Copy,
PartialEq,
Eq,
RuntimeDebug,
TypeInfo)]
#[derive(Encode,
Decode,
Clone,
PartialEq,
Eq,
RuntimeDebug,
TypeInfo)]
pub
struct
SmithMeta
{
pub
struct
SmithMeta
<
IdtyIndex
>
{
/// current status of the smith
/// current status of the smith
pub
status
:
SmithStatus
,
pub
status
:
SmithStatus
,
/// the session at which the smith will expire (for lack of validation activity)
/// the session at which the smith will expire (for lack of validation activity)
pub
expires_on
:
Option
<
SessionIndex
>
,
pub
expires_on
:
Option
<
SessionIndex
>
,
/// the recertifications received from other smiths
pub
received_certs
:
Vec
<
IdtyIndex
>
,
}
}
// TODO: check what is really used
/// certification metadata attached to an identity
/// certification metadata attached to an identity
#[derive(Encode,
Decode,
Clone,
Copy,
PartialEq,
Eq,
RuntimeDebug,
TypeInfo)]
#[derive(Encode,
Decode,
Clone,
Copy,
PartialEq,
Eq,
RuntimeDebug,
TypeInfo)]
pub
struct
SmithCertMeta
<
BlockNumber
:
Default
>
{
pub
struct
SmithCertMeta
<
BlockNumber
:
Default
>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment