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
b871e19d
Commit
b871e19d
authored
1 year ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
refac certification creation checks
parent
c39d14cc
No related branches found
No related tags found
1 merge request
!215
refac membership
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pallets/certification/src/lib.rs
+49
-31
49 additions, 31 deletions
pallets/certification/src/lib.rs
pallets/duniter-wot/src/lib.rs
+4
-31
4 additions, 31 deletions
pallets/duniter-wot/src/lib.rs
with
53 additions
and
62 deletions
pallets/certification/src/lib.rs
+
49
−
31
View file @
b871e19d
...
@@ -283,38 +283,8 @@ pub mod pallet {
...
@@ -283,38 +283,8 @@ pub mod pallet {
)
->
DispatchResultWithPostInfo
{
)
->
DispatchResultWithPostInfo
{
let
who
=
ensure_signed
(
origin
)
?
;
let
who
=
ensure_signed
(
origin
)
?
;
// Forbid self cert
ensure!
(
issuer
!=
receiver
,
Error
::
<
T
,
I
>
::
CannotCertifySelf
);
// Verify caller ownership
let
issuer_owner_key
=
T
::
OwnerKeyOf
::
convert
(
issuer
)
.ok_or
(
Error
::
<
T
,
I
>
::
IssuerNotFound
)
?
;
ensure!
(
issuer_owner_key
==
who
,
DispatchError
::
BadOrigin
);
// Verify compatibility with other pallets state
T
::
CheckCertAllowed
::
check_cert_allowed
(
issuer
,
receiver
)
?
;
// Verify rule MinReceivedCertToBeAbleToIssueCert
let
issuer_idty_cert_meta
=
<
StorageIdtyCertMeta
<
T
,
I
>>
::
get
(
issuer
);
ensure!
(
issuer_idty_cert_meta
.received_count
>=
T
::
MinReceivedCertToBeAbleToIssueCert
::
get
(),
Error
::
<
T
,
I
>
::
NotEnoughCertReceived
);
// Verify rule MaxByIssuer
ensure!
(
issuer_idty_cert_meta
.issued_count
<
T
::
MaxByIssuer
::
get
(),
Error
::
<
T
,
I
>
::
IssuedTooManyCert
);
// Verify rule CertPeriod
let
block_number
=
frame_system
::
pallet
::
Pallet
::
<
T
>
::
block_number
();
let
block_number
=
frame_system
::
pallet
::
Pallet
::
<
T
>
::
block_number
();
ensure!
(
Self
::
check_cert_allowed
(
who
,
issuer
,
receiver
,
block_number
)
?
;
block_number
>=
issuer_idty_cert_meta
.next_issuable_on
,
Error
::
<
T
,
I
>
::
NotRespectCertPeriod
);
Self
::
do_add_cert
(
block_number
,
issuer
,
receiver
)
Self
::
do_add_cert
(
block_number
,
issuer
,
receiver
)
}
}
...
@@ -524,6 +494,54 @@ pub mod pallet {
...
@@ -524,6 +494,54 @@ pub mod pallet {
}
}
total_weight
total_weight
}
}
/// check cert allowed
// first internal checks
// then external checks
fn
check_cert_allowed
(
caller_key
:
T
::
AccountId
,
issuer
:
T
::
IdtyIndex
,
receiver
:
T
::
IdtyIndex
,
block_number
:
T
::
BlockNumber
,
)
->
DispatchResult
{
// --- first internal checks
// 1. Forbid self cert
ensure!
(
issuer
!=
receiver
,
Error
::
<
T
,
I
>
::
CannotCertifySelf
);
// 2. Verify caller ownership
let
issuer_owner_key
=
T
::
OwnerKeyOf
::
convert
(
issuer
)
.ok_or
(
Error
::
<
T
,
I
>
::
IssuerNotFound
)
?
;
ensure!
(
issuer_owner_key
==
caller_key
,
DispatchError
::
BadOrigin
);
// 3. Verify rule MinReceivedCertToBeAbleToIssueCert
// (this number can differ from the one necessary to be member)
let
issuer_idty_cert_meta
=
<
StorageIdtyCertMeta
<
T
,
I
>>
::
get
(
issuer
);
ensure!
(
issuer_idty_cert_meta
.received_count
>=
T
::
MinReceivedCertToBeAbleToIssueCert
::
get
(),
Error
::
<
T
,
I
>
::
NotEnoughCertReceived
);
// 4. Verify rule MaxByIssuer
ensure!
(
issuer_idty_cert_meta
.issued_count
<
T
::
MaxByIssuer
::
get
(),
Error
::
<
T
,
I
>
::
IssuedTooManyCert
);
// 5. Verify rule CertPeriod
ensure!
(
block_number
>=
issuer_idty_cert_meta
.next_issuable_on
,
Error
::
<
T
,
I
>
::
NotRespectCertPeriod
);
// --- then external checks
// - issuer is member
// - receiver is confirmed
// - receiver is not revoked
T
::
CheckCertAllowed
::
check_cert_allowed
(
issuer
,
receiver
)
?
;
Ok
(())
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
pallets/duniter-wot/src/lib.rs
+
4
−
31
View file @
b871e19d
...
@@ -190,26 +190,12 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::CheckCertAllowed<Id
...
@@ -190,26 +190,12 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::CheckCertAllowed<Id
{
{
// check the following:
// check the following:
// - issuer has identity
// - issuer has identity
// - issuer identity is
validated
// - issuer identity is
member
// - receiver has identity
// - receiver has identity
// - receiver identity is confirmed or validated
// - receiver identity is confirmed and not revoked
// - receiver has membership
//
// /!\ do not check the following:
// - receiver has membership
// - issuer has membership
// this has the following consequences:
// - issuer can issue cert even if he lost his membership
// (not renewed or passed below cert threshold and above again without claiming membership)
// this is counterintuitive behavior but not a big problem
//
// TODO to fix this strange behavior, we will have to make the tests
// (CheckCertAllowed and CheckMembershipCallAllowed) run on the relevant instance
// i.e. Cert for Wot, SmithCert for SmithWot...
// → see issue #136
fn
check_cert_allowed
(
issuer
:
IdtyIndex
,
receiver
:
IdtyIndex
)
->
Result
<
(),
DispatchError
>
{
fn
check_cert_allowed
(
issuer
:
IdtyIndex
,
receiver
:
IdtyIndex
)
->
Result
<
(),
DispatchError
>
{
// issuer checks
// issuer checks
// ensure issuer
has validated identity
// ensure issuer
is member
if
let
Some
(
issuer_data
)
=
pallet_identity
::
Pallet
::
<
T
>
::
identity
(
issuer
)
{
if
let
Some
(
issuer_data
)
=
pallet_identity
::
Pallet
::
<
T
>
::
identity
(
issuer
)
{
ensure!
(
ensure!
(
issuer_data
.status
==
IdtyStatus
::
Member
,
issuer_data
.status
==
IdtyStatus
::
Member
,
...
@@ -218,15 +204,9 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::CheckCertAllowed<Id
...
@@ -218,15 +204,9 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::CheckCertAllowed<Id
}
else
{
}
else
{
return
Err
(
Error
::
<
T
,
I
>
::
IdtyNotFound
.into
());
return
Err
(
Error
::
<
T
,
I
>
::
IdtyNotFound
.into
());
}
}
// issue #136 this has to be done on the correct instance of membership pallet
// // ensure issuer has membership
// if pallet_membership::Pallet::<T, I>::membership(issuer).is_none() {
// // improvement: give reason why issuer can not emit cert (not member)
// return Err(Error::<T, I>::IssuerNotMember.into());
// }
// receiver checks
// receiver checks
// ensure receiver
ha
s confirmed
or validated identity
// ensure receiver
identity i
s confirmed
and not revoked
if
let
Some
(
receiver_data
)
=
pallet_identity
::
Pallet
::
<
T
>
::
identity
(
receiver
)
{
if
let
Some
(
receiver_data
)
=
pallet_identity
::
Pallet
::
<
T
>
::
identity
(
receiver
)
{
match
receiver_data
.status
{
match
receiver_data
.status
{
IdtyStatus
::
Unvalidated
|
IdtyStatus
::
Member
|
IdtyStatus
::
NotMember
=>
{}
// able to receive cert
IdtyStatus
::
Unvalidated
|
IdtyStatus
::
Member
|
IdtyStatus
::
NotMember
=>
{}
// able to receive cert
...
@@ -236,13 +216,6 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::CheckCertAllowed<Id
...
@@ -236,13 +216,6 @@ impl<T: Config<I>, I: 'static> pallet_certification::traits::CheckCertAllowed<Id
}
else
{
}
else
{
return
Err
(
Error
::
<
T
,
I
>
::
IdtyNotFound
.into
());
return
Err
(
Error
::
<
T
,
I
>
::
IdtyNotFound
.into
());
}
}
// issue #136 this has to be done on the correct instance of membership pallet
// // ensure receiver has a membership or a pending membership
// if pallet_membership::Pallet::<T, I>::pending_membership(issuer).is_none()
// && pallet_membership::Pallet::<T, I>::membership(issuer).is_none()
// {
// return Err(Error::<T, I>::CertToUndefined.into());
// }
Ok
(())
Ok
(())
}
}
}
}
...
...
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