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
0e9cf55d
Commit
0e9cf55d
authored
1 year ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
fix(
#148
): remove AuthoritiesCounter
parent
d62c033a
No related branches found
No related tags found
1 merge request
!224
Resolve "use counted maps instead of counters in authority members"
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pallets/authority-members/src/lib.rs
+7
-15
7 additions, 15 deletions
pallets/authority-members/src/lib.rs
with
7 additions
and
15 deletions
pallets/authority-members/src/lib.rs
+
7
−
15
View file @
0e9cf55d
...
@@ -116,18 +116,12 @@ pub mod pallet {
...
@@ -116,18 +116,12 @@ pub mod pallet {
.collect
::
<
Vec
<
T
::
MemberId
>>
();
.collect
::
<
Vec
<
T
::
MemberId
>>
();
members_ids
.sort
();
members_ids
.sort
();
AuthoritiesCounter
::
<
T
>
::
put
(
members_ids
.len
()
as
u32
);
OnlineAuthorities
::
<
T
>
::
put
(
members_ids
.clone
());
OnlineAuthorities
::
<
T
>
::
put
(
members_ids
.clone
());
}
}
}
}
// STORAGE //
// STORAGE //
/// count the number of authorities
#[pallet::storage]
#[pallet::getter(fn
authorities_counter)]
pub
type
AuthoritiesCounter
<
T
:
Config
>
=
StorageValue
<
_
,
u32
,
ValueQuery
>
;
/// list incoming authorities
/// list incoming authorities
#[pallet::storage]
#[pallet::storage]
#[pallet::getter(fn
incoming)]
#[pallet::getter(fn
incoming)]
...
@@ -264,7 +258,7 @@ pub mod pallet {
...
@@ -264,7 +258,7 @@ pub mod pallet {
if
Self
::
is_online
(
member_id
)
&&
!
is_outgoing
{
if
Self
::
is_online
(
member_id
)
&&
!
is_outgoing
{
return
Err
(
Error
::
<
T
>
::
AlreadyOnline
.into
());
return
Err
(
Error
::
<
T
>
::
AlreadyOnline
.into
());
}
}
if
A
uthorities
C
ounter
::
<
T
>
::
get
()
>=
T
::
MaxAuthorities
::
get
()
{
if
Self
::
a
uthorities
_c
ounter
()
>=
T
::
MaxAuthorities
::
get
()
{
return
Err
(
Error
::
<
T
>
::
TooManyAuthorities
.into
());
return
Err
(
Error
::
<
T
>
::
TooManyAuthorities
.into
());
}
}
...
@@ -371,6 +365,12 @@ pub mod pallet {
...
@@ -371,6 +365,12 @@ pub mod pallet {
Ok
(()
.into
())
Ok
(()
.into
())
}
}
pub
fn
authorities_counter
()
->
u32
{
let
count
=
OnlineAuthorities
::
<
T
>
::
get
()
.len
()
+
IncomingAuthorities
::
<
T
>
::
get
()
.len
()
-
OutgoingAuthorities
::
<
T
>
::
get
()
.len
();
count
as
u32
}
}
}
// INTERNAL FUNCTIONS //
// INTERNAL FUNCTIONS //
...
@@ -414,7 +414,6 @@ pub mod pallet {
...
@@ -414,7 +414,6 @@ pub mod pallet {
}
}
});
});
if
not_already_inserted
{
if
not_already_inserted
{
AuthoritiesCounter
::
<
T
>
::
mutate
(|
counter
|
*
counter
+=
1
);
Self
::
deposit_event
(
Event
::
MemberGoOnline
{
member
:
member_id
});
Self
::
deposit_event
(
Event
::
MemberGoOnline
{
member
:
member_id
});
}
}
not_already_inserted
not_already_inserted
...
@@ -430,11 +429,6 @@ pub mod pallet {
...
@@ -430,11 +429,6 @@ pub mod pallet {
}
}
});
});
if
not_already_inserted
{
if
not_already_inserted
{
AuthoritiesCounter
::
<
T
>
::
mutate
(|
counter
|
{
if
*
counter
>
0
{
*
counter
-=
1
}
});
Self
::
deposit_event
(
Event
::
MemberGoOffline
{
member
:
member_id
});
Self
::
deposit_event
(
Event
::
MemberGoOffline
{
member
:
member_id
});
}
}
not_already_inserted
not_already_inserted
...
@@ -463,7 +457,6 @@ pub mod pallet {
...
@@ -463,7 +457,6 @@ pub mod pallet {
}
}
/// perform removal from incoming authorities
/// perform removal from incoming authorities
fn
remove_in
(
member_id
:
T
::
MemberId
)
{
fn
remove_in
(
member_id
:
T
::
MemberId
)
{
AuthoritiesCounter
::
<
T
>
::
mutate
(|
counter
|
counter
.saturating_sub
(
1
));
IncomingAuthorities
::
<
T
>
::
mutate
(|
members_ids
|
{
IncomingAuthorities
::
<
T
>
::
mutate
(|
members_ids
|
{
if
let
Ok
(
index
)
=
members_ids
.binary_search
(
&
member_id
)
{
if
let
Ok
(
index
)
=
members_ids
.binary_search
(
&
member_id
)
{
members_ids
.remove
(
index
);
members_ids
.remove
(
index
);
...
@@ -472,7 +465,6 @@ pub mod pallet {
...
@@ -472,7 +465,6 @@ pub mod pallet {
}
}
/// perform removal from online authorities
/// perform removal from online authorities
fn
remove_online
(
member_id
:
T
::
MemberId
)
{
fn
remove_online
(
member_id
:
T
::
MemberId
)
{
AuthoritiesCounter
::
<
T
>
::
mutate
(|
counter
|
counter
.saturating_add
(
1
));
OnlineAuthorities
::
<
T
>
::
mutate
(|
members_ids
|
{
OnlineAuthorities
::
<
T
>
::
mutate
(|
members_ids
|
{
if
let
Ok
(
index
)
=
members_ids
.binary_search
(
&
member_id
)
{
if
let
Ok
(
index
)
=
members_ids
.binary_search
(
&
member_id
)
{
members_ids
.remove
(
index
);
members_ids
.remove
(
index
);
...
...
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