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
e9b62cbb
Commit
e9b62cbb
authored
3 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
mod(pallet-ud): change ud formula: apply current M/N instead of previous
parent
ecf2bb16
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pallets/universal-dividend/src/lib.rs
+11
-27
11 additions, 27 deletions
pallets/universal-dividend/src/lib.rs
pallets/universal-dividend/src/tests.rs
+12
-12
12 additions, 12 deletions
pallets/universal-dividend/src/tests.rs
with
23 additions
and
39 deletions
pallets/universal-dividend/src/lib.rs
+
11
−
27
View file @
e9b62cbb
...
@@ -109,8 +109,8 @@ pub mod pallet {
...
@@ -109,8 +109,8 @@ pub mod pallet {
/// Last reevaluation
/// Last reevaluation
#[pallet::storage]
#[pallet::storage]
#[pallet::getter(fn
last_reeval
)]
#[pallet::getter(fn
current_ud
)]
pub
type
LastReeval
Storage
<
T
:
Config
>
=
StorageValue
<
_
,
LastReeval
<
T
>
,
ValueQuery
>
;
pub
type
CurrentUd
Storage
<
T
:
Config
>
=
StorageValue
<
_
,
BalanceOf
<
T
>
,
ValueQuery
>
;
/// Total quantity of money created by universal dividend (does not take into account the possible destruction of money)
/// Total quantity of money created by universal dividend (does not take into account the possible destruction of money)
#[pallet::storage]
#[pallet::storage]
...
@@ -142,11 +142,7 @@ pub mod pallet {
...
@@ -142,11 +142,7 @@ pub mod pallet {
assert!
(
self
.initial_monetary_mass
>=
T
::
Currency
::
total_issuance
());
assert!
(
self
.initial_monetary_mass
>=
T
::
Currency
::
total_issuance
());
<
StorageVersion
<
T
>>
::
put
(
Releases
::
V1_0_0
);
<
StorageVersion
<
T
>>
::
put
(
Releases
::
V1_0_0
);
<
LastReevalStorage
<
T
>>
::
put
(
LastReeval
{
<
CurrentUdStorage
<
T
>>
::
put
(
self
.first_ud
);
monetary_mass
:
T
::
Currency
::
total_issuance
(),
members_count
:
T
::
MembersCount
::
get
(),
ud_amount
:
self
.first_ud
,
});
<
MonetaryMassStorage
<
T
>>
::
put
(
self
.initial_monetary_mass
);
<
MonetaryMassStorage
<
T
>>
::
put
(
self
.initial_monetary_mass
);
}
}
}
}
...
@@ -188,11 +184,10 @@ pub mod pallet {
...
@@ -188,11 +184,10 @@ pub mod pallet {
// INTERNAL FUNCTIONS //
// INTERNAL FUNCTIONS //
impl
<
T
:
Config
>
Pallet
<
T
>
{
impl
<
T
:
Config
>
Pallet
<
T
>
{
fn
create_ud
(
current_
members_count
:
BalanceOf
<
T
>
,
n
:
T
::
BlockNumber
)
->
Weight
{
fn
create_ud
(
members_count
:
BalanceOf
<
T
>
,
n
:
T
::
BlockNumber
)
->
Weight
{
let
total_weight
:
Weight
=
0
;
let
total_weight
:
Weight
=
0
;
let
LastReeval
{
ud_amount
,
..
}
=
let
ud_amount
=
<
CurrentUdStorage
<
T
>>
::
try_get
()
.expect
(
"corrupted storage"
);
<
LastReevalStorage
<
T
>>
::
try_get
()
.expect
(
"corrupted storage"
);
let
mut
monetary_mass
=
<
MonetaryMassStorage
<
T
>>
::
try_get
()
.expect
(
"corrupted storage"
);
let
mut
monetary_mass
=
<
MonetaryMassStorage
<
T
>>
::
try_get
()
.expect
(
"corrupted storage"
);
for
account_id
in
T
::
MembersIds
::
get
()
{
for
account_id
in
T
::
MembersIds
::
get
()
{
...
@@ -202,22 +197,16 @@ pub mod pallet {
...
@@ -202,22 +197,16 @@ pub mod pallet {
}
}
<
MonetaryMassStorage
<
T
>>
::
put
(
monetary_mass
);
<
MonetaryMassStorage
<
T
>>
::
put
(
monetary_mass
);
Self
::
deposit_event
(
Event
::
NewUdCreated
(
ud_amount
,
current_
members_count
));
Self
::
deposit_event
(
Event
::
NewUdCreated
(
ud_amount
,
members_count
));
total_weight
total_weight
}
}
fn
reeval_ud
(
current_
members_count
:
BalanceOf
<
T
>
)
->
Weight
{
fn
reeval_ud
(
members_count
:
BalanceOf
<
T
>
)
->
Weight
{
let
total_weight
:
Weight
=
0
;
let
total_weight
:
Weight
=
0
;
let
LastReeval
{
let
ud_amount
=
<
CurrentUdStorage
<
T
>>
::
try_get
()
.expect
(
"corrupted storage"
);
members_count
,
mut
monetary_mass
,
ud_amount
,
}
=
<
LastReevalStorage
<
T
>>
::
try_get
()
.expect
(
"corrupted storage"
);
if
monetary_mass
.is_zero
()
{
let
monetary_mass
=
<
MonetaryMassStorage
<
T
>>
::
try_get
()
.expect
(
"corrupted storage"
);
monetary_mass
=
ud_amount
*
members_count
;
}
let
new_ud_amount
=
Self
::
reeval_ud_formula
(
let
new_ud_amount
=
Self
::
reeval_ud_formula
(
ud_amount
,
ud_amount
,
...
@@ -227,19 +216,14 @@ pub mod pallet {
...
@@ -227,19 +216,14 @@ pub mod pallet {
T
::
UdReevalPeriod
::
get
(),
T
::
UdReevalPeriod
::
get
(),
);
);
<
CurrentUdStorage
<
T
>>
::
put
(
new_ud_amount
);
Self
::
deposit_event
(
Event
::
UdReevalued
(
Self
::
deposit_event
(
Event
::
UdReevalued
(
new_ud_amount
,
new_ud_amount
,
monetary_mass
,
monetary_mass
,
members_count
,
members_count
,
));
));
let
monetary_mass
=
<
MonetaryMassStorage
<
T
>>
::
try_get
()
.expect
(
"corrupted storage"
);
<
LastReevalStorage
<
T
>>
::
put
(
LastReeval
{
members_count
:
current_members_count
,
monetary_mass
,
ud_amount
:
new_ud_amount
,
});
total_weight
total_weight
}
}
fn
reeval_ud_formula
(
fn
reeval_ud_formula
(
...
...
This diff is collapsed.
Click to expand it.
pallets/universal-dividend/src/tests.rs
+
12
−
12
View file @
e9b62cbb
...
@@ -82,26 +82,26 @@ fn test_ud_creation() {
...
@@ -82,26 +82,26 @@ fn test_ud_creation() {
// Block #8 should cause a re-evaluation of UD
// Block #8 should cause a re-evaluation of UD
run_to_block
(
8
);
run_to_block
(
8
);
assert_eq!
(
Balances
::
free_balance
(
1
),
4_0
2
5
);
assert_eq!
(
Balances
::
free_balance
(
1
),
4_0
7
5
);
assert_eq!
(
Balances
::
free_balance
(
2
),
4_0
2
5
);
assert_eq!
(
Balances
::
free_balance
(
2
),
4_0
7
5
);
assert_eq!
(
Balances
::
free_balance
(
3
),
4_0
2
5
);
assert_eq!
(
Balances
::
free_balance
(
3
),
4_0
7
5
);
assert_eq!
(
Balances
::
free_balance
(
4
),
0
);
assert_eq!
(
Balances
::
free_balance
(
4
),
0
);
assert_eq!
(
UniversalDividend
::
total_money_created
(),
12_
07
5
);
assert_eq!
(
UniversalDividend
::
total_money_created
(),
12_
22
5
);
// Block #10 #12 and #14should creates the reevalued UD
// Block #10 #12 and #14should creates the reevalued UD
run_to_block
(
14
);
run_to_block
(
14
);
assert_eq!
(
Balances
::
free_balance
(
1
),
7_
1
00
);
assert_eq!
(
Balances
::
free_balance
(
1
),
7_
3
00
);
assert_eq!
(
Balances
::
free_balance
(
2
),
7_
1
00
);
assert_eq!
(
Balances
::
free_balance
(
2
),
7_
3
00
);
assert_eq!
(
Balances
::
free_balance
(
3
),
7_
1
00
);
assert_eq!
(
Balances
::
free_balance
(
3
),
7_
3
00
);
assert_eq!
(
Balances
::
free_balance
(
4
),
0
);
assert_eq!
(
Balances
::
free_balance
(
4
),
0
);
assert_eq!
(
UniversalDividend
::
total_money_created
(),
21_
3
00
);
assert_eq!
(
UniversalDividend
::
total_money_created
(),
21_
9
00
);
// Block #16 should cause a second re-evaluation of UD
// Block #16 should cause a second re-evaluation of UD
run_to_block
(
16
);
run_to_block
(
16
);
assert_eq!
(
Balances
::
free_balance
(
1
),
8_
200
);
assert_eq!
(
Balances
::
free_balance
(
1
),
8_
557
);
assert_eq!
(
Balances
::
free_balance
(
2
),
8_
200
);
assert_eq!
(
Balances
::
free_balance
(
2
),
8_
557
);
assert_eq!
(
Balances
::
free_balance
(
3
),
8_
200
);
assert_eq!
(
Balances
::
free_balance
(
3
),
8_
557
);
assert_eq!
(
Balances
::
free_balance
(
4
),
0
);
assert_eq!
(
Balances
::
free_balance
(
4
),
0
);
assert_eq!
(
UniversalDividend
::
total_money_created
(),
2
4
_6
00
);
assert_eq!
(
UniversalDividend
::
total_money_created
(),
2
5
_6
71
);
});
});
}
}
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