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
Merge requests
!36
feat(runtimes): add account random id & provide randomness calls
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
feat(runtimes): add account random id & provide randomness calls
elois-random-id
into
master
Overview
0
Commits
5
Pipelines
0
Changes
1
Merged
Éloïs
requested to merge
elois-random-id
into
master
3 years ago
Overview
0
Commits
5
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Viewing commit
d149ce46
Prev
Next
Show latest version
1 file
+
19
−
14
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
d149ce46
fix(account): forbid account destruction until random id assignment
· d149ce46
Éloïs
authored
3 years ago
pallets/duniter-account/src/lib.rs
+
19
−
14
Options
@@ -134,8 +134,18 @@ pub mod pallet {
ExistenceRequirement
::
KeepAlive
,
);
if
let
Ok
(
imbalance
)
=
res
{
// The fees have been collected, we handle the collected amount and we
// request the random id
// The fees have been succesfully collected, we should:
// 1. Increment consumers to prevent the destruction of the account before
// the random id is assigned
// 2. Manage the funds collected
// 3. Submit random id generation request
// 4. Save the id of the random generation request.
let
res
=
frame_system
::
Pallet
::
<
T
>
::
inc_consumers_without_limit
(
&
account_id
);
debug_assert!
(
res
.is_ok
(),
"Cannot fail because providers are incremented just before"
);
T
::
OnUnbalanced
::
on_unbalanced
(
imbalance
);
let
request_id
=
pallet_provide_randomness
::
Pallet
::
<
T
>
::
force_request
(
pallet_provide_randomness
::
RandomnessType
::
RandomnessFromTwoEpochsAgo
,
@@ -167,19 +177,14 @@ where
{
fn
on_filled_randomness
(
request_id
:
RequestId
,
randomness
:
H256
)
->
Weight
{
if
let
Some
(
account_id
)
=
PendingRandomIdAssignments
::
<
T
>
::
take
(
request_id
)
{
// Can only fail if the account has been deleted in the meantime,
// but this case does not require any processing
let
res
=
frame_system
::
Pallet
::
<
T
>
::
mutate_exists
(
&
account_id
,
|
maybe_account_data
|
{
if
let
Some
(
ref
mut
account_data
)
=
maybe_account_data
{
account_data
.random_id
=
Some
(
randomness
);
}
frame_system
::
Account
::
<
T
>
::
mutate
(
&
account_id
,
|
account
|
{
account
.consumers
=
account
.consumers
.saturating_sub
(
1
);
account
.data.random_id
=
Some
(
randomness
);
});
Self
::
deposit_event
(
Event
::
RandomIdAssigned
{
account_id
,
random_id
:
randomness
,
});
if
res
.is_ok
()
{
Self
::
deposit_event
(
Event
::
RandomIdAssigned
{
account_id
,
random_id
:
randomness
,
});
}
200_000
}
else
{
100_000
Loading