From 98ab0053e10c23876aad74322b3c93962a61d6cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Tue, 15 Mar 2022 16:47:15 +0100 Subject: [PATCH 1/2] Proto-env,Proto-updater: Use local (rather than global) return/fail --- src/lib_protocol_environment/environment_protocol_T.ml | 2 +- src/lib_protocol_environment/test/test_cache.ml | 1 + src/lib_protocol_updater/registered_protocol.ml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib_protocol_environment/environment_protocol_T.ml b/src/lib_protocol_environment/environment_protocol_T.ml index 32bb6b922d34..f134741bf74f 100644 --- a/src/lib_protocol_environment/environment_protocol_T.ml +++ b/src/lib_protocol_environment/environment_protocol_T.ml @@ -92,7 +92,7 @@ module V0toV3 let value_of_key ~chain_id:_ ~predecessor_context:_ ~predecessor_timestamp:_ ~predecessor_level:_ ~predecessor_fitness:_ ~predecessor:_ ~timestamp:_ = - return (fun _ -> + Lwt.return_ok (fun _ -> Lwt.return (Error_monad.error_with "element_of_key called on environment protocol < V3")) diff --git a/src/lib_protocol_environment/test/test_cache.ml b/src/lib_protocol_environment/test/test_cache.ml index a798c66aeaa9..b4d7afc91bca 100644 --- a/src/lib_protocol_environment/test/test_cache.ml +++ b/src/lib_protocol_environment/test/test_cache.ml @@ -695,6 +695,7 @@ let load_cache_correctly_restores_cache_in_memory builder mode Context.Cache.Internal_for_tests.same_cache_domains ctxt0 ctxt1 let load_cache_correctly_restores_cache_in_memory_normal_case = + let open Lwt_result_syntax in let builder entries key = let value = Stdlib.List.assoc key entries in return (Int value) diff --git a/src/lib_protocol_updater/registered_protocol.ml b/src/lib_protocol_updater/registered_protocol.ml index 7ab308959ffe..2bb14299b157 100644 --- a/src/lib_protocol_updater/registered_protocol.ml +++ b/src/lib_protocol_updater/registered_protocol.ml @@ -203,6 +203,7 @@ let () = (fun hash -> Unregistered_protocol hash) let get_result hash = + let open Lwt_tzresult_syntax in match get hash with | Some hash -> return hash | None -> fail (Unregistered_protocol hash) -- GitLab From 117640eb6d9c6362948c4bf40ca3c3ecf591d9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Tue, 15 Mar 2022 16:47:15 +0100 Subject: [PATCH 2/2] Protos: Use local (rather than global) return/fail Does not affect protos, only binaries and side libs. --- src/proto_000_Ps9mPmXa/lib_client/client_proto_main.ml | 7 ++----- .../lib_client/client_proto_multisig.ml | 2 +- .../lib_client/client_proto_multisig.ml | 4 ++-- .../lib_client/client_proto_multisig.ml | 4 ++-- .../lib_client/client_proto_multisig.ml | 4 ++-- .../lib_client/client_proto_multisig.ml | 4 ++-- .../test/helpers/liquidity_baking_machine.ml | 2 +- .../lib_client/client_proto_multisig.ml | 4 ++-- .../test/helpers/liquidity_baking_machine.ml | 2 +- src/proto_alpha/bin_tx_rollup_node/daemon.ml | 2 +- .../bin_tx_rollup_node/main_tx_rollup_node_alpha.ml | 4 +--- src/proto_alpha/lib_client/client_proto_multisig.ml | 4 ++-- .../test/helpers/liquidity_baking_machine.ml | 2 +- src/proto_genesis/lib_client/client_proto_main.ml | 10 +++------- .../lib_client/client_proto_main.ml | 10 +++------- 15 files changed, 26 insertions(+), 39 deletions(-) diff --git a/src/proto_000_Ps9mPmXa/lib_client/client_proto_main.ml b/src/proto_000_Ps9mPmXa/lib_client/client_proto_main.ml index 3798909f29aa..edd247c79fc8 100644 --- a/src/proto_000_Ps9mPmXa/lib_client/client_proto_main.ml +++ b/src/proto_000_Ps9mPmXa/lib_client/client_proto_main.ml @@ -77,8 +77,7 @@ let timestamp_arg = (Clic.parameter (fun _ t -> match Time.Protocol.of_notation t with | None -> - Error_monad.failwith - "Could not parse value provided to -timestamp option" + failwith "Could not parse value provided to -timestamp option" | Some t -> return t)) let test_delay_arg = @@ -89,9 +88,7 @@ let test_delay_arg = ~default:(Int64.to_string (Int64.mul 24L 3600L)) (Clic.parameter (fun _ t -> match Int64.of_string_opt t with - | None -> - Error_monad.failwith - "Could not parse value provided to -delay option" + | None -> failwith "Could not parse value provided to -delay option" | Some t -> return t)) let proto_param ~name ~desc t = diff --git a/src/proto_006_PsCARTHA/lib_client/client_proto_multisig.ml b/src/proto_006_PsCARTHA/lib_client/client_proto_multisig.ml index 223c3a612a2e..8db84c61233d 100644 --- a/src/proto_006_PsCARTHA/lib_client/client_proto_multisig.ml +++ b/src/proto_006_PsCARTHA/lib_client/client_proto_multisig.ml @@ -492,7 +492,7 @@ let action_to_expr ~loc = function let action_of_expr e = let fail () = - Error_monad.fail + fail (Action_deserialisation_error (Tezos_micheline.Micheline.strip_locations e)) in diff --git a/src/proto_008_PtEdo2Zk/lib_client/client_proto_multisig.ml b/src/proto_008_PtEdo2Zk/lib_client/client_proto_multisig.ml index 760064efabd0..9de5516df8df 100644 --- a/src/proto_008_PtEdo2Zk/lib_client/client_proto_multisig.ml +++ b/src/proto_008_PtEdo2Zk/lib_client/client_proto_multisig.ml @@ -691,7 +691,7 @@ let action_to_expr ~loc ~generic action = let action_of_expr_generic e = let fail () = - Error_monad.fail + fail (Action_deserialisation_error (Tezos_micheline.Micheline.strip_locations e)) in @@ -726,7 +726,7 @@ let action_of_expr_generic e = let action_of_expr_not_generic e = let fail () = - Error_monad.fail + fail (Action_deserialisation_error (Tezos_micheline.Micheline.strip_locations e)) in diff --git a/src/proto_009_PsFLoren/lib_client/client_proto_multisig.ml b/src/proto_009_PsFLoren/lib_client/client_proto_multisig.ml index 760064efabd0..9de5516df8df 100644 --- a/src/proto_009_PsFLoren/lib_client/client_proto_multisig.ml +++ b/src/proto_009_PsFLoren/lib_client/client_proto_multisig.ml @@ -691,7 +691,7 @@ let action_to_expr ~loc ~generic action = let action_of_expr_generic e = let fail () = - Error_monad.fail + fail (Action_deserialisation_error (Tezos_micheline.Micheline.strip_locations e)) in @@ -726,7 +726,7 @@ let action_of_expr_generic e = let action_of_expr_not_generic e = let fail () = - Error_monad.fail + fail (Action_deserialisation_error (Tezos_micheline.Micheline.strip_locations e)) in diff --git a/src/proto_010_PtGRANAD/lib_client/client_proto_multisig.ml b/src/proto_010_PtGRANAD/lib_client/client_proto_multisig.ml index a687ffa89f8f..14c0667b99b9 100644 --- a/src/proto_010_PtGRANAD/lib_client/client_proto_multisig.ml +++ b/src/proto_010_PtGRANAD/lib_client/client_proto_multisig.ml @@ -674,7 +674,7 @@ let action_to_expr ~loc ~generic action = let action_of_expr_generic e = let fail () = - Error_monad.fail + fail (Action_deserialisation_error (Tezos_micheline.Micheline.strip_locations e)) in @@ -709,7 +709,7 @@ let action_of_expr_generic e = let action_of_expr_not_generic e = let fail () = - Error_monad.fail + fail (Action_deserialisation_error (Tezos_micheline.Micheline.strip_locations e)) in diff --git a/src/proto_011_PtHangz2/lib_client/client_proto_multisig.ml b/src/proto_011_PtHangz2/lib_client/client_proto_multisig.ml index a687ffa89f8f..14c0667b99b9 100644 --- a/src/proto_011_PtHangz2/lib_client/client_proto_multisig.ml +++ b/src/proto_011_PtHangz2/lib_client/client_proto_multisig.ml @@ -674,7 +674,7 @@ let action_to_expr ~loc ~generic action = let action_of_expr_generic e = let fail () = - Error_monad.fail + fail (Action_deserialisation_error (Tezos_micheline.Micheline.strip_locations e)) in @@ -709,7 +709,7 @@ let action_of_expr_generic e = let action_of_expr_not_generic e = let fail () = - Error_monad.fail + fail (Action_deserialisation_error (Tezos_micheline.Micheline.strip_locations e)) in diff --git a/src/proto_011_PtHangz2/lib_protocol/test/helpers/liquidity_baking_machine.ml b/src/proto_011_PtHangz2/lib_protocol/test/helpers/liquidity_baking_machine.ml index 15029f71a4dd..778eeb892f9d 100644 --- a/src/proto_011_PtHangz2/lib_protocol/test/helpers/liquidity_baking_machine.ml +++ b/src/proto_011_PtHangz2/lib_protocol/test/helpers/liquidity_baking_machine.ml @@ -727,7 +727,7 @@ module ConcreteBaseMachine : let fold_m = Environment.List.fold_left_es - let pure = Error_monad.return + let pure = return let get_xtz_balance contract blk = Context.Contract.balance (B blk) contract >>= fun x -> diff --git a/src/proto_012_Psithaca/lib_client/client_proto_multisig.ml b/src/proto_012_Psithaca/lib_client/client_proto_multisig.ml index 7ffb4f883006..4f55086fb152 100644 --- a/src/proto_012_Psithaca/lib_client/client_proto_multisig.ml +++ b/src/proto_012_Psithaca/lib_client/client_proto_multisig.ml @@ -674,7 +674,7 @@ let action_to_expr ~loc ~generic action = let action_of_expr_generic e = let fail () = - Error_monad.fail + fail (Action_deserialisation_error (Tezos_micheline.Micheline.strip_locations e)) in @@ -709,7 +709,7 @@ let action_of_expr_generic e = let action_of_expr_not_generic e = let fail () = - Error_monad.fail + fail (Action_deserialisation_error (Tezos_micheline.Micheline.strip_locations e)) in diff --git a/src/proto_012_Psithaca/lib_protocol/test/helpers/liquidity_baking_machine.ml b/src/proto_012_Psithaca/lib_protocol/test/helpers/liquidity_baking_machine.ml index 0e19624e0cce..025e97098fbc 100644 --- a/src/proto_012_Psithaca/lib_protocol/test/helpers/liquidity_baking_machine.ml +++ b/src/proto_012_Psithaca/lib_protocol/test/helpers/liquidity_baking_machine.ml @@ -727,7 +727,7 @@ module ConcreteBaseMachine : let fold_m = Environment.List.fold_left_es - let pure = Error_monad.return + let pure = return let get_xtz_balance contract blk = Context.Contract.balance (B blk) contract >>= fun x -> diff --git a/src/proto_alpha/bin_tx_rollup_node/daemon.ml b/src/proto_alpha/bin_tx_rollup_node/daemon.ml index 95f74db43b88..d7241266c1e1 100644 --- a/src/proto_alpha/bin_tx_rollup_node/daemon.ml +++ b/src/proto_alpha/bin_tx_rollup_node/daemon.ml @@ -368,7 +368,7 @@ let rec connect ~delay cctxt = let open Lwt_syntax in let* res = Monitor_services.heads cctxt cctxt#chain in match res with - | Ok (stream, stopper) -> Error_monad.return (stream, stopper) + | Ok (stream, stopper) -> return_ok (stream, stopper) | Error _ -> let* () = Event.(emit cannot_connect) delay in let* () = Lwt_unix.sleep delay in diff --git a/src/proto_alpha/bin_tx_rollup_node/main_tx_rollup_node_alpha.ml b/src/proto_alpha/bin_tx_rollup_node/main_tx_rollup_node_alpha.ml index 006d538c3e08..24455ed7c279 100644 --- a/src/proto_alpha/bin_tx_rollup_node/main_tx_rollup_node_alpha.ml +++ b/src/proto_alpha/bin_tx_rollup_node/main_tx_rollup_node_alpha.ml @@ -119,9 +119,7 @@ let group = title = "Commands related to the transaction rollup node"; } -let to_tzresult msg = function - | Some x -> Error_monad.return x - | None -> Error_monad.failwith msg +let to_tzresult msg = function Some x -> return x | None -> failwith msg let configuration_init_command = let open Clic in diff --git a/src/proto_alpha/lib_client/client_proto_multisig.ml b/src/proto_alpha/lib_client/client_proto_multisig.ml index 17b6261c984e..ce080f0bdf52 100644 --- a/src/proto_alpha/lib_client/client_proto_multisig.ml +++ b/src/proto_alpha/lib_client/client_proto_multisig.ml @@ -677,7 +677,7 @@ let action_to_expr ~loc ~generic action = let action_of_expr_generic e = let fail () = - Error_monad.fail + fail (Action_deserialisation_error (Tezos_micheline.Micheline.strip_locations e)) in @@ -712,7 +712,7 @@ let action_of_expr_generic e = let action_of_expr_not_generic e = let fail () = - Error_monad.fail + fail (Action_deserialisation_error (Tezos_micheline.Micheline.strip_locations e)) in diff --git a/src/proto_alpha/lib_protocol/test/helpers/liquidity_baking_machine.ml b/src/proto_alpha/lib_protocol/test/helpers/liquidity_baking_machine.ml index a43e6aca7739..e01b2436df96 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/liquidity_baking_machine.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/liquidity_baking_machine.ml @@ -728,7 +728,7 @@ module ConcreteBaseMachine : let fold_m = Environment.List.fold_left_es - let pure = Error_monad.return + let pure = return let get_xtz_balance contract blk = Context.Contract.balance (B blk) contract >>= fun x -> diff --git a/src/proto_genesis/lib_client/client_proto_main.ml b/src/proto_genesis/lib_client/client_proto_main.ml index fd8ea25d98de..0478fd5f31c2 100644 --- a/src/proto_genesis/lib_client/client_proto_main.ml +++ b/src/proto_genesis/lib_client/client_proto_main.ml @@ -73,8 +73,7 @@ let timestamp_arg = (Clic.parameter (fun _ t -> match Time.System.of_notation_opt t with | None -> - Error_monad.failwith - "Could not parse value provided to -timestamp option" + failwith "Could not parse value provided to -timestamp option" | Some t -> return t)) let test_delay_arg = @@ -85,9 +84,7 @@ let test_delay_arg = ~default:(Int64.to_string (Int64.mul 24L 3600L)) (Clic.parameter (fun _ t -> match Int64.of_string_opt t with - | None -> - Error_monad.failwith - "Could not parse value provided to -delay option" + | None -> failwith "Could not parse value provided to -delay option" | Some t -> return t)) let proto_param ~name ~desc t = @@ -108,8 +105,7 @@ let commands () = (parameter (fun _ t -> match Time.Protocol.of_notation t with | None -> - Error_monad.failwith - "Could not parse value provided to -timestamp option" + failwith "Could not parse value provided to -timestamp option" | Some t -> return t))) in [ diff --git a/src/proto_genesis_carthagenet/lib_client/client_proto_main.ml b/src/proto_genesis_carthagenet/lib_client/client_proto_main.ml index 177d533839b7..6ace9b8d575b 100644 --- a/src/proto_genesis_carthagenet/lib_client/client_proto_main.ml +++ b/src/proto_genesis_carthagenet/lib_client/client_proto_main.ml @@ -77,8 +77,7 @@ let timestamp_arg = (Clic.parameter (fun _ t -> match Time.System.of_notation_opt t with | None -> - Error_monad.failwith - "Could not parse value provided to -timestamp option" + failwith "Could not parse value provided to -timestamp option" | Some t -> return t)) let test_delay_arg = @@ -89,9 +88,7 @@ let test_delay_arg = ~default:(Int64.to_string (Int64.mul 24L 3600L)) (Clic.parameter (fun _ t -> match Int64.of_string_opt t with - | None -> - Error_monad.failwith - "Could not parse value provided to -delay option" + | None -> failwith "Could not parse value provided to -delay option" | Some t -> return t)) let proto_param ~name ~desc t = @@ -112,8 +109,7 @@ let commands () = (parameter (fun _ t -> match Time.Protocol.of_notation t with | None -> - Error_monad.failwith - "Could not parse value provided to -timestamp option" + failwith "Could not parse value provided to -timestamp option" | Some t -> return t))) in [ -- GitLab