diff --git a/src/proto_alpha/lib_baking/client_baking_endorsement.ml b/src/proto_alpha/lib_baking/client_baking_endorsement.ml index d2581a60a..559a3e158 100644 --- a/src/proto_alpha/lib_baking/client_baking_endorsement.ml +++ b/src/proto_alpha/lib_baking/client_baking_endorsement.ml @@ -60,12 +60,16 @@ end = struct load wallet >>=? fun l -> let delegate_key = Signature.Public_key_hash.to_short_b58check delegate in - match List.assoc_opt delegate_key l with - | None -> - save wallet ((delegate_key, new_lvl)::l) - | Some _ -> - save wallet ((delegate_key, new_lvl):: - List.remove_assoc delegate_key l) + let rec remove_old acc = function + | [] -> List.rev acc + | ((_,lvl) as hd)::tl -> + if Raw_level.diff new_lvl lvl > 50l (*?*) then + remove_old (hd::acc) tl + else + List.rev acc + in + save wallet ((delegate_key, new_lvl):: + List.remove_assoc delegate_key (remove_old [] l)) end) end end