From 0cf6f8fff21601807c6b5b8b5be1fb2c6ca9a492 Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Fri, 16 Mar 2018 17:24:22 +0100 Subject: [PATCH] Alpha: do not decrease delegation rights expiration date when provisioning --- .../lib_protocol/src/delegate_storage.ml | 2 +- .../lib_protocol/src/roll_storage.ml | 21 +++++++++++++------ .../lib_protocol/src/roll_storage.mli | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/proto_alpha/lib_protocol/src/delegate_storage.ml b/src/proto_alpha/lib_protocol/src/delegate_storage.ml index 4d8ae62b1..3d185a98f 100644 --- a/src/proto_alpha/lib_protocol/src/delegate_storage.ml +++ b/src/proto_alpha/lib_protocol/src/delegate_storage.ml @@ -151,7 +151,7 @@ let set c contract delegate = begin if self_delegation then Storage.Delegates.add c delegate >>= fun c -> - Roll_storage.Delegate.set_active c ~init:true delegate >>=? fun c -> + Roll_storage.Delegate.set_active c delegate >>=? fun c -> return c else return c diff --git a/src/proto_alpha/lib_protocol/src/roll_storage.ml b/src/proto_alpha/lib_protocol/src/roll_storage.ml index f74863e47..1122aed8f 100644 --- a/src/proto_alpha/lib_protocol/src/roll_storage.ml +++ b/src/proto_alpha/lib_protocol/src/roll_storage.ml @@ -272,21 +272,30 @@ module Delegate = struct Storage.Roll.Delegate_change.set ctxt delegate change >>=? fun ctxt -> return ctxt - let set_active ctxt ?(init = false) delegate = + let set_active ctxt delegate = Storage.Contract.Inactive_delegate.mem ctxt (Contract_repr.implicit_contract delegate) >>= fun inactive -> let current_cycle = (Raw_context.current_level ctxt).cycle in let preserved_cycles = Constants_storage.preserved_cycles ctxt in (* When the delegate is new or inactive, she will become active in - `1+preserved_cycles`, and we allows `preserved_cycles` for the + `1+preserved_cycles`, and we allow `preserved_cycles` for the delegate to start baking. When the delegate is active, we only - give me at least `preserved_cycles` after the current cycle + give her at least `preserved_cycles` after the current cycle before to be deactivated. *) - let delay = - if init || inactive then (1+2*preserved_cycles) else 1+preserved_cycles in + Storage.Contract.Delegate_desactivation.get_option ctxt + (Contract_repr.implicit_contract delegate) >>=? fun current_expiration -> + let expiration = match current_expiration with + | None -> + Cycle_repr.add current_cycle (1+2*preserved_cycles) + | Some current_expiration -> + let delay = + if inactive then (1+2*preserved_cycles) else 1+preserved_cycles in + let updated = + Cycle_repr.add current_cycle delay in + Cycle_repr.max current_expiration updated in Storage.Contract.Delegate_desactivation.init_set ctxt (Contract_repr.implicit_contract delegate) - Cycle_repr.(add current_cycle delay) >>= fun ctxt -> + expiration >>= fun ctxt -> if not inactive then return ctxt else begin diff --git a/src/proto_alpha/lib_protocol/src/roll_storage.mli b/src/proto_alpha/lib_protocol/src/roll_storage.mli index ee622bea5..8c3d680c7 100644 --- a/src/proto_alpha/lib_protocol/src/roll_storage.mli +++ b/src/proto_alpha/lib_protocol/src/roll_storage.mli @@ -52,7 +52,7 @@ module Delegate : sig val set_inactive : Raw_context.t -> Ed25519.Public_key_hash.t -> Raw_context.t tzresult Lwt.t - val set_active : Raw_context.t -> ?init:bool -> Ed25519.Public_key_hash.t -> Raw_context.t tzresult Lwt.t + val set_active : Raw_context.t -> Ed25519.Public_key_hash.t -> Raw_context.t tzresult Lwt.t end