From 3fcc6df97534519537a3381b38ccce45a9c35ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Sun, 19 Nov 2017 18:00:04 +0100 Subject: [PATCH] Alpha: use recursive removal when possible --- src/proto/alpha/reward_storage.ml | 5 +++-- src/proto/alpha/roll_storage.ml | 10 ++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/proto/alpha/reward_storage.ml b/src/proto/alpha/reward_storage.ml index e01d00d2a..22be03d33 100644 --- a/src/proto/alpha/reward_storage.ml +++ b/src/proto/alpha/reward_storage.ml @@ -47,10 +47,11 @@ let pay_rewards_for_cycle c cycle = match c with | Error _ -> Lwt.return c | Ok c -> - Storage.Rewards.Amount.remove (c, cycle) delegate >>= fun c -> Contract_storage.credit c (Contract_repr.default_contract delegate) - amount) + amount) >>=? fun c -> + Storage.Rewards.Amount.clear (c, cycle) >>= fun c -> + return c let pay_due_rewards c = let timestamp = Raw_context.current_timestamp c in diff --git a/src/proto/alpha/roll_storage.ml b/src/proto/alpha/roll_storage.ml index 28844ed13..7ec4615d2 100644 --- a/src/proto/alpha/roll_storage.ml +++ b/src/proto/alpha/roll_storage.ml @@ -18,15 +18,9 @@ let get_contract_delegate c contract = | None -> Storage.Contract.Delegate.get_option c contract let clear_cycle c cycle = - Storage.Roll.Last_for_cycle.get c cycle >>=? fun last -> Storage.Roll.Last_for_cycle.delete c cycle >>=? fun c -> - let rec loop c roll = - if Roll_repr.(roll = last) then - return c - else - Storage.Roll.Owner_for_cycle.delete (c, cycle) roll >>=? fun c -> - loop c (Roll_repr.succ roll) in - loop c Roll_repr.first + Storage.Roll.Owner_for_cycle.clear (c, cycle) >>= fun c -> + return c let fold ctxt ~f init = Storage.Roll.Next.get ctxt >>=? fun last ->