Skip to content
GitLab
About GitLab
GitLab: the DevOps platform
Explore GitLab
Install GitLab
How GitLab compares
Get started
GitLab docs
GitLab Learn
Pricing
Talk to an expert
/
Help
What's new
2
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Projects
Groups
Snippets
Sign up now
Login
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nomadic Labs
tezos
Commits
079eda15
Verified
Commit
079eda15
authored
Feb 15, 2019
by
Grégoire Henry
Committed by
Marco Stronati
Feb 20, 2019
Browse files
Alpha/Delegation: allow to change the roll value
This patch adds a function to reassign rolls given a new roll size.
parent
a96b03dd
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/proto_alpha/lib_protocol/src/roll_storage.ml
View file @
079eda15
...
...
@@ -194,6 +194,16 @@ let get_rolls ctxt delegate =
|
None
->
return_nil
|
Some
head_roll
->
traverse_rolls
ctxt
head_roll
let
count_rolls
ctxt
delegate
=
Storage
.
Roll
.
Delegate_roll_list
.
get_option
ctxt
delegate
>>=?
function
|
None
->
return
0
|
Some
head_roll
->
let
rec
loop
acc
roll
=
Storage
.
Roll
.
Successor
.
get_option
ctxt
roll
>>=?
function
|
None
->
return
acc
|
Some
next
->
loop
(
succ
acc
)
next
in
loop
1
head_roll
let
get_change
c
delegate
=
Storage
.
Roll
.
Delegate_change
.
get_option
c
delegate
>>=?
function
|
None
->
return
Tez_repr
.
zero
...
...
@@ -480,3 +490,26 @@ let cycle_end ctxt last_cycle =
Storage
.
Roll
.
Snapshot_for_cycle
.
init
ctxt
(
Cycle_repr
.
succ
(
Cycle_repr
.
succ
frozen_roll_cycle
))
0
>>=?
fun
ctxt
->
return
ctxt
let
update_tokens_per_roll
ctxt
new_tokens_per_roll
=
let
constants
=
Raw_context
.
constants
ctxt
in
let
old_tokens_per_roll
=
constants
.
tokens_per_roll
in
Raw_context
.
patch_constants
ctxt
begin
fun
constants
->
{
constants
with
Constants_repr
.
tokens_per_roll
=
new_tokens_per_roll
}
end
>>=
fun
ctxt
->
let
decrease
=
Tez_repr
.(
new_tokens_per_roll
<
old_tokens_per_roll
)
in
begin
if
decrease
then
Lwt
.
return
Tez_repr
.(
old_tokens_per_roll
-?
new_tokens_per_roll
)
else
Lwt
.
return
Tez_repr
.(
new_tokens_per_roll
-?
old_tokens_per_roll
)
end
>>=?
fun
abs_diff
->
Storage
.
Delegates
.
fold
ctxt
(
Ok
ctxt
)
begin
fun
pkh
ctxt
->
Lwt
.
return
ctxt
>>=?
fun
ctxt
->
count_rolls
ctxt
pkh
>>=?
fun
rolls
->
Lwt
.
return
Tez_repr
.(
abs_diff
*?
Int64
.
of_int
rolls
)
>>=?
fun
amount
->
if
decrease
then
Delegate
.
add_amount
ctxt
pkh
amount
else
Delegate
.
remove_amount
ctxt
pkh
amount
end
src/proto_alpha/lib_protocol/src/roll_storage.mli
View file @
079eda15
...
...
@@ -95,6 +95,9 @@ val get_rolls:
val
get_change
:
Raw_context
.
t
->
Signature
.
Public_key_hash
.
t
->
Tez_repr
.
t
tzresult
Lwt
.
t
val
update_tokens_per_roll
:
Raw_context
.
t
->
Tez_repr
.
t
->
Raw_context
.
t
tzresult
Lwt
.
t
(**/**)
val
get_contract_delegate
:
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment