From 43401e4048f48d2d62f4eeec679fa55bff8a32e8 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Thu, 7 Nov 2024 11:47:45 +0100 Subject: [PATCH] proto/staking.ml: remove now useless amount wrapping The wrapping was used for autostaking, which has been removed. --- .../lib_protocol/alpha_context.mli | 2 +- src/proto_alpha/lib_protocol/apply.ml | 2 +- src/proto_alpha/lib_protocol/staking.ml | 26 +++++-------------- src/proto_alpha/lib_protocol/staking.mli | 2 +- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 60ccef1fbe7c..0201fbcb4361 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2538,7 +2538,7 @@ module Staking : sig to [delegate]. *) val stake : context -> - amount:[`At_most of Tez.t | `Exactly of Tez.t] -> + amount:Tez.t -> sender:public_key_hash -> delegate:public_key_hash -> (context * Receipt.balance_updates) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index eb5ea70a8182..cf1828aa1d66 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -410,7 +410,7 @@ let apply_stake ~ctxt ~sender ~amount ~destination ~before_operation = error_when forbidden Staking_to_delegate_that_refuses_external_staking in let* ctxt, balance_updates = - Staking.stake ctxt ~amount:(`Exactly amount) ~sender ~delegate + Staking.stake ctxt ~amount ~sender ~delegate in (* Since [delegate] is an already existing delegate, it is already allocated. *) let allocated_destination_contract = false in diff --git a/src/proto_alpha/lib_protocol/staking.ml b/src/proto_alpha/lib_protocol/staking.ml index e3b5c797f1cc..19c39cc1e392 100644 --- a/src/proto_alpha/lib_protocol/staking.ml +++ b/src/proto_alpha/lib_protocol/staking.ml @@ -265,14 +265,13 @@ let stake_from_unstake_for_delegate ctxt ~delegate ~unfinalizable_requests_opt in return (ctxt, balance_updates, remaining_amount_to_transfer) -let stake ctxt ~(amount : [`At_most of Tez_repr.t | `Exactly of Tez_repr.t]) - ~sender ~delegate = +let stake ctxt ~(amount : Tez_repr.t) ~sender ~delegate = let open Lwt_result_syntax in let check_unfinalizable ctxt Unstake_requests_storage.{delegate = unstake_delegate; requests} = - match (requests, amount) with - | [], _ | _ :: _, `At_most _ -> return ctxt - | _ :: _, `Exactly _ -> + match requests with + | [] -> return ctxt + | _ :: _ -> if Signature.Public_key_hash.(delegate <> unstake_delegate) then tzfail Cannot_stake_with_unfinalizable_unstake_requests_to_another_delegate @@ -282,29 +281,16 @@ let stake ctxt ~(amount : [`At_most of Tez_repr.t | `Exactly of Tez_repr.t]) let* ctxt, finalize_balance_updates, unfinalizable_requests_opt = finalize_unstake_and_check ~check_unfinalizable ctxt sender_contract in - let tez_amount = - match amount with `Exactly amount | `At_most amount -> amount - in (* stake from unstake for eligible delegates *) let* ctxt, stake_balance_updates1, amount_from_liquid = if Signature.Public_key_hash.(sender <> delegate) then - return (ctxt, [], tez_amount) + return (ctxt, [], amount) else stake_from_unstake_for_delegate ctxt ~delegate ~unfinalizable_requests_opt - tez_amount - in - (* Get amount to transfer from liquid wrt mode *) - let* amount_from_liquid = - match amount with - | `Exactly _ -> return amount_from_liquid - | `At_most _ -> - let* spendable = - Contract_storage.get_balance ctxt (Implicit delegate) - in - return Tez_repr.(min amount_from_liquid spendable) + amount in (* Issue pseudotokens for delegators *) let* ctxt, stake_balance_updates2 = diff --git a/src/proto_alpha/lib_protocol/staking.mli b/src/proto_alpha/lib_protocol/staking.mli index b2b7149e05e0..4caad45fcf9d 100644 --- a/src/proto_alpha/lib_protocol/staking.mli +++ b/src/proto_alpha/lib_protocol/staking.mli @@ -30,7 +30,7 @@ type error += stake to [delegate]. *) val stake : Raw_context.t -> - amount:[`At_most of Tez_repr.t | `Exactly of Tez_repr.t] -> + amount:Tez_repr.t -> sender:Signature.Public_key_hash.t -> delegate:Signature.public_key_hash -> (Raw_context.t * Receipt_repr.balance_updates) tzresult Lwt.t -- GitLab