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
ed46bb93
Unverified
Commit
ed46bb93
authored
1 year ago
by
bgallois
Browse files
Options
Downloads
Patches
Plain Diff
add handlers documentation
parent
dcb34e4c
No related branches found
No related tags found
1 merge request
!246
Fix weight accounting
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
primitives/membership/src/traits.rs
+6
-0
6 additions, 0 deletions
primitives/membership/src/traits.rs
runtime/common/src/handlers.rs
+19
-11
19 additions, 11 deletions
runtime/common/src/handlers.rs
with
25 additions
and
11 deletions
primitives/membership/src/traits.rs
+
6
−
0
View file @
ed46bb93
...
@@ -16,8 +16,11 @@
...
@@ -16,8 +16,11 @@
use
frame_support
::
pallet_prelude
::
*
;
use
frame_support
::
pallet_prelude
::
*
;
/// A trait defining operations for checking if membership-related operations are allowed.
pub
trait
CheckMembershipOpAllowed
<
IdtyId
>
{
pub
trait
CheckMembershipOpAllowed
<
IdtyId
>
{
/// Checks if adding a membership is allowed.
fn
check_add_membership
(
idty_id
:
IdtyId
)
->
Result
<
(),
DispatchError
>
;
fn
check_add_membership
(
idty_id
:
IdtyId
)
->
Result
<
(),
DispatchError
>
;
/// Checks if renewing a membership is allowed.
fn
check_renew_membership
(
idty_id
:
IdtyId
)
->
Result
<
(),
DispatchError
>
;
fn
check_renew_membership
(
idty_id
:
IdtyId
)
->
Result
<
(),
DispatchError
>
;
}
}
...
@@ -31,11 +34,14 @@ impl<IdtyId> CheckMembershipOpAllowed<IdtyId> for () {
...
@@ -31,11 +34,14 @@ impl<IdtyId> CheckMembershipOpAllowed<IdtyId> for () {
}
}
}
}
/// A trait defining behavior for handling new memberships and membership renewals.
pub
trait
OnNewMembership
<
IdtyId
>
{
pub
trait
OnNewMembership
<
IdtyId
>
{
/// Called when a new membership is created.
fn
on_created
(
idty_index
:
&
IdtyId
);
fn
on_created
(
idty_index
:
&
IdtyId
);
fn
on_renewed
(
idty_index
:
&
IdtyId
);
fn
on_renewed
(
idty_index
:
&
IdtyId
);
}
}
/// Called when an existing membership is renewed.
pub
trait
OnRemoveMembership
<
IdtyId
>
{
pub
trait
OnRemoveMembership
<
IdtyId
>
{
fn
on_removed
(
idty_index
:
&
IdtyId
)
->
Weight
;
fn
on_removed
(
idty_index
:
&
IdtyId
)
->
Weight
;
}
}
...
...
This diff is collapsed.
Click to expand it.
runtime/common/src/handlers.rs
+
19
−
11
View file @
ed46bb93
...
@@ -20,7 +20,8 @@ use frame_support::pallet_prelude::Weight;
...
@@ -20,7 +20,8 @@ use frame_support::pallet_prelude::Weight;
use
frame_support
::
traits
::
UnfilteredDispatchable
;
use
frame_support
::
traits
::
UnfilteredDispatchable
;
use
pallet_smith_members
::
SmithRemovalReason
;
use
pallet_smith_members
::
SmithRemovalReason
;
// new session handler
/// OnNewSession handler for the runtime calling all the implementation
/// of OnNewSession
pub
struct
OnNewSessionHandler
<
Runtime
>
(
core
::
marker
::
PhantomData
<
Runtime
>
);
pub
struct
OnNewSessionHandler
<
Runtime
>
(
core
::
marker
::
PhantomData
<
Runtime
>
);
impl
<
Runtime
>
pallet_authority_members
::
traits
::
OnNewSession
for
OnNewSessionHandler
<
Runtime
>
impl
<
Runtime
>
pallet_authority_members
::
traits
::
OnNewSession
for
OnNewSessionHandler
<
Runtime
>
where
where
...
@@ -32,13 +33,12 @@ where
...
@@ -32,13 +33,12 @@ where
}
}
}
}
/// New membership event runtime handler
/// Runtime handler for OnNewMembership, calling all implementations of
/// OnNewMembership and implementing logic at the runtime level.
pub
struct
OnNewMembershipHandler
<
Runtime
>
(
core
::
marker
::
PhantomData
<
Runtime
>
);
pub
struct
OnNewMembershipHandler
<
Runtime
>
(
core
::
marker
::
PhantomData
<
Runtime
>
);
impl
<
impl
<
Runtime
:
frame_system
::
Config
<
AccountId
=
AccountId
>
Runtime
:
frame_system
::
Config
<
AccountId
=
AccountId
>
+
pallet_identity
::
Config
<
IdtyData
=
IdtyData
,
IdtyIndex
=
IdtyIndex
>
+
pallet_identity
::
Config
<
IdtyData
=
IdtyData
,
IdtyIndex
=
IdtyIndex
>
+
pallet_membership
::
Config
+
pallet_smith_members
::
Config
<
IdtyIndex
=
IdtyIndex
>
+
pallet_duniter_wot
::
Config
+
pallet_duniter_wot
::
Config
+
pallet_universal_dividend
::
Config
,
+
pallet_universal_dividend
::
Config
,
>
sp_membership
::
traits
::
OnNewMembership
<
IdtyIndex
>
for
OnNewMembershipHandler
<
Runtime
>
>
sp_membership
::
traits
::
OnNewMembership
<
IdtyIndex
>
for
OnNewMembershipHandler
<
Runtime
>
...
@@ -46,7 +46,8 @@ impl<
...
@@ -46,7 +46,8 @@ impl<
fn
on_created
(
idty_index
:
&
IdtyIndex
)
{
fn
on_created
(
idty_index
:
&
IdtyIndex
)
{
// duniter-wot related actions
// duniter-wot related actions
pallet_duniter_wot
::
Pallet
::
<
Runtime
>
::
on_created
(
idty_index
);
pallet_duniter_wot
::
Pallet
::
<
Runtime
>
::
on_created
(
idty_index
);
// when main membership is acquired, it starts getting right to UD
// When main membership is acquired, it starts getting right to UD.
pallet_identity
::
Identities
::
<
Runtime
>
::
mutate_exists
(
idty_index
,
|
idty_val_opt
|
{
pallet_identity
::
Identities
::
<
Runtime
>
::
mutate_exists
(
idty_index
,
|
idty_val_opt
|
{
if
let
Some
(
ref
mut
idty_val
)
=
idty_val_opt
{
if
let
Some
(
ref
mut
idty_val
)
=
idty_val_opt
{
idty_val
.data
=
IdtyData
{
idty_val
.data
=
IdtyData
{
...
@@ -60,12 +61,14 @@ impl<
...
@@ -60,12 +61,14 @@ impl<
fn
on_renewed
(
_idty_index
:
&
IdtyIndex
)
{}
fn
on_renewed
(
_idty_index
:
&
IdtyIndex
)
{}
}
}
/// Remove membership event runtime handler
/// Runtime handler for OnRemoveMembership, calling all implementations of
/// OnRemoveMembership and implementing logic at the runtime level.
/// As the weight accounting is not trivial in this handler, the weight is
/// done at the handler level.
pub
struct
OnRemoveMembershipHandler
<
Runtime
>
(
core
::
marker
::
PhantomData
<
Runtime
>
);
pub
struct
OnRemoveMembershipHandler
<
Runtime
>
(
core
::
marker
::
PhantomData
<
Runtime
>
);
impl
<
impl
<
Runtime
:
frame_system
::
Config
<
AccountId
=
AccountId
>
Runtime
:
frame_system
::
Config
<
AccountId
=
AccountId
>
+
pallet_identity
::
Config
<
IdtyData
=
IdtyData
,
IdtyIndex
=
IdtyIndex
>
+
pallet_identity
::
Config
<
IdtyData
=
IdtyData
,
IdtyIndex
=
IdtyIndex
>
+
pallet_membership
::
Config
+
pallet_smith_members
::
Config
<
IdtyIndex
=
IdtyIndex
>
+
pallet_smith_members
::
Config
<
IdtyIndex
=
IdtyIndex
>
+
pallet_duniter_wot
::
Config
+
pallet_duniter_wot
::
Config
+
pallet_universal_dividend
::
Config
,
+
pallet_universal_dividend
::
Config
,
...
@@ -74,11 +77,12 @@ impl<
...
@@ -74,11 +77,12 @@ impl<
fn
on_removed
(
idty_index
:
&
IdtyIndex
)
->
Weight
{
fn
on_removed
(
idty_index
:
&
IdtyIndex
)
->
Weight
{
// duniter-wot related actions
// duniter-wot related actions
let
mut
weight
=
pallet_duniter_wot
::
Pallet
::
<
Runtime
>
::
on_removed
(
idty_index
);
let
mut
weight
=
pallet_duniter_wot
::
Pallet
::
<
Runtime
>
::
on_removed
(
idty_index
);
let
mut
add_db_reads_writes
=
|
reads
,
writes
|
{
let
mut
add_db_reads_writes
=
|
reads
,
writes
|
{
weight
+=
crate
::
constants
::
DbWeight
::
get
()
.reads_writes
(
reads
,
writes
);
weight
+=
crate
::
constants
::
DbWeight
::
get
()
.reads_writes
(
reads
,
writes
);
};
};
//
w
hen membership is removed, call on_removed_member handler which auto claims UD
//
W
hen membership is removed, call on_removed_member handler which auto claims UD
.
if
let
Some
(
idty_value
)
=
pallet_identity
::
Identities
::
<
Runtime
>
::
get
(
idty_index
)
{
if
let
Some
(
idty_value
)
=
pallet_identity
::
Identities
::
<
Runtime
>
::
get
(
idty_index
)
{
add_db_reads_writes
(
1
,
0
);
add_db_reads_writes
(
1
,
0
);
if
let
Some
(
first_ud_index
)
=
idty_value
.data.first_eligible_ud
.into
()
{
if
let
Some
(
first_ud_index
)
=
idty_value
.data.first_eligible_ud
.into
()
{
...
@@ -89,12 +93,15 @@ impl<
...
@@ -89,12 +93,15 @@ impl<
);
);
}
}
}
}
weight
+=
pallet_smith_members
::
Pallet
::
<
Runtime
>
::
on_removed_wot_member
(
*
idty_index
);
weight
// When membership is removed, also remove from smith member.
weight
.saturating_add
(
pallet_smith_members
::
Pallet
::
<
Runtime
>
::
on_removed_wot_member
(
*
idty_index
),
)
}
}
}
}
//
spend treasury handler
//
/ Runtime handler for TreasurySpendFunds.
pub
struct
TreasurySpendFunds
<
Runtime
>
(
core
::
marker
::
PhantomData
<
Runtime
>
);
pub
struct
TreasurySpendFunds
<
Runtime
>
(
core
::
marker
::
PhantomData
<
Runtime
>
);
impl
<
Runtime
>
pallet_treasury
::
SpendFunds
<
Runtime
>
for
TreasurySpendFunds
<
Runtime
>
impl
<
Runtime
>
pallet_treasury
::
SpendFunds
<
Runtime
>
for
TreasurySpendFunds
<
Runtime
>
where
where
...
@@ -110,6 +117,7 @@ where
...
@@ -110,6 +117,7 @@ where
}
}
}
}
/// Runtime handler for OnSmithDelete.
pub
struct
OnSmithDeletedHandler
<
Runtime
>
(
core
::
marker
::
PhantomData
<
Runtime
>
);
pub
struct
OnSmithDeletedHandler
<
Runtime
>
(
core
::
marker
::
PhantomData
<
Runtime
>
);
impl
<
Runtime
>
pallet_smith_members
::
traits
::
OnSmithDelete
<
Runtime
::
MemberId
>
impl
<
Runtime
>
pallet_smith_members
::
traits
::
OnSmithDelete
<
Runtime
::
MemberId
>
for
OnSmithDeletedHandler
<
Runtime
>
for
OnSmithDeletedHandler
<
Runtime
>
...
...
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