From 5672840f58ff6f0e90c0aaab806d1694f380a431 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Mon, 27 May 2024 16:45:34 +0200 Subject: [PATCH 1/2] Proto/AI: fix UX --- src/proto_alpha/lib_protocol/staking.ml | 7 ++-- .../lib_protocol/unstake_requests_storage.ml | 41 ++++++++++++++++--- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/proto_alpha/lib_protocol/staking.ml b/src/proto_alpha/lib_protocol/staking.ml index 6b7fce09b3e4..53b30cb6b8fb 100644 --- a/src/proto_alpha/lib_protocol/staking.ml +++ b/src/proto_alpha/lib_protocol/staking.ml @@ -195,9 +195,10 @@ let stake_from_unstake_for_delegate ctxt ~for_next_cycle_use_only_after_slashing match unfinalizable_requests_opt with | None -> return (ctxt, [], amount) | Some Unstake_requests_storage.{delegate = delegate_requests; requests} -> - if Signature.Public_key_hash.(delegate <> delegate_requests) then - (* Possible. If reached, stake should not do anything, - so we also set the amount to stake from the liquid part to zero. *) + if + Signature.Public_key_hash.(delegate <> delegate_requests) + && not (List.is_empty requests) + then (* Should not be possible *) return (ctxt, [], Tez_repr.zero) else let* allowed = diff --git a/src/proto_alpha/lib_protocol/unstake_requests_storage.ml b/src/proto_alpha/lib_protocol/unstake_requests_storage.ml index d6ca6d6deb5b..046954b03d02 100644 --- a/src/proto_alpha/lib_protocol/unstake_requests_storage.ml +++ b/src/proto_alpha/lib_protocol/unstake_requests_storage.ml @@ -23,6 +23,27 @@ (* *) (*****************************************************************************) +type error += + | Cannot_unstake_with_unfinalizable_unstake_requests_to_another_delegate + +let () = + register_error_kind + `Permanent + ~id: + "operation.cannot_unstake_with_unfinalizable_unstake_requests_to_another_delegate" + ~title: + "Cannot unstake with unfinalizable unstake requests to another delegate" + ~description: + "Cannot unstake with unfinalizable unstake requests to another delegate" + Data_encoding.unit + (function + | Cannot_unstake_with_unfinalizable_unstake_requests_to_another_delegate + -> + Some () + | _ -> None) + (fun () -> + Cannot_unstake_with_unfinalizable_unstake_requests_to_another_delegate) + type finalizable = (Signature.Public_key_hash.t * Cycle_repr.t * Tez_repr.t) list @@ -165,12 +186,22 @@ let update = Storage.Contract.Unstake_requests.update let add ctxt ~contract ~delegate cycle amount = let open Lwt_result_syntax in let* requests_opt = Storage.Contract.Unstake_requests.find ctxt contract in - let requests = + let*? requests = match requests_opt with - | None -> [] - | Some {delegate = request_delegate; requests} -> - assert (Signature.Public_key_hash.(delegate = request_delegate)) ; - requests + | None -> Ok [] + | Some {delegate = request_delegate; requests} -> ( + match requests with + | [] -> Ok [] + | _ -> + if Signature.Public_key_hash.(delegate <> request_delegate) then + (* This would happen if the staker was allowed to stake towards + a new delegate while having unfinalizable unstake requests, + which is not allowed: it will fail earlier. Also, unstaking + for 0 tez is a noop and does not change the state of the storage, + so it does not allow to reach this error either. *) + Result_syntax.tzfail + Cannot_unstake_with_unfinalizable_unstake_requests_to_another_delegate + else Ok requests) in let*? requests = Storage.Unstake_request.add cycle amount requests in let unstake_request = Storage.Unstake_request.{delegate; requests} in -- GitLab From 0da5d9ef8f48afe6df5bde4324a076ed160c281c Mon Sep 17 00:00:00 2001 From: Killian Delarue Date: Mon, 27 May 2024 20:54:46 +0200 Subject: [PATCH 2/2] Alpha: Update vanity nonce --- src/proto_alpha/lib_protocol/main.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/main.ml b/src/proto_alpha/lib_protocol/main.ml index b734598c6bf3..727ff7616ea1 100644 --- a/src/proto_alpha/lib_protocol/main.ml +++ b/src/proto_alpha/lib_protocol/main.ml @@ -480,4 +480,4 @@ module Mempool = struct ~predecessor_hash:head_hash) end -(* Vanity nonce: 6782933743299446 *) +(* Vanity nonce: 2904751756914914 *) -- GitLab