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
!301
Resolve "[test] UD out of reeval window"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "[test] UD out of reeval window"
275-test-ud-out-of-reeval-window
into
master
Overview
1
Commits
2
Pipelines
7
Changes
1
Merged
Cédric Moreau
requested to merge
275-test-ud-out-of-reeval-window
into
master
4 months ago
Overview
1
Commits
2
Pipelines
7
Changes
1
Expand
Closes
#275 (closed)
1
0
1
1
Merge request reports
Compare
master
version 2
96006c99
4 months ago
version 1
23b94a16
4 months ago
master (base)
and
latest version
latest version
074f4141
2 commits,
3 months ago
version 2
96006c99
2 commits,
4 months ago
version 1
23b94a16
1 commit,
4 months ago
1 file
+
24
−
5
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
pallets/universal-dividend/src/compute_claim_uds.rs
+
24
−
5
Options
@@ -24,18 +24,22 @@ pub(super) fn compute_claim_uds<Balance: AtLeast32BitUnsigned>(
)
->
(
UdIndex
,
Balance
)
{
let
mut
total_amount
=
Zero
::
zero
();
let
mut
total_count
=
0
;
for
(
ud_index
,
ud_amount
)
in
past_reevals
.rev
()
{
if
ud_index
<=
first_ud_index
{
// We start in reverse order, i.e. the most recent reeval first
for
(
reeval_index
,
ud_amount
)
in
past_reevals
.rev
()
{
// Therefore, if our first UD is above the current reeval index, we have reached our final useful reeval and must break
if
reeval_index
<=
first_ud_index
{
let
count
=
current_ud_index
-
first_ud_index
;
total_amount
+=
Balance
::
from
(
count
)
*
ud_amount
;
total_count
+=
count
;
// First unclaimed UD is reached; stop counting now.
break
;
}
else
{
let
count
=
current_ud_index
-
ud_index
;
}
// Otherwise, we consume the full reeval contained UDs
else
{
let
count
=
current_ud_index
-
reeval_index
;
total_amount
+=
Balance
::
from
(
count
)
*
ud_amount
;
total_count
+=
count
;
current_ud_index
=
ud
_index
;
current_ud_index
=
reeval
_index
;
}
}
@@ -109,4 +113,19 @@ mod tests {
(
2
,
110_000
)
);
}
#[test]
fn
very_old_unclaimed_ud_out_of_reevals
()
{
let
past_reevals
=
vec!
[
// (3, 100 as Balance), "old" reeval which has gone out of reevals window.
(
4
,
1_000
as
Balance
),
(
5
,
10_000
as
Balance
),
(
6
,
100_000
as
Balance
),
];
// All the UDs out of the reeval window must produce 0 money units
assert_eq!
(
compute_claim_uds
(
7
,
1
,
past_reevals
.into_iter
()),
(
3
,
111_000
)
);
}
}
Loading