diff --git a/docs/developer/error_monad_p2_tzresult.rst b/docs/developer/error_monad_p2_tzresult.rst index 261df8aa08e713ae2ee88934bac2128a8402011e..4231bd46f7a67d0d615bdb65dc47a92c4047f4d1 100644 --- a/docs/developer/error_monad_p2_tzresult.rst +++ b/docs/developer/error_monad_p2_tzresult.rst @@ -233,30 +233,29 @@ Exercises attempted_insertion: int } -The ``Tzresult_syntax`` module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The ``Result_syntax``'s ``tz`` extensions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Remember that ``'a tzresult`` is a special case of ``('a, 'e) result``. Specifically, a special case where ``'e`` is ``error trace``. Consequently, you can handle ``tzresult`` values using the -``Result_syntax`` module. However, a more specialised module -``Tzresult_syntax`` is available. +``Result_syntax`` module. -The ``Tzresult_syntax`` module is identical to the ``Result_syntax`` -module but for the following differences. +The module ``Result_syntax`` exports a few functions dedicated to handling +``tzresult``. These functions were omitted from Part 1. -- ``fail: 'e -> ('a, 'e trace) result``: the expression ``fail e`` +- ``tzfail: 'e -> ('a, 'e trace) result``: the expression ``tzfail e`` wraps ``e`` in a ``trace`` inside an ``Error``. When ``e`` is of type - ``error`` as is the case throughout Octez, ``fail e`` is of type + ``error`` as is the case throughout Octez, ``tzfail e`` is of type ``'a tzresult``. -- ``and*``: a binding operator alias for ``both`` (see below). You can +- ``and*``: a binding operator alias for ``tzboth`` (see below). You can use it with ``let*`` the same way you use ``and`` with ``let``. :: let apply_triple f (x, y, z) = - let open Tzresult_syntax in + let open Result_syntax in let* u = f x and* v = f y and* w = f z @@ -268,24 +267,24 @@ module but for the following differences. of the others. The expression which follows the ``in`` (``return ..``) is evaluated if all the bound results are successful. -- ``both : ('a, 'e trace) result -> ('b, 'e trace) result -> ('a * 'b, 'e trace) result``: +- ``tzboth : ('a, 'e trace) result -> ('b, 'e trace) result -> ('a * 'b, 'e trace) result``: the expression ``both a b`` is ``Ok`` if both ``a`` and ``b`` are ``Ok`` and ``Error`` otherwise`. - Note that unlike ``Result_syntax.both``, the type of errors + Note that unlike ``both``, the type of errors (``error trace``) is the same on both the argument and return side of this function: the traces are combined automatically. This remark - applies to the ``all`` and ``join`` (see below) as well. + applies to the ``tzall`` and ``tzjoin`` (see below) as well. The stability of the return type is what allows this syntax module to include an ``and*`` binding operator. -- ``all : ('a, 'e trace) result list -> ('a list, 'e trace) result``: - the function ``all`` is a generalisation of ``both`` from tuples to +- ``tzall : ('a, 'e trace) result list -> ('a list, 'e trace) result``: + the function ``tzall`` is a generalisation of ``tzboth`` from tuples to lists. -- ``join : (unit, 'e trace) result list -> (unit, 'e trace) result``: - the function ``join`` is a specialisation of ``all`` for list of +- ``tzjoin : (unit, 'e trace) result list -> (unit, 'e trace) result``: + the function ``tzjoin`` is a specialisation of ``tzall`` for list of unit-typed expressions (typically, for side-effects). - ``and+`` is a binding operator similar to ``and*`` but for use with @@ -301,7 +300,7 @@ Exercises :: let twice f = - let open Tzresult_syntax in + let open Result_syntax in let* () = f () in let* () = f () in return_unit @@ -309,19 +308,19 @@ Exercises :: let twice f = - let open Tzresult_syntax in + let open Result_syntax in let* () = f () and* () = f () in return_unit -The ``Lwt_tzresult_syntax`` module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The ``Lwt_result_syntax``'s ``tz`` extensions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In the same way ``result`` can be combined with Lwt, ``tzresult`` can -also be combined with Lwt. And in the same way that ``Tzresult_syntax`` -is a small variation of ``Result_syntax``, ``Lwt_tzresult_syntax`` is a -small variation of ``Lwt_result_syntax``. +also be combined with Lwt. And in the same way that ``Result_syntax`` exports a +few ``tz``-specific extensions, ``Lwt_result_syntax`` exports a few Lwt+``tz`` +specific extensions. There are possibly too many parallels to keep track of, so the diagram below might help. @@ -334,21 +333,21 @@ below might help. V V V 'a Lwt.t ------> ('a, 'e) result Lwt.t ------> 'a tzresult Lwt.t -Anyway, the ``Lwt_tzresult_syntax`` module is identical to the -``Lwt_result_syntax`` module but for the following differences. +Anyway, the ``Lwt_result_syntax`` module exports a few functions dedicated to +handling Lwt+``tzresult``. These functions were omitted from Part 1. -- ``fail: 'e -> ('a, 'e trace) result Lwt.t``: the expression - ``fail e`` wraps ``e`` in a ``trace`` inside an ``Error`` inside a +- ``tzfail: 'e -> ('a, 'e trace) result Lwt.t``: the expression + ``tzfail e`` wraps ``e`` in a ``trace`` inside an ``Error`` inside a promise. When ``e`` is of type ``error`` as is the case throughout - Octez, ``fail e`` is of type ``'a tzresult Lwt.t``. + Octez, ``tzfail e`` is of type ``'a tzresult Lwt.t``. -- ``and*``: a binding operator alias for ``both``. You can use it with +- ``and*``: a binding operator alias for ``tzboth``. You can use it with ``let*`` the same way you use ``and`` with ``let``. :: let apply_triple f (x, y, z) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* u = f x and* v = f y and* w = f z @@ -361,32 +360,32 @@ Anyway, the ``Lwt_tzresult_syntax`` module is identical to the have all resolved but only if all of them resolve successfully. Note how this ``and*`` binding operator inherits the properties of - both ``Lwt_syntax.( and* )`` and ``Tzresult_syntax.( and* )``. + both ``Lwt_syntax.( and* )`` and ``Result_syntax.( and* )``. Specifically, the promises are evaluated concurrently and the expression which follows the ``in`` is evaluated only if all the bound promises have successfully resolved. These two orthogonal - properties are combined. This remark also applies to ``both``, - ``all``, ``join`` and ``and+`` below. + properties are combined. This remark also applies to ``tzboth``, + ``tzall``, ``tzjoin`` and ``and+`` below. -- ``both : ('a, 'e trace) result Lwt.t -> ('b, 'e trace) result Lwt.t -> ('a * 'b, 'e trace) result Lwt.t``: - the expression ``both p q`` is a promise that resolves once both +- ``tzboth : ('a, 'e trace) result Lwt.t -> ('b, 'e trace) result Lwt.t -> ('a * 'b, 'e trace) result Lwt.t``: + the expression ``tzboth p q`` is a promise that resolves once both ``p`` and ``q`` have resolved. It resolves to ``Ok`` if both ``p`` and ``q`` do, and to ``Error`` otherwise`. Note that unlike ``Lwt_result_syntax.both``, the type of errors (``error trace``) is the same on both the argument and return side of this function: the trace are combined automatically. This remark - applies to the ``all`` and ``join`` (see below) as well. + applies to the ``tzall`` and ``tzjoin`` (see below) as well. The stability of the return type is what allows this syntax module to include an ``and*`` binding operator. -- ``all : ('a, 'e trace) result Lwt.t list -> ('a list, 'e trace) result Lwt.t``: - the function ``all`` is a generalisation of ``both`` from tuples to +- ``tzall : ('a, 'e trace) result Lwt.t list -> ('a list, 'e trace) result Lwt.t``: + the function ``tzall`` is a generalisation of ``tzboth`` from tuples to lists. - ``join : (unit, 'e trace) result Lwt.t list -> (unit, 'e trace) result Lwt.t``: - the function ``join`` is a specialisation of ``all`` for lists of + the function ``tzjoin`` is a specialisation of ``tzall`` for lists of unit-typed expressions (typically, for side-effects). - ``and+`` is a binding operator similar to ``and*`` but for use with @@ -397,7 +396,7 @@ Anyway, the ``Lwt_tzresult_syntax`` module is identical to the Exercises ^^^^^^^^^ -- Rewrite this function to use the ``Lwt_tzresult_syntax`` module and +- Rewrite this function to use the ``Lwt_result_syntax`` module and no other syntax module. :: @@ -407,7 +406,7 @@ Exercises let* u = f x and* v = g y in - let r = Tzresult_syntax.both u v in + let r = Result_syntax.tzboth u v in return r - Write the implementation for @@ -416,7 +415,7 @@ Exercises (** [map f [x1; x2; ..]] is [[y1; y2; ..]] where [y1] is the successful result of [f x1], [y2] is the successful result of [f x2], etc. If [f] - fails on any of the inputs, returns an `Error` instead. Either way, all + fails on any of the inputs, returns an [Error] instead. Either way, all the calls to [f] on all the inputs are evaluated concurrently and all the calls to [f] have resolved before the whole promise resolves. *) val map : ('a -> 'b tzresult Lwt.t) -> 'a list -> 'b list tzresult @@ -431,9 +430,8 @@ Lwt-``tzresult``), you may occasionally need to call functions that return a simple promise (i.e., within Lwt-only) or a simple ``tzresult`` (i.e., within ``tzresult``-only). -This situation is similar to that of ``Lwt_result_syntax`` and the -solutions are the same. Specifically, the additional binding operators provided -by ``Lwt_result_syntax`` are also available in ``Lwt_tzresult_syntax``. +Because ``tzresult`` is a special case of ``result``, you can use the same +operators ``let*!`` and ``let*?`` as presented in Part 1. :: @@ -442,35 +440,6 @@ by ``Lwt_result_syntax`` are also available in ``Lwt_tzresult_syntax``. .. -Are you kidding me?! there is even more! what module am I supposed to open locally and what operators should I use? -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You can also use simple guidelines to use these syntax modules -effectively. - -- If your function returns ``_ tzresult Lwt.t`` values, then you start - the function with ``let open Lwt_tzresult_syntax in``. Within the - function you use - - - ``let`` for vanilla expressions, - - ``let*`` for Lwt-``tzresult`` expressions, - - ``let*!`` for Lwt-only expressions, - - ``let*?`` for ``tzresult``-only expressions. - - And you end your function with a call to ``return``. - -- If your function returns ``_ tzresult`` values, then you start the - function with ``let open Tzresult_syntax in``. Within the function - you use - - - ``let`` for vanilla expressions, - - ``let*`` for ``tzresult`` expressions, - - And you end your function with a call to ``return``. - -The rest of the guidelines (for ``(_, _) result Lwt.t``, -``(_, _) result``, and ``_ Lwt.t``) remain valid. - Tracing ~~~~~~~ @@ -502,7 +471,7 @@ storage layer) into another (say the shell). :: let check_hashes head block operation = - let open Tzresult_syntax in + let open Result_syntax in let* () = record_trace (Invalid_hash { kind: "head"; hash: head}) @@ check_hash chain @@ -542,7 +511,7 @@ storage layer) into another (say the shell). :: let get_data_and_gossip_it () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* data = trace Cannot_get_random_data_from_storage @@ Storage.get_random_data () diff --git a/docs/developer/error_monad_p4_appendices.rst b/docs/developer/error_monad_p4_appendices.rst index 675b51ca19b0f3208fe7bd193890c908745abe47..5e230649e8c4a7e36d311f758e566c767ecaa975 100644 --- a/docs/developer/error_monad_p4_appendices.rst +++ b/docs/developer/error_monad_p4_appendices.rst @@ -106,23 +106,23 @@ a given syntax module, the legacy code relied on global values. +--------------------------------------+-------------------------------+ | :: | :: | | | | -| let open Tzresult_syntax in | ok x | +| let open Result_syntax in | ok x | | return x | | +--------------------------------------+-------------------------------+ | :: | :: | | | | -| let open Tzresult_syntax in | error e | -| fail e | | +| let open Result_syntax in | error e | +| tzfail e | | +--------------------------------------+-------------------------------+ | :: | :: | | | | -| let open Lwt_tzresult_syntax in | return x | +| let open Lwt_result_syntax in | return x | | return x | | +--------------------------------------+-------------------------------+ | :: | :: | | | | -| let open Lwt_tzresult_syntax in | fail e | -| fail e | | +| let open Lwt_result_syntax in | fail e | +| tzfail e | | +--------------------------------------+-------------------------------+ In addition to these syntactic differences, there are also usage @@ -262,7 +262,7 @@ The ``Error_monad`` module exports: - the ``error`` type along with the ``register_error_kind`` function, - the ``'a tzresult`` type, - the ``TzTrace`` module, -- the ``Tzresult_syntax`` and ``Lwt_tzresult_syntax`` modules +- the ``Result_syntax`` and ``Lwt_result_syntax`` modules (from a different, more generic name), - and exports a few more functions. diff --git a/scripts/yes-wallet/yes_wallet_lib.ml b/scripts/yes-wallet/yes_wallet_lib.ml index 100a68ce9129aa14a8f31754ff528a819f27b453..f8cc0daa36dc5f17b7178fd60fc4cbea6839b707 100644 --- a/scripts/yes-wallet/yes_wallet_lib.ml +++ b/scripts/yes-wallet/yes_wallet_lib.ml @@ -191,7 +191,7 @@ let filter_up_to_staking_share share total_stake to_mutez keys_list = let get_delegates (proto : protocol) context (header : Block_header.shell_header) active_bakers_only staking_share_opt = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let level = header.Block_header.level in let predecessor_timestamp = header.timestamp in let timestamp = Time.Protocol.add predecessor_timestamp 10000L in @@ -517,7 +517,7 @@ let protocol_of_hash protocol_hash = *) let load_mainnet_bakers_public_keys base_dir active_bakers_only staking_share_opt = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Tezos_store in let mainnet_genesis = { diff --git a/src/bin_client/client_rpc_commands.ml b/src/bin_client/client_rpc_commands.ml index a282b38f5a048e1151fa111efcf6d6ecb13f9287..3fac63ff06c5d425642905d4f78a4ec4af10edb2 100644 --- a/src/bin_client/client_rpc_commands.ml +++ b/src/bin_client/client_rpc_commands.ml @@ -534,7 +534,7 @@ let meth_params ?(name = "HTTP method") ?(desc = "") params = @@ List.map Resto.string_of_meth @@ [`GET; `POST; `DELETE; `PUT; `PATCH]) (fun _ name -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Resto.meth_of_string (String.uppercase_ascii name) with | None -> failwith "Unknown HTTP method: %s" name | Some meth -> return meth)) diff --git a/src/bin_node/node_config_file.ml b/src/bin_node/node_config_file.ml index 3534901ec206b041e7284d33e8cf93ba56d91617..9f7a91c1c43747d405684999b27f3f692541e7b0 100644 --- a/src/bin_node/node_config_file.ml +++ b/src/bin_node/node_config_file.ml @@ -1251,24 +1251,24 @@ let string_of_json_encoding_error exn = Format.asprintf "%a" (Json_encoding.print_error ?print_unknown:None) exn let read fp = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in if Sys.file_exists fp then let* json = Lwt_utils_unix.Json.read_file fp in try return (Data_encoding.Json.destruct encoding json) with | Json_encoding.Cannot_destruct (path, exn) -> let path = Json_query.json_pointer_of_path path in let exn = string_of_json_encoding_error exn in - fail (Invalid_content (Some path, exn)) + tzfail (Invalid_content (Some path, exn)) | ( Json_encoding.Unexpected _ | Json_encoding.No_case_matched _ | Json_encoding.Bad_array_size _ | Json_encoding.Missing_field _ | Json_encoding.Unexpected_field _ | Json_encoding.Bad_schema _ ) as exn -> let exn = string_of_json_encoding_error exn in - fail (Invalid_content (None, exn)) + tzfail (Invalid_content (None, exn)) else return default_config let write fp cfg = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = Node_data_version.ensure_data_dir (Filename.dirname fp) in Lwt_utils_unix.Json.write_file fp (Data_encoding.Json.construct encoding cfg) @@ -1287,7 +1287,7 @@ let update ?(disable_config_validation = false) ?data_dir ?min_connections ?(enable_testchain = false) ?(cors_origins = []) ?(cors_headers = []) ?rpc_tls ?log_output ?synchronisation_threshold ?history_mode ?network ?latency cfg = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let disable_config_validation = cfg.disable_config_validation || disable_config_validation in @@ -1456,15 +1456,15 @@ let to_ipv4 ipv6_l = let resolve_addr ~default_addr ?(no_peer_id_expected = true) ?default_port ?(passive = false) peer : (P2p_point.Id.t * P2p_peer.Id.t option) list tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match P2p_point.Id.parse_addr_port_id peer with | (Error (P2p_point.Id.Bad_id_format _) | Ok {peer_id = Some _; _}) when no_peer_id_expected -> - fail + tzfail (Failed_to_parse_address (peer, "no peer identity should be specified here")) | Error err -> - fail + tzfail (Failed_to_parse_address (peer, P2p_point.Id.string_of_parsing_error err)) | Ok {addr; port; peer_id} -> let service_port = @@ -1485,7 +1485,7 @@ let resolve_addrs ?default_port ?passive ?no_peer_id_expected ~default_addr addrs let resolve_discovery_addrs discovery_addr = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* addrs = resolve_addr ~default_addr:Ipaddr.V4.(to_string broadcast) @@ -1497,7 +1497,7 @@ let resolve_discovery_addrs discovery_addr = return addrs let resolve_listening_addrs listen_addr = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let+ addrs = resolve_addr ~default_addr:"::" @@ -1508,7 +1508,7 @@ let resolve_listening_addrs listen_addr = List.map fst addrs let resolve_rpc_listening_addrs listen_addr = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let+ addrs = resolve_addr ~default_addr:"localhost" @@ -1519,7 +1519,7 @@ let resolve_rpc_listening_addrs listen_addr = List.map fst addrs let resolve_metrics_addrs metrics_addr = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let+ addrs = resolve_addr ~default_addr:"localhost" diff --git a/src/bin_node/node_config_validation.ml b/src/bin_node/node_config_validation.ml index d40f73b56f0651864c8748790ed661574ef43fd5..72d64c63b8c08f6f7a06735b8d0b4d2becf20f4d 100644 --- a/src/bin_node/node_config_validation.ml +++ b/src/bin_node/node_config_validation.ml @@ -454,7 +454,7 @@ let validate_passes config = (* Main validation functions. *) let check config = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in if config.Node_config_file.disable_config_validation then let*! () = Event.(emit disabled_event ()) in return_unit @@ -462,7 +462,7 @@ let check config = let* t = validate_passes config in if has_error t then let*! () = Event.report t in - fail Invalid_node_configuration + tzfail Invalid_node_configuration else if has_warning t then let*! () = Event.report t in return_unit diff --git a/src/bin_node/node_data_version.ml b/src/bin_node/node_data_version.ml index 809a9ced522e3c82f64640e193e265dd2585f12c..1a4713a8537f00988d6e9fab1459c801b4f7667a 100644 --- a/src/bin_node/node_data_version.ml +++ b/src/bin_node/node_data_version.ml @@ -61,7 +61,7 @@ let data_version = "0.0.8" converter), and to sequence them dynamically instead of statically. *) let upgradable_data_version = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in [ ( "0.0.6", fun ~data_dir:_ _ ~chain_name:_ ~sandbox_parameters:_ -> return_unit ); @@ -245,7 +245,7 @@ let write_version_file data_dir = |> trace (Could_not_write_version_file version_file) let read_version_file version_file = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* json = trace (Could_not_read_data_dir_version version_file) @@ -257,15 +257,15 @@ let read_version_file version_file = | Data_encoding.Json.No_case_matched _ | Data_encoding.Json.Bad_array_size _ | Data_encoding.Json.Missing_field _ | Data_encoding.Json.Unexpected_field _ -> - fail (Could_not_read_data_dir_version version_file) + tzfail (Could_not_read_data_dir_version version_file) let check_data_dir_version files data_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let version_file = version_file data_dir in let*! file_exists = Lwt_unix.file_exists version_file in if not file_exists then let msg = Some (clean_directory files) in - fail (Invalid_data_dir {data_dir; msg}) + tzfail (Invalid_data_dir {data_dir; msg}) else let* version = read_version_file version_file in if String.equal version data_version then return_none @@ -276,10 +276,10 @@ let check_data_dir_version files data_dir = upgradable_data_version with | Some f -> return_some f - | None -> fail (Invalid_data_dir_version (data_version, version)) + | None -> tzfail (Invalid_data_dir_version (data_version, version)) let ensure_data_dir bare data_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let write_version () = let* () = write_version_file data_dir in return_none @@ -304,13 +304,13 @@ let ensure_data_dir bare data_dir = | [] -> write_version () | files when bare -> let msg = Some (clean_directory files) in - fail (Invalid_data_dir {data_dir; msg}) + tzfail (Invalid_data_dir {data_dir; msg}) | files -> check_data_dir_version files data_dir else let*! () = Lwt_utils_unix.create_dir ~perm:0o700 data_dir in write_version ()) (function - | Unix.Unix_error _ -> fail (Invalid_data_dir {data_dir; msg = None}) + | Unix.Unix_error _ -> tzfail (Invalid_data_dir {data_dir; msg = None}) | exc -> raise exc) let upgrade_data_dir ~data_dir genesis ~chain_name ~sandbox_parameters = @@ -333,7 +333,7 @@ let upgrade_data_dir ~data_dir genesis ~chain_name ~sandbox_parameters = Lwt.return (Error e)) let ensure_data_dir ?(bare = false) data_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* o = ensure_data_dir bare data_dir in match o with | None -> return_unit @@ -344,7 +344,8 @@ let ensure_data_dir ?(bare = false) data_dir = -> upgrade_data_dir ~data_dir () ~chain_name:() ~sandbox_parameters:() | Some (version, _) -> - fail (Data_dir_needs_upgrade {expected = data_version; actual = version}) + tzfail + (Data_dir_needs_upgrade {expected = data_version; actual = version}) let upgrade_status data_dir = let open Lwt_result_syntax in diff --git a/src/bin_node/node_identity_file.ml b/src/bin_node/node_identity_file.ml index 91a89893fb0b695e3605bc221b9ee3be52d364f9..509d0f91152aff4b002e425363b0dd25809b9f63 100644 --- a/src/bin_node/node_identity_file.ml +++ b/src/bin_node/node_identity_file.ml @@ -127,19 +127,19 @@ let () = Identity_keys_mismatch {filename; expected_key}) let read ?expected_pow filename = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! file_exists = Lwt_unix.file_exists filename in - if not file_exists then fail (No_identity_file filename) + if not file_exists then tzfail (No_identity_file filename) else let* json = Lwt_utils_unix.Json.read_file filename in let id = Data_encoding.Json.destruct P2p_identity.encoding json in let pkh = Crypto_box.hash id.public_key in (* check public_key hash *) if not (Crypto_box.Public_key_hash.equal pkh id.peer_id) then - fail (Identity_mismatch {filename; peer_id = pkh}) + tzfail (Identity_mismatch {filename; peer_id = pkh}) (* check public/private keys correspondence *) else if not Crypto_box.(equal (neuterize id.secret_key) id.public_key) then - fail (Identity_keys_mismatch {filename; expected_key = id.public_key}) + tzfail (Identity_keys_mismatch {filename; expected_key = id.public_key}) else (* check PoW level *) match expected_pow with @@ -152,7 +152,7 @@ let read ?expected_pow filename = id.public_key id.proof_of_work_stamp target) - then fail (Insufficient_proof_of_work {expected}) + then tzfail (Insufficient_proof_of_work {expected}) else return id type error += Existent_identity_file of string @@ -175,8 +175,8 @@ let () = (fun file -> Existent_identity_file file) let write file identity = - let open Lwt_tzresult_syntax in - if Sys.file_exists file then fail (Existent_identity_file file) + let open Lwt_result_syntax in + if Sys.file_exists file then tzfail (Existent_identity_file file) else let* () = Node_data_version.ensure_data_dir (Filename.dirname file) in Lwt_utils_unix.Json.write_file @@ -205,9 +205,9 @@ let generate_with_animation ppf target = 10000 let generate identity_file expected_pow = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in if Sys.file_exists identity_file then - fail (Existent_identity_file identity_file) + tzfail (Existent_identity_file identity_file) else let target = Crypto_box.make_pow_target expected_pow in Format.eprintf "Generating a new identity... (level: %.2f) " expected_pow ; diff --git a/src/bin_node/node_reconstruct_command.ml b/src/bin_node/node_reconstruct_command.ml index 8984e9d7b3ade96ce63ea2fbcd247e36e39d9e51..632c36d1a026faa7d7630b419ef841c0877b7f35 100644 --- a/src/bin_node/node_reconstruct_command.ml +++ b/src/bin_node/node_reconstruct_command.ml @@ -46,7 +46,7 @@ let () = module Term = struct let process args sandbox_file = let run = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Tezos_base_unix.Internal_event_unix.init () in let* node_config = Node_shared_arg.read_and_patch_config_file args in let data_dir = node_config.data_dir in @@ -64,11 +64,11 @@ module Term = struct let*! r = Lwt_utils_unix.Json.read_file filename in match r with | Error _err -> - fail (Node_run_command.Invalid_sandbox_file filename) + tzfail (Node_run_command.Invalid_sandbox_file filename) | Ok json -> return_some ("sandbox_parameter", json)) in Lwt_lock_file.try_with_lock - ~when_locked:(fun () -> fail Locked_directory) + ~when_locked:(fun () -> tzfail Locked_directory) ~filename:(Node_data_version.lock_file data_dir) @@ fun () -> let context_dir = Node_data_version.context_dir data_dir in diff --git a/src/bin_node/node_replay_command.ml b/src/bin_node/node_replay_command.ml index c174615423f3c9b98a38aa09ffa0b111e5150c58..3697f5e0af6cfbe4a53fb61c404c19d3952c6a78 100644 --- a/src/bin_node/node_replay_command.ml +++ b/src/bin_node/node_replay_command.ml @@ -152,7 +152,7 @@ let () = (fun () -> Cannot_replay_below_savepoint) let replay ~singleprocess (config : Node_config_file.t) blocks = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let store_root = Node_data_version.store_dir config.data_dir in let context_root = Node_data_version.context_dir config.data_dir in let protocol_root = Node_data_version.protocol_dir config.data_dir in @@ -220,13 +220,13 @@ let replay ~singleprocess (config : Node_config_file.t) blocks = in let* block = protect - ~on_error:(fun _ -> fail Block_not_found) + ~on_error:(fun _ -> tzfail Block_not_found) (fun () -> let*! o = Store.Chain.block_of_identifier_opt main_chain_store block in match o with - | None -> fail Block_not_found + | None -> tzfail Block_not_found | Some block -> return block) in let predecessor_hash = Store.Block.predecessor block in @@ -234,13 +234,13 @@ let replay ~singleprocess (config : Node_config_file.t) blocks = Store.Block.read_block_opt main_chain_store predecessor_hash in match predecessor_opt with - | None -> fail Cannot_replay_orphan + | None -> tzfail Cannot_replay_orphan | Some predecessor -> let*! (_, savepoint_level) = Store.Chain.savepoint main_chain_store in if Store.Block.level block <= savepoint_level then - fail Cannot_replay_below_savepoint + tzfail Cannot_replay_below_savepoint else let expected_context_hash = Store.Block.context_hash block in let* metadata = diff --git a/src/bin_node/node_run_command.ml b/src/bin_node/node_run_command.ml index c2b8da4f72f86cd5ab7c5b14891fe64deb0af8e1..5ae760684abce731bd5c6995d52e92792e6a5284 100644 --- a/src/bin_node/node_run_command.ml +++ b/src/bin_node/node_run_command.ml @@ -228,7 +228,7 @@ let init_identity_file (config : Node_config_file.t) = let init_node ?sandbox ?target ~identity ~singleprocess ~force_history_mode_switch (config : Node_config_file.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* TODO "WARN" when pow is below our expectation. *) let*! () = if config.disable_config_validation then @@ -262,7 +262,7 @@ let init_node ?sandbox ?target ~identity ~singleprocess | (Some addr, Some _) when Ipaddr.V6.(compare addr unspecified) = 0 -> return_none | (Some addr, Some _) when not (Ipaddr.V6.is_private addr) -> - fail (Non_private_sandbox addr) + tzfail (Non_private_sandbox addr) | (None, Some _) -> return_none | _ -> let* trusted_points = @@ -360,7 +360,7 @@ let sanitize_cors_headers ~default headers = let launch_rpc_server ~acl_policy ~media_types (config : Node_config_file.t) node (addr, port) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let rpc_config = config.rpc in let host = Ipaddr.V6.to_string addr in let dir = Node.build_rpc_directory node in @@ -409,11 +409,11 @@ let launch_rpc_server ~acl_policy ~media_types (config : Node_config_file.t) This exception seems to be unreachable. *) | Unix.Unix_error (Unix.EADDRINUSE, "bind", "") -> - fail (RPC_Port_already_in_use [(addr, port)]) + tzfail (RPC_Port_already_in_use [(addr, port)]) | exn -> fail_with_exn exn) let init_rpc (config : Node_config_file.t) node = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let media_types = config.rpc.media_type in List.concat_map_es (fun addr -> @@ -433,7 +433,7 @@ let init_rpc (config : Node_config_file.t) node = module Metrics_server = Prometheus_app.Cohttp (Cohttp_lwt_unix.Server) let metrics_serve metrics_addrs = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* addrs = List.map_ep Node_config_file.resolve_metrics_addrs metrics_addrs in @@ -456,7 +456,7 @@ let metrics_serve metrics_addrs = let run ?verbosity ?sandbox ?target ~singleprocess ~force_history_mode_switch (config : Node_config_file.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = Node_data_version.ensure_data_dir config.data_dir in (* Main loop *) let log_cfg = @@ -526,7 +526,7 @@ let run ?verbosity ?sandbox ?target ~singleprocess ~force_history_mode_switch let process sandbox verbosity target singleprocess force_history_mode_switch args = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let verbosity = let open Internal_event in match verbosity with [] -> None | [_] -> Some Info | _ -> Some Debug diff --git a/src/bin_node/node_shared_arg.ml b/src/bin_node/node_shared_arg.ml index 458da29d8be0720417c3598bc1b58b3db44c2ff2..1bb4b9e1f43715d9c2884ef65e4eb98d8a78dac2 100644 --- a/src/bin_node/node_shared_arg.ml +++ b/src/bin_node/node_shared_arg.ml @@ -108,7 +108,7 @@ let () = (fun (status, body) -> Network_http_error (status, body)) let decode_net_config source json = - let open Tzresult_syntax in + let open Result_syntax in match Data_encoding.Json.destruct Node_config_file.blockchain_network_encoding @@ -117,16 +117,16 @@ let decode_net_config source json = | net_cfg -> return net_cfg | exception Json_encoding.Cannot_destruct (path, exn) -> let path = Json_query.json_pointer_of_path path in - fail (Invalid_network_config (path, Printexc.to_string exn)) + tzfail (Invalid_network_config (path, Printexc.to_string exn)) | exception (( Json_encoding.Unexpected _ | Json_encoding.No_case_matched _ | Json_encoding.Bad_array_size _ | Json_encoding.Missing_field _ | Json_encoding.Unexpected_field _ | Json_encoding.Bad_schema _ ) as exn) -> - fail (Invalid_network_config (source, Printexc.to_string exn)) + tzfail (Invalid_network_config (source, Printexc.to_string exn)) let load_net_config = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in function | BuiltIn net -> return net | Url uri -> @@ -137,9 +137,9 @@ let load_net_config = | `OK -> ( try return (Ezjsonm.from_string body_str) with Ezjsonm.Parse_error (_, msg) -> - fail (Invalid_network_config (Uri.to_string uri, msg))) + tzfail (Invalid_network_config (Uri.to_string uri, msg))) | #Cohttp.Code.status_code -> - fail (Network_http_error (resp.status, body_str)) + tzfail (Network_http_error (resp.status, body_str)) in let*? net_config = decode_net_config (Uri.to_string uri) netconfig in return net_config @@ -668,13 +668,13 @@ module Term = struct end let read_config_file args = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in if Sys.file_exists args.config_file then Node_config_file.read args.config_file else return Node_config_file.default_config let read_data_dir args = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* cfg = read_config_file args in let {data_dir; _} = args in let data_dir = Option.value ~default:cfg.data_dir data_dir in @@ -750,7 +750,7 @@ end let read_and_patch_config_file ?(may_override_network = false) ?(ignore_bootstrap_peers = false) args = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* cfg = read_config_file args in let { data_dir; @@ -791,7 +791,7 @@ let read_and_patch_config_file ?(may_override_network = false) let* synchronisation_threshold = match (bootstrap_threshold, synchronisation_threshold) with | (Some _, Some _) -> - fail + tzfail (Invalid_command_line_arguments "--bootstrap-threshold is deprecated; use \ --synchronisation-threshold instead. Do not use both at the same \ @@ -822,7 +822,7 @@ let read_and_patch_config_file ?(may_override_network = false) net.chain_name then return_unit else - fail + tzfail (Network_configuration_mismatch { configuration_file_chain_name = diff --git a/src/bin_node/node_snapshot_command.ml b/src/bin_node/node_snapshot_command.ml index 93760656225b3f4a63b4f14c8e4b947ab4939cfe..4172673460e30f9fdc63dac0ece71ac093bbfa55 100644 --- a/src/bin_node/node_snapshot_command.ml +++ b/src/bin_node/node_snapshot_command.ml @@ -114,17 +114,17 @@ module Term = struct type subcommand = Export | Import | Info let check_snapshot_path = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in function - | None -> fail Missing_file_argument + | None -> tzfail Missing_file_argument | Some path -> if Sys.file_exists path then return path - else fail (Cannot_locate_file path) + else tzfail (Cannot_locate_file path) let process subcommand args snapshot_path block disable_check export_format rolling reconstruct in_memory_index on_disk_index sandbox_file = let run = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Tezos_base_unix.Internal_event_unix.init () in match subcommand with | Export -> @@ -203,7 +203,7 @@ module Term = struct let*! r = Lwt_utils_unix.Json.read_file filename in match r with | Error _err -> - fail (Node_run_command.Invalid_sandbox_file filename) + tzfail (Node_run_command.Invalid_sandbox_file filename) | Ok json -> return_some ("sandbox_parameter", json)) in let context_root = Node_data_version.context_dir data_dir in diff --git a/src/bin_node/node_storage_command.ml b/src/bin_node/node_storage_command.ml index 14593ff46dc246c2ed66a964729965971a5d83ee..f868ef69441cdc75951c39d56cf2a0ab85e1f597 100644 --- a/src/bin_node/node_storage_command.ml +++ b/src/bin_node/node_storage_command.ml @@ -57,7 +57,7 @@ module Term = struct | Head_commit let read_config_file config_file = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let+ config = Option.filter Sys.file_exists config_file |> Option.map_es Node_config_file.read @@ -65,25 +65,25 @@ module Term = struct Option.value ~default:Node_config_file.default_config config let ensure_context_dir context_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt.catch (fun () -> let*! b = Lwt_unix.file_exists context_dir in if not b then - fail + tzfail (Node_data_version.Invalid_data_dir {data_dir = context_dir; msg = None}) else let pack = context_dir // "store.pack" in let*! b = Lwt_unix.file_exists pack in if not b then - fail + tzfail (Node_data_version.Invalid_data_dir {data_dir = context_dir; msg = None}) else return_unit) (function | Unix.Unix_error _ -> - fail + tzfail (Node_data_version.Invalid_data_dir {data_dir = context_dir; msg = None}) | exc -> raise exc) @@ -115,10 +115,10 @@ module Term = struct return_unit let index_dir_exists context_dir output = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let index_dir = Option.value output ~default:(context_dir // "index") in let*! b = Lwt_unix.file_exists index_dir in - if not b then return_unit else fail (Existing_index_dir index_dir) + if not b then return_unit else tzfail (Existing_index_dir index_dir) let reconstruct_index config_file data_dir output index_log_size = let open Lwt_result_syntax in diff --git a/src/bin_node/node_upgrade_command.ml b/src/bin_node/node_upgrade_command.ml index 9deaa582a6cbefe0ae8d5e444ef840844b1cf575..5dcbb578606bf0980d1a21a57f261ae97f6027bb 100644 --- a/src/bin_node/node_upgrade_command.ml +++ b/src/bin_node/node_upgrade_command.ml @@ -59,7 +59,7 @@ module Term = struct let process subcommand args status sandbox_file = let run = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Tezos_base_unix.Internal_event_unix.init () in match subcommand with | Storage -> ( @@ -94,7 +94,7 @@ module Term = struct let*! r = Lwt_utils_unix.Json.read_file filename in match r with | Error _err -> - fail + tzfail (Node_run_command.Invalid_sandbox_file filename) | Ok json -> return_some ("sandbox_parameter", json)) in @@ -108,7 +108,7 @@ module Term = struct | Error (Exn (Unix.Unix_error (Unix.ENOENT, _, _)) :: _) -> (* The provided data directory to upgrade cannot be found. *) - fail (Invalid_directory data_dir) + tzfail (Invalid_directory data_dir) | Ok v -> Lwt.return (Ok v) | errs -> Lwt.return errs) in diff --git a/src/bin_proxy_server/main_proxy_server.ml b/src/bin_proxy_server/main_proxy_server.ml index d1eafcfce8a0e3db71b675e49d7c40b6adba7b6a..47b4418312eaeed5f13bc7fc73c6f6ae585048f0 100644 --- a/src/bin_proxy_server/main_proxy_server.ml +++ b/src/bin_proxy_server/main_proxy_server.ml @@ -99,7 +99,7 @@ let load_config_from_file (config_file : string) = and the command line, and translates the result to a value of type [Proxy_server_config.runtime]. *) let get_runtime config_from_file config_args = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Proxy_server_config in let config = match config_from_file with diff --git a/src/bin_proxy_server/proxy_server_main_run.ml b/src/bin_proxy_server/proxy_server_main_run.ml index a13084d035a22a8b1c24b5dddf95a0840f116cf3..f42ca9365e87e04b983ca3f47c3b542eb8e79a60 100644 --- a/src/bin_proxy_server/proxy_server_main_run.ml +++ b/src/bin_proxy_server/proxy_server_main_run.ml @@ -53,7 +53,7 @@ let () = (fun addrlist -> Proxy_server_RPC_Port_already_in_use addrlist) let launch_rpc_server dir {address; port; tls_cert_and_key} = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let host = Ipaddr.V6.to_string address in let mode = match tls_cert_and_key with @@ -71,7 +71,7 @@ let launch_rpc_server dir {address; port; tls_cert_and_key} = ~media_types:Tezos_rpc_http.Media_type.all_media_types) (function | Unix.Unix_error (Unix.EADDRINUSE, "bind", "") -> - fail (Proxy_server_RPC_Port_already_in_use [(address, port)]) + tzfail (Proxy_server_RPC_Port_already_in_use [(address, port)]) | exn -> fail_with_exn exn) let run dir ({address; port; _} as args) = diff --git a/src/bin_signer/handler.ml b/src/bin_signer/handler.ml index 5fd8a09e9739b79bfda26d4b153f4a06769fc858..23aa20ec25b5fdaddd7ed06dd60a7a9523704a98 100644 --- a/src/bin_signer/handler.ml +++ b/src/bin_signer/handler.ml @@ -49,7 +49,7 @@ module High_watermark = struct let get_level_and_round_for_tenderbake_block bytes = (* ... *) (* FITNESS= *) - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in try let level = Bytes.get_int32_be bytes (1 + 4) in let fitness_offset = 1 + 4 + 4 + 1 + 32 + 8 + 1 + 32 in @@ -67,7 +67,7 @@ module High_watermark = struct let get_level_and_round_for_tenderbake_endorsement bytes = (* ... *) - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in try let level_offset = 1 + 4 + 32 + 1 + 2 in let level = Bytes.get_int32_be bytes level_offset in @@ -82,7 +82,7 @@ module High_watermark = struct let check_mark name (previous_level, previous_round_opt, previous_hash, previous_signature_opt) level round_opt hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let round = Option.value ~default:0l round_opt in match (previous_round_opt, previous_signature_opt) with | (None, None) -> @@ -230,7 +230,7 @@ module Authorized_key = Client_aliases.Alias (struct end) let check_magic_byte magic_bytes data = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match magic_bytes with | None -> return_unit | Some magic_bytes -> diff --git a/src/bin_signer/main_signer.ml b/src/bin_signer/main_signer.ml index a503d222f17ea047bfb9566e7806edefb8b2d044..231e2faf8e41de3fed1ef219c67b245566cf046d 100644 --- a/src/bin_signer/main_signer.ml +++ b/src/bin_signer/main_signer.ml @@ -383,4 +383,4 @@ end let () = Client_main_run.run (module Signer_config) - ~select_commands:(fun _ _ -> Lwt_tzresult_syntax.return_nil) + ~select_commands:(fun _ _ -> Lwt_result_syntax.return_nil) diff --git a/src/bin_snoop/commands.ml b/src/bin_snoop/commands.ml index 1b225ba64280541d0d0f4c493361f7d0926a07da..829f78139fb6989c0f98aaaa60b759d8e62e9f3e 100644 --- a/src/bin_snoop/commands.ml +++ b/src/bin_snoop/commands.ml @@ -767,7 +767,7 @@ module List_cmd = struct (fun (module Bench : Benchmark.S) -> Format.fprintf Format.std_formatter "%s: %s\n" Bench.name Bench.info) bench_list ; - Lwt_tzresult_syntax.return_unit + Lwt_result_syntax.return_unit let handler_all_bench show_tags () = base_handler_bench (Registration.all_benchmarks ()) show_tags @@ -778,7 +778,7 @@ module List_cmd = struct List.iter (fun tag -> Format.fprintf Format.std_formatter "%s\n" tag) (Registration.all_tags ()) ; - Lwt_tzresult_syntax.return_unit + Lwt_result_syntax.return_unit let params_bench_tags_any = Clic.( diff --git a/src/bin_validation/validator.ml b/src/bin_validation/validator.ml index 51568d993ff47136e43466a8ff51a6f3241e0b27..1a15084952be71c57e780fca9898100c78e0bb9c 100644 --- a/src/bin_validation/validator.ml +++ b/src/bin_validation/validator.ml @@ -112,7 +112,7 @@ end open Filename.Infix let load_protocol proto protocol_root = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in if Registered_protocol.mem proto then return_unit else let cmxs_file = @@ -126,7 +126,7 @@ let load_protocol proto protocol_root = | exception Dynlink.Error err -> Format.ksprintf (fun msg -> - fail + tzfail Block_validator_errors.( Validation_process_failed (Protocol_dynlink_failure msg))) "Cannot load file: %s. (Expected location: %s.)" @@ -192,7 +192,7 @@ let init input = operation_metadata_size_limit ) let run input output = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = handshake input output in let*! ( context_index, protocol_root, @@ -255,7 +255,7 @@ let run input output = match o with | Some context -> return context | None -> - fail + tzfail (Block_validator_errors.Failed_to_checkout_context pred_context_hash)) in @@ -333,7 +333,7 @@ let run input output = match context with | Some context -> return context | None -> - fail + tzfail (Block_validator_errors.Failed_to_checkout_context pred_context_hash)) in @@ -400,7 +400,7 @@ let run input output = match o with | Some context -> return context | None -> - fail + tzfail (Block_validator_errors.Failed_to_checkout_context predecessor_block_header.shell.context)) in @@ -444,7 +444,7 @@ let run input output = External_validation.send output (Error_monad.result_encoding Data_encoding.empty) - (Tzresult_syntax.fail + (Result_syntax.tzfail (Block_validator_errors.Failed_to_checkout_context context_hash)) in diff --git a/src/lib_base/network_version.ml b/src/lib_base/network_version.ml index 94837f8615ffdb566debe51ea0e25fe62e8de283..59fc8341543143ee7f11c601b945483b05f0b798 100644 --- a/src/lib_base/network_version.ml +++ b/src/lib_base/network_version.ml @@ -85,7 +85,7 @@ let may_select_version ~compare accepted_versions remote_version motive = else P2p_rejection.rejecting motive let select ~chain_name ~distributed_db_versions ~p2p_versions remote = - let open Error_monad.Tzresult_syntax in + let open Error_monad.Result_syntax in assert (distributed_db_versions <> []) ; assert (p2p_versions <> []) ; if chain_name <> remote.chain_name then diff --git a/src/lib_base/p2p_rejection.ml b/src/lib_base/p2p_rejection.ml index 76b8692d63fd1b58fb83b4c45bc2878c0f76a998..4f3cb00b10a1eedca755d2d1a9f40e763e170bd0 100644 --- a/src/lib_base/p2p_rejection.ml +++ b/src/lib_base/p2p_rejection.ml @@ -97,4 +97,4 @@ let () = (function Rejecting {motive} -> Some motive | _ -> None) (fun motive -> Rejecting {motive}) -let rejecting motive = Tzresult_syntax.fail (Rejecting {motive}) +let rejecting motive = Result_syntax.tzfail (Rejecting {motive}) diff --git a/src/lib_base/unix/internal_event_unix.ml b/src/lib_base/unix/internal_event_unix.ml index 5c2364c9061897c9240bc4dabc23ba1f8cce664b..fcea47dfb188897ac582378a5f5ffcaf3aaddfb1 100644 --- a/src/lib_base/unix/internal_event_unix.ml +++ b/src/lib_base/unix/internal_event_unix.ml @@ -31,7 +31,7 @@ module Configuration = struct include Tezos_base.Internal_event_config let of_file path = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* json = Lwt_utils_unix.Json.read_file path in protect (fun () -> return (Data_encoding.Json.destruct encoding json)) end @@ -47,7 +47,7 @@ let init ?lwt_log_sink ?(configuration = Configuration.default) () = File_event_sink.Sink_implementation.uri_scheme; ] in - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! r = let* () = Lwt_result.ok @@ Lwt_log_sink_unix.initialize ?cfg:lwt_log_sink () diff --git a/src/lib_base/unix/socket.ml b/src/lib_base/unix/socket.ml index c7d16863d0b0dbf3b21630f596d4d45fa7a0c78c..bd23644131227bd0e32e47e727a5bf9cd0284045 100644 --- a/src/lib_base/unix/socket.ml +++ b/src/lib_base/unix/socket.ml @@ -36,7 +36,7 @@ let handle_literal_ipv6 host = | Ok ipaddr -> Ipaddr.to_string ipaddr let connect ?(timeout = !Lwt_utils_unix.default_net_timeout) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in function | Unix path -> let addr = Lwt_unix.ADDR_UNIX path in @@ -140,7 +140,7 @@ let maximum_length_of_message_payload = 1 lsl (size_of_length_of_message_payload * 8) let send fd encoding message = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let length_of_message_payload = Data_encoding.Binary.length encoding message in @@ -166,7 +166,7 @@ let send fd encoding message = assert (Option.is_some serialisation_state) ; let serialisation_state = Stdlib.Option.get serialisation_state in match Data_encoding.Binary.write encoding message serialisation_state with - | Error we -> fail (Encoding_error we) + | Error we -> tzfail (Encoding_error we) | Ok last -> let* () = fail_unless @@ -183,7 +183,7 @@ let send fd encoding message = @@ Lwt_utils_unix.write_bytes fd message_serialisation_buffer) let recv ?timeout fd encoding = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let header_buf = Bytes.create size_of_length_of_message_payload in let* () = protect (fun () -> @@ -203,7 +203,7 @@ let recv ?timeout fd encoding = in let buf = Bytes.unsafe_to_string buf in match Data_encoding.Binary.read encoding buf 0 len with - | Error re -> fail (Decoding_error re) + | Error re -> tzfail (Decoding_error re) | Ok (read_len, message) -> - if read_len <> len then fail (Decoding_error Extra_bytes) + if read_len <> len then tzfail (Decoding_error Extra_bytes) else return message diff --git a/src/lib_clic/clic.ml b/src/lib_clic/clic.ml index b410bce112cc402e318d92fe94f7b0f56e997bbe..7776593dea91d66de2ab1b2f2b9428140becc369 100644 --- a/src/lib_clic/clic.ml +++ b/src/lib_clic/clic.ml @@ -765,7 +765,7 @@ let parse_arg : ctx -> a tzresult Lwt.t = fun ?command spec args_dict ctx -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match spec with | Arg {label = {long; short = _}; kind = {converter; _}; _} -> ( match StringMap.find_opt long args_dict with @@ -776,7 +776,7 @@ let parse_arg : @@ converter ctx s in Some x - | Some (_ :: _) -> fail (Multiple_occurrences ("--" ^ long, command))) + | Some (_ :: _) -> tzfail (Multiple_occurrences ("--" ^ long, command))) | DefArg {label = {long; short = _}; kind = {converter; _}; default; _} -> ( let*! r = converter ctx default in match r with @@ -791,12 +791,12 @@ let parse_arg : | None | Some [] -> return default | Some [s] -> trace (Bad_option_argument (long, command)) (converter ctx s) - | Some (_ :: _) -> fail (Multiple_occurrences (long, command)))) + | Some (_ :: _) -> tzfail (Multiple_occurrences (long, command)))) | Switch {label = {long; short = _}; _} -> ( match StringMap.find_opt long args_dict with | None | Some [] -> return_false | Some [_] -> return_true - | Some (_ :: _) -> fail (Multiple_occurrences (long, command))) + | Some (_ :: _) -> tzfail (Multiple_occurrences (long, command))) | Constant c -> return c (* Argument parsing *) @@ -808,7 +808,7 @@ let rec parse_args : ctx -> a tzresult Lwt.t = fun ?command spec args_dict ctx -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match spec with | NoArgs -> return_unit | AddArg (arg, rest) -> @@ -844,14 +844,14 @@ type error += Version : error type error += Help : 'a command option -> error let check_help_flag ?command = - let open Lwt_tzresult_syntax in - function ("-h" | "--help") :: _ -> fail (Help command) | _ -> return_unit + let open Lwt_result_syntax in + function ("-h" | "--help") :: _ -> tzfail (Help command) | _ -> return_unit let check_version_flag = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in function (* No "-v", it is taken by man output verbosity *) - | "--version" :: _ -> fail Version + | "--version" :: _ -> tzfail Version | _ -> return_unit let add_occurrence long value acc = @@ -860,7 +860,7 @@ let add_occurrence long value acc = | None -> StringMap.add long [value] acc let make_args_dict_consume ?command spec args = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let rec make_args_dict completing arities acc args = let* () = check_help_flag ?command args in let* () = check_version_flag args in @@ -885,12 +885,12 @@ let make_args_dict_consume ?command spec args = (add_occurrence long value acc) tl' | (1, []) when completing -> return (acc, []) - | (1, []) -> fail (Option_expected_argument (arg, None)) + | (1, []) -> tzfail (Option_expected_argument (arg, None)) | (_, _) -> Stdlib.failwith "cli_entries: Arguments with arity not equal to 1 or 0 \ unsupported") - | None -> fail (Unknown_option (arg, None)) + | None -> tzfail (Unknown_option (arg, None)) else return (acc, args) in make_args_dict @@ -900,7 +900,7 @@ let make_args_dict_consume ?command spec args = args let make_args_dict_filter ?command spec args = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let rec make_args_dict arities (dict, other_args) args = let* () = check_help_flag ?command args in match args with @@ -920,7 +920,7 @@ let make_args_dict_filter ?command spec args = arities (add_occurrence long value dict, other_args) tl' - | (1, []) -> fail (Option_expected_argument (arg, command)) + | (1, []) -> tzfail (Option_expected_argument (arg, command)) | (_, _) -> Stdlib.failwith "cli_entries: Arguments with arity not equal to 1 or 0 \ @@ -1576,7 +1576,7 @@ let exec (type ctx) conv; _; } as command) (ctx : ctx) params args_dict = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let rec exec : type ctx a. int -> ctx -> (a, ctx) params -> a -> string list -> unit tzresult Lwt.t = @@ -1769,7 +1769,7 @@ and gather_assoc ?(acc = []) trees = List.fold_left (fun acc (_, tree) -> gather_commands tree ~acc) acc trees let find_command tree initial_arguments = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let rec traverse tree arguments acc = match (tree, arguments) with | ( ( TStop _ | TSeq _ @@ -1779,8 +1779,8 @@ let find_command tree initial_arguments = ("-h" | "--help") :: _ ) -> ( match gather_commands tree with | [] -> assert false - | [command] -> fail (Help (Some command)) - | more -> fail (Unterminated_command (initial_arguments, more))) + | [command] -> tzfail (Help (Some command)) + | more -> tzfail (Unterminated_command (initial_arguments, more))) | (TStop c, []) -> return (c, empty_args_dict, initial_arguments) | (TStop (Command {options = Argument {spec; _}; _} as command), remaining) -> ( @@ -1791,22 +1791,22 @@ let find_command tree initial_arguments = | [] -> return (command, args_dict, initial_arguments) | hd :: _ -> if String.length hd > 0 && hd.[0] = '-' then - fail (Unknown_option (hd, Some command)) - else fail (Extra_arguments (unparsed, command))) + tzfail (Unknown_option (hd, Some command)) + else tzfail (Extra_arguments (unparsed, command))) | ( TSeq ((Command {options = Argument {spec; _}; _} as command), _), remaining ) -> if List.exists (function "-h" | "--help" -> true | _ -> false) remaining - then fail (Help (Some command)) + then tzfail (Help (Some command)) else let+ (dict, remaining) = make_args_dict_filter ~command spec remaining in (command, dict, List.rev_append acc remaining) | (TNonTerminalSeq {stop = None; _}, ([] | ("-h" | "--help") :: _)) -> - fail (Unterminated_command (initial_arguments, gather_commands tree)) + tzfail (Unterminated_command (initial_arguments, gather_commands tree)) | (TNonTerminalSeq {stop = Some c; _}, []) -> return (c, empty_args_dict, initial_arguments) | ( (TNonTerminalSeq {tree; suffix; _} as nts), @@ -1830,18 +1830,18 @@ let find_command tree initial_arguments = | (TPrefix {stop = Some cmd; _}, []) -> return (cmd, empty_args_dict, initial_arguments) | (TPrefix {stop = None; prefix}, ([] | ("-h" | "--help") :: _)) -> - fail (Unterminated_command (initial_arguments, gather_assoc prefix)) + tzfail (Unterminated_command (initial_arguments, gather_assoc prefix)) | (TPrefix {prefix; _}, hd_arg :: tl) -> ( match List.assoc ~equal:String.equal hd_arg prefix with - | None -> fail (Command_not_found (List.rev acc, gather_assoc prefix)) + | None -> tzfail (Command_not_found (List.rev acc, gather_assoc prefix)) | Some tree' -> traverse tree' tl (hd_arg :: acc)) | (TParam {stop = None; _}, ([] | ("-h" | "--help") :: _)) -> - fail (Unterminated_command (initial_arguments, gather_commands tree)) + tzfail (Unterminated_command (initial_arguments, gather_commands tree)) | (TParam {stop = Some c; _}, []) -> return (c, empty_args_dict, initial_arguments) | (TParam {tree; _}, parameter :: arguments') -> traverse tree arguments' (parameter :: acc) - | (TEmpty, _) -> fail (Command_not_found (List.rev acc, [])) + | (TEmpty, _) -> tzfail (Command_not_found (List.rev acc, [])) in traverse tree initial_arguments [] @@ -1864,7 +1864,7 @@ let rec list_args : type arg ctx. (arg, ctx) args -> string list = function | AddArg (arg, args) -> get_arg arg @ list_args args let complete_func autocomplete cctxt = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match autocomplete with | None -> return_nil | Some autocomplete -> autocomplete cctxt @@ -1875,7 +1875,7 @@ let list_command_args (Command {options = Argument {spec; _}; _}) = let complete_arg : type a ctx. ctx -> (a, ctx) arg -> string list tzresult Lwt.t = fun ctx -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in function | Arg {kind = {autocomplete; _}; _} -> complete_func autocomplete ctx | DefArg {kind = {autocomplete; _}; _} -> complete_func autocomplete ctx @@ -1897,7 +1897,7 @@ let complete_options (type ctx) continuation args args_spec ind (ctx : ctx) = let rec complete_spec : type a. string -> (a, ctx) args -> string list tzresult Lwt.t = fun name -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in function | NoArgs -> return_nil | AddArg (Constant _, rest) -> complete_spec name rest @@ -1974,7 +1974,7 @@ let rec args_starting_from_suffix original_suffix ind matched_args = function let complete_tree cctxt tree index args = let rec help tree args ind = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in if ind = 0 then complete_next_tree cctxt tree else match (tree, args) with @@ -2029,14 +2029,14 @@ let autocompletion ~script ~cur_arg ~prev_arg ~args ~global_options commands completions let parse_global_options global_options ctx args = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let (Argument {spec; converter}) = global_options in let* (dict, remaining) = make_args_dict_consume spec args in let* nested = parse_args spec dict ctx in return (converter nested, remaining) let dispatch commands ctx args = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let tree = make_dispatch_tree commands in match args with | [] @@ -2047,8 +2047,8 @@ let dispatch commands ctx args = | TSeq (_, _) -> false | TNonTerminalSeq {stop; _} -> stop = None | TEmpty -> true -> - fail (Help None) - | [("-h" | "--help")] -> fail (Help None) + tzfail (Help None) + | [("-h" | "--help")] -> tzfail (Help None) | _ -> let* (command, args_dict, filtered_args) = find_command tree args in exec command ctx filtered_args args_dict @@ -2084,7 +2084,7 @@ let add_manual ~executable_name ~global_options format ppf commands = (parameter ~autocomplete:(fun _ -> Lwt.return_ok ["0"; "1"; "2"; "3"]) (fun _ arg -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match arg with | "0" -> return Terse | "1" -> return Short @@ -2104,7 +2104,7 @@ let add_manual ~executable_name ~global_options format ppf commands = ~autocomplete:(fun _ -> Lwt.return_ok ["colors"; "plain"; "html"]) (fun _ arg -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match arg with | "colors" -> return Ansi | "plain" -> return Plain @@ -2133,9 +2133,9 @@ let add_manual ~executable_name ~global_options format ppf commands = | None when Compare.List_length_with.(commands <= 3) -> Full | None -> Short in - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match commands with - | [] -> fail (No_manual_entry keywords) + | [] -> tzfail (No_manual_entry keywords) | _ -> let state = setup_formatter ppf format verbosity in let commands = List.map (fun c -> Ex c) commands in diff --git a/src/lib_clic/examples/clic_example.ml b/src/lib_clic/examples/clic_example.ml index 0ff3284caa883008cb8928c91543e36821368c36..1656da669aa48bc2c31946727637632d92054422 100644 --- a/src/lib_clic/examples/clic_example.ml +++ b/src/lib_clic/examples/clic_example.ml @@ -29,7 +29,7 @@ module List_known_contracts = struct fun () ctxt -> let module C = (val ctxt) in C.list_known_contracts () ; - Lwt_tzresult_syntax.return_unit + Lwt_result_syntax.return_unit let command = Clic.command diff --git a/src/lib_clic/test/test_clic.ml b/src/lib_clic/test/test_clic.ml index 859db2a67fc70332df7654a636fb54bdb109caba..6b660cec73484d7a438ffcd7b4cbf1c8d66890cb 100644 --- a/src/lib_clic/test/test_clic.ml +++ b/src/lib_clic/test/test_clic.ml @@ -37,7 +37,7 @@ open Tezos_error_monad.Error_monad (* definitions *) let keywords words = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let words = List.map (fun (w, v) -> (String.lowercase_ascii w, v)) words in let matcher _ w = let w = String.lowercase_ascii w in @@ -330,7 +330,7 @@ let int_param ~autocomplete next = next) let test_autocompletion_case ~commands ~args ~expected () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let script = "script" in let (prev_arg, cur_arg) = match List.rev args with @@ -363,7 +363,7 @@ let test_autocompletion_case ~commands ~args ~expected () = and [non_terminal_seq]. *) let test_parameters_autocompletion = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let param_commands = Clic. [ diff --git a/src/lib_clic/unix/scriptable.ml b/src/lib_clic/unix/scriptable.ml index 53fb183a6fe868e73d5567de0bfbfb2f07b9174f..3ff58943443776d0cc15551ba6be87aa98545c0a 100644 --- a/src/lib_clic/unix/scriptable.ml +++ b/src/lib_clic/unix/scriptable.ml @@ -15,7 +15,7 @@ let clic_arg () = ~long:"for-script" ~placeholder:"FORMAT" (parameter (fun _ spec -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match String.lowercase_ascii spec with | "tsv" -> return tsv | "csv" -> return csv diff --git a/src/lib_client_base/client_aliases.ml b/src/lib_client_base/client_aliases.ml index 17780fc2ea94477b951029f9c1d9ee46500d9222..ace1955a564e9234a69ac6fbb787d61dfac9dcf7 100644 --- a/src/lib_client_base/client_aliases.ml +++ b/src/lib_client_base/client_aliases.ml @@ -177,7 +177,7 @@ module Alias (Entity : Entity) = struct {cache.mtime = mt}; otherwise, {cache.mtime} is generated by [wallet#last_modification_time]. *) let replace_cache (wallet : #wallet) ?mtime list_assoc = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* mtime = match mtime with | None -> wallet#last_modification_time Entity.name @@ -193,7 +193,7 @@ module Alias (Entity : Entity) = struct file does not exist or if its last modification time changed; then returns it. *) let get_cache (wallet : #wallet) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* mtime = wallet#last_modification_time Entity.name in let cache = peek_cache wallet in match (mtime, Option.bind cache (fun c -> c.mtime)) with @@ -215,7 +215,7 @@ module Alias (Entity : Entity) = struct {Some v}, then the bindings of [key] are replaced by one binding of [key] to {v} in the resulting cache. *) let update_cache (wallet : #wallet) cache key value = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (match value with | Some value -> cache.list_assoc <- update_assoc key (Some value) cache.list_assoc ; @@ -229,17 +229,17 @@ module Alias (Entity : Entity) = struct return_unit let load (wallet : #wallet) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* cache = get_cache wallet in return cache.list_assoc let load_map (wallet : #wallet) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* cache = get_cache wallet in return cache.map let set (wallet : #wallet) entries = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = wallet#write Entity.name entries wallet_encoding in let* _cache = replace_cache wallet entries in return_unit @@ -252,24 +252,24 @@ module Alias (Entity : Entity) = struct | Ok list -> return_ok (List.map fst list) let find_opt (wallet : #wallet) name = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let+ map = load_map wallet in Map.find name map let find (wallet : #wallet) name = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* map = load_map wallet in match Map.find name map with | Some v -> return v | None -> failwith "no %s alias named %s" Entity.name name let rev_find (wallet : #wallet) v = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let+ list = load wallet in Option.map fst @@ List.find (fun (_, v') -> Entity.(v = v')) list let rev_find_all (wallet : #wallet) v = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* list = load wallet in return (List.filter_map @@ -277,12 +277,12 @@ module Alias (Entity : Entity) = struct list) let mem (wallet : #wallet) name = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let+ map = load_map wallet in Map.mem name map let add ~force (wallet : #wallet) name value = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let keep = ref false in let* cache = get_cache wallet in let* () = @@ -310,7 +310,7 @@ module Alias (Entity : Entity) = struct if !keep then return_unit else update_cache wallet cache name (Some value) let add_many (wallet : #wallet) xs = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* cache = get_cache wallet in let map_to_add = Map.of_seq (List.to_seq xs) in cache.map <- Map.union (fun _key x _existing -> Some x) map_to_add cache.map ; @@ -321,19 +321,19 @@ module Alias (Entity : Entity) = struct return_unit let del (wallet : #wallet) name = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* cache = get_cache wallet in update_cache wallet cache name None let update (wallet : #wallet) name value = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* cache = get_cache wallet in update_cache wallet cache name (Some value) include Entity let alias_parameter () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in parameter ~autocomplete (fun cctxt s -> let* v = find cctxt s in return (s, v)) @@ -343,7 +343,7 @@ module Alias (Entity : Entity) = struct param ~name ~desc (alias_parameter ()) next let aliases_parameter () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in parameter ~autocomplete (fun cctxt s -> String.split_no_empty ',' s |> List.map_es (fun s -> @@ -357,7 +357,7 @@ module Alias (Entity : Entity) = struct type fresh_param = Fresh of string let of_fresh (wallet : #wallet) force (Fresh s) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* list = load wallet in let* () = if force then return_unit diff --git a/src/lib_client_base/client_confirmations.ml b/src/lib_client_base/client_confirmations.ml index 451ef7f3abf70513bfe7b243215e9f244832a2f1..a4bbb04fa93715bb658ab3aec8e7ab265ec7a969 100644 --- a/src/lib_client_base/client_confirmations.ml +++ b/src/lib_client_base/client_confirmations.ml @@ -43,7 +43,7 @@ type operation_status = let wait_for_operation_inclusion (ctxt : #Client_context.full) ~chain ?(predecessors = 10) ?(confirmations = 1) ?branch operation_hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let exception WrapError of error list in let exception Outdated of Operation_hash.t in (* Table of known blocks: @@ -243,7 +243,7 @@ let wait_for_operation_inclusion (ctxt : #Client_context.full) ~chain loop block_hook let lookup_operation_in_previous_block ctxt chain operation_hash i = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* block = Block_services.Empty.hash ctxt ~block:(`Head i) () in let* operations = Shell_services.Blocks.Operation_hashes.operation_hashes diff --git a/src/lib_client_base/client_keys.ml b/src/lib_client_base/client_keys.ml index cda3e35cd340a569f37a8158aa6b2119aca51658..4a06c2b5911a5ee0cd263e1e73722cf056c32a92 100644 --- a/src/lib_client_base/client_keys.ml +++ b/src/lib_client_base/client_keys.ml @@ -119,10 +119,10 @@ module Pk_uri_hashtbl = Hashtbl.Make (struct end) let make_pk_uri (x : Uri.t) : pk_uri tzresult = - let open Tzresult_syntax in + let open Result_syntax in match Uri.scheme x with | None -> - fail (Exn (Failure "Error while parsing URI: PK_URI needs a scheme")) + tzfail (Exn (Failure "Error while parsing URI: PK_URI needs a scheme")) | Some _ -> return x type sk_uri = Uri.t @@ -134,27 +134,27 @@ module CompareUri = Compare.Make (struct end) let make_sk_uri (x : Uri.t) : sk_uri tzresult = - let open Tzresult_syntax in + let open Result_syntax in match Uri.scheme x with | None -> - fail (Exn (Failure "Error while parsing URI: SK_URI needs a scheme")) + tzfail (Exn (Failure "Error while parsing URI: SK_URI needs a scheme")) | Some _ -> return x type sapling_uri = Uri.t let make_sapling_uri (x : Uri.t) : sapling_uri tzresult = - let open Tzresult_syntax in + let open Result_syntax in match Uri.scheme x with - | None -> fail (Exn (Failure "SAPLING_URI needs a scheme")) + | None -> tzfail (Exn (Failure "SAPLING_URI needs a scheme")) | Some _ -> return x type pvss_sk_uri = Uri.t let make_pvss_sk_uri (x : Uri.t) : pvss_sk_uri tzresult = - let open Tzresult_syntax in + let open Result_syntax in match Uri.scheme x with | None -> - fail (Exn (Failure "Error while parsing URI: PVSS_URI needs a scheme")) + tzfail (Exn (Failure "Error while parsing URI: PVSS_URI needs a scheme")) | Some _ -> return x type aggregate_pk_uri = Uri.t @@ -162,10 +162,10 @@ type aggregate_pk_uri = Uri.t type aggregate_sk_uri = Uri.t let make_aggregate_pk_uri (x : Uri.t) : aggregate_pk_uri tzresult = - let open Tzresult_syntax in + let open Result_syntax in match Uri.scheme x with | None -> - fail + tzfail (Exn (Failure "Error while parsing URI: AGGREGATE_PK_URI needs a scheme")) (* because it's possible to make an aggregate pk uri without having the signer @@ -173,10 +173,10 @@ let make_aggregate_pk_uri (x : Uri.t) : aggregate_pk_uri tzresult = | Some _ -> return x let make_aggregate_sk_uri (x : Uri.t) : aggregate_sk_uri tzresult = - let open Tzresult_syntax in + let open Result_syntax in match Uri.scheme x with | None -> - fail + tzfail (Exn (Failure "Error while parsing URI: AGGREGATE_SK_URI needs a scheme")) | Some _ -> return x @@ -319,7 +319,7 @@ module Sapling_key = Client_aliases.Alias (struct (req "address_index" S.Viewing_key.index_encoding)) let of_source s = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Data_encoding in match Json.from_string s with | Error _ -> failwith "corrupted wallet" @@ -362,7 +362,7 @@ module Aggregate_alias = struct let of_source s = Lwt.return (of_b58check s) - let to_source p = Lwt_tzresult_syntax.return (to_b58check p) + let to_source p = Lwt_result_syntax.return (to_b58check p) let name = "Aggregate_public_key_hash" end) @@ -371,10 +371,10 @@ module Aggregate_alias = struct type pk_uri = Uri.t let make_pk_uri (x : Uri.t) : pk_uri tzresult = - let open Tzresult_syntax in + let open Result_syntax in match Uri.scheme x with | None -> - fail + tzfail (Exn (Failure "Error while parsing URI: AGGREGATE_PK_URI needs a scheme")) | Some _ -> return x @@ -397,7 +397,7 @@ module Aggregate_alias = struct let*? pk_uri = make_pk_uri @@ Uri.of_string s in return (pk_uri, None) - let to_source (t, _) = Lwt_tzresult_syntax.return (Uri.to_string t) + let to_source (t, _) = Lwt_result_syntax.return (Uri.to_string t) let encoding = let open Data_encoding in @@ -423,7 +423,7 @@ module Aggregate_alias = struct type sk_uri = Uri.t let make_sk_uri (x : Uri.t) : sk_uri tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Uri.scheme x with | None -> failwith "Error while parsing URI: AGGREGATE_SK_URI needs a scheme" @@ -440,7 +440,7 @@ module Aggregate_alias = struct let of_source s = make_sk_uri @@ Uri.of_string s - let to_source t = Lwt_tzresult_syntax.return (Uri.to_string t) + let to_source t = Lwt_result_syntax.return (Uri.to_string t) end) end @@ -558,23 +558,23 @@ let register_aggregate_signer signer = String.Hashtbl.replace signers_table Signer.scheme (Aggregate signer) let find_signer_for_key ~scheme : signer tzresult = - let open Tzresult_syntax in + let open Result_syntax in match String.Hashtbl.find signers_table scheme with - | None -> fail (Unregistered_key_scheme scheme) + | None -> tzfail (Unregistered_key_scheme scheme) | Some signer -> return signer let find_simple_signer_for_key ~scheme = - let open Tzresult_syntax in + let open Result_syntax in let* signer = find_signer_for_key ~scheme in match signer with | Simple signer -> return signer - | Aggregate _signer -> fail (Wrong_key_scheme ("simple", "aggregate")) + | Aggregate _signer -> tzfail (Wrong_key_scheme ("simple", "aggregate")) let find_aggregate_signer_for_key ~scheme = - let open Tzresult_syntax in + let open Result_syntax in let* signer = find_signer_for_key ~scheme in match signer with - | Simple _signer -> fail (Wrong_key_scheme ("aggregate", "standard")) + | Simple _signer -> tzfail (Wrong_key_scheme ("aggregate", "standard")) | Aggregate signer -> return signer let registered_signers () : (string * signer) list = @@ -600,27 +600,27 @@ let () = let with_scheme_signer (uri : Uri.t) (f : signer -> 'a tzresult Lwt.t) : 'a tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Uri.scheme uri with - | None -> fail @@ Unexisting_scheme uri + | None -> tzfail @@ Unexisting_scheme uri | Some scheme -> let*? signer = find_signer_for_key ~scheme in f signer let with_scheme_simple_signer (uri : Uri.t) (f : (module SIGNER) -> 'a tzresult Lwt.t) : 'a tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Uri.scheme uri with - | None -> fail @@ Unexisting_scheme uri + | None -> tzfail @@ Unexisting_scheme uri | Some scheme -> let*? signer = find_simple_signer_for_key ~scheme in f signer let with_scheme_aggregate_signer (uri : Uri.t) (f : (module AGGREGATE_SIGNER) -> 'a tzresult Lwt.t) : 'a tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Uri.scheme uri with - | None -> fail @@ Unexisting_scheme uri + | None -> tzfail @@ Unexisting_scheme uri | Some scheme -> let*? signer = find_aggregate_signer_for_key ~scheme in f signer @@ -642,7 +642,7 @@ let import_secret_key ~io pk_uri = Signer.import_secret_key ~io pk_uri) let sign cctxt ?watermark sk_uri buf = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in with_scheme_simple_signer sk_uri (fun (module Signer : SIGNER) -> let* signature = Signer.sign ?watermark sk_uri buf in let* pk_uri = Signer.neuterize sk_uri in @@ -685,7 +685,7 @@ let deterministic_nonce_hash sk_uri data = Signer.deterministic_nonce_hash sk_uri data) let supports_deterministic_nonces sk_uri = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in with_scheme_signer sk_uri (function | Simple (module Signer : SIGNER) -> Signer.supports_deterministic_nonces sk_uri @@ -734,7 +734,7 @@ let join_keys keys1_opt keys2 = [pks], [sks] represent the already loaded list of public key hashes, public keys, and secret keys. *) let raw_get_key_aux (cctxt : #Client_context.wallet) pkhs pks sks pkh = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let rev_find_all list pkh = List.filter_map (fun (name, pkh') -> @@ -792,7 +792,7 @@ let raw_get_key (cctxt : #Client_context.wallet) pkh = raw_get_key_aux cctxt pkhs pks sks pkh let get_key cctxt pkh = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* r = raw_get_key cctxt pkh in match r with | (pkh, Some pk, Some sk) -> return (pkh, pk, sk) @@ -802,7 +802,7 @@ let get_key cctxt pkh = failwith "Unknown public key for %a" Signature.Public_key_hash.pp pkh let get_public_key cctxt pkh = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* r = raw_get_key cctxt pkh in match r with | (pkh, Some pk, _sk) -> return (pkh, pk) @@ -810,7 +810,7 @@ let get_public_key cctxt pkh = failwith "Unknown public key for %a" Signature.Public_key_hash.pp pkh let get_keys (cctxt : #Client_context.wallet) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* sks = Secret_key.load cctxt in let* pkhs = Public_key_hash.load cctxt in let* pks = Public_key.load cctxt in @@ -884,7 +884,7 @@ let aggregate_public_key pk_uri = hashes, public keys, and secret keys. *) let raw_get_aggregate_key_aux (cctxt : #Client_context.wallet) pkhs pks sks pkh = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let rev_find_all list pkh = List.filter_map (fun (name, pkh') -> diff --git a/src/lib_client_base_unix/client_config.ml b/src/lib_client_base_unix/client_config.ml index feb32c0d267a095f28adb3c6d194a34f527cd20b..ec054f86850fedc5f6b8f1090e13b3ad361c20e5 100644 --- a/src/lib_client_base_unix/client_config.ml +++ b/src/lib_client_base_unix/client_config.ml @@ -330,33 +330,33 @@ let string_parameter () : (string, #Client_context.full) parameter = let media_type_parameter () : (Media_type.Command_line.t, #Client_context.full) parameter = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in parameter (fun _ x -> match Media_type.Command_line.parse_cli_parameter x with | Some v -> return v - | None -> fail (Invalid_media_type_arg x)) + | None -> tzfail (Invalid_media_type_arg x)) let endpoint_parameter () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in parameter (fun _ x -> let parsed = Uri.of_string x in let* _ = match Uri.scheme parsed with | Some "http" | Some "https" -> return () | _ -> - fail + tzfail (Invalid_endpoint_arg ("only http and https endpoints are supported: " ^ x)) in match (Uri.query parsed, Uri.fragment parsed) with | ([], None) -> return parsed | _ -> - fail + tzfail (Invalid_endpoint_arg ("endpoint uri should not have query string or fragment: " ^ x))) let sources_parameter () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in parameter (fun _ path -> let*! r = Lwt_utils_unix.Json.read_file path in match r with @@ -380,31 +380,31 @@ let sources_parameter () = let chain_parameter () = parameter (fun _ chain -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Chain_services.parse_chain chain with - | Error _ -> fail (Invalid_chain_argument chain) + | Error _ -> tzfail (Invalid_chain_argument chain) | Ok chain -> return chain) let block_parameter () = parameter (fun _ block -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Block_services.parse_block block with - | Error _ -> fail (Invalid_block_argument block) + | Error _ -> tzfail (Invalid_block_argument block) | Ok block -> return block) let wait_parameter () = parameter (fun _ wait -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match wait with | "no" | "none" -> return_none | _ -> ( match int_of_string_opt wait with | Some w when 0 <= w -> return_some w - | None | Some _ -> fail (Invalid_wait_arg wait))) + | None | Some _ -> tzfail (Invalid_wait_arg wait))) let protocol_parameter () = parameter (fun _ arg -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Seq.filter (fun (hash, _commands) -> @@ -413,7 +413,7 @@ let protocol_parameter () = @@ () with | Cons ((hash, _commands), _) -> return_some hash - | Nil -> fail (Invalid_protocol_argument arg)) + | Nil -> tzfail (Invalid_protocol_argument arg)) (* Command-line only args (not in config file) *) let base_dir_arg () = @@ -520,10 +520,10 @@ let port_arg () = ~placeholder:"number" ~doc:"[DEPRECATED: use --endpoint instead] RPC port of the node" (parameter (fun _ x -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match int_of_string_opt x with | Some i -> return i - | None -> fail (Invalid_port_arg x))) + | None -> tzfail (Invalid_port_arg x))) let tls_confdesc = "-S/--tls ('tls' in config file)" @@ -590,7 +590,7 @@ let password_filename_arg () = let client_mode_arg () = let mode_strings = List.map client_mode_to_string all_modes in let parse_client_mode (str : string) : client_mode tzresult = - let open Tzresult_syntax in + let open Result_syntax in let* modes_and_strings = List.combine ~when_different_lengths:(TzTrace.make @@ Exn (Failure __LOC__)) @@ -598,7 +598,7 @@ let client_mode_arg () = all_modes in match List.assoc_opt ~equal:String.equal str modes_and_strings with - | None -> fail (Invalid_mode_arg str) + | None -> tzfail (Invalid_mode_arg str) | Some mode -> return mode in default_arg @@ -612,7 +612,7 @@ let client_mode_arg () = (fun _ param -> Lwt.return (parse_client_mode param))) let read_config_file config_file = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! r = Lwt_utils_unix.Json.read_file config_file in match r with | Error errs -> @@ -631,7 +631,7 @@ let read_config_file config_file = exn) let fail_on_non_mockup_dir (cctxt : #Client_context.full) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let base_dir = cctxt#get_base_dir in let open Tezos_mockup.Persistence in let* b = classify_base_dir base_dir in @@ -676,7 +676,7 @@ let config_show_client (cctxt : #Client_context.full) (config_file : string) cfg (* The implementation of ["config"; "show"] when --mode is "mockup" *) let config_show_mockup (cctxt : #Client_context.full) (protocol_hash_opt : Protocol_hash.t option) (base_dir : string) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = fail_on_non_mockup_dir cctxt in let* (mockup, _) = Tezos_mockup.Persistence.get_mockup_context_from_disk @@ -714,7 +714,7 @@ let config_init_client config_file cfg = (* The implementation of ["config"; "init"] when --mode is "mockup" *) let config_init_mockup cctxt protocol_hash_opt bootstrap_accounts_file protocol_constants_file base_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = fail_on_non_mockup_dir cctxt in let* () = fail_when @@ -900,7 +900,7 @@ let default_parsed_config_args = * fail). *) let check_base_dir_for_mode (ctx : #Client_context.full) client_mode base_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Tezos_mockup.Persistence in let* base_dir_class = classify_base_dir base_dir in match client_mode with @@ -987,7 +987,7 @@ let build_endpoint addr port tls = |> updatecomp Uri.with_scheme scheme let light_mode_checks mode endpoint sources = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match (mode, sources) with | (`Mode_client, None) | (`Mode_mockup, None) | (`Mode_proxy, None) -> (* No --mode light, no --sources; good *) @@ -1025,7 +1025,7 @@ let light_mode_checks mode endpoint sources = (List.hd sources_uris) let parse_config_args (ctx : #Client_context.full) argv = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* ( ( base_dir, config_file, timings, @@ -1119,7 +1119,7 @@ let parse_config_args (ctx : #Client_context.full) argv = |> checkabs tls_confdesc tls in if superr <> [] then - fail (Suppressed_arg {args = superr; by = endpoint_confdesc}) + tzfail (Suppressed_arg {args = superr; by = endpoint_confdesc}) else return () in let tls = if tls then Some true else None in diff --git a/src/lib_client_base_unix/client_context_unix.ml b/src/lib_client_base_unix/client_context_unix.ml index 0a1edb5ee5e5858ae7ea9268a511d88959c52995..9ce5f4b3f03c21b45949d03417e380587374fc02 100644 --- a/src/lib_client_base_unix/client_context_unix.ml +++ b/src/lib_client_base_unix/client_context_unix.ml @@ -104,7 +104,7 @@ class unix_wallet ~base_dir ~password_filename : Client_context.wallet = method write : type a. string -> a -> a Data_encoding.encoding -> unit tzresult Lwt.t = fun alias_name list encoding -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in trace_eval (fun () -> error_of_fmt "could not write the %s alias file." alias_name) @@ Error_monad.catch_es (fun () -> @@ -117,7 +117,7 @@ class unix_wallet ~base_dir ~password_filename : Client_context.wallet = return_unit) method last_modification_time : string -> float option tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in fun alias_name -> let filename = self#filename alias_name in let*! exists = Lwt_unix.file_exists filename in diff --git a/src/lib_client_base_unix/client_main_run.ml b/src/lib_client_base_unix/client_main_run.ml index b18bfb7f3c71097c473451cd2d2660d51017ff2f..137a5ae0a91653612efc449937a8738729989906 100644 --- a/src/lib_client_base_unix/client_main_run.ml +++ b/src/lib_client_base_unix/client_main_run.ml @@ -82,7 +82,7 @@ let setup_remote_signer (module C : M) client_config (rpc_config : RPC_client_unix.config) parsed_config_file = let module Remote_params = struct let authenticate pkhs payload = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* keys = Client_keys.list_keys client_config in match List.filter_map @@ -161,7 +161,7 @@ let warn_if_duplicates_light_sources (printer : unix_logger) uris = else Lwt.return_unit let setup_default_proxy_client_config parsed_args base_dir rpc_config mode = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Make sure that base_dir is not a mockup. *) let* () = let* b = Tezos_mockup.Persistence.classify_base_dir base_dir in @@ -315,7 +315,7 @@ let setup_client_config (cctxt : Tezos_client_base.Client_context.printer) (* Main (lwt) entry *) let main (module C : M) ~select_commands = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let global_options = C.global_options () in let executable_name = Filename.basename Sys.executable_name in let (original_args, autocomplete) = diff --git a/src/lib_client_base_unix/test/test_mockup_wallet.ml b/src/lib_client_base_unix/test/test_mockup_wallet.ml index fdbd8cce56cebc35df55eae9ae487529562ad0d9..c156eef2ee463b612c6f857c6e9e00f8f9196b9a 100644 --- a/src/lib_client_base_unix/test/test_mockup_wallet.ml +++ b/src/lib_client_base_unix/test/test_mockup_wallet.ml @@ -61,7 +61,7 @@ let testable_string_list_ignoring_order : string list Alcotest.testable = (** Validate SK and PK consistency *) let validate_key (_, pk_hash, pk_sig_opt, sk_uri_opt) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match (pk_sig_opt, sk_uri_opt) with | (Some pk_sig, Some sk_uri) -> ( let* (pk_hash_from_sk, pk_sig_from_sk_opt) = @@ -126,7 +126,7 @@ let test_with_valid_bootstrap_accounts_file_populates = `Quick (fun () -> Lwt_utils_unix.with_tempdir "test_mockup_wallet" (fun base_dir -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let io_wallet = new Client_context_unix.unix_io_wallet ~base_dir diff --git a/src/lib_client_commands/client_admin_commands.ml b/src/lib_client_commands/client_admin_commands.ml index b2cacc41b049658ecb149361fb5e4339ac37c1cd..7c69dd897d00e19376c40c04555fe01e3646a9e8 100644 --- a/src/lib_client_commands/client_admin_commands.ml +++ b/src/lib_client_commands/client_admin_commands.ml @@ -39,7 +39,7 @@ let operation_param ~name ~desc t = t let commands () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Clic in let group = { diff --git a/src/lib_client_commands/client_event_logging_commands.ml b/src/lib_client_commands/client_event_logging_commands.ml index cfd80083bd0f5829b314504628fe81d9ca12568a..b1f22268113c22009d0e8b62c718230444022950 100644 --- a/src/lib_client_commands/client_event_logging_commands.ml +++ b/src/lib_client_commands/client_event_logging_commands.ml @@ -32,7 +32,7 @@ let group = let date_parameter option_name build = let open Clic in - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in parameter (fun _ s -> let problem fmt = Printf.ksprintf invalid_arg fmt in try @@ -79,7 +79,7 @@ let flat_pp pp o = ()) let commands () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Clic in let command ~desc = command ~group ~desc in [ diff --git a/src/lib_client_commands/client_helpers_commands.ml b/src/lib_client_commands/client_helpers_commands.ml index a9d4dd2081917ca0baf51eb70c8ec1bd9eeecff0..fd24b620f8d2fa672644f787887a030643bc4f9c 100644 --- a/src/lib_client_commands/client_helpers_commands.ml +++ b/src/lib_client_commands/client_helpers_commands.ml @@ -31,7 +31,7 @@ let unique_switch = () let commands () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Clic in [ command diff --git a/src/lib_client_commands/client_keys_commands.ml b/src/lib_client_commands/client_keys_commands.ml index 62fb1f5e22e7d7ddbe7a61f151c7089656631845..093e685e75f67f4e569b149f5b2aeb8f87e37aa0 100644 --- a/src/lib_client_commands/client_keys_commands.ml +++ b/src/lib_client_commands/client_keys_commands.ml @@ -32,7 +32,7 @@ let group = } let algo_param () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Clic.parameter ~autocomplete:(fun _ -> return ["ed25519"; "secp256k1"; "p256"]) (fun _ name -> @@ -57,7 +57,7 @@ let sig_algo_arg = let gen_keys_containing ?(encrypted = false) ?(prefix = false) ?(force = false) ~containing ~name (cctxt : #Client_context.io_wallet) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let unrepresentable = List.filter (fun s -> @@ -178,7 +178,7 @@ let gen_keys_containing ?(encrypted = false) ?(prefix = false) ?(force = false) return_unit) let rec input_fundraiser_params (cctxt : #Client_context.io_wallet) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let rec get_boolean_answer (cctxt : #Client_context.io_wallet) ~default ~msg = let prompt = if default then "(Y/n/q)" else "(y/N/q)" in let* gen = cctxt#prompt "%s %s: " msg prompt in @@ -225,7 +225,7 @@ let rec input_fundraiser_params (cctxt : #Client_context.io_wallet) = match b with true -> return sk | false -> input_fundraiser_params cctxt) let fail_if_already_registered cctxt force pk_uri name = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* o = Public_key.find_opt cctxt name in match o with | None -> return_unit @@ -243,7 +243,7 @@ let keys_count_param = ~name:"keys_count" ~desc:"How many keys to generate" (parameter (fun _ s -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match int_of_string_opt s with | None -> failwith "number of keys must be an integer" | Some x -> @@ -309,7 +309,7 @@ let generate_test_keys = return_unit) let aggregate_fail_if_already_registered cctxt force pk_uri name = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* pk_opt = Aggregate_alias.Public_key.find_opt cctxt name in match pk_opt with | None -> return_unit @@ -322,7 +322,7 @@ let aggregate_fail_if_already_registered cctxt force pk_uri name = name) let commands network : Client_context.full Clic.command list = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Clic in let encrypted_switch () = if diff --git a/src/lib_client_commands/client_p2p_commands.ml b/src/lib_client_commands/client_p2p_commands.ml index 3caf09d967f02f2d79f129485ebede8252225d63..c67a28b846dcd850484a52536aedb05bee129086 100644 --- a/src/lib_client_commands/client_p2p_commands.ml +++ b/src/lib_client_commands/client_p2p_commands.ml @@ -48,7 +48,7 @@ let p2p_peer_id_param ~name ~desc t = t let commands () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Clic in [ command diff --git a/src/lib_client_commands/client_report_commands.ml b/src/lib_client_commands/client_report_commands.ml index 15291022f0391f6f4dcb20c5e1dd0fa43e282b6d..6a4816cb343fc39d6fdd41eedc0ec5dd47b7939c 100644 --- a/src/lib_client_commands/client_report_commands.ml +++ b/src/lib_client_commands/client_report_commands.ml @@ -36,7 +36,7 @@ let print_invalid_blocks ppf (b : Shell_services.Chain.invalid_block) = b.errors let commands () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Clic in let group = {name = "report"; title = "Commands to report the node's status"} diff --git a/src/lib_context/context.ml b/src/lib_context/context.ml index 03c3c4f7539d5dc361bc4b9b15d7b98263379d57..34bf4528bc51db5503c8ee613d05f8e8dcfee18f 100644 --- a/src/lib_context/context.ml +++ b/src/lib_context/context.ml @@ -311,9 +311,10 @@ module Make (Encoding : module type of Tezos_context_encoding.Context) = struct let get_hash_version _c = Context_hash.Version.of_int 0 let set_hash_version c v = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in if Context_hash.Version.(of_int 0 = v) then return c - else fail (Tezos_context_helpers.Context.Unsupported_context_hash_version v) + else + tzfail (Tezos_context_helpers.Context.Unsupported_context_hash_version v) let raw_commit ~time ?(message = "") context = let open Lwt_syntax in @@ -982,7 +983,7 @@ module Make (Encoding : module type of Tezos_context_encoding.Context) = struct Store.Tree.of_contents bytes let add_dir batch l = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let add sub_tree (step, hash) = match sub_tree with | None -> Lwt.return_some (Store.Tree.empty ()) diff --git a/src/lib_context/context_dump.ml b/src/lib_context/context_dump.ml index cb08726e4ac2ea6e8787a385ceb1824be00050b6..ebf006a6a43f008c74ee7b33ec624d954d21a58d 100644 --- a/src/lib_context/context_dump.ml +++ b/src/lib_context/context_dump.ml @@ -95,7 +95,7 @@ let () = (* IO toolkit. *) let rec read_string rbuf ~len = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let (fd, buf, ofs, total) = !rbuf in if Bytes.length buf - ofs < len then ( let blen = Bytes.length buf - ofs in @@ -103,7 +103,7 @@ let rec read_string rbuf ~len = Bytes.blit buf ofs neu 0 blen ; let*! bread = Lwt_unix.read fd neu blen 1_000_000 in total := !total + bread ; - if bread = 0 then fail Inconsistent_context_dump + if bread = 0 then tzfail Inconsistent_context_dump else let neu = if bread <> 1_000_000 then Bytes.sub neu 0 (blen + bread) else neu @@ -172,7 +172,7 @@ module Make_legacy (I : Dump_interface) = struct let length = Int32.to_int l in let (fd, buf, ofs, total) = !rbuf in rbuf := (fd, buf, ofs - 4, total) ; - Lwt.return_ok (length + 4) + return (length + 4) let read_variable_length_string rbuf = let open Lwt_result_syntax in @@ -193,13 +193,13 @@ module Make_legacy (I : Dump_interface) = struct let read_seq rbuf total = let open Lwt_result_syntax in let step i = - if i >= total then Lwt.return_ok None + if i >= total then return_none else let* (length_name, name) = read_variable_length_string rbuf in - let+ (length_hash, hash) = read_fixed_length_hash rbuf in + let* (length_hash, hash) = read_fixed_length_hash rbuf in let node = (name, hash) in let i = i + length_name + length_hash in - Some (node, i) + return_some (node, i) in Seq_es.unfold_es step 0 @@ -210,7 +210,7 @@ module Make_legacy (I : Dump_interface) = struct (req "parents" (list I.Commit_hash.encoding)) let get_command rbuf = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* t = get_int64 rbuf in let total = Int64.to_int t in let* t = get_char rbuf in @@ -246,13 +246,13 @@ module Make_legacy (I : Dump_interface) = struct let* s = get_int4 rbuf in let list_size = Int32.to_int s in let data = read_seq rbuf list_size in - Lwt.return_ok (Node_seq data) - | _ -> fail Restore_context_failure + return (Node_seq data) + | _ -> tzfail Restore_context_failure (* Restoring *) let restore_context_fd index ~expected_context_hash ~fd ~nb_context_elements = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let read = ref 0 in let rbuf = ref (fd, Bytes.empty, 0, read) in (* Editing the repository *) @@ -263,13 +263,15 @@ module Make_legacy (I : Dump_interface) = struct let add_dir t keys = let* r = I.add_dir t keys in match r with - | None -> fail Restore_context_failure + | None -> tzfail Restore_context_failure | Some tree -> return tree in let restore () = let first_pass () = let* r = get_command rbuf in - match r with Root -> return_unit | _ -> fail Inconsistent_context_dump + match r with + | Root -> return_unit + | _ -> tzfail Inconsistent_context_dump in let rec second_pass batch ctxt context_hash notify = let*! () = notify () in @@ -284,13 +286,15 @@ module Make_legacy (I : Dump_interface) = struct | Eoc {info; parents} -> ( let*! b = I.set_context ~info ~parents ctxt context_hash in match b with - | false -> fail Inconsistent_context_dump + | false -> tzfail Inconsistent_context_dump | true -> return_unit) - | _ -> fail Inconsistent_context_dump + | _ -> tzfail Inconsistent_context_dump in let check_eof () = let* e = get_command rbuf in - match e with Eof -> return_unit | _ -> fail Inconsistent_context_dump + match e with + | Eof -> return_unit + | _ -> tzfail Inconsistent_context_dump in let* block_data = first_pass () in let* () = @@ -321,7 +325,7 @@ module Make_legacy (I : Dump_interface) = struct (fun () -> restore ()) (function | Unix.Unix_error (e, _, _) -> - fail @@ System_read_error (Unix.error_message e) + tzfail @@ System_read_error (Unix.error_message e) | err -> Lwt.fail err) end @@ -440,7 +444,7 @@ module Make (I : Dump_interface) = struct tree let dump_context_fd idx context_hash ~context_fd ~on_disk = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Dumping *) let buf = Buffer.create 1_000_000 in let written = ref 0 in @@ -450,7 +454,7 @@ module Make (I : Dump_interface) = struct match o with | None -> (* FIXME: dirty *) - fail @@ Context_not_found (I.Commit_hash.to_bytes context_hash) + tzfail @@ Context_not_found (I.Commit_hash.to_bytes context_hash) | Some ctxt -> Animation.display_progress ~every:1000 @@ -484,14 +488,14 @@ module Make (I : Dump_interface) = struct return elements)) (function | Unix.Unix_error (e, _, _) -> - fail @@ System_write_error (Unix.error_message e) + tzfail @@ System_write_error (Unix.error_message e) | err -> Lwt.fail err) (* Restoring *) let restore_context_fd index ~expected_context_hash ~fd ~nb_context_elements ~in_memory = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let read = ref 0 in let rbuf = ref (fd, Bytes.empty, 0, read) in (* Editing the repository *) @@ -500,13 +504,15 @@ module Make (I : Dump_interface) = struct let add_inode i = let*! tree = save_inode i in match tree with - | None -> fail Restore_context_failure + | None -> tzfail Restore_context_failure | Some tree -> return tree in let restore () = let first_pass () = let* r = get_command rbuf in - match r with Root -> return_unit | _ -> fail Inconsistent_context_dump + match r with + | Root -> return_unit + | _ -> tzfail Inconsistent_context_dump in let rec second_pass batch ctxt context_hash notify = let*! () = notify () in @@ -521,9 +527,9 @@ module Make (I : Dump_interface) = struct | Eoc {info; parents} -> ( let*! b = I.set_context ~info ~parents ctxt context_hash in match b with - | false -> fail Inconsistent_context_dump + | false -> tzfail Inconsistent_context_dump | true -> return_unit) - | _ -> fail Inconsistent_context_dump + | _ -> tzfail Inconsistent_context_dump in let check_eof () = let* e = get_command rbuf in @@ -531,7 +537,7 @@ module Make (I : Dump_interface) = struct | Eof -> I.close_import import_t ; return_unit - | _ -> fail Inconsistent_context_dump + | _ -> tzfail Inconsistent_context_dump in let* block_data = first_pass () in let* () = @@ -562,7 +568,7 @@ module Make (I : Dump_interface) = struct (fun () -> restore ()) (function | Unix.Unix_error (e, _, _) -> - fail @@ System_read_error (Unix.error_message e) + tzfail @@ System_read_error (Unix.error_message e) | err -> Lwt.fail err) end diff --git a/src/lib_context/helpers/merkle_proof_encoding.ml b/src/lib_context/helpers/merkle_proof_encoding.ml index 8b63a399bac23f45b2ee4620a512667e2a79c9ac..f178632ce38c626d2c437a17abbe2069dc803d0e 100644 --- a/src/lib_context/helpers/merkle_proof_encoding.ml +++ b/src/lib_context/helpers/merkle_proof_encoding.ml @@ -93,7 +93,7 @@ struct Buffer.to_bytes buf in let decode b = - let open Tzresult_syntax in + let open Result_syntax in let error = Error "invalid 5bit list" in let* l = let sl = Bytes.length b in @@ -165,7 +165,7 @@ struct Buffer.to_bytes buf in let decode b = - let open Tzresult_syntax in + let open Result_syntax in let error = Error "invalid binary list" in let* l = let sl = Bytes.length b in diff --git a/src/lib_context/memory/context.ml b/src/lib_context/memory/context.ml index 7eea8599552d9066e66fa7a494ccc23884bfdd10..2fa85b69888cd0a8e9751e709099a3ed9eec630f 100644 --- a/src/lib_context/memory/context.ml +++ b/src/lib_context/memory/context.ml @@ -220,9 +220,10 @@ module Make (Encoding : module type of Tezos_context_encoding.Context) = struct let get_hash_version _c = Context_hash.Version.of_int 0 let set_hash_version c v = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in if Context_hash.Version.(of_int 0 = v) then return c - else fail (Tezos_context_helpers.Context.Unsupported_context_hash_version v) + else + tzfail (Tezos_context_helpers.Context.Unsupported_context_hash_version v) let add_predecessor_block_metadata_hash v hash = let data = diff --git a/src/lib_error_monad/TzMonad.ml b/src/lib_error_monad/TzMonad.ml index 1ad0b6fccead7bd66fe33f4c5e7792ec0cc7b35b..9feb1a8b323eaac5d7770eca4b36411f7389c89e 100644 --- a/src/lib_error_monad/TzMonad.ml +++ b/src/lib_error_monad/TzMonad.ml @@ -24,7 +24,6 @@ (* *) (*****************************************************************************) -type error = TzCore.error = .. - -include TzLwtreslib.Monad -include Monad_extension_maker.Make (TzCore) (TzTrace) (TzLwtreslib.Monad) +module Option_syntax = TzLwtreslib.Monad.Option_syntax +module Lwt_option_syntax = TzLwtreslib.Monad.Option_syntax +include Monad_maker.Make (TzCore) (TzTrace) (TzLwtreslib.Monad) diff --git a/src/lib_error_monad/TzMonad.mli b/src/lib_error_monad/TzMonad.mli index 5b342738d71693f215cec61e6250a2308f8d9e1f..44e39a736a11d94b2cc34dba0142a14cd28675b5 100644 --- a/src/lib_error_monad/TzMonad.mli +++ b/src/lib_error_monad/TzMonad.mli @@ -24,13 +24,10 @@ (* *) (*****************************************************************************) -type error = TzCore.error = .. +module Option_syntax = TzLwtreslib.Monad.Option_syntax +module Lwt_option_syntax = TzLwtreslib.Monad.Option_syntax include - Tezos_lwt_result_stdlib.Lwtreslib.TRACED_MONAD - with type 'error trace := 'error TzTrace.trace - -include - Sig.MONAD_EXTENSION - with type error := error + Monad_maker.S + with type error := TzCore.error and type 'error trace := 'error TzTrace.trace diff --git a/src/lib_error_monad/error_monad.ml b/src/lib_error_monad/error_monad.ml index 0142db8ec6f00d15682180da6863ca55c98a823d..202ee8bdb09b512d12541dc463296d24ac88beae 100644 --- a/src/lib_error_monad/error_monad.ml +++ b/src/lib_error_monad/error_monad.ml @@ -33,16 +33,12 @@ type error_category = [`Branch | `Temporary | `Permanent] include ( TzCore : module type of TzCore with type error_category := error_category) -include TzMonad module TzTrace = TzTrace -(* We offer shorter names for monads. These short names only make sense in the - context of Tezos' error-monads which is why it is defined here. *) -module Tzresult_syntax = Traced_result_syntax -module Lwt_tzresult_syntax = Lwt_traced_result_syntax - type 'error trace = 'error TzTrace.trace +include TzMonad + type error += Exn of exn let () = @@ -60,10 +56,10 @@ let () = (fun msg -> Exn (Failure msg)) let error_with fmt = - Format.kasprintf (fun s -> Tzresult_syntax.fail (Exn (Failure s))) fmt + Format.kasprintf (fun s -> Result_syntax.tzfail (Exn (Failure s))) fmt let failwith fmt = - Format.kasprintf (fun s -> Lwt_tzresult_syntax.fail (Exn (Failure s))) fmt + Format.kasprintf (fun s -> Lwt_result_syntax.tzfail (Exn (Failure s))) fmt let error_of_exn e = Exn e @@ -90,8 +86,8 @@ let () = (fun () -> Canceled) let protect_no_canceler ?on_error t = - let open Lwt_tzresult_syntax in - let res = Lwt.catch t (fun exn -> fail (Exn exn)) in + let open Lwt_result_syntax in + let res = Lwt.catch t (fun exn -> tzfail (Exn exn)) in let*! r = res in match r with | Ok _ -> res @@ -99,15 +95,17 @@ let protect_no_canceler ?on_error t = match on_error with | None -> res | Some on_error -> - Lwt.catch (fun () -> on_error trace) (fun exn -> fail (Exn exn))) + Lwt.catch (fun () -> on_error trace) (fun exn -> tzfail (Exn exn))) let protect_canceler ?on_error canceler t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let cancellation = let*! () = Lwt_canceler.when_canceling canceler in - fail Canceled + tzfail Canceled + in + let res = + Lwt.pick [cancellation; Lwt.catch t (fun exn -> tzfail (Exn exn))] in - let res = Lwt.pick [cancellation; Lwt.catch t (fun exn -> fail (Exn exn))] in let*! r = res in match r with | Ok _ -> res @@ -118,7 +116,7 @@ let protect_canceler ?on_error canceler t = match on_error with | None -> Lwt.return_error trace | Some on_error -> - Lwt.catch (fun () -> on_error trace) (fun exn -> fail (Exn exn))) + Lwt.catch (fun () -> on_error trace) (fun exn -> tzfail (Exn exn))) let protect ?on_error ?canceler t = match canceler with @@ -139,7 +137,7 @@ let () = (fun () -> Timeout) let with_timeout ?(canceler = Lwt_canceler.create ()) timeout f = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let target = f canceler in let*! () = Lwt.choose @@ -154,7 +152,9 @@ let with_timeout ?(canceler = Lwt_canceler.create ()) timeout f = target) else let*! r = Lwt_canceler.cancel canceler in - match r with Ok () | Error [] -> fail Timeout | Error (h :: _) -> raise h + match r with + | Ok () | Error [] -> tzfail Timeout + | Error (h :: _) -> raise h let errs_tag = Tag.def ~doc:"Errors" "errs" pp_print_trace diff --git a/src/lib_error_monad/error_monad.mli b/src/lib_error_monad/error_monad.mli index 7a3a8ddbf236d13ac5ee05fb2b842833f16c62c1..3991494aeef9e909547f1ba984fa3ce62d26aebb 100644 --- a/src/lib_error_monad/error_monad.mli +++ b/src/lib_error_monad/error_monad.mli @@ -68,43 +68,21 @@ module TzTrace : Sig.TRACE with type 'error trace = 'error list type 'error trace = 'error TzTrace.trace -include - Tezos_lwt_result_stdlib.Lwtreslib.TRACED_MONAD - with type 'error trace := 'error TzTrace.trace - -(** Syntax module (with let and returns) for the TzResult monad (i.e., the - TzTraced Result monad). *) -module Tzresult_syntax : module type of TzLwtreslib.Monad.Traced_result_syntax - -(** Syntax module (with let and returns) for the TzResult+Lwt monad (i.e., the - Lwt TzTraced Result monad*) -module Lwt_tzresult_syntax : - module type of TzLwtreslib.Monad.Lwt_traced_result_syntax - -(** Syntax module (with let and returns) for the error-agnostic Result monad is - available under the name [Result_syntax] from the [TRACED_MONAD]. - Unlike {!Tzresult_syntax}, with syntax module - - [fail] does not wrap errors in traces, - - there is no [and*] (because there is no way to compose errors). *) - -(** Syntax module (with let and returns) for the Lwt and error-agnostic Result - combined monad is available under the name [Lwt_result_syntax] from the - [TRACED_MONAD]. - Unlike {!Lwt_tzresult_syntax}, with syntax module - - [fail] does not wrap errors in traces, - - there is no [and*] (because there is no way to compose errors). *) - -(** [MONAD_EXTENSION]: the Tezos-specific extension to the monad part of - [Error_monad]. It includes +(** [TzMonad]: the Tezos-specific monad part of the [Error_monad]. It includes + - syntax modules - consistent defaults, - some tracing helpers, - some other misc helpers. *) include - Sig.MONAD_EXTENSION - with type error := error + Monad_maker.S + with type error := TzCore.error and type 'error trace := 'error TzTrace.trace +(* Other syntax module *) +module Option_syntax = TzLwtreslib.Monad.Option_syntax +module Lwt_option_syntax = TzLwtreslib.Monad.Option_syntax + (** {1 Exception-Error bridge} This part of the interface groups functions that are used to interact with diff --git a/src/lib_error_monad/monad_extension_maker.ml b/src/lib_error_monad/monad_extension_maker.ml deleted file mode 100644 index 816599d14c37e5132c99c8a57b6b2bb361d4d002..0000000000000000000000000000000000000000 --- a/src/lib_error_monad/monad_extension_maker.ml +++ /dev/null @@ -1,164 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2020 Nomadic Labs *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -module Make (Error : sig - type error = .. - - include Sig.CORE with type error := error -end) -(Trace : Sig.TRACE) -(Monad : Tezos_lwt_result_stdlib.Lwtreslib.TRACED_MONAD - with type 'error trace := 'error Trace.trace) : - Sig.MONAD_EXTENSION - with type error := Error.error - and type 'error trace := 'error Trace.trace = struct - module Legacy_monad_globals = struct - (* we default to exposing the combined monad syntax everywhere. - We do the bulk of this by including [Lwt_traced_result_syntax] directly. *) - include Monad.Lwt_traced_result_syntax - - (* Some globals that Lwtreslib does not expose but that the Tezos code uses a - lot. *) - let ( >>= ) = Monad.Lwt_syntax.( let* ) - - let ( >|= ) = Monad.Lwt_syntax.( let+ ) - - let ( >>? ) = Monad.Result_syntax.( let* ) - - let ( >|? ) = Monad.Result_syntax.( let+ ) - - let ok = Monad.Result_syntax.return - - let error = Monad.Traced_result_syntax.fail - - let ( >>=? ) = Monad.Lwt_result_syntax.( let* ) - - let ( >|=? ) = Monad.Lwt_result_syntax.( let+ ) - - let ( >>?= ) = Monad.Lwt_result_syntax.( let*? ) - - let ( >|?= ) r f = - match r with Error _ as e -> Lwt.return e | Ok o -> Lwt_result.ok (f o) - end - - (* default (traced-everywhere) helper types *) - type tztrace = Error.error Trace.trace - - type 'a tzresult = ('a, tztrace) result - - let trace_encoding = Trace.encoding Error.error_encoding - - let result_encoding a_encoding = - let open Data_encoding in - let trace_encoding = obj1 (req "error" trace_encoding) in - let a_encoding = obj1 (req "result" a_encoding) in - union - ~tag_size:`Uint8 - [ - case - (Tag 0) - a_encoding - ~title:"Ok" - (function Ok x -> Some x | _ -> None) - (function res -> Ok res); - case - (Tag 1) - trace_encoding - ~title:"Error" - (function Error x -> Some x | _ -> None) - (function x -> Error x); - ] - - let pp_print_trace = Trace.pp_print Error.pp - - let pp_print_top_error_of_trace = Trace.pp_print_top Error.pp - - let classify_trace trace = - Trace.fold - (fun c e -> Error_classification.combine c (Error.classify_error e)) - Error_classification.default - trace - - let record_trace err result = - match result with - | Ok _ as res -> res - | Error trace -> Error (Trace.cons err trace) - - let trace err f = - let open Monad.Lwt_syntax in - let* r = f in - match r with - | Error trace -> Lwt.return_error (Trace.cons err trace) - | ok -> Lwt.return ok - - let record_trace_eval mk_err = function - | Error trace -> - let err = mk_err () in - Error (Trace.cons err trace) - | ok -> ok - - let trace_eval mk_err f = - let open Monad.Lwt_syntax in - let* r = f in - match r with - | Error trace -> - let err = mk_err () in - Lwt.return_error (Trace.cons err trace) - | ok -> Lwt.return ok - - let error_unless cond exn = - let open Monad.Traced_result_syntax in - if cond then return_unit else fail exn - - let error_when cond exn = - let open Monad.Traced_result_syntax in - if cond then fail exn else return_unit - - let fail_unless cond exn = - let open Monad.Lwt_traced_result_syntax in - if cond then return_unit else fail exn - - let fail_when cond exn = - let open Monad.Lwt_traced_result_syntax in - if cond then fail exn else return_unit - - let unless cond f = - if cond then Monad.Lwt_traced_result_syntax.return_unit else f () - - let when_ cond f = - if cond then f () else Monad.Lwt_traced_result_syntax.return_unit - - let dont_wait f err_handler exc_handler = - let open Monad.Lwt_syntax in - Lwt.dont_wait - (fun () -> - let* r = f () in - match r with - | Ok () -> Lwt.return_unit - | Error trace -> - err_handler trace ; - Lwt.return_unit) - exc_handler -end diff --git a/src/lib_error_monad/monad_extension_maker.mli b/src/lib_error_monad/monad_extension_maker.mli deleted file mode 100644 index 1334acf087c62f8b5c5605f150f1857ffb3e9d48..0000000000000000000000000000000000000000 --- a/src/lib_error_monad/monad_extension_maker.mli +++ /dev/null @@ -1,39 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2020 Nomadic Labs *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -module Make (Error : sig - type error_category - - type error = .. - - include - Sig.CORE with type error := error and type error_category := error_category -end) -(Trace : Sig.TRACE) -(Monad : Tezos_lwt_result_stdlib.Lwtreslib.TRACED_MONAD - with type 'error trace := 'error Trace.trace) : - Sig.MONAD_EXTENSION - with type error := Error.error - and type 'error trace := 'error Trace.trace diff --git a/src/lib_error_monad/monad_maker.ml b/src/lib_error_monad/monad_maker.ml new file mode 100644 index 0000000000000000000000000000000000000000..35a7f995569604e1319642304140a915bd6e4367 --- /dev/null +++ b/src/lib_error_monad/monad_maker.ml @@ -0,0 +1,353 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +module type S = sig + (** for substitution *) + type error + + (** for substitution *) + type 'error trace + + type tztrace = error trace + + type 'a tzresult = ('a, tztrace) result + + (** You can find a lot of information about the [Lwt_syntax] module in the + error monad tutorial: https://tezos.gitlab.io/developer/error_monad.html + *) + module Lwt_syntax : module type of TzLwtreslib.Monad.Lwt_syntax + + (** You can find a lot of information about the [Result_syntax] module in the + error monad tutorial: https://tezos.gitlab.io/developer/error_monad.html + *) + module Result_syntax : sig + include module type of TzLwtreslib.Monad.Result_syntax + + (* NOTE: the [tzfail] functions is over-specialised. It could have the more + general type ['e -> ('a, 'e trace) result]. In practice no part of the + code uses that generalisation. In the future, it might be worth + generalising if we start using traces to carry other things than just + [error]. The same remark applies to the other [val] below and to the + [Lwt_result_syntax] [val]s too. *) + + (** [tzfail e] is for failing into the [tzresult] type. It wraps the given + error in a trace. This is meant as syntactic sugar for a very common + pattern that is otherwise written [fail (TzTrace.make e)]. *) + val tzfail : error -> 'a tzresult + + val ( and* ) : 'a tzresult -> 'b tzresult -> ('a * 'b) tzresult + + val ( and+ ) : 'a tzresult -> 'b tzresult -> ('a * 'b) tzresult + + val tzjoin : unit tzresult list -> unit tzresult + + val tzall : 'a tzresult list -> 'a list tzresult + + val tzboth : 'a tzresult -> 'b tzresult -> ('a * 'b) tzresult + end + + (** You can find a lot of information about the [Lwt_result_syntax] module in the + error monad tutorial: https://tezos.gitlab.io/developer/error_monad.html + *) + module Lwt_result_syntax : sig + include module type of TzLwtreslib.Monad.Lwt_result_syntax + + (** [tzfail e] is for failing into the [tzresult Lwt.t] type. It wraps the + given error in a trace. This is meant as syntactic sugar for a very + common pattern that is otherwise written [fail (TzTrace.make e)]. *) + val tzfail : error -> 'a tzresult Lwt.t + + val ( and* ) : + 'a tzresult Lwt.t -> 'b tzresult Lwt.t -> ('a * 'b) tzresult Lwt.t + + val ( and+ ) : + 'a tzresult Lwt.t -> 'b tzresult Lwt.t -> ('a * 'b) tzresult Lwt.t + + val tzjoin : unit tzresult Lwt.t list -> unit tzresult Lwt.t + + val tzall : 'a tzresult Lwt.t list -> 'a list tzresult Lwt.t + + val tzboth : + 'a tzresult Lwt.t -> 'b tzresult Lwt.t -> ('a * 'b) tzresult Lwt.t + end + + val classify_trace : tztrace -> Error_classification.t + + module Legacy_monad_globals : sig + val return : 'a -> ('a, 'e) result Lwt.t + + val return_unit : (unit, 'e) result Lwt.t + + val return_none : ('a option, 'e) result Lwt.t + + val return_some : 'a -> ('a option, 'e) result Lwt.t + + val return_nil : ('a list, 'e) result Lwt.t + + val return_true : (bool, 'e) result Lwt.t + + val return_false : (bool, 'e) result Lwt.t + + val ( >>= ) : 'a Lwt.t -> ('a -> 'b Lwt.t) -> 'b Lwt.t + + val ( >|= ) : 'a Lwt.t -> ('a -> 'b) -> 'b Lwt.t + + val ok : 'a -> ('a, 'e) result + + val error : 'e -> ('a, 'e trace) result + + val ( >>? ) : ('a, 'e) result -> ('a -> ('b, 'e) result) -> ('b, 'e) result + + val ( >|? ) : ('a, 'e) result -> ('a -> 'b) -> ('b, 'e) result + + val fail : 'e -> ('a, 'e trace) result Lwt.t + + val ( >>=? ) : + ('a, 'e) result Lwt.t -> + ('a -> ('b, 'e) result Lwt.t) -> + ('b, 'e) result Lwt.t + + val ( >|=? ) : ('a, 'e) result Lwt.t -> ('a -> 'b) -> ('b, 'e) result Lwt.t + + val ( >>?= ) : + ('a, 'e) result -> ('a -> ('b, 'e) result Lwt.t) -> ('b, 'e) result Lwt.t + + val ( >|?= ) : ('a, 'e) result -> ('a -> 'b Lwt.t) -> ('b, 'e) result Lwt.t + end + + val pp_print_trace : Format.formatter -> tztrace -> unit + + val pp_print_top_error_of_trace : Format.formatter -> tztrace -> unit + + val trace_encoding : tztrace Data_encoding.t + + val result_encoding : 'a Data_encoding.t -> 'a tzresult Data_encoding.t + + val record_trace : 'err -> ('a, 'err trace) result -> ('a, 'err trace) result + + val trace : + 'err -> ('b, 'err trace) result Lwt.t -> ('b, 'err trace) result Lwt.t + + val record_trace_eval : + (unit -> 'err) -> ('a, 'err trace) result -> ('a, 'err trace) result + + val trace_eval : + (unit -> 'err) -> + ('b, 'err trace) result Lwt.t -> + ('b, 'err trace) result Lwt.t + + val error_unless : bool -> 'err -> (unit, 'err trace) result + + val error_when : bool -> 'err -> (unit, 'err trace) result + + val fail_unless : bool -> 'err -> (unit, 'err trace) result Lwt.t + + val fail_when : bool -> 'err -> (unit, 'err trace) result Lwt.t + + val unless : + bool -> (unit -> (unit, 'trace) result Lwt.t) -> (unit, 'trace) result Lwt.t + + val when_ : + bool -> (unit -> (unit, 'trace) result Lwt.t) -> (unit, 'trace) result Lwt.t + + val dont_wait : + (unit -> (unit, 'trace) result Lwt.t) -> + ('trace -> unit) -> + (exn -> unit) -> + unit +end + +module Make (Error : sig + type error = .. + + include Sig.CORE with type error := error +end) +(Trace : Sig.TRACE) +(Monad : Tezos_lwt_result_stdlib.Lwtreslib.TRACED_MONAD + with type 'error trace := 'error Trace.trace) : + S with type error := Error.error and type 'error trace := 'error Trace.trace = +struct + module Lwt_syntax = Monad.Lwt_syntax + + module Result_syntax = struct + include Monad.Result_syntax + + let tzfail = Monad.Traced_result_syntax.fail + + let ( and* ) = Monad.Traced_result_syntax.( and* ) + + let ( and+ ) = Monad.Traced_result_syntax.( and+ ) + + let tzboth = Monad.Traced_result_syntax.both + + let tzall = Monad.Traced_result_syntax.all + + let tzjoin = Monad.Traced_result_syntax.join + end + + module Lwt_result_syntax = struct + include Monad.Lwt_result_syntax + + let tzfail = Monad.Lwt_traced_result_syntax.fail + + let ( and* ) = Monad.Lwt_traced_result_syntax.( and* ) + + let ( and+ ) = Monad.Lwt_traced_result_syntax.( and+ ) + + let tzboth = Monad.Lwt_traced_result_syntax.both + + let tzall = Monad.Lwt_traced_result_syntax.all + + let tzjoin = Monad.Lwt_traced_result_syntax.join + end + + module Legacy_monad_globals = struct + (* we default to exposing the combined monad syntax everywhere. + We do the bulk of this by including [Lwt_traced_result_syntax] directly. *) + include Monad.Lwt_traced_result_syntax + + (* Some globals that Lwtreslib does not expose but that the Tezos code uses a + lot. *) + let ( >>= ) = Monad.Lwt_syntax.( let* ) + + let ( >|= ) = Monad.Lwt_syntax.( let+ ) + + let ( >>? ) = Monad.Result_syntax.( let* ) + + let ( >|? ) = Monad.Result_syntax.( let+ ) + + let ok = Monad.Result_syntax.return + + let error = Monad.Traced_result_syntax.fail + + let ( >>=? ) = Monad.Lwt_result_syntax.( let* ) + + let ( >|=? ) = Monad.Lwt_result_syntax.( let+ ) + + let ( >>?= ) = Monad.Lwt_result_syntax.( let*? ) + + let ( >|?= ) r f = + match r with Error _ as e -> Lwt.return e | Ok o -> Lwt_result.ok (f o) + end + + (* default (traced-everywhere) helper types *) + type tztrace = Error.error Trace.trace + + type 'a tzresult = ('a, tztrace) result + + let trace_encoding = Trace.encoding Error.error_encoding + + let result_encoding a_encoding = + let open Data_encoding in + let trace_encoding = obj1 (req "error" trace_encoding) in + let a_encoding = obj1 (req "result" a_encoding) in + union + ~tag_size:`Uint8 + [ + case + (Tag 0) + a_encoding + ~title:"Ok" + (function Ok x -> Some x | _ -> None) + (function res -> Ok res); + case + (Tag 1) + trace_encoding + ~title:"Error" + (function Error x -> Some x | _ -> None) + (function x -> Error x); + ] + + let pp_print_trace = Trace.pp_print Error.pp + + let pp_print_top_error_of_trace = Trace.pp_print_top Error.pp + + let classify_trace trace = + Trace.fold + (fun c e -> Error_classification.combine c (Error.classify_error e)) + Error_classification.default + trace + + let record_trace err result = + match result with + | Ok _ as res -> res + | Error trace -> Error (Trace.cons err trace) + + let trace err f = + let open Monad.Lwt_syntax in + let* r = f in + match r with + | Error trace -> Lwt.return_error (Trace.cons err trace) + | ok -> Lwt.return ok + + let record_trace_eval mk_err = function + | Error trace -> + let err = mk_err () in + Error (Trace.cons err trace) + | ok -> ok + + let trace_eval mk_err f = + let open Monad.Lwt_syntax in + let* r = f in + match r with + | Error trace -> + let err = mk_err () in + Lwt.return_error (Trace.cons err trace) + | ok -> Lwt.return ok + + let error_unless cond exn = + let open Monad.Traced_result_syntax in + if cond then return_unit else fail exn + + let error_when cond exn = + let open Monad.Traced_result_syntax in + if cond then fail exn else return_unit + + let fail_unless cond exn = + let open Monad.Lwt_traced_result_syntax in + if cond then return_unit else fail exn + + let fail_when cond exn = + let open Monad.Lwt_traced_result_syntax in + if cond then fail exn else return_unit + + let unless cond f = + if cond then Monad.Lwt_traced_result_syntax.return_unit else f () + + let when_ cond f = + if cond then f () else Monad.Lwt_traced_result_syntax.return_unit + + let dont_wait f err_handler exc_handler = + let open Monad.Lwt_syntax in + Lwt.dont_wait + (fun () -> + let* r = f () in + match r with + | Ok () -> Lwt.return_unit + | Error trace -> + err_handler trace ; + Lwt.return_unit) + exc_handler +end diff --git a/src/lib_error_monad/monad_maker.mli b/src/lib_error_monad/monad_maker.mli new file mode 100644 index 0000000000000000000000000000000000000000..099ebfe89db9750c6b525875f7eb2fc65ad49951 --- /dev/null +++ b/src/lib_error_monad/monad_maker.mli @@ -0,0 +1,276 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** [S] is the Tezos-specific extension to the generic monad + provided by Lwtreslib. It sets some defaults (e.g., it defaults traced + failures), it brings some qualified identifiers into the main unqualified + part (e.g., [return_unit]), it provides some tracing helpers and some + in-monad assertion checks. *) +module type S = sig + (** for substitution *) + type error + + (** for substitution *) + type 'error trace + + type tztrace = error trace + + type 'a tzresult = ('a, tztrace) result + + module Lwt_syntax : module type of TzLwtreslib.Monad.Lwt_syntax + + module Result_syntax : sig + include module type of TzLwtreslib.Monad.Result_syntax + + val tzfail : error -> 'a tzresult + + val ( and* ) : 'a tzresult -> 'b tzresult -> ('a * 'b) tzresult + + val ( and+ ) : 'a tzresult -> 'b tzresult -> ('a * 'b) tzresult + + val tzjoin : unit tzresult list -> unit tzresult + + val tzall : 'a tzresult list -> 'a list tzresult + + val tzboth : 'a tzresult -> 'b tzresult -> ('a * 'b) tzresult + end + + module Lwt_result_syntax : sig + include module type of TzLwtreslib.Monad.Lwt_result_syntax + + val tzfail : error -> 'a tzresult Lwt.t + + val ( and* ) : + 'a tzresult Lwt.t -> 'b tzresult Lwt.t -> ('a * 'b) tzresult Lwt.t + + val ( and+ ) : + 'a tzresult Lwt.t -> 'b tzresult Lwt.t -> ('a * 'b) tzresult Lwt.t + + val tzjoin : unit tzresult Lwt.t list -> unit tzresult Lwt.t + + val tzall : 'a tzresult Lwt.t list -> 'a list tzresult Lwt.t + + val tzboth : + 'a tzresult Lwt.t -> 'b tzresult Lwt.t -> ('a * 'b) tzresult Lwt.t + end + + val classify_trace : tztrace -> Error_classification.t + + module Legacy_monad_globals : sig + val return : 'a -> ('a, 'e) result Lwt.t + + val return_unit : (unit, 'e) result Lwt.t + + val return_none : ('a option, 'e) result Lwt.t + + val return_some : 'a -> ('a option, 'e) result Lwt.t + + val return_nil : ('a list, 'e) result Lwt.t + + val return_true : (bool, 'e) result Lwt.t + + val return_false : (bool, 'e) result Lwt.t + + (** more globals *) + val ( >>= ) : 'a Lwt.t -> ('a -> 'b Lwt.t) -> 'b Lwt.t + + val ( >|= ) : 'a Lwt.t -> ('a -> 'b) -> 'b Lwt.t + + val ok : 'a -> ('a, 'e) result + + val error : 'e -> ('a, 'e trace) result + + val ( >>? ) : ('a, 'e) result -> ('a -> ('b, 'e) result) -> ('b, 'e) result + + val ( >|? ) : ('a, 'e) result -> ('a -> 'b) -> ('b, 'e) result + + val fail : 'e -> ('a, 'e trace) result Lwt.t + + val ( >>=? ) : + ('a, 'e) result Lwt.t -> + ('a -> ('b, 'e) result Lwt.t) -> + ('b, 'e) result Lwt.t + + val ( >|=? ) : ('a, 'e) result Lwt.t -> ('a -> 'b) -> ('b, 'e) result Lwt.t + + val ( >>?= ) : + ('a, 'e) result -> ('a -> ('b, 'e) result Lwt.t) -> ('b, 'e) result Lwt.t + + val ( >|?= ) : ('a, 'e) result -> ('a -> 'b Lwt.t) -> ('b, 'e) result Lwt.t + end + + (* Pretty-prints an error trace. *) + val pp_print_trace : Format.formatter -> tztrace -> unit + + (** Pretty-prints the top error of a trace *) + val pp_print_top_error_of_trace : Format.formatter -> tztrace -> unit + + val trace_encoding : tztrace Data_encoding.t + + (** A serializer for result of a given type *) + val result_encoding : 'a Data_encoding.t -> 'a tzresult Data_encoding.t + + (** [record_trace err res] is either [res] if [res] is [Ok _], or it is + [Error (Trace.cons err tr)] if [res] is [Error tr]. + + In other words, [record_trace err res] enriches the trace that is carried + by [res] (if it is carrying a trace) with the error [err]. It leaves [res] + untouched if [res] is not carrying a trace. + + You can use this to add high-level information to potential low-level + errors. E.g., + +{[ +record_trace + Failure_to_load_config + (load_data_from_file config_encoding config_file_name) +]} + + Note that [record_trace] takes a {e fully evaluated} error [err] as + argument. It means that, whatever the value of the result [res], the error + [err] is evaluated. This is not an issue if the error is a simple + expression (a literal or a constructor with simple parameters). However, + for any expression that is more complex (e.g., one that calls a function) + you should prefer [record_trace_eval]. *) + val record_trace : 'err -> ('a, 'err trace) result -> ('a, 'err trace) result + + (** [trace] is identical to [record_trace] but applies to a promise. More + formally, [trace err p] is a promise that resolves to [Ok v] if [p] + resolves to [Ok v], or it resolves to [Error (Trace.cons err tr)] if + [res] resolves to [Error tr]. + + In other words, [trace err p] enriches the trace that [p] resolves to (if + it does resolve to a trace) with the error [err]. It leaves the value that + [p] resolves to untouched if it is not a trace. + + You can use this to add high-level information to potential low-level + errors. + + Note that, like {!record_trace}, [trace] takes a fully evaluated error as + argument. For a similar reason as explained there, you should only use + [trace] with simple expressions (literal or constructor with simple + parameters) and prefer [trace_eval] for any other expression (such as ones + that include functions calls). *) + val trace : + 'err -> ('b, 'err trace) result Lwt.t -> ('b, 'err trace) result Lwt.t + + (** [record_trace_eval] is identical to [record_trace] except that the error + that enriches the trace is wrapped in a function that is evaluated only if + it is needed. More formally [record_trace_eval mkerr res] is [res] if + [res] is [Ok _], or it is [Error (Trace.cons (mkerr ()) tr)] if [res] is + [Error tr]. + + You can achieve the same effect by hand with + +{[ +match res with +| Ok _ -> res +| Error tr -> Error (Trace.cons (mkerr ()) tr) +]} + + Prefer [record_trace_eval] over [record_trace] when the enriching error is + expensive to compute or heavy to allocate. *) + val record_trace_eval : + (unit -> 'err) -> ('a, 'err trace) result -> ('a, 'err trace) result + + (** [trace_eval] is identical to [trace] except that the error that enriches + the trace is wrapped in a function that is evaluated only if {e and when} + it is needed. More formally [trace_eval mkerr p] is a promise that + resolves to [Ok v] if [p] resolves to [Ok v], or it resolves to + [Error (Trace.cons err tr)] if [p] resolves to [Error tr] and then [mkerr + ()] resolves to [err]. + + You can achieve the same effect by hand with + +{[ +p >>= function +| Ok _ -> p +| Error tr -> + mkerr () >>= fun err -> + Lwt.return (Error (Trace.cons err tr)) +]} + + Note that the evaluation of the error can be arbitrarily delayed. Avoid + using references and other mutable values in the function [mkerr]. + + Prefer [trace_eval] over [trace] when the enriching error is expensive to + compute or heavy to allocate or when evaluating it requires the use of + Lwt. *) + val trace_eval : + (unit -> 'err) -> + ('b, 'err trace) result Lwt.t -> + ('b, 'err trace) result Lwt.t + + (** [error_unless flag err] is [Ok ()] if [b] is [true], it is + [Error (Trace.make err)] otherwise. *) + val error_unless : bool -> 'err -> (unit, 'err trace) result + + (** [error_when flag err] is [Error (Trace.make err)] if [b] is [true], it is + [Ok ()] otherwise. *) + val error_when : bool -> 'err -> (unit, 'err trace) result + + (** [fail_unless flag err] is [Lwt.return @@ Ok ()] if [b] is [true], it is + [Lwt.return @@ Error (Trace.make err)] otherwise. *) + val fail_unless : bool -> 'err -> (unit, 'err trace) result Lwt.t + + (** [fail_when flag err] is [Lwt.return @@ Error (Trace.make err)] if [b] is + [true], it is [Lwt.return @@ Ok ()] otherwise. *) + val fail_when : bool -> 'err -> (unit, 'err trace) result Lwt.t + + (** [unless b f] is [f ()] if [b] is [false] and it is a promise already + resolved to [Ok ()] otherwise. + + You can use [unless] to avoid having to write an [if] statement that you + then need to populate entirely to satisfy the type-checker. E.g, you can + write [unless b f] instead of [if not b then f () else return_unit]. *) + val unless : + bool -> (unit -> (unit, 'trace) result Lwt.t) -> (unit, 'trace) result Lwt.t + + (** [when_ b f] is [f ()] if [b] is [true] and it is a promise already + resolved to [Ok ()] otherwise. + + You can use [when_] to avoid having to write an [if] statement that you + then need to populate entirely to satisfy the type-checker. E.g, you can + write [when_ b f] instead of [if b then f () else return_unit]. *) + val when_ : + bool -> (unit -> (unit, 'trace) result Lwt.t) -> (unit, 'trace) result Lwt.t + + (** Wrapper around [Lwt_utils.dont_wait] *) + val dont_wait : + (unit -> (unit, 'trace) result Lwt.t) -> + ('trace -> unit) -> + (exn -> unit) -> + unit +end + +module Make (Error : sig + type error = .. + + include Sig.CORE with type error := error +end) +(Trace : Sig.TRACE) +(Monad : Tezos_lwt_result_stdlib.Lwtreslib.TRACED_MONAD + with type 'error trace := 'error Trace.trace) : + S with type error := Error.error and type 'error trace := 'error Trace.trace diff --git a/src/lib_event_logging/internal_event.ml b/src/lib_event_logging/internal_event.ml index ecabf6d99b8137476d0b5b9dfe170fda395b17b0..efd15c8b4e1adbf5c4caf68eba87868a4b2779b7 100644 --- a/src/lib_event_logging/internal_event.ml +++ b/src/lib_event_logging/internal_event.ml @@ -300,14 +300,14 @@ module All_sinks = struct (fun reason -> Activation_error reason) let activate uri = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Uri.scheme uri with - | None -> fail (Activation_error (Missing_uri_scheme (Uri.to_string uri))) + | None -> tzfail (Activation_error (Missing_uri_scheme (Uri.to_string uri))) | Some scheme_to_activate -> let* act = match find_registered scheme_to_activate with | None -> - fail + tzfail (Activation_error (Uri_scheme_not_registered (Uri.to_string uri))) | Some (Registered {scheme; definition}) -> @@ -344,7 +344,7 @@ module All_sinks = struct (fun (Active {sink; definition; _}) -> close_one sink definition) to_close_list in - Tzresult_syntax.join close_results + Result_syntax.tzjoin close_results let handle def section v = let handle (type a) sink definition = @@ -1554,7 +1554,7 @@ module Lwt_log_sink = struct let uri_scheme = "lwt-log" - let configure _ = Lwt_tzresult_syntax.return_unit + let configure _ = Lwt_result_syntax.return_unit let handle (type a) () m ?section (v : unit -> a) = let open Lwt_syntax in diff --git a/src/lib_event_logging/test_helpers/mock_sink.ml b/src/lib_event_logging/test_helpers/mock_sink.ml index 37744a41bb47fab5350f3fdc6934e9dce31238d5..cd8c5b2360dab26a1aa40b9358e72d85e8ef54e8 100644 --- a/src/lib_event_logging/test_helpers/mock_sink.ml +++ b/src/lib_event_logging/test_helpers/mock_sink.ml @@ -105,11 +105,11 @@ let uri_scheme = "mock-log" let configure _ = activated := true ; - Lwt_tzresult_syntax.return_unit + Lwt_result_syntax.return_unit let is_activated () = !activated -let close (_ : t) : unit tzresult Lwt.t = Lwt_tzresult_syntax.return_unit +let close (_ : t) : unit tzresult Lwt.t = Lwt_result_syntax.return_unit let handle (type a) (_ : t) m ?section (f : unit -> a) = let module M = (val m : Internal_event.EVENT_DEFINITION with type t = a) in @@ -124,7 +124,7 @@ let handle (type a) (_ : t) m ?section (f : unit -> a) = } in recorded_events := !recorded_events @ [event] ; - Lwt_tzresult_syntax.return_unit + Lwt_result_syntax.return_unit (** testing stuff *) diff --git a/src/lib_mockup/local_services.ml b/src/lib_mockup/local_services.ml index 9422ee4f29247ee08ce78e8c2b37ac51151bb4b3..11b4014b5b6b0c09f8f13e8fb3567d355e7bb148 100644 --- a/src/lib_mockup/local_services.ml +++ b/src/lib_mockup/local_services.ml @@ -318,7 +318,7 @@ module Make (E : MENV) = struct module Trashpool = Rw (Files.Trashpool) let to_applied (shell_header, operation_data) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let op = {E.Protocol.shell = shell_header; protocol_data = operation_data} in @@ -406,7 +406,7 @@ module Make (E : MENV) = struct RPC_answer.return set)) let simulate_operation (validation_state, preapply_result) op = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Data_encoding.Binary.to_bytes E.Protocol.operation_data_encoding @@ -440,7 +440,7 @@ module Make (E : MENV) = struct } )) let preapply_block () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Directory.prefix (Tezos_rpc.RPC_path.prefix (* /chains/ *) @@ -526,7 +526,7 @@ module Make (E : MENV) = struct | Ok v -> RPC_answer.return v)) let preapply () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Directory.prefix (Tezos_rpc.RPC_path.prefix (* /chains/ *) @@ -579,7 +579,7 @@ module Make (E : MENV) = struct Stdlib.compare a_operation_data b_operation_data = 0 let need_operation op = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* mempool_operations = Mempool.read () in if List.mem ~equal:equal_op op mempool_operations then return `Equal else @@ -603,7 +603,7 @@ module Make (E : MENV) = struct failwith "%s" notification_msg let inject_operation_with_mempool operation_bytes = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Data_encoding.Binary.of_bytes Operation.encoding operation_bytes with | Error _ -> RPC_answer.fail [Cannot_parse_op] | Ok ({Operation.shell = shell_header; proto} as op) -> ( @@ -675,7 +675,7 @@ module Make (E : MENV) = struct let inject_block_generic (write_context_callback : callback_writer) (update_mempool_callback : Operation.t list list -> unit tzresult Lwt.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let reconstruct (operations : Operation.t list list) (block_header : Block_header.t) = match @@ -758,7 +758,7 @@ module Make (E : MENV) = struct and uses a mempool. *) let inject_block (write_context_callback : callback_writer) = inject_block_generic write_context_callback (fun operations -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* mempool_operations = Mempool.read () in let* mempool_map = List.fold_left_es diff --git a/src/lib_mockup/migration.ml b/src/lib_mockup/migration.ml index 188cf0e8d86ca98a0784d7705a3a5576cdd35e14..61f13ade3682a1314a61d0f250166d4c532c0f0c 100644 --- a/src/lib_mockup/migration.ml +++ b/src/lib_mockup/migration.ml @@ -27,7 +27,7 @@ open Persistence let migrate_mockup ~(cctxt : Tezos_client_base.Client_context.full) ~protocol_hash ~next_protocol_hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let base_dir = cctxt#get_base_dir in let explain_will_not_work explain = let*! () = diff --git a/src/lib_mockup/mockup_commands.ml b/src/lib_mockup/mockup_commands.ml index b456901ada487f4948a22c05fe1206f0f7fbfa2a..7d5bafb79d30f8a5f87032b3f7c85904b1f9b9ab 100644 --- a/src/lib_mockup/mockup_commands.ml +++ b/src/lib_mockup/mockup_commands.ml @@ -35,7 +35,7 @@ let list_mockup_command_handler _ _ = let module Mockup = (val mockup) in Format.printf "%a@." Protocol_hash.pp Mockup.protocol_hash) available ; - Lwt_tzresult_syntax.return_unit + Lwt_result_syntax.return_unit let list_mockup_command : Tezos_client_base.Client_context.full Clic.command = let open Clic in diff --git a/src/lib_mockup/mockup_wallet.ml b/src/lib_mockup/mockup_wallet.ml index c107f47ea4cbb6552c7c1d0c593d5f935adc4c2c..24a93902791ab7c830011c4ead826605bb8a056f 100644 --- a/src/lib_mockup/mockup_wallet.ml +++ b/src/lib_mockup/mockup_wallet.ml @@ -86,7 +86,7 @@ let bootstrap_secrets_encoding = Data_encoding.list bootstrap_secret_encoding let populate (cctxt : #Tezos_client_base.Client_context.io_wallet) bootstrap_accounts_file = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* accounts = match bootstrap_accounts_file with | None -> default_bootstrap_accounts diff --git a/src/lib_mockup/persistence.ml b/src/lib_mockup/persistence.ml index 6b56fcce01fc8448177ba691aaf405c2adbd9792..9049d24adae5ef497fb651227d53cc4ea31975b0 100644 --- a/src/lib_mockup/persistence.ml +++ b/src/lib_mockup/persistence.ml @@ -131,7 +131,7 @@ module Make (Registration : Registration.S) = struct (Registration.mockup_environment * Registration.mockup_context) tzresult Lwt.t = fun cctxt -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* mockup = get_registered_mockup None cctxt in let (module Mockup) = mockup in let* rpc_context = @@ -151,7 +151,7 @@ module Make (Registration : Registration.S) = struct (Registration.mockup_environment * Registration.mockup_context) tzresult Lwt.t = fun ~cctxt ~protocol_hash ~constants_overrides_json ~bootstrap_accounts_json -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* mockup = get_registered_mockup (Some protocol_hash) cctxt in let (module Mockup) = mockup in let* menv = @@ -167,7 +167,7 @@ module Make (Registration : Registration.S) = struct ({protocol_hash; chain_id; rpc_context; protocol_data} : Persistent_mockup_environment.t) (printer : #Tezos_client_base.Client_context.printer) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* mockup = get_registered_mockup (Some protocol_hash) printer in return ( mockup, @@ -176,7 +176,7 @@ module Make (Registration : Registration.S) = struct let get_mockup_context_from_disk ~base_dir ~protocol_hash (printer : #Tezos_client_base.Client_context.printer) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let file = (Files.Context.get ~dirname:base_dir :> string) in if not (Sys.file_exists file) then failwith "get_mockup_context_from_disk: file %s not found" file @@ -306,7 +306,7 @@ module Make (Registration : Registration.S) = struct let create_mockup ~(cctxt : Tezos_client_base.Client_context.full) ~protocol_hash ~constants_overrides_json ~bootstrap_accounts_json ~asynchronous = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let base_dir = cctxt#get_base_dir in let create_base_dir () = let*! () = Tezos_stdlib_unix.Lwt_utils_unix.create_dir base_dir in diff --git a/src/lib_mockup/test/test_persistence.ml b/src/lib_mockup/test/test_persistence.ml index 6021a2a04f9c153a81c75252ecdc5d01836f603c..5dd100b0256721fa1af85f2cf938b74d9a099c7c 100644 --- a/src/lib_mockup/test/test_persistence.ml +++ b/src/lib_mockup/test/test_persistence.ml @@ -41,7 +41,7 @@ let check_base_dir s bd1 bd2 = Alcotest.check base_dir_class_testable s bd1 bd2 (** [classify_base_dir] a non existing directory *) let test_classify_does_not_exist = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Tztest.tztest "Classify a non existing directory" `Quick (fun () -> Lwt_utils_unix.with_tempdir "test_persistence" (fun base_dir -> let+ bd = @@ -52,7 +52,7 @@ let test_classify_does_not_exist = (** [classify_base_dir] a file *) let test_classify_is_file = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Tztest.tztest "Classify a file" `Quick (fun () -> let tmp_file = Filename.temp_file "" "" in let+ bd = Persistence.classify_base_dir tmp_file in @@ -60,7 +60,7 @@ let test_classify_is_file = (** [classify_base_dir] a mockup directory *) let test_classify_is_mockup = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Tztest.tztest "Classify a mockup directory" `Quick (fun () -> Lwt_utils_unix.with_tempdir "test_persistence" (fun dirname -> let mockup_directory = (Files.get_mockup_directory ~dirname :> string) @@ -72,7 +72,7 @@ let test_classify_is_mockup = (** [classify_base_dir] a non empty directory *) let test_classify_is_nonempty = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Tztest.tztest "Classify a non empty directory" `Quick (fun () -> Lwt_utils_unix.with_tempdir "test_persistence" (fun temp_dir -> let _ = Filename.temp_file ~temp_dir "" "" in @@ -81,7 +81,7 @@ let test_classify_is_nonempty = (** [classify_base_dir] an empty directory *) let test_classify_is_empty = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Tztest.tztest "Classify an empty directory" `Quick (fun () -> Lwt_utils_unix.with_tempdir "test_persistence" (fun base_dir -> let+ bd = Persistence.classify_base_dir base_dir in diff --git a/src/lib_p2p/p2p.ml b/src/lib_p2p/p2p.ml index 0154bb6cf9a4707a35970c9bb358111807c95ddd..c4041b1e0791a8afcc7932fadb6512979edb96cc 100644 --- a/src/lib_p2p/p2p.ml +++ b/src/lib_p2p/p2p.ml @@ -193,7 +193,7 @@ module Real = struct } let create ~config ~limits meta_cfg msg_cfg conn_meta_cfg = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let io_sched = create_scheduler limits in let watcher = Lwt_watcher.create_input () in let log event = Lwt_watcher.notify watcher event in @@ -581,10 +581,10 @@ let faked_network (msg_cfg : 'msg P2p_params.message_config) peer_cfg set_peer_metadata = (fun _ _ -> ()); connect = (fun ?timeout:_ _ -> - Lwt_tzresult_syntax.fail P2p_errors.Connection_refused); + Lwt_result_syntax.tzfail P2p_errors.Connection_refused); recv = (fun _ -> Lwt_utils.never_ending ()); recv_any = (fun () -> Lwt_utils.never_ending ()); - send = (fun _ _ -> Lwt_tzresult_syntax.fail P2p_errors.Connection_closed); + send = (fun _ _ -> Lwt_result_syntax.tzfail P2p_errors.Connection_closed); try_send = (fun _ _ -> false); fold_connections = (fun ~init ~f:_ -> init); iter_connections = (fun _f -> ()); diff --git a/src/lib_p2p/p2p_buffer_reader.ml b/src/lib_p2p/p2p_buffer_reader.ml index cb5862743c91fc3b118e5c4859cad977e130d0f2..fa80d7a87c290ee764e5040236af38cd482a339c 100644 --- a/src/lib_p2p/p2p_buffer_reader.ml +++ b/src/lib_p2p/p2p_buffer_reader.ml @@ -81,14 +81,14 @@ let mk_readable ~read_buffer ~read_queue = type buffer = {length_to_copy : int; pos : int; buf : Bytes.t} let mk_buffer ?pos ?length_to_copy buf : buffer tzresult = - let open Tzresult_syntax in + let open Result_syntax in let buflen = Bytes.length buf in let pos = Option.value ~default:0 pos in let length_to_copy = Option.value ~default:(buflen - pos) length_to_copy in let check cond ~expected = if cond then return_unit else - fail + tzfail (Invalid_read_request { expected; @@ -131,7 +131,7 @@ let read_from readable {pos = offset; length_to_copy; buf} data = ~into:buf ~offset) ; Ok read_len - | Error _ -> Tzresult_syntax.fail P2p_errors.Connection_closed + | Error _ -> Result_syntax.tzfail P2p_errors.Connection_closed let read ?canceler readable buffer = let open Lwt_syntax in diff --git a/src/lib_p2p/p2p_conn.ml b/src/lib_p2p/p2p_conn.ml index 6e4b3000b65853d294167e0836b8566710d4b348..f56414c50bd9f1a6a3bfee084a90a0f265c509a6 100644 --- a/src/lib_p2p/p2p_conn.ml +++ b/src/lib_p2p/p2p_conn.ml @@ -136,7 +136,7 @@ let create ~conn ~point_info ~peer_info ~messages ~canceler ~greylister t let pipe_exn_handler = function - | Lwt_pipe.Closed -> Lwt_tzresult_syntax.fail P2p_errors.Connection_closed + | Lwt_pipe.Closed -> Lwt_result_syntax.tzfail P2p_errors.Connection_closed | exc -> Lwt.fail exc (* see [Lwt_pipe.Maybe_bounded.pop] *) @@ -154,7 +154,7 @@ let read t = pipe_exn_handler let is_readable t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt.catch (fun () -> let*! _ = Lwt_pipe.Maybe_bounded.peek t.messages in diff --git a/src/lib_p2p/p2p_connect_handler.ml b/src/lib_p2p/p2p_connect_handler.ml index cd801b782dad83cc67c2541c0a59f72cc484e099..f7bba0b5cc20bf10d7242d7e63d06df545107603 100644 --- a/src/lib_p2p/p2p_connect_handler.ml +++ b/src/lib_p2p/p2p_connect_handler.ml @@ -208,7 +208,7 @@ let create_connection t p2p_conn id_point point_info peer_info conn let is_acceptable t connection_point_info peer_info incoming version = - let open Tzresult_syntax in + let open Result_syntax in (* Private mode only accept trusted *) let unexpected = t.config.private_mode @@ -221,7 +221,7 @@ let is_acceptable t connection_point_info peer_info incoming version = in if unexpected then ( Events.(emit__dont_wait__use_with_care peer_rejected) () ; - fail P2p_errors.Private_mode) + tzfail P2p_errors.Private_mode) else (* checking if point is acceptable *) let* version = @@ -256,7 +256,7 @@ let may_register_my_id_point pool = function *) let check_expected_peer_id (point_info : 'a P2p_point_state.Info.t option) (conn_info : 'b P2p_connection.Info.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match point_info with | None -> (* if no point info, nothing is expected from the point, it cannot @@ -272,7 +272,7 @@ let check_expected_peer_id (point_info : 'a P2p_point_state.Info.t option) Events.(emit authenticate_status_peer_id_incorrect) ("peer_id", point, expected_peer_id, conn_info.peer_id) in - fail + tzfail P2p_errors.( Identity_check_failure { @@ -288,7 +288,7 @@ let check_expected_peer_id (point_info : 'a P2p_point_state.Info.t option) return_unit) let raw_authenticate t ?point_info canceler scheduled_conn point = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let incoming = point_info = None in let incoming_str = if incoming then "incoming" else "outgoing" in let*! () = Events.(emit authenticate_start) (point, incoming_str) in @@ -360,7 +360,7 @@ let raw_authenticate t ?point_info canceler scheduled_conn point = (* [acceptable] is either Ok with a network version, or a Rejecting error with a motive *) let acceptable = - let open Tzresult_syntax in + let open Result_syntax in let* version = Network_version.select ~chain_name:t.message_config.chain_name @@ -430,10 +430,10 @@ let raw_authenticate t ?point_info canceler scheduled_conn point = t.custom_p2p_versions, info.announced_version.p2p_version ) in - fail + tzfail (P2p_errors.Rejected_no_common_protocol {announced = info.announced_version}) - | _ -> fail (P2p_errors.Rejected {peer = info.peer_id; motive})) + | _ -> tzfail (P2p_errors.Rejected {peer = info.peer_id; motive})) | Error errs as err -> let*! () = Events.(emit authenticate_status) ("reject", point, info.peer_id) @@ -530,7 +530,7 @@ let raw_authenticate t ?point_info canceler scheduled_conn point = return conn let authenticate t ?point_info canceler fd point = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let scheduled_conn = P2p_io_scheduler.register t.io_sched fd in let*! r = raw_authenticate t ?point_info canceler scheduled_conn point in match r with @@ -587,14 +587,14 @@ let accept t fd point = (Printexc.to_string exc)) let fail_unless_disconnected_point point_info = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match P2p_point_state.get point_info with | Disconnected -> return_unit - | Requested _ | Accepted _ -> fail P2p_errors.Pending_connection - | Running _ -> fail P2p_errors.Connected + | Requested _ | Accepted _ -> tzfail P2p_errors.Pending_connection + | Running _ -> tzfail P2p_errors.Connected let connect ?timeout t point = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = fail_when (P2p_pool.Points.banned t.pool point) @@ -643,7 +643,7 @@ let connect ?timeout t point = close_res ; match err with | [Exn (Unix.Unix_error (Unix.ECONNREFUSED, _, _))] -> - fail P2p_errors.Connection_refused + tzfail P2p_errors.Connection_refused | err -> Lwt.return_error err) in let*! () = Events.(emit connect_status) ("authenticate", point) in diff --git a/src/lib_p2p/p2p_directory.ml b/src/lib_p2p/p2p_directory.ml index 14452a37619a6ed865bc2d5526113277157814a2..5fd7d512ff58cd33e81320e92f8805981ce5743b 100644 --- a/src/lib_p2p/p2p_directory.ml +++ b/src/lib_p2p/p2p_directory.ml @@ -84,7 +84,7 @@ let info_of_peer_info pool i = } let build_rpc_directory net = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let dir = RPC_directory.empty in (* Network : Global *) (* DEPRECATED: use [version] from "lib_shell_services/version_services" @@ -101,13 +101,13 @@ let build_rpc_directory net = let dir = RPC_directory.register0 dir P2p_services.S.self (fun () () -> match P2p.pool net with - | None -> fail P2p_errors.P2p_layer_disabled + | None -> tzfail P2p_errors.P2p_layer_disabled | Some pool -> return (P2p_pool.config pool).identity.peer_id) in let dir = RPC_directory.register0 dir P2p_services.S.stat (fun () () -> match P2p.connect_handler net with - | None -> fail P2p_errors.P2p_layer_disabled + | None -> tzfail P2p_errors.P2p_layer_disabled | Some connect_handler -> return (P2p_connect_handler.stat connect_handler)) in @@ -120,9 +120,8 @@ let build_rpc_directory net = in let dir = RPC_directory.register1 dir P2p_services.S.connect (fun point q () -> - let open Lwt_tzresult_syntax in match P2p.connect_handler net with - | None -> fail P2p_errors.P2p_layer_disabled + | None -> tzfail P2p_errors.P2p_layer_disabled | Some connect_handler -> let* _conn = P2p_connect_handler.connect @@ -159,7 +158,7 @@ let build_rpc_directory net = let dir = RPC_directory.register0 dir P2p_services.Connections.S.list (fun () () -> match P2p.pool net with - | None -> fail P2p_errors.P2p_layer_disabled + | None -> tzfail P2p_errors.P2p_layer_disabled | Some pool -> return @@ P2p_pool.Connection.fold pool ~init:[] ~f:(fun _peer_id c acc -> @@ -169,7 +168,7 @@ let build_rpc_directory net = let dir = RPC_directory.register0 dir P2p_services.Peers.S.list (fun q () -> match P2p.pool net with - | None -> fail P2p_errors.P2p_layer_disabled + | None -> tzfail P2p_errors.P2p_layer_disabled | Some pool -> return @@ P2p_pool.Peers.fold_known pool ~init:[] ~f:(fun peer_id i a -> @@ -186,7 +185,7 @@ let build_rpc_directory net = P2p_services.Peers.S.info (fun peer_id () () -> match P2p.pool net with - | None -> fail P2p_errors.P2p_layer_disabled + | None -> tzfail P2p_errors.P2p_layer_disabled | Some pool -> return @@ Option.map @@ -304,7 +303,7 @@ let build_rpc_directory net = P2p_services.Peers.S.banned (fun peer_id () () -> match P2p.pool net with - | None -> fail P2p_errors.P2p_layer_disabled + | None -> tzfail P2p_errors.P2p_layer_disabled | Some pool when P2p_pool.Peers.get_trusted pool peer_id -> return_false | Some pool -> return (P2p_pool.Peers.banned pool peer_id)) in @@ -314,14 +313,14 @@ let build_rpc_directory net = P2p_services.ACL.S.get_greylisted_peers (fun () () -> match P2p.pool net with - | None -> fail P2p_errors.P2p_layer_disabled + | None -> tzfail P2p_errors.P2p_layer_disabled | Some pool -> return (P2p_pool.Peers.get_greylisted_list pool)) in (* Network : Point *) let dir = RPC_directory.register0 dir P2p_services.Points.S.list (fun q () -> match P2p.pool net with - | None -> fail P2p_errors.P2p_layer_disabled + | None -> tzfail P2p_errors.P2p_layer_disabled | Some pool -> return @@ P2p_pool.Points.fold_known pool ~init:[] ~f:(fun point i a -> @@ -338,7 +337,7 @@ let build_rpc_directory net = P2p_services.Points.S.info (fun point () () -> match P2p.pool net with - | None -> fail P2p_errors.P2p_layer_disabled + | None -> tzfail P2p_errors.P2p_layer_disabled | Some pool -> return @@ Option.map info_of_point_info (P2p_pool.Points.info pool point)) @@ -468,7 +467,7 @@ let build_rpc_directory net = P2p_services.ACL.S.get_greylisted_ips (fun () () -> match P2p.pool net with - | None -> fail P2p_errors.P2p_layer_disabled + | None -> tzfail P2p_errors.P2p_layer_disabled | Some pool -> return { @@ -481,7 +480,7 @@ let build_rpc_directory net = let dir = RPC_directory.register0 dir P2p_services.ACL.S.clear (fun () () -> match P2p.pool net with - | None -> fail P2p_errors.P2p_layer_disabled + | None -> tzfail P2p_errors.P2p_layer_disabled | Some pool -> P2p_pool.acl_clear pool ; return_unit) diff --git a/src/lib_p2p/p2p_io_scheduler.ml b/src/lib_p2p/p2p_io_scheduler.ml index 1779582f849645be7d3b6de50d3d60232b2abbbf..458ab8c51a4b54a879aee2f6cceb7b3d543bbd39 100644 --- a/src/lib_p2p/p2p_io_scheduler.ml +++ b/src/lib_p2p/p2p_io_scheduler.ml @@ -288,7 +288,7 @@ module Scheduler (IO : IO) = struct in_param; out_param; current_pop = Lwt.fail Not_found (* dummy *); - current_push = Lwt_tzresult_syntax.return_unit; + current_push = Lwt_result_syntax.return_unit; counter = Moving_average.create st.ma_state ~init:0 ~alpha; quota = 0; } @@ -360,18 +360,18 @@ module ReadIO = struct Invariant: Given a connection, there is not concurrent call to pop. *) let pop {fd; maxlen; read_buffer} = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt.catch (fun () -> let*! data = Circular_buffer.write ~maxlen ~fill_using:(P2p_fd.read fd) read_buffer in if Circular_buffer.length data = 0 then - fail P2p_errors.Connection_closed + tzfail P2p_errors.Connection_closed else return data) (function | Unix.Unix_error (Unix.ECONNRESET, _, _) -> - fail P2p_errors.Connection_closed + tzfail P2p_errors.Connection_closed | exn -> fail_with_exn exn) type out_param = Circular_buffer.data tzresult Lwt_pipe.Maybe_bounded.t @@ -416,7 +416,7 @@ module WriteIO = struct (* [push] bytes in the network. *) let push fd buf = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt.catch (fun () -> let*! () = P2p_fd.write fd buf in @@ -425,7 +425,7 @@ module WriteIO = struct | Unix.Unix_error (Unix.ECONNRESET, _, _) | Unix.Unix_error (Unix.EPIPE, _, _) | Lwt.Canceled | End_of_file -> - fail P2p_errors.Connection_closed + tzfail P2p_errors.Connection_closed | exn -> fail_with_exn exn) (* [close] does nothing, it will still be possible to push values to @@ -642,7 +642,7 @@ let stat {read_conn; write_conn; _} = (* [close conn] prevents further data to be pushed to the remote peer and start a cascade of effects that should close the connection. *) let close ?timeout conn = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let id = P2p_fd.id conn.fd in conn.remove_from_connection_table () ; Lwt_pipe.Maybe_bounded.close conn.write_queue ; diff --git a/src/lib_p2p/p2p_socket.ml b/src/lib_p2p/p2p_socket.ml index 782d0f5d7438d477ce7bf087068f8fe60bf17654..dc93f69be6885a91357b10d32dfaaeeb4aaca3a2 100644 --- a/src/lib_p2p/p2p_socket.ml +++ b/src/lib_p2p/p2p_socket.ml @@ -55,7 +55,7 @@ module Crypto = struct (* msg is overwritten and should not be used after this invocation *) let write_chunk ?canceler fd cryptobox_data msg = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let msg_length = Bytes.length msg in let* () = fail_unless @@ -75,7 +75,7 @@ module Crypto = struct P2p_io_scheduler.write ?canceler fd payload let read_chunk ?canceler fd cryptobox_data = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open P2p_buffer_reader in let header_buf = Bytes.create header_length in let* () = read_full ?canceler fd @@ mk_buffer_safe header_buf in @@ -100,7 +100,7 @@ module Crypto = struct tag msg with - | false -> fail P2p_errors.Decipher_error + | false -> tzfail P2p_errors.Decipher_error | true -> return msg end @@ -141,7 +141,7 @@ module Connection_message = struct (req "version" Network_version.encoding)) let write ~canceler fd message = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let encoded_message_len = Data_encoding.Binary.length encoding message in let* () = fail_unless @@ -158,7 +158,7 @@ module Connection_message = struct ~allowed_bytes:encoded_message_len in match Data_encoding.Binary.write encoding message state with - | Error we -> fail (Tezos_base.Data_encoding_wrapper.Encoding_error we) + | Error we -> tzfail (Tezos_base.Data_encoding_wrapper.Encoding_error we) | Ok last -> let* () = fail_unless @@ -172,7 +172,7 @@ module Connection_message = struct return buf let read ~canceler fd = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open P2p_buffer_reader in let header_buf = Bytes.create Crypto.header_length in let* () = read_full ~canceler fd @@ mk_buffer_safe header_buf in @@ -193,16 +193,16 @@ module Connection_message = struct in let buf = Bytes.unsafe_to_string buf in match Data_encoding.Binary.read encoding buf pos len with - | Error re -> fail (P2p_errors.Decoding_error re) + | Error re -> tzfail (P2p_errors.Decoding_error re) | Ok (next_pos, message) -> if next_pos <> pos + len then - fail (P2p_errors.Decoding_error Data_encoding.Binary.Extra_bytes) + tzfail (P2p_errors.Decoding_error Data_encoding.Binary.Extra_bytes) else return (message, buf) end module Metadata = struct let write ~canceler metadata_config cryptobox_data fd message = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let encoded_message_len = Data_encoding.Binary.length metadata_config.P2p_params.conn_meta_encoding @@ -222,7 +222,7 @@ module Metadata = struct message state with - | Error we -> fail (Tezos_base.Data_encoding_wrapper.Encoding_error we) + | Error we -> tzfail (Tezos_base.Data_encoding_wrapper.Encoding_error we) | Ok last -> let* () = fail_unless @@ -232,16 +232,16 @@ module Metadata = struct Crypto.write_chunk ~canceler cryptobox_data fd buf let read ~canceler metadata_config fd cryptobox_data = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* buf = Crypto.read_chunk ~canceler fd cryptobox_data in let buf = Bytes.unsafe_to_string buf in let length = String.length buf in let encoding = metadata_config.P2p_params.conn_meta_encoding in match Data_encoding.Binary.read encoding buf 0 length with - | Error re -> fail (P2p_errors.Decoding_error re) + | Error re -> tzfail (P2p_errors.Decoding_error re) | Ok (read_len, message) -> if read_len <> length then - fail (P2p_errors.Decoding_error Data_encoding.Binary.Extra_bytes) + tzfail (P2p_errors.Decoding_error Data_encoding.Binary.Extra_bytes) else return message end @@ -295,7 +295,7 @@ module Ack = struct union [ack_case (Tag 0); nack_v_0_case (Tag 255); nack_case (Tag 1)] let write ?canceler fd cryptobox_data message = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let encoded_message_len = Data_encoding.Binary.length encoding message in let buf = Bytes.create encoded_message_len in let state = @@ -306,7 +306,7 @@ module Ack = struct ~allowed_bytes:encoded_message_len in match Data_encoding.Binary.write encoding message state with - | Error we -> fail (Tezos_base.Data_encoding_wrapper.Encoding_error we) + | Error we -> tzfail (Tezos_base.Data_encoding_wrapper.Encoding_error we) | Ok last -> let* () = fail_unless @@ -316,15 +316,15 @@ module Ack = struct Crypto.write_chunk ?canceler fd cryptobox_data buf let read ?canceler fd cryptobox_data = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* buf = Crypto.read_chunk ?canceler fd cryptobox_data in let buf = Bytes.unsafe_to_string buf in let length = String.length buf in match Data_encoding.Binary.read encoding buf 0 length with - | Error re -> fail (P2p_errors.Decoding_error re) + | Error re -> tzfail (P2p_errors.Decoding_error re) | Ok (read_len, message) -> if read_len <> length then - fail (P2p_errors.Decoding_error Data_encoding.Binary.Extra_bytes) + tzfail (P2p_errors.Decoding_error Data_encoding.Binary.Extra_bytes) else return message end @@ -362,7 +362,7 @@ let nack {scheduled_conn; cryptobox_data; info} motive let authenticate ~canceler ~proof_of_work_target ~incoming scheduled_conn ((remote_addr, remote_socket_port) as point) ?advertised_port identity announced_version metadata_config = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let local_nonce_seed = Crypto_box.random_nonce () in let*! () = Events.(emit sending_authentication) point in let* sent_msg = @@ -452,14 +452,14 @@ module Reader = struct let read_message st init = let rec loop status = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Lwt.pause () in let open Data_encoding.Binary in match status with | Success {result; size; stream} -> return (result, size, stream) | Error err -> let*! () = Events.(emit read_error) () in - fail (P2p_errors.Decoding_error err) + tzfail (P2p_errors.Decoding_error err) | Await decode_next_buf -> let* buf = Crypto.read_chunk @@ -561,7 +561,7 @@ module Writer = struct let encode_message st msg = match Data_encoding.Binary.to_bytes st.encoding msg with | Error we -> - Tzresult_syntax.fail + Result_syntax.tzfail (Tezos_base.Data_encoding_wrapper.Encoding_error we) | Ok bytes -> Ok (Utils.cut st.binary_chunks_size bytes) @@ -589,7 +589,7 @@ module Writer = struct (fun u -> Lwt.wakeup_later u - (Tzresult_syntax.fail P2p_errors.Connection_closed)) + (Result_syntax.tzfail P2p_errors.Connection_closed)) wakener ; match err with | (Canceled | Exn Lwt_pipe.Closed) :: _ -> @@ -689,7 +689,7 @@ let private_node {conn; _} = conn.info.private_node let accept ?incoming_message_queue_size ?outgoing_message_queue_size ?binary_chunks_size ~canceler conn encoding = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* ack = protect (fun () -> @@ -706,8 +706,8 @@ let accept ?incoming_message_queue_size ?outgoing_message_queue_size in match err with | [P2p_errors.Connection_closed] -> - fail P2p_errors.Rejected_socket_connection - | [P2p_errors.Decipher_error] -> fail P2p_errors.Invalid_auth + tzfail P2p_errors.Rejected_socket_connection + | [P2p_errors.Decipher_error] -> tzfail P2p_errors.Invalid_auth | err -> Lwt.return_error err) in match ack with @@ -732,23 +732,23 @@ let accept ?incoming_message_queue_size ?outgoing_message_queue_size Lwt.return_unit) ; return conn | Nack_v_0 -> - fail + tzfail (P2p_errors.Rejected_by_nack {motive = P2p_rejection.No_motive; alternative_points = None}) | Nack {motive; potential_peers_to_connect} -> - fail + tzfail (P2p_errors.Rejected_by_nack {motive; alternative_points = Some potential_peers_to_connect}) let catch_closed_pipe f = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! r = Lwt.catch f (function - | Lwt_pipe.Closed -> fail P2p_errors.Connection_closed + | Lwt_pipe.Closed -> tzfail P2p_errors.Connection_closed | exn -> fail_with_exn exn) in match r with - | Error (Exn Lwt_pipe.Closed :: _) -> fail P2p_errors.Connection_closed + | Error (Exn Lwt_pipe.Closed :: _) -> tzfail P2p_errors.Connection_closed | (Error _ | Ok _) as v -> Lwt.return v let write {writer; _} msg = @@ -769,10 +769,10 @@ let write_sync {writer; _} msg = waiter) let write_now {writer; _} msg = - let open Tzresult_syntax in + let open Result_syntax in let* buf = Writer.encode_message writer msg in try Ok (Lwt_pipe.Maybe_bounded.push_now writer.messages (buf, None)) - with Lwt_pipe.Closed -> fail P2p_errors.Connection_closed + with Lwt_pipe.Closed -> tzfail P2p_errors.Connection_closed let rec split_bytes size bytes = if Bytes.length bytes <= size then [bytes] @@ -796,7 +796,7 @@ let read {reader; _} = let read_now {reader; _} = try Lwt_pipe.Maybe_bounded.pop_now reader.messages with Lwt_pipe.Closed -> - Some (Tzresult_syntax.fail P2p_errors.Connection_closed) + Some (Result_syntax.tzfail P2p_errors.Connection_closed) let stat {conn = {scheduled_conn; _}; _} = P2p_io_scheduler.stat scheduled_conn diff --git a/src/lib_p2p/p2p_welcome.ml b/src/lib_p2p/p2p_welcome.ml index 208c36c168148e04bb6923090576378ade0309ae..c69e2942a155852ef179704bdb159b60e1e8e5de 100644 --- a/src/lib_p2p/p2p_welcome.ml +++ b/src/lib_p2p/p2p_welcome.ml @@ -152,7 +152,7 @@ let rec worker_loop st = | Error err -> Events.(emit unexpected_error) err let create_listening_socket ~backlog ?(addr = Ipaddr.V6.unspecified) port = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt.catch (fun () -> let main_socket = Lwt_unix.(socket PF_INET6 SOCK_STREAM 0) in @@ -166,13 +166,13 @@ let create_listening_socket ~backlog ?(addr = Ipaddr.V6.unspecified) port = return main_socket) (function | Unix.Unix_error (err, _, _) -> - fail + tzfail (Failed_to_open_listening_socket {reason = err; address = addr; port}) | exn -> Lwt.fail exn) let create ?addr ~backlog connect_handler port = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt.catch (fun () -> let* socket = create_listening_socket ~backlog ?addr port in @@ -193,7 +193,7 @@ let create ?addr ~backlog connect_handler port = (fun exn -> let error = error_of_exn exn in let*! () = Events.(emit incoming_connection_error) error in - fail error) + tzfail error) let activate st = st.worker <- diff --git a/src/lib_p2p/test/node.ml b/src/lib_p2p/test/node.ml index 802d0121134042481834c4795329d3b1b9d3b24a..a6b05628b3b2669ede262d4eb94389c1963e1b6d 100644 --- a/src/lib_p2p/test/node.ml +++ b/src/lib_p2p/test/node.ml @@ -321,6 +321,6 @@ let detach_nodes ?timeout ?prefix ?min_connections ?max_connections port) points in - let*? nodes = Error_monad.Tzresult_syntax.all nodes in + let*? nodes = Error_monad.Result_syntax.tzall nodes in Lwt.ignore_result (sync_nodes nodes) ; Process.wait_all nodes diff --git a/src/lib_p2p/test/p2p_test_utils.ml b/src/lib_p2p/test/p2p_test_utils.ml index 55351af64d13b9d54e86fdcc5bb0f94a78f0a066..21cd70fa85fe29dc71ed623740d0220cde8914fe 100644 --- a/src/lib_p2p/test/p2p_test_utils.ml +++ b/src/lib_p2p/test/p2p_test_utils.ml @@ -50,7 +50,7 @@ type 'a timeout_t = {time : float; msg : 'a -> string} [timeout] is exceed an error is raised. There is a Lwt cooperation point. *) let wait_pred ?timeout ~pred ~arg () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let rec inner_wait_pred () = let*! () = Lwt.pause () in if not (pred arg) then inner_wait_pred () else return_unit @@ -61,12 +61,12 @@ let wait_pred ?timeout ~pred ~arg () = Lwt.pick [ (let*! () = Lwt_unix.sleep timeout.time in - fail (Timeout_exceed (timeout.msg arg))); + tzfail (Timeout_exceed (timeout.msg arg))); inner_wait_pred (); ] let wait_pred_s ?timeout ~pred ~arg () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let rec inner_wait_pred () = let*! () = Lwt.pause () in let*! cond = pred arg in @@ -78,7 +78,7 @@ let wait_pred_s ?timeout ~pred ~arg () = Lwt.pick [ (let*! () = Lwt_unix.sleep timeout.time in - fail (Timeout_exceed (timeout.msg arg))); + tzfail (Timeout_exceed (timeout.msg arg))); inner_wait_pred (); ] diff --git a/src/lib_p2p/test/process.ml b/src/lib_p2p/test/process.ml index 0b4190945862cbe3a265d675071351eaf8a5551c..a083d1eea4f7214fb7bff9bff73cd07b4e34cdec 100644 --- a/src/lib_p2p/test/process.ml +++ b/src/lib_p2p/test/process.ml @@ -55,7 +55,7 @@ let dummy_encoding flags : 'a Data_encoding.encoding = Data_encoding.bytes let write ~value_encoding ~flags outch v = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let value_encoding = Option.value ~default:(dummy_encoding flags) value_encoding in @@ -77,7 +77,7 @@ let write ~value_encoding ~flags outch v = @@ TzTrace.cons (error_of_fmt "write error %s" __LOC__) trace) let read ~value_encoding ~flags inch = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let value_encoding = Option.value ~default:(dummy_encoding flags) value_encoding in @@ -180,7 +180,7 @@ let terminate pid = Lwt.return_unit let wait ~value_encoding ~flags pid result_ch = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt.catch (fun () -> let*! s = Lwt_unix.waitpid [] pid in @@ -193,7 +193,7 @@ let wait ~value_encoding ~flags pid result_ch = (function | Lwt.Canceled -> let*! () = terminate pid in - fail Canceled + tzfail Canceled | exn -> fail_with_exn exn) type ('a, 'b, 'c) t = { diff --git a/src/lib_p2p/test/test_p2p_node.ml b/src/lib_p2p/test/test_p2p_node.ml index 4ff43b9f6e71b2a907ad67ed7cbaea2c32bdb563..23e7d41d87098fdb636e33e9400179a7b5cbe1d7 100644 --- a/src/lib_p2p/test/test_p2p_node.ml +++ b/src/lib_p2p/test/test_p2p_node.ml @@ -70,14 +70,14 @@ let () = In [propagation_tzresult] a random [node] is selected to fail with an error. Then it is checked that the result of [Node.detach_nodes] is an error. *) let propagation_tzresult points = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let x = Random.int (List.length points) in let*! r = Node.detach_nodes - (fun i _ -> if x = i then fail Some_error else return_unit) + (fun i _ -> if x = i then tzfail Some_error else return_unit) points in - match r with Ok () -> fail Invalid_test_result | Error _ -> return_unit + match r with Ok () -> tzfail Invalid_test_result | Error _ -> return_unit let points = ref [] diff --git a/src/lib_p2p/test/test_p2p_pool.ml b/src/lib_p2p/test/test_p2p_pool.ml index 1bbd16c171bf5677377acebefb14455353419126..c55fe2934d5d0d17ff8e526ca037de37c3b56a66 100644 --- a/src/lib_p2p/test/test_p2p_pool.ml +++ b/src/lib_p2p/test/test_p2p_pool.ml @@ -313,7 +313,7 @@ module Overcrowded = struct and either get a list of pairs or have an established connection. *) let client_connect connect_handler pool legacy trusted_points all_points = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in debug "@[client connects to %a in the universe @[%a@]@]@." P2p_point.Id.pp_list @@ -427,7 +427,7 @@ module Overcrowded = struct (Advertisement_failure unknowns) let client legacy (node : Node.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in if Compare.List_length_with.(node.points > 50) then ( log_error "This test only works for less clients than the advertisement list \ @@ -463,7 +463,7 @@ module Overcrowded = struct (** Code of the target that should be overcrowded by all the clients. *) let target (node : Node.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let unknowns_knowns () = P2p_pool.Points.fold_known node.pool @@ -625,7 +625,7 @@ module No_common_network = struct and either get a list of pairs or have an established connection. *) let client_connect connect_handler pool trusted_points all_points = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in debug "@[client connects to %a in the universe @[%a@]@]@." P2p_point.Id.pp_list diff --git a/src/lib_p2p/test/test_p2p_socket.ml b/src/lib_p2p/test/test_p2p_socket.ml index bb4906028de7ca8215433943a3ea01d10331c399..e14830c38a33cfd8dd1249454aea2be4d51ab6d8 100644 --- a/src/lib_p2p/test/test_p2p_socket.ml +++ b/src/lib_p2p/test/test_p2p_socket.ml @@ -39,7 +39,7 @@ include Internal_event.Legacy_logging.Make (struct end) let tzassert b pos = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let p (file, lnum, cnum, _) = (file, lnum, cnum) in if b then return_unit else fail_with_exn (Assert_failure (p pos)) @@ -129,7 +129,7 @@ module Crypto_test = struct tzassert (payload_length = i) __POS__ let read_chunk fd cryptobox_data = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let header_buf = Bytes.create header_length in let* i = return (Unix.read fd header_buf 0 header_length) in let* () = tzassert (header_length = i) __POS__ in diff --git a/src/lib_protocol_environment/environment_V0.ml b/src/lib_protocol_environment/environment_V0.ml index c8340b3246b86ab1c4cf6df027f0104efdaf1e19..e3b0a3992f2390f235cf71493a93636ef0152b09 100644 --- a/src/lib_protocol_environment/environment_V0.ml +++ b/src/lib_protocol_environment/environment_V0.ml @@ -378,7 +378,7 @@ struct include Error_core include Tezos_error_monad.TzLwtreslib.Monad include - Tezos_error_monad.Monad_extension_maker.Make (Error_core) (TzTrace) + Tezos_error_monad.Monad_maker.Make (Error_core) (TzTrace) (Tezos_error_monad.TzLwtreslib.Monad) (* below is for backward compatibility *) diff --git a/src/lib_protocol_environment/environment_V1.ml b/src/lib_protocol_environment/environment_V1.ml index aa85063df0355876f4548c7704dfc994da968228..27fe11804bfab1c6337d3a0929373e4782296531 100644 --- a/src/lib_protocol_environment/environment_V1.ml +++ b/src/lib_protocol_environment/environment_V1.ml @@ -565,7 +565,7 @@ struct include Error_core include Tezos_error_monad.TzLwtreslib.Monad include - Tezos_error_monad.Monad_extension_maker.Make (Error_core) (TzTrace) + Tezos_error_monad.Monad_maker.Make (Error_core) (TzTrace) (Tezos_error_monad.TzLwtreslib.Monad) (* Backwards compatibility additions (traversors, dont_wait, trace) *) @@ -585,11 +585,11 @@ struct (* Shouldn't be used, only to keep the same environment interface *) let classify_error error = (find_info_of_error error).category - let both_e = Tzresult_syntax.both + let both_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.both - let join_e = Tzresult_syntax.join + let join_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.join - let all_e = Tzresult_syntax.all + let all_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.all end let () = diff --git a/src/lib_protocol_environment/environment_V2.ml b/src/lib_protocol_environment/environment_V2.ml index ebac989eb089714d8088a53966086a1851ca0a25..3e9d2f4ff3a0a80e8e0e38fde9664f5794b58593 100644 --- a/src/lib_protocol_environment/environment_V2.ml +++ b/src/lib_protocol_environment/environment_V2.ml @@ -573,7 +573,7 @@ struct include Error_core include Tezos_error_monad.TzLwtreslib.Monad include - Tezos_error_monad.Monad_extension_maker.Make (Error_core) (TzTrace) + Tezos_error_monad.Monad_maker.Make (Error_core) (TzTrace) (Tezos_error_monad.TzLwtreslib.Monad) (* Backwards compatibility additions (traversors, dont_wait, trace helpers) *) @@ -597,11 +597,11 @@ struct (* Shouldn't be used, only to keep the same environment interface *) let classify_error error = (find_info_of_error error).category - let both_e = Tzresult_syntax.both + let both_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.both - let join_e = Tzresult_syntax.join + let join_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.join - let all_e = Tzresult_syntax.all + let all_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.all end let () = diff --git a/src/lib_protocol_environment/environment_V3.ml b/src/lib_protocol_environment/environment_V3.ml index 831017b7b8e679f4efe867b26f8d207204ac7e2b..59a0966c87312571fdffb747c9f4c34ab4f0d1fe 100644 --- a/src/lib_protocol_environment/environment_V3.ml +++ b/src/lib_protocol_environment/environment_V3.ml @@ -660,7 +660,7 @@ struct include Error_core include Tezos_error_monad.TzLwtreslib.Monad include - Tezos_error_monad.Monad_extension_maker.Make (Error_core) (TzTrace) + Tezos_error_monad.Monad_maker.Make (Error_core) (TzTrace) (Tezos_error_monad.TzLwtreslib.Monad) (* Backwards compatibility additions (dont_wait, trace helpers) *) @@ -720,11 +720,11 @@ struct (* Shouldn't be used, only to keep the same environment interface *) let classify_error error = (find_info_of_error error).category - let both_e = Tzresult_syntax.both + let both_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.both - let join_e = Tzresult_syntax.join + let join_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.join - let all_e = Tzresult_syntax.all + let all_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.all end let () = diff --git a/src/lib_protocol_environment/environment_V4.ml b/src/lib_protocol_environment/environment_V4.ml index 0d894ecf713c4893e2a7a665dee60acf22af374f..f170ce1e77d4496d9a85ef8e509f399b21ea6300 100644 --- a/src/lib_protocol_environment/environment_V4.ml +++ b/src/lib_protocol_environment/environment_V4.ml @@ -709,7 +709,7 @@ struct include Error_core include Tezos_error_monad.TzLwtreslib.Monad include - Tezos_error_monad.Monad_extension_maker.Make (Error_core) (TzTrace) + Tezos_error_monad.Monad_maker.Make (Error_core) (TzTrace) (Tezos_error_monad.TzLwtreslib.Monad) (* Backwards compatibility additions (dont_wait, trace helpers) *) @@ -761,11 +761,11 @@ struct let+ r = Result.catch_s ?catch_only f in Result.map_error (fun e -> error_of_exn e) r - let both_e = Tzresult_syntax.both + let both_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.both - let join_e = Tzresult_syntax.join + let join_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.join - let all_e = Tzresult_syntax.all + let all_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.all end let () = diff --git a/src/lib_protocol_environment/environment_V5.ml b/src/lib_protocol_environment/environment_V5.ml index cda3ffaa6bb08a6ff61b6bf7dc4ba0340d8ce50d..6cb3e277ebd329bf7b4ef875ef458365ada3b2d5 100644 --- a/src/lib_protocol_environment/environment_V5.ml +++ b/src/lib_protocol_environment/environment_V5.ml @@ -682,7 +682,7 @@ struct module Tzresult_syntax = Traced_result_syntax module Lwt_tzresult_syntax = Lwt_traced_result_syntax include - Tezos_error_monad.Monad_extension_maker.Make (Error_core) (TzTrace) + Tezos_error_monad.Monad_maker.Make (Error_core) (TzTrace) (Tezos_error_monad.TzLwtreslib.Monad) (* Backwards compatibility additions (dont_wait, trace helpers) *) @@ -734,11 +734,11 @@ struct let+ r = Result.catch_s ?catch_only f in Result.map_error (fun e -> error_of_exn e) r - let both_e = Tzresult_syntax.both + let both_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.both - let join_e = Tzresult_syntax.join + let join_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.join - let all_e = Tzresult_syntax.all + let all_e = Tezos_error_monad.TzLwtreslib.Monad.Traced_result_syntax.all end let () = diff --git a/src/lib_protocol_updater/registered_protocol.ml b/src/lib_protocol_updater/registered_protocol.ml index 2bb14299b157c12927d19e4c5b1f2867aa6651f7..4f661cbfcf5ec44dba7e647aa03017b7ff73df04 100644 --- a/src/lib_protocol_updater/registered_protocol.ml +++ b/src/lib_protocol_updater/registered_protocol.ml @@ -203,10 +203,10 @@ let () = (fun hash -> Unregistered_protocol hash) let get_result hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match get hash with | Some hash -> return hash - | None -> fail (Unregistered_protocol hash) + | None -> tzfail (Unregistered_protocol hash) let seq () = VersionTable.to_seq_values versions diff --git a/src/lib_proxy/light_internal.ml b/src/lib_proxy/light_internal.ml index 5ac69834ce60779b8b1c6c7f8adcf51366863101..1b2fd916a4c937fe326c326b629e12388620959d 100644 --- a/src/lib_proxy/light_internal.ml +++ b/src/lib_proxy/light_internal.ml @@ -189,7 +189,7 @@ module Merkle = struct else return_none let union_irmin_tree_merkle_tree repo tree mtree = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* tree_opt = union_irmin_tree_merkle_tree repo [] tree mtree in let tree = Option.value ~default:tree tree_opt in return tree diff --git a/src/lib_proxy/proxy_getter.ml b/src/lib_proxy/proxy_getter.ml index 3aab45a5bf744813657b5c05c066750cd4a9f5bf..d75adfd7d26eb12172d1bc43a470f6bbd200a145 100644 --- a/src/lib_proxy/proxy_getter.ml +++ b/src/lib_proxy/proxy_getter.ml @@ -241,7 +241,7 @@ module Core let do_rpc : Proxy.proxy_getter_input -> Local.key -> unit tzresult Lwt.t = fun pgi key -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* tree = X.do_rpc pgi key in let*! current_store = lazy_load_store () in (* Update cache with data obtained *) @@ -259,7 +259,7 @@ module Make (C : Proxy.CORE) (X : Proxy_proto.PROTO_RPC) : M = struct (** Handles the application of [X.split_key] to optimize queries. *) let do_rpc (pgi : Proxy.proxy_getter_input) (kind : kind) (requested_key : Local.key) : unit tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let (key_to_get, split) = match kind with | Mem -> @@ -312,7 +312,7 @@ module Make (C : Proxy.CORE) (X : Proxy_proto.PROTO_RPC) : M = struct Local.key -> Local.tree option tzresult Lwt.t = fun (kind : kind) (pgi : Proxy.proxy_getter_input) (key : Local.key) -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = if is_all key then (* This exact request was done already. @@ -332,7 +332,7 @@ module Make (C : Proxy.CORE) (X : Proxy_proto.PROTO_RPC) : M = struct let proxy_get pgi key = generic_call Get pgi key let proxy_dir_mem pgi key = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* tree_opt = generic_call Mem pgi key in match tree_opt with | None -> return_false @@ -342,7 +342,7 @@ module Make (C : Proxy.CORE) (X : Proxy_proto.PROTO_RPC) : M = struct | `Value -> return_false) let proxy_mem pgi key = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* tree_opt = generic_call Mem pgi key in match tree_opt with | None -> return_false diff --git a/src/lib_proxy/proxy_services.ml b/src/lib_proxy/proxy_services.ml index 7eff842de0ade80e06233dfb1f87557fb68d3e6c..00e4fcdc6f9c6dc29283b7a0ff30e4cb34219045 100644 --- a/src/lib_proxy/proxy_services.ml +++ b/src/lib_proxy/proxy_services.ml @@ -76,7 +76,7 @@ module BlockToHashClient (S : Registration.Proxy_sig) : BLOCK_TO_HASH = struct let hash_of_block (rpc_context : #RPC_context.simple) (chain : Tezos_shell_services.Shell_services.chain) (block : Tezos_shell_services.Block_services.block) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match raw_hash_of_block block with | Some h -> (* Block is defined by its hash *) @@ -307,7 +307,7 @@ let build_directory (printer : Tezos_client_base.Client_context.printer) | Proxy_client | Light_client _ -> 16) in let get_env_rpc_context chain block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* block_hash_opt = B2H.hash_of_block rpc_context chain block in let (block_key, (fill_b2h : Block_hash.t -> unit)) = match block_hash_opt with diff --git a/src/lib_proxy/registration.ml b/src/lib_proxy/registration.ml index e118856888b45fc5d0734b8990d79c1157e85abd..756b39ba365fae77af71a2913d34302d64c4bf2d 100644 --- a/src/lib_proxy/registration.ml +++ b/src/lib_proxy/registration.ml @@ -28,7 +28,7 @@ open Tezos_shell_services let check_client_node_proto_agree (rpc_context : #RPC_context.simple) (proto_hash : Protocol_hash.t) (chain : Block_services.chain) (block : Block_services.block) : unit tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* {current_protocol; _} = Block_services.protocols rpc_context ~chain ~block () in @@ -44,7 +44,7 @@ let check_client_node_proto_agree (rpc_context : #RPC_context.simple) let get_node_protocol (rpc_context : #RPC_context.simple) (chain : Block_services.chain) (block : Block_services.block) : Protocol_hash.t tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* {current_protocol; _} = Block_services.protocols rpc_context ~chain ~block () in @@ -105,7 +105,7 @@ let get_registered_proxy (printer : Tezos_client_base.Client_context.printer) ?(chain = `Main) ?(block = `Head 0) (protocol_hash_opt : Protocol_hash.t option) : proxy_environment tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let mode_str = match mode with `Mode_light -> "light mode" | `Mode_proxy -> "proxy" in diff --git a/src/lib_proxy/test/test_fuzzing_light.ml b/src/lib_proxy/test/test_fuzzing_light.ml index 1ea475b024090a46fb8a2ec2a0ef6de349f3e1cf..20a83f2e2d833dcaff99d3cdc0d0a2532a7caa83 100644 --- a/src/lib_proxy/test/test_fuzzing_light.ml +++ b/src/lib_proxy/test/test_fuzzing_light.ml @@ -507,7 +507,7 @@ module Consensus = struct | Ok rogue_mtree -> rogue_mtree | _ -> QCheck2.assume_fail () else mtree) - |> Lwt_tzresult_syntax.return + |> Lwt.return_ok end : Tezos_proxy.Light_proto.PROTO_RPCS) let mock_printer () = diff --git a/src/lib_proxy/test/test_proxy.ml b/src/lib_proxy/test/test_proxy.ml index a52e9ff4c9c561710af4ca2b168d2e29fbf607ed..4a39cb9652816e9a066cf31cd747bc80de153d0a 100644 --- a/src/lib_proxy/test/test_proxy.ml +++ b/src/lib_proxy/test/test_proxy.ml @@ -76,7 +76,7 @@ let mock_proto_rpc () = in (* Remember call *) Stack.push k calls ; - Lwt_tzresult_syntax.return @@ mock_raw_context k + Lwt_result_syntax.return @@ mock_raw_context k end : MOCKED_PROTO_RPC) class mock_rpc_context : RPC_context.simple = diff --git a/src/lib_requester/requester.ml b/src/lib_requester/requester.ml index be79e860b07156413be0cbe83e48a3f638ed02b6..ea0b4166440d43cfd50546b863a6aae1606893b0 100644 --- a/src/lib_requester/requester.ml +++ b/src/lib_requester/requester.ml @@ -515,11 +515,11 @@ module Make (fun key -> Timeout key) let read s k = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Memory_table.find s.memory k with | None -> trace (Missing_data k) @@ Disk_table.read s.disk k | Some (Found v) -> return v - | Some (Pending _) -> fail (Missing_data k) + | Some (Pending _) -> tzfail (Missing_data k) let wrap s k ?timeout t = let open Lwt_syntax in @@ -533,13 +533,13 @@ module Make if data.waiters = 0 then ( Memory_table.remove s.memory k ; Scheduler.notify_cancellation s.scheduler k ; - Lwt.wakeup_later w (Tzresult_syntax.fail (Canceled k)))) ; + Lwt.wakeup_later w (Result_syntax.tzfail (Canceled k)))) ; match timeout with | None -> t | Some delay -> let timeout = let* () = Systime_os.sleep delay in - Lwt_tzresult_syntax.fail (Timeout k) + Lwt_result_syntax.tzfail (Timeout k) in Lwt.pick [t; timeout] @@ -632,7 +632,7 @@ module Make | Some (Pending {wakener = w; _}) -> Scheduler.notify_cancellation s.scheduler k ; Memory_table.remove s.memory k ; - Lwt.wakeup_later w (Tzresult_syntax.fail (Canceled k)) + Lwt.wakeup_later w (Result_syntax.tzfail (Canceled k)) | Some (Found _) -> Memory_table.remove s.memory k let watch s = Lwt_watcher.create_stream s.input diff --git a/src/lib_requester/requester_impl.ml b/src/lib_requester/requester_impl.ml index 6c774a25d4827d26e0065b9958716889854c0797..7f7b75772e97dbadd1dffe746e28d87c37e48dfa 100644 --- a/src/lib_requester/requester_impl.ml +++ b/src/lib_requester/requester_impl.ml @@ -50,7 +50,7 @@ module Disk_memory_table (P : PARAMETERS) = struct let known (st : store) (k : P.key) = Lwt.return @@ mem st k let read st k = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match find st k with Some v -> return v | None -> fail_with_exn Not_found let read_opt st k = Lwt.return @@ find st k diff --git a/src/lib_rpc/RPC_context.ml b/src/lib_rpc/RPC_context.ml index 6fbf28db3853b5c4e6952508a7f7bc3d5aac45e2..4f933027eb7d4dcb2e670b79e80551193c4951e3 100644 --- a/src/lib_rpc/RPC_context.ml +++ b/src/lib_rpc/RPC_context.ml @@ -113,19 +113,19 @@ let not_found s p q = let {RPC_service.meth; uri; _} = RPC_service.forge_partial_request s ~base p q in - Lwt_tzresult_syntax.fail (Not_found {meth; uri}) + Lwt_result_syntax.tzfail (Not_found {meth; uri}) let gone s p q = let {RPC_service.meth; uri; _} = RPC_service.forge_partial_request s ~base p q in - Lwt_tzresult_syntax.fail (Gone {meth; uri}) + Lwt_result_syntax.tzfail (Gone {meth; uri}) let error_with s p q = let {RPC_service.meth; uri; _} = RPC_service.forge_partial_request s ~base p q in - Lwt_tzresult_syntax.fail (Generic_error {meth; uri}) + Lwt_result_syntax.tzfail (Generic_error {meth; uri}) class ['pr] of_directory (dir : 'pr RPC_directory.t) = object diff --git a/src/lib_rpc_http/RPC_client.ml b/src/lib_rpc_http/RPC_client.ml index eede2b88618e19da573f47b7fa82406c8311938b..4cace450c09ffbfe7a96cbaa9c0a3ba77c760319 100644 --- a/src/lib_rpc_http/RPC_client.ml +++ b/src/lib_rpc_http/RPC_client.ml @@ -133,7 +133,7 @@ module Make (Client : Resto_cohttp_client.Client.CALL) = struct let request_failed meth uri error = let meth = (meth : [< RPC_service.meth] :> RPC_service.meth) in - Lwt_tzresult_syntax.fail + Lwt_result_syntax.tzfail (RPC_client_errors.Request_failed {meth; uri; error}) let generic_call ?headers ?accept ?body ?media meth uri : @@ -304,7 +304,7 @@ module Make (Client : Resto_cohttp_client.Client.CALL) = struct (* This function checks that the content type of the answer belongs to accepted ones in [accept]. If not, it is processed as an error. If the answer lacks content-type, the response is decoded as JSON if possible. *) let generic_media_type_call ?headers ~accept ?body meth uri : RPC_context.generic_call_result tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let body = Option.map (fun b -> Cohttp_lwt.Body.of_string (Data_encoding.Json.to_string b)) @@ -342,17 +342,17 @@ module Make (Client : Resto_cohttp_client.Client.CALL) = struct | Error _ -> return (`Other (content_type, other_resp))) let handle accept (meth, uri, ans) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match ans with | `Ok (Some v) -> return v | `Ok None -> request_failed meth uri Empty_answer - | `Gone None -> fail (RPC_context.Gone {meth; uri}) + | `Gone None -> tzfail (RPC_context.Gone {meth; uri}) | `Not_found None -> (* The client's proxy mode matches on the error raised here, to detect that a local RPC is unavailable at call_service and call_streamed_service, and hence that delegation to the endpoint must be done. *) - fail (RPC_context.Not_found {meth; uri}) + tzfail (RPC_context.Not_found {meth; uri}) | `Conflict (Some err) | `Error (Some err) | `Forbidden (Some err) @@ -363,7 +363,7 @@ module Make (Client : Resto_cohttp_client.Client.CALL) = struct | `Unauthorized None -> request_failed meth uri Unauthorized_uri | `Forbidden None -> request_failed meth uri Forbidden | `Conflict None | `Error None -> - fail (RPC_context.Generic_error {meth; uri}) + tzfail (RPC_context.Generic_error {meth; uri}) | `Unexpected_status_code (code, (content, _, media_type)) -> let media_type = Option.map Media_type.name media_type in let*! content = Cohttp_lwt.Body.to_string content in diff --git a/src/lib_sapling/test/example.ml b/src/lib_sapling/test/example.ml index 028706479fe287c500000be89dc34922c6b6173c..1b6ca40077807bc606aee35beda45a45761e0aa7 100644 --- a/src/lib_sapling/test/example.ml +++ b/src/lib_sapling/test/example.ml @@ -372,7 +372,7 @@ module Validator = struct let verify_update (transaction : Core.UTXO.transaction) (state : Storage.state) (key : string) : (Int64.t * Storage.state) tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Check the transaction *) (* Check the memo_size*) let coherence_of_memo_size = @@ -382,18 +382,18 @@ module Validator = struct = Storage.get_memo_size state) transaction.outputs in - if not coherence_of_memo_size then fail (Incoherent_memo_size ()) + if not coherence_of_memo_size then tzfail (Incoherent_memo_size ()) else if (* To avoid overflowing the balance, the number of inputs and outputs must be bounded *) Compare.List_length_with.(transaction.inputs >= 5208) - then fail (Too_many_inputs transaction.inputs) + then tzfail (Too_many_inputs transaction.inputs) else if Compare.List_length_with.(transaction.outputs >= 2019) then - fail (Too_many_outputs transaction.outputs) + tzfail (Too_many_outputs transaction.outputs) else if (* Check the root is a recent state *) not (Storage.mem_root state transaction.root) - then fail (Too_old_root transaction.root) + then tzfail (Too_old_root transaction.root) else let* () = Core.Verification.with_verification_ctx (fun ctx -> @@ -413,7 +413,7 @@ module Validator = struct if Core.Verification.check_spend ctx input transaction.root key then return_unit - else fail (Input_incorrect input)) + else tzfail (Input_incorrect input)) transaction.inputs in (* Check the signature and balance of the whole transaction *) @@ -427,7 +427,7 @@ module Validator = struct List.fold_left_es (fun state input -> if Storage.mem_nullifier state Core.UTXO.(input.nf) then - fail (Input_spent input) + tzfail (Input_spent input) else return (Storage.add_nullifier state Core.UTXO.(input.nf))) state transaction.inputs diff --git a/src/lib_shell/block_directory.ml b/src/lib_shell/block_directory.ml index 10301a4fda4def9220d42558e7b478ec8c1d9703..51904ce3eda834cfcba75a2c5a53dc5746fed30a 100644 --- a/src/lib_shell/block_directory.ml +++ b/src/lib_shell/block_directory.ml @@ -58,7 +58,7 @@ let read_partial_context = | Some v -> raw_context_insert (k, Key v) acc) let build_raw_header_rpc_directory (module Proto : Block_services.PROTO) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let dir : (Store.chain_store * Block_hash.t * Block_header.t) RPC_directory.t ref = ref RPC_directory.empty diff --git a/src/lib_shell/block_validator.ml b/src/lib_shell/block_validator.ml index 6bcfca7a993db41f31c26307daa391ddb6c942bc..0617a28370f2a70ee353b845c8075a5441cfbb22 100644 --- a/src/lib_shell/block_validator.ml +++ b/src/lib_shell/block_validator.ml @@ -120,7 +120,7 @@ module Worker = Worker.Make (Name) (Event) (Request) (Types) (Logger) type t = Worker.infinite Worker.queue Worker.t let check_chain_liveness chain_db hash (header : Block_header.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_store = Distributed_db.chain_store chain_db in match Store.Chain.expiration chain_store with | Some eol when Time.Protocol.(eol <= header.shell.timestamp) -> @@ -132,7 +132,7 @@ let check_chain_liveness chain_db hash (header : Block_header.t) = timestamp = header.shell.timestamp; } in - fail (invalid_block hash error) + tzfail (invalid_block hash error) | None | Some _ -> return_unit let precheck_block bvp chain_store ~predecessor block_header block_hash @@ -433,7 +433,7 @@ let create limits db validation_process ~start_testchain = let on_completion = on_completion - let on_no_request _ = Lwt_tzresult_syntax.return_unit + let on_no_request _ = Lwt_result_syntax.return_unit end in Worker.launch table @@ -451,7 +451,7 @@ type block_validity = let validate w ?canceler ?peer ?(notify_new_block = fun _ -> ()) ?(precheck_and_notify = false) chain_db hash (header : Block_header.t) operations : block_validity Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_store = Distributed_db.chain_store chain_db in let*! b = Store.Block.is_known_valid chain_store hash in match b with diff --git a/src/lib_shell/block_validator_process.ml b/src/lib_shell/block_validator_process.ml index 274f5baacb114bedf2de49e84a80274be6a98eb8..fdb73f57990f3b873580a81c23d2670d3d5fcfd7 100644 --- a/src/lib_shell/block_validator_process.ml +++ b/src/lib_shell/block_validator_process.ml @@ -186,7 +186,7 @@ module Internal_validator_process = struct operation_metadata_size_limit; _; } chain_store predecessor max_operations_ttl = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_id = Store.Chain.chain_id chain_store in let predecessor_block_header = Store.Block.header predecessor in let context_hash = predecessor_block_header.shell.context in @@ -195,7 +195,8 @@ module Internal_validator_process = struct let*! o = Context.checkout context_index context_hash in match o with | None -> - fail (Block_validator_errors.Failed_to_checkout_context context_hash) + tzfail + (Block_validator_errors.Failed_to_checkout_context context_hash) | Some ctx -> return ctx in let predecessor_block_metadata_hash = @@ -219,7 +220,7 @@ module Internal_validator_process = struct let apply_block validator chain_store ~predecessor ~max_operations_ttl block_header operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* env = make_apply_environment validator @@ -257,7 +258,7 @@ module Internal_validator_process = struct ~live_operations ~predecessor_shell_header ~predecessor_hash ~predecessor_max_operations_ttl ~predecessor_block_metadata_hash ~predecessor_ops_metadata_hash operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let context_index = Store.context_index (Store.Chain.global_store validator.chain_store) in @@ -266,7 +267,8 @@ module Internal_validator_process = struct let*! o = Context.checkout context_index context_hash in match o with | None -> - fail (Block_validator_errors.Failed_to_checkout_context context_hash) + tzfail + (Block_validator_errors.Failed_to_checkout_context context_hash) | Some ctx -> return ctx in let user_activated_upgrades = validator.user_activated_upgrades in @@ -299,7 +301,7 @@ module Internal_validator_process = struct let precheck_block validator chain_store ~predecessor header _hash operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_id = Store.Chain.chain_id chain_store in let context_index = Store.context_index (Store.Chain.global_store validator.chain_store) @@ -310,7 +312,8 @@ module Internal_validator_process = struct let*! o = Context.checkout context_index context_hash in match o with | None -> - fail (Block_validator_errors.Failed_to_checkout_context context_hash) + tzfail + (Block_validator_errors.Failed_to_checkout_context context_hash) | Some ctx -> return ctx in let cache = @@ -339,12 +342,12 @@ module Internal_validator_process = struct ~protocol:genesis.protocol let init_test_chain validator forking_block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let forked_header = Store.Block.header forking_block in let* context = Store.Block.context validator.chain_store forking_block in Block_validation.init_test_chain context forked_header - let reconfigure_event_logging _ _ = Lwt_tzresult_syntax.return_unit + let reconfigure_event_logging _ _ = Lwt_result_syntax.return_unit end (** Block validation using an external process *) @@ -526,7 +529,7 @@ module External_validator_process = struct | Some _ | None -> Filename.get_temp_dir_name () let start_process vp = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let canceler = Lwt_canceler.create () in (* We assume that there is only one validation process per socket *) let socket_dir = get_temporary_socket_dir () in @@ -633,7 +636,7 @@ module External_validator_process = struct return (process, process_stdin, process_stdout) let send_request vp request result_encoding = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (process, process_stdin, process_stdout) = match vp.validator_process with | Running @@ -655,7 +658,7 @@ module External_validator_process = struct | Uninitialized -> start_process vp | Exiting -> let*! () = Events.(emit cannot_start_process ()) in - fail Block_validator_errors.Cannot_validate_while_shutting_down + tzfail Block_validator_errors.Cannot_validate_while_shutting_down in Lwt.catch (fun () -> @@ -709,7 +712,7 @@ module External_validator_process = struct } : validator_environment) ~genesis ~data_dir ~context_root ~protocol_root ~process_path ~sandbox_parameters = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Events.(emit init ()) in let validator = { @@ -863,7 +866,7 @@ module External_validator_process = struct end let init validator_environment validator_kind = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match validator_kind with | Internal chain_store -> let* (validator : 'a) = @@ -905,7 +908,7 @@ let reconfigure_event_logging (E {validator_process = (module VP); validator}) let apply_block (E {validator_process = (module VP); validator}) chain_store ~predecessor header operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* metadata = Store.Block.get_block_metadata chain_store predecessor in let max_operations_ttl = Store.Block.max_operations_ttl metadata in let* (live_blocks, live_operations) = @@ -940,7 +943,7 @@ let init_test_chain (E {validator_process = (module VP); validator}) let preapply_block (E {validator_process = (module VP); validator} : t) chain_store ~predecessor ~protocol_data ~timestamp operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_id = Store.Chain.chain_id chain_store in let* (live_blocks, live_operations) = Store.Chain.compute_live_blocks chain_store ~block:predecessor diff --git a/src/lib_shell/bootstrap_pipeline.ml b/src/lib_shell/bootstrap_pipeline.ml index a68a3c244c0b14496163d056c685222065fe5dd3..a7ae3c7bfb2431efba2d7d4d143c7042a19f38a8 100644 --- a/src/lib_shell/bootstrap_pipeline.ml +++ b/src/lib_shell/bootstrap_pipeline.ml @@ -152,7 +152,7 @@ type t = { - The checkpoint has been reached (that is, the head of the chain is past the checkpoint) but the block is not yet in the chain. *) let assert_acceptable_header pipeline hash (header : Block_header.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_store = Distributed_db.chain_store pipeline.chain_db in let time_now = Time.System.now () in let* () = @@ -201,7 +201,7 @@ let assert_acceptable_header pipeline hash (header : Block_header.t) = 4. It loops on the predecessor of the current block. *) let fetch_step pipeline (step : Block_locator.step) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let rec fetch_loop acc hash cpt = let*! () = Lwt.pause () in let*! () = @@ -217,13 +217,13 @@ let fetch_step pipeline (step : Block_locator.step) = let*! () = Bootstrap_pipeline_event.(emit step_too_long) pipeline.peer_id in - fail (Invalid_locator (pipeline.peer_id, pipeline.locator)) + tzfail (Invalid_locator (pipeline.peer_id, pipeline.locator)) else if Block_hash.equal hash step.predecessor then if step.strict_step && cpt <> step.step then let*! () = Bootstrap_pipeline_event.(emit step_too_short) pipeline.peer_id in - fail (Invalid_locator (pipeline.peer_id, pipeline.locator)) + tzfail (Invalid_locator (pipeline.peer_id, pipeline.locator)) else return acc else let chain_store = Distributed_db.chain_store pipeline.chain_db in @@ -265,7 +265,7 @@ let fetch_step pipeline (step : Block_locator.step) = A step may be truncated in [rolling] or in [full] mode if the blocks are below the [savepoint].*) let headers_fetch_worker_loop pipeline = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! r = let sender_id = Distributed_db.my_peer_id pipeline.chain_db in (* sender and receiver are inverted here because they are from the @@ -303,7 +303,7 @@ let headers_fetch_worker_loop pipeline = (locator_length, pipeline.peer_id, number_of_steps) in match steps with - | [] -> fail (Too_short_locator (sender_id, pipeline.locator)) + | [] -> tzfail (Too_short_locator (sender_id, pipeline.locator)) | {Block_locator.predecessor; _} :: _ -> let*! predecessor_known = Store.Block.is_known chain_store predecessor @@ -396,7 +396,7 @@ let headers_fetch_worker_loop pipeline = successfuly in the queue. It is canceled if one operation could not be fetched. *) let rec operations_fetch_worker_loop pipeline = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! r = let*! () = Lwt.pause () in let* batch = @@ -474,7 +474,7 @@ let rec operations_fetch_worker_loop pipeline = fulfilled if every block from the locator was validated. It is canceled if the validation of one block fails. *) let rec validation_worker_loop pipeline = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! r = let*! () = Lwt.pause () in let* (hash, header, operations) = diff --git a/src/lib_shell/chain_directory.ml b/src/lib_shell/chain_directory.ml index 1a4a02baab8902a9048468e46fb8490b67a561ec..760a7c301ca0264a1a7de148576a8ed0ca48c6ba 100644 --- a/src/lib_shell/chain_directory.ml +++ b/src/lib_shell/chain_directory.ml @@ -122,7 +122,7 @@ let list_blocks chain_store ?(length = 1) ?min_date heads = return (List.rev blocks) let rpc_directory validator = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let dir : Store.chain_store RPC_directory.t ref = ref RPC_directory.empty in let register0 s f = dir := diff --git a/src/lib_shell/config_directory.ml b/src/lib_shell/config_directory.ml index 5a0cd4a82c6ebba231d8ad21686b4ac6afd391e9..dd836b6cea0ebda2159bb50e012245290df9622d 100644 --- a/src/lib_shell/config_directory.ml +++ b/src/lib_shell/config_directory.ml @@ -25,7 +25,7 @@ let build_rpc_directory ~user_activated_upgrades ~user_activated_protocol_overrides ~mainchain_validator store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let register endpoint f directory = RPC_directory.register directory endpoint f in diff --git a/src/lib_shell/distributed_db.ml b/src/lib_shell/distributed_db.ml index 728b0bb754ba309adb8274906530f2fba6228992..b5d78cdf47408ab29dd84c647f2df14b63493f2c 100644 --- a/src/lib_shell/distributed_db.ml +++ b/src/lib_shell/distributed_db.ml @@ -175,7 +175,7 @@ let activate P2p.send p2p conn (Get_current_branch chain_id) :: acc) in Error_monad.dont_wait - (fun () -> Error_monad.Lwt_tzresult_syntax.join sends) + (fun () -> Error_monad.Lwt_result_syntax.tzjoin sends) (fun trace -> Format.eprintf "Uncaught error: %a\n%!" diff --git a/src/lib_shell/injection_directory.ml b/src/lib_shell/injection_directory.ml index 33c8eb6f45b63d2492e020c5c6e5745842751dce..63e9bea205d9cf939ee3a15da908d40caaa36bf5 100644 --- a/src/lib_shell/injection_directory.ml +++ b/src/lib_shell/injection_directory.ml @@ -46,7 +46,7 @@ let inject_block validator ?force ?chain bytes operations = return_unit ) let inject_operation validator ~force ?chain bytes = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! chain_id = read_chain_id validator chain in let t = match Data_encoding.Binary.of_bytes_opt Operation.encoding bytes with @@ -57,7 +57,7 @@ let inject_operation validator ~force ?chain bytes = Lwt.return (hash, t) let inject_protocol store proto = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let proto_bytes = Data_encoding.Binary.to_bytes_exn Protocol.encoding proto in let hash = Protocol_hash.hash_bytes [proto_bytes] in let validation = diff --git a/src/lib_shell/node.ml b/src/lib_shell/node.ml index ea0b91d08eeff9e2726e0409ffddde8e99d3d55e..794245f262be2e920966c20d57030a42a362f45b 100644 --- a/src/lib_shell/node.ml +++ b/src/lib_shell/node.ml @@ -203,7 +203,7 @@ let store_known_protocols store = embedded_protocols let check_context_consistency store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let main_chain_store = Store.main_chain_store store in let*! block = Store.Chain.current_head main_chain_store in let*! b = Store.Block.context_exists main_chain_store block in @@ -213,7 +213,7 @@ let check_context_consistency store = return_unit | false -> let*! () = Node_event.(emit storage_corrupted_context_detected ()) in - fail Non_recoverable_context + tzfail Non_recoverable_context let create ?(sandboxed = false) ?sandbox_parameters ~singleprocess { @@ -234,7 +234,7 @@ let create ?(sandboxed = false) ?sandbox_parameters ~singleprocess enable_testchain; } peer_validator_limits block_validator_limits prevalidator_limits chain_validator_limits history_mode = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let (start_prevalidator, start_testchain) = match p2p_params with | Some _ -> (not disable_mempool, enable_testchain) diff --git a/src/lib_shell/peer_validator.ml b/src/lib_shell/peer_validator.ml index b6e17c7cb6bd3b152db07c97c59ca9ea1d02c024..dae592e70aad7ea328cd1f8a7a6b5b92ab0ed7c0 100644 --- a/src/lib_shell/peer_validator.ml +++ b/src/lib_shell/peer_validator.ml @@ -223,7 +223,7 @@ let validate_new_head w hash (header : Block_header.t) = return_unit let assert_acceptable_head w hash (header : Block_header.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let pv = Worker.state w in let chain_store = Distributed_db.chain_store pv.parameters.chain_db in let*! acceptable = @@ -234,7 +234,7 @@ let assert_acceptable_head w hash (header : Block_header.t) = (Validation_errors.Checkpoint_error (hash, Some pv.peer_id)) let may_validate_new_head w hash (header : Block_header.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let pv = Worker.state w in let chain_store = Distributed_db.chain_store pv.parameters.chain_db in let*! valid_block = Store.Block.is_known_valid chain_store hash in @@ -253,7 +253,7 @@ let may_validate_new_head w hash (header : Block_header.t) = return_unit else if invalid_block then let*! () = Worker.log_event w (Ignoring_invalid_block block_received) in - fail Validation_errors.Known_invalid + tzfail Validation_errors.Known_invalid else if invalid_predecessor then let*! () = Worker.log_event w (Ignoring_invalid_block block_received) in let* _ = @@ -263,7 +263,7 @@ let may_validate_new_head w hash (header : Block_header.t) = header [Validation_errors.Known_invalid] in - fail Validation_errors.Known_invalid + tzfail Validation_errors.Known_invalid else if not valid_predecessor then ( let*! () = Worker.log_event w (Missing_new_head_predecessor block_received) @@ -279,7 +279,7 @@ let may_validate_new_head w hash (header : Block_header.t) = validate_new_head w hash header let may_validate_new_branch w locator = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Make sure this is still ok w.r.t @phink fix *) let pv = Worker.state w in let {Block_locator.head_header = distant_header; head_hash = distant_hash; _} @@ -312,12 +312,12 @@ let may_validate_new_branch w locator = w (Ignoring_branch_without_common_ancestor block_received) in - fail Validation_errors.Unknown_ancestor + tzfail Validation_errors.Unknown_ancestor | (Known_invalid, _) -> let*! () = Worker.log_event w (Ignoring_branch_with_invalid_locator block_received) in - fail (Validation_errors.Invalid_locator (pv.peer_id, locator)) + tzfail (Validation_errors.Invalid_locator (pv.peer_id, locator)) let on_no_request w = let open Lwt_syntax in diff --git a/src/lib_shell/prevalidation.ml b/src/lib_shell/prevalidation.ml index a45177eaa1ff8edab44f2c5793b66d4384e375aa..34dca6c72889d602a03779f39293284357519d41 100644 --- a/src/lib_shell/prevalidation.ml +++ b/src/lib_shell/prevalidation.ml @@ -104,9 +104,9 @@ end (** Doesn't depend on heavy [Registered_protocol.T] for testability. *) let safe_binary_of_bytes (encoding : 'a Data_encoding.t) (bytes : bytes) : 'a tzresult = - let open Tzresult_syntax in + let open Result_syntax in match Data_encoding.Binary.of_bytes_opt encoding bytes with - | None -> fail Parse_error + | None -> tzfail Parse_error | Some protocol_data -> return protocol_data module MakeAbstract @@ -142,10 +142,10 @@ module MakeAbstract safe_binary_of_bytes Proto.operation_data_encoding proto let parse hash (raw : Operation.t) = - let open Tzresult_syntax in + let open Result_syntax in let size = Data_encoding.Binary.length Operation.encoding raw in if size > Proto.max_operation_data_length then - fail (Oversized_operation {size; max = Proto.max_operation_data_length}) + tzfail (Oversized_operation {size; max = Proto.max_operation_data_length}) else let+ protocol_data = parse_unsafe raw.proto in { @@ -171,7 +171,7 @@ module MakeAbstract () = (* The prevalidation module receives input from the system byt handles protocol values. It translates timestamps here. *) - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let { Block_header.shell = { diff --git a/src/lib_shell/prevalidator.ml b/src/lib_shell/prevalidator.ml index 4a20199c221130b47864b06d3fa84dbb35e9e628..a768031f8133da1a9cc9a8171d40bcf0580ae241 100644 --- a/src/lib_shell/prevalidator.ml +++ b/src/lib_shell/prevalidator.ml @@ -1124,7 +1124,7 @@ module Make let build_rpc_directory w = lazy - (let open Lwt_tzresult_syntax in + (let open Lwt_result_syntax in let dir : state RPC_directory.t ref = ref RPC_directory.empty in let module Proto_services = Block_services.Make (Filter.Proto) (Filter.Proto) @@ -1568,7 +1568,7 @@ module Make | View (Notify _) | View Leftover | View (Arrived _) | View Advertise -> Event.(emit request_completed_debug) (Request.view r, st) - let on_no_request _ = Lwt_tzresult_syntax.return_unit + let on_no_request _ = Lwt_result_syntax.return_unit end let table = Worker.create_table Queue diff --git a/src/lib_shell/prevalidator_filters.ml b/src/lib_shell/prevalidator_filters.ml index 0d982d95780425e6a58a47e5a00dae35bba8a091..8ae30734bfe49b2a0500c6cd728b4d1c0c7a4c67 100644 --- a/src/lib_shell/prevalidator_filters.ml +++ b/src/lib_shell/prevalidator_filters.ml @@ -105,12 +105,12 @@ module No_filter (Proto : Registered_protocol.T) = struct type state = unit let init _ ?validation_state:_ ~predecessor:_ () = - Lwt_tzresult_syntax.return_unit + Lwt_result_syntax.return_unit let remove ~filter_state _ = filter_state let on_flush _ _ ?validation_state:_ ~predecessor:_ () = - Lwt_tzresult_syntax.return_unit + Lwt_result_syntax.return_unit let precheck _ ~filter_state:_ ~validation_state:_ _ _ ~nb_successful_prechecks:_ = diff --git a/src/lib_shell/protocol_validator.ml b/src/lib_shell/protocol_validator.ml index c0785f37b4c8e5b424db3742f5200ac73ed90d29..d72adcfdacfbaa2ee74e726ec3ac252578dac4c4 100644 --- a/src/lib_shell/protocol_validator.ml +++ b/src/lib_shell/protocol_validator.ml @@ -58,7 +58,7 @@ let rec worker_loop bv = | None -> Lwt.wakeup_later wakener - (Tzresult_syntax.fail + (Result_syntax.tzfail (Invalid_protocol {hash; error = Dynlinking_failed}))) ; return_unit) else ( @@ -66,7 +66,7 @@ let rec worker_loop bv = prevents us from being spammed with protocol validation. *) Lwt.wakeup_later wakener - (Tzresult_syntax.fail + (Result_syntax.tzfail (Invalid_protocol {hash; error = Compilation_failed})) ; return_unit) in diff --git a/src/lib_shell/test/test_prevalidation.ml b/src/lib_shell/test/test_prevalidation.ml index 204738d09e0cdd831838a78e0db952e9d59adc5e..28250bf022c9e061758b99241958dfd7f29a8ae2 100644 --- a/src/lib_shell/test/test_prevalidation.ml +++ b/src/lib_shell/test/test_prevalidation.ml @@ -47,7 +47,7 @@ let test_safe_decode () = check bool "A broken encoding should return None" - (actual = Tzresult_syntax.fail Validation_errors.Parse_error) + (actual = Result_syntax.tzfail Validation_errors.Parse_error) true) open Tezos_requester diff --git a/src/lib_shell/test/test_prevalidation_t.ml b/src/lib_shell/test/test_prevalidation_t.ml index 0d5b3964e7649d13e9d7ea4afbdf4c640b81626f..e324c2fdbdc6457abb0d5c3764f1bfcbd9671e57 100644 --- a/src/lib_shell/test/test_prevalidation_t.ml +++ b/src/lib_shell/test/test_prevalidation_t.ml @@ -43,7 +43,7 @@ module Mock_protocol : (* We need to override this function (so that it's not [assert false]), because Prevalidation.create calls this function, so we need it to work in all tests below. *) - Lwt_tzresult_syntax.return_unit + Lwt_result_syntax.return_unit end module Internal_for_tests = Tezos_shell.Prevalidation.Internal_for_tests @@ -99,7 +99,7 @@ let create_prevalidation type chain_store = unit let context () _block : Tezos_context.Context.t tzresult Lwt.t = - Lwt_tzresult_syntax.return ctxt + Lwt_result_syntax.return ctxt let chain_id () = Init.chain_id end in diff --git a/src/lib_shell/test/test_prevalidator_pending_operations.ml b/src/lib_shell/test/test_prevalidator_pending_operations.ml index ff8d0ff7b9a90eafff3497f9bec9787e6936a31d..86d022651707f84a860694f296587f4001888b26 100644 --- a/src/lib_shell/test/test_prevalidator_pending_operations.ml +++ b/src/lib_shell/test/test_prevalidator_pending_operations.ml @@ -88,7 +88,7 @@ let test_fold_es_ordering = test_iterators_ordering ~name:"fold_es" ~iterator:Pending_ops.fold_es - Lwt_tzresult_syntax.return_unit + Lwt_result_syntax.return_unit (* 2. Test partial iteration with fold_es *) diff --git a/src/lib_shell/validator.ml b/src/lib_shell/validator.ml index 424166b2c3e732875878f4b9608d4caa369d2a79..4c877a3f2313ffeba2573723e8250e18ab2b3d6d 100644 --- a/src/lib_shell/validator.ml +++ b/src/lib_shell/validator.ml @@ -88,10 +88,10 @@ let activate v ~start_prevalidator ~validator_process chain_store = v.chain_validator_limits let get {active_chains; _} chain_id = - let open Tzresult_syntax in + let open Result_syntax in match Chain_id.Table.find active_chains chain_id with | Some nv -> return nv - | None -> fail (Validation_errors.Inactive_chain chain_id) + | None -> tzfail (Validation_errors.Inactive_chain chain_id) let get_active_chains {active_chains; _} = let l = Chain_id.Table.fold (fun c _ acc -> c :: acc) active_chains [] in diff --git a/src/lib_signer_backends/encrypted.ml b/src/lib_signer_backends/encrypted.ml index c87091dae64b9063ff7871ef73194e9b1ff16923..aefb26bd82c6164c57c1a6254de18ea4e4fc2bfb 100644 --- a/src/lib_signer_backends/encrypted.ml +++ b/src/lib_signer_backends/encrypted.ml @@ -71,7 +71,7 @@ module Raw = struct Bytes.cat salt (Crypto_box.Secretbox.secretbox key msg nonce) let decrypt algo ~password ~encrypted_sk = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let salt = Bytes.sub encrypted_sk 0 salt_len in let encrypted_sk = Bytes.sub encrypted_sk salt_len encrypted_size in let key = Crypto_box.Secretbox.unsafe_of_bytes (pbkdf ~salt ~password) in @@ -164,7 +164,7 @@ let passwords = ref [] given more than `retries_left` *) let interactive_decrypt_loop (cctxt : #Client_context.io) ?name ~retries_left ~encrypted_sk algo = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let rec interactive_decrypt_loop (cctxt : #Client_context.io) name ~current_retries ~retries ~encrypted_sk algo = match current_retries with @@ -428,7 +428,7 @@ struct let* sk = decrypt C.cctxt sk_uri in return (Signature.deterministic_nonce_hash sk buf) - let supports_deterministic_nonces _ = Lwt_tzresult_syntax.return_true + let supports_deterministic_nonces _ = Lwt_result_syntax.return_true end let encrypt_pvss_key cctxt sk = diff --git a/src/lib_signer_backends/http_gen.ml b/src/lib_signer_backends/http_gen.ml index 321025106b163248d6f037ad0be432141f16bcda..6bad86381904e1a658e4233bbf13a4aff0e590c7 100644 --- a/src/lib_signer_backends/http_gen.ml +++ b/src/lib_signer_backends/http_gen.ml @@ -92,7 +92,7 @@ struct let parse uri = (* extract `tz1..` from the last component of the path *) - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in assert (Uri.scheme uri = Some scheme) ; let path = Uri.path uri in let* (base, pkh) = diff --git a/src/lib_signer_backends/test/test_encrypted.ml b/src/lib_signer_backends/test/test_encrypted.ml index b8ed030ab0cada1a2349c70d126d6fa16929f38b..01d87ebde8fda2ce537b325bd1ebf1905b322454 100644 --- a/src/lib_signer_backends/test/test_encrypted.ml +++ b/src/lib_signer_backends/test/test_encrypted.ml @@ -105,7 +105,7 @@ let fake_ctx () : Client_context.io_wallet = fun _ _ _ -> Lwt.return_ok () method last_modification_time : string -> float option tzresult Lwt.t = - fun _ -> Lwt_tzresult_syntax.return_none + fun _ -> Lwt_result_syntax.return_none end let make_sk_uris = diff --git a/src/lib_signer_backends/unencrypted.ml b/src/lib_signer_backends/unencrypted.ml index 4810487146312d9ab5580433dbe4780950fe9f10..612ebf3b39ea163448ed948cc2fd3226ad5dc158 100644 --- a/src/lib_signer_backends/unencrypted.ml +++ b/src/lib_signer_backends/unencrypted.ml @@ -124,7 +124,7 @@ let deterministic_nonce_hash sk_uri buf = let* sk = secret_key sk_uri in return (Signature.deterministic_nonce_hash sk buf) -let supports_deterministic_nonces _ = Lwt_tzresult_syntax.return_true +let supports_deterministic_nonces _ = Lwt_result_syntax.return_true module Aggregate = struct include Make_common (struct @@ -139,7 +139,7 @@ module Aggregate = struct end) let sign sk_uri buf = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let+ sk = secret_key sk_uri in Aggregate_signature.sign sk buf end diff --git a/src/lib_signer_backends/unix/ledger.available.ml b/src/lib_signer_backends/unix/ledger.available.ml index 0bcc3502a8efd598d173c88b9180b2c62212a0da..f84d37913975a749faa43dc06e95cf9a3ab9d11f 100644 --- a/src/lib_signer_backends/unix/ledger.available.ml +++ b/src/lib_signer_backends/unix/ledger.available.ml @@ -119,7 +119,7 @@ let pp_round_opt fmt = function (** Wrappers around Ledger APDUs. *) module Ledger_commands = struct let wrap_ledger_cmd f = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let buf = Buffer.create 100 in let pp = Format.make_formatter @@ -135,12 +135,12 @@ module Ledger_commands = struct (Ledgerwallet.Transport.AppError {status = Ledgerwallet.Transport.Status.Incorrect_length_for_ins; msg}) -> - fail (Ledger_msg_chunk_too_long msg) - | Error err -> fail (LedgerError err) + tzfail (Ledger_msg_chunk_too_long msg) + | Error err -> tzfail (LedgerError err) | Ok v -> return v let get_version ~device_info h = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let buf = Buffer.create 100 in let pp = Format.formatter_of_buffer buf in let version = Ledgerwallet_tezos.get_version ~pp h in @@ -185,7 +185,7 @@ module Ledger_commands = struct let public_key_returning_instruction which ?(prompt = false) hidapi curve path = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let path = Bip32_path.tezos_root @ path in let+ pk = match which with @@ -238,7 +238,7 @@ module Ledger_commands = struct let public_key ?(first_import : Client_context.io_wallet option) hid curve path = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match first_import with | Some cctxt -> let* pk = get_public_key ~prompt:false hid curve path in @@ -254,12 +254,12 @@ module Ledger_commands = struct | None -> get_public_key ~prompt:false hid curve path let public_key_hash ?first_import hid curve path = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* pk = public_key ?first_import hid curve path in return (pkh_of_pk pk, pk) let get_authorized_path hid version = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Ledgerwallet_tezos.Version in if version.major < 2 then let+ path = @@ -286,7 +286,7 @@ module Ledger_commands = struct | Ok (path, curve) -> return (`Path_curve (path, curve)) let sign ?watermark ~version hid curve path (base_msg : Bytes.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let msg = Option.fold watermark ~none:base_msg ~some:(fun watermark -> Bytes.cat (Signature.bytes_of_watermark watermark) base_msg) @@ -320,7 +320,7 @@ module Ledger_commands = struct let ledger_one = Blake2B.of_bytes_exn (Cstruct.to_bytes hsh) in if Blake2B.equal hash_msg ledger_one then return_unit else - fail + tzfail (Ledger_signing_hash_mismatch (Blake2B.to_string ledger_one, Blake2B.to_string hash_msg)) in @@ -349,7 +349,7 @@ module Ledger_commands = struct return (Signature.of_p256 signature) let get_deterministic_nonce hid curve path msg = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let path = Bip32_path.tezos_root @ path in let* nonce = wrap_ledger_cmd (fun pp -> @@ -378,7 +378,7 @@ module Ledger_id = struct let curve = Ledgerwallet_tezos.Ed25519 let get hidapi = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* pk = Ledger_commands.get_public_key hidapi curve [] in let pkh = Signature.Public_key.hash pk in let animals = animals_of_pkh pkh in @@ -440,7 +440,7 @@ module Ledger_uri = struct | Ledgerwallet_tezos.Bip32_ed25519 -> true let parse ?allow_weak uri : t tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let host = Uri.host uri in let* ledger = match Option.bind host Signature.Public_key_hash.of_b58check_opt with @@ -480,7 +480,7 @@ module Ledger_uri = struct | [] -> return (`Ledger ledger) let ledger_uri_or_alias_param next = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let name = "account-alias-or-ledger-uri" in let desc = "An imported ledger alias or a ledger URI (e.g. \ @@ -521,14 +521,14 @@ module Ledger_uri = struct path) let if_matches (meta_uri : t) ledger_id cont = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match meta_uri with | `Ledger l -> if Ledger_id.equal l ledger_id then cont () else return_none | `Ledger_account {Ledger_account.ledger; _} -> if Ledger_id.equal ledger ledger_id then cont () else return_none let full_account (ledger_uri : t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match ledger_uri with | `Ledger_account acc -> return acc | `Ledger ledger_id -> @@ -575,7 +575,7 @@ let nano_s_product_ids = [0x0001] @ (0x1000 -- 0x101f) let nano_x_product_ids = [0x0004] @ (0x4000 -- 0x401f) let use_ledger ?(filter : Filter.t = `None) f = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let ledgers = let all_product_ids = nano_s_product_ids @ nano_x_product_ids in let open Hidapi in @@ -647,7 +647,7 @@ let is_derivation_scheme_supported version curve = (major, minor, patch) >= min_version_of_derivation_scheme curve) let use_ledger_or_fail ~ledger_uri ?filter ?msg f = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* o = use_ledger ?filter @@ -735,7 +735,7 @@ module Signer_implementation : Client_keys.SIGNER = struct let public_key_maybe_prompt ?(first_import : Client_context.io_wallet option) (pk_uri : pk_uri) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Global_cache.get pk_uri with | Some (_, pk) -> return pk | None -> ( @@ -757,7 +757,7 @@ module Signer_implementation : Client_keys.SIGNER = struct | Ok v -> return v) let public_key_hash_maybe_prompt ?first_import pk_uri = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Global_cache.get pk_uri with | Some (pkh, pk) -> return (pkh, Some pk) | None -> @@ -772,7 +772,7 @@ module Signer_implementation : Client_keys.SIGNER = struct public_key_hash_maybe_prompt ~first_import:io pk_uri let sign ?watermark (sk_uri : sk_uri) msg = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* ledger_uri = Ledger_uri.parse (sk_uri :> Uri.t) in let* {curve; path; _} = Ledger_uri.full_account ledger_uri in use_ledger_or_fail @@ -784,7 +784,7 @@ module Signer_implementation : Client_keys.SIGNER = struct return_some bytes) let deterministic_nonce (sk_uri : sk_uri) msg = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* ledger_uri = Ledger_uri.parse (sk_uri :> Uri.t) in let* {curve; path; _} = Ledger_uri.full_account ledger_uri in use_ledger_or_fail @@ -796,11 +796,11 @@ module Signer_implementation : Client_keys.SIGNER = struct return_some (Bigstring.to_bytes bytes)) let deterministic_nonce_hash (sk : sk_uri) msg = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* nonce = deterministic_nonce sk msg in return (Blake2B.to_bytes (Blake2B.hash_bytes [nonce])) - let supports_deterministic_nonces _ = Lwt_tzresult_syntax.return_true + let supports_deterministic_nonces _ = Lwt_result_syntax.return_true end (* The Ledger uses a special value 0x00000000 for the “any” chain-id: *) @@ -811,7 +811,7 @@ let pp_ledger_chain_id fmt s = (** Commands for both ledger applications. *) let generic_commands group = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Clic. [ command @@ -1005,7 +1005,7 @@ let generic_commands group = (** Commands specific to the Baking app minus the high-water-mark ones which get a specific treatment in {!high_water_mark_commands}. *) let baking_commands group = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Clic. [ Clic.command @@ -1285,7 +1285,7 @@ let baking_commands group = with the correct one “high water mark” (it's a mark of the highest water level). *) let high_water_mark_commands group watermark_spelling = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let make_desc desc = if Compare.List_length_with.(watermark_spelling = 1) then desc ^ " (legacy/deprecated spelling)" diff --git a/src/lib_signer_backends/unix/ledger.none.ml b/src/lib_signer_backends/unix/ledger.none.ml index 71e86205520dbdc6beb23080b62b09ca45b2b2db..5d69804392ae1c3e6f5c9e745b52bd580528c279 100644 --- a/src/lib_signer_backends/unix/ledger.none.ml +++ b/src/lib_signer_backends/unix/ledger.none.ml @@ -54,23 +54,23 @@ module Signer_implementation : Client_keys.SIGNER = struct "In order to communicate with a Ledger Nano, recompile with \ ledgerwallet-tezos library installed" - let neuterize _sk = Lwt_tzresult_syntax.fail NoLedgerSupport + let neuterize _sk = Lwt_result_syntax.tzfail NoLedgerSupport - let public_key _sk_uri = Lwt_tzresult_syntax.fail NoLedgerSupport + let public_key _sk_uri = Lwt_result_syntax.tzfail NoLedgerSupport - let public_key_hash _sk_uri = Lwt_tzresult_syntax.fail NoLedgerSupport + let public_key_hash _sk_uri = Lwt_result_syntax.tzfail NoLedgerSupport - let import_secret_key ~io:_ _pk_uri = Lwt_tzresult_syntax.fail NoLedgerSupport + let import_secret_key ~io:_ _pk_uri = Lwt_result_syntax.tzfail NoLedgerSupport - let sign ?watermark:_k _sk_uri _msg = Lwt_tzresult_syntax.fail NoLedgerSupport + let sign ?watermark:_k _sk_uri _msg = Lwt_result_syntax.tzfail NoLedgerSupport let deterministic_nonce _sk_uri _msg = - Lwt_tzresult_syntax.fail NoLedgerSupport + Lwt_result_syntax.tzfail NoLedgerSupport let deterministic_nonce_hash _sk_uri _msg = - Lwt_tzresult_syntax.fail NoLedgerSupport + Lwt_result_syntax.tzfail NoLedgerSupport - let supports_deterministic_nonces _ = Lwt_tzresult_syntax.return_false + let supports_deterministic_nonces _ = Lwt_result_syntax.return_false end let commands () = [] diff --git a/src/lib_signer_backends/unix/remote.ml b/src/lib_signer_backends/unix/remote.ml index cbea0169db65379522a861f9caa906322883313c..a3c092be4f8645235d6e8a9685c81a38bbcc3599 100644 --- a/src/lib_signer_backends/unix/remote.ml +++ b/src/lib_signer_backends/unix/remote.ml @@ -134,7 +134,7 @@ let make_pk pk = (Uri.make ~scheme ~path:(Signature.Public_key.to_b58check pk) ()) let read_base_uri_from_env () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match ( Sys.getenv_opt "TEZOS_SIGNER_UNIX_PATH", Sys.getenv_opt "TEZOS_SIGNER_TCP_HOST", diff --git a/src/lib_signer_backends/unix/socket.ml b/src/lib_signer_backends/unix/socket.ml index 14926335fdbfc2c7bcc44ead5a07e8a93f7de118..f96dd29cd5ae8410a5eace376b9b4da87417326a 100644 --- a/src/lib_signer_backends/unix/socket.ml +++ b/src/lib_signer_backends/unix/socket.ml @@ -161,7 +161,7 @@ struct include Client_keys.Signature_type let parse uri = - let open Tzresult_syntax in + let open Result_syntax in assert (Uri.scheme uri = Some scheme) ; match Uri.get_query_param uri "pkh" with | None -> error_with "Missing the query parameter: 'pkh=tz1...'" @@ -221,7 +221,7 @@ struct include Client_keys.Signature_type let parse uri = - let open Tzresult_syntax in + let open Result_syntax in assert (Uri.scheme uri = Some scheme) ; match (Uri.host uri, Uri.port uri) with | (None, _) -> error_with "Missing host address" diff --git a/src/lib_stdlib_unix/file_descriptor_sink.ml b/src/lib_stdlib_unix/file_descriptor_sink.ml index a678b339cefe5c7a6c3b9f6c5cd2b4841516afeb..d86f8bf5a2838eaaae8364d8570535a6305690a0 100644 --- a/src/lib_stdlib_unix/file_descriptor_sink.ml +++ b/src/lib_stdlib_unix/file_descriptor_sink.ml @@ -77,7 +77,7 @@ end) : Internal_event.SINK with type t = t = struct | `Stderr -> "file-descriptor-stderr" let configure uri = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let fail_parsing fmt = Format.kasprintf (failwith "Parsing URI: %s: %s" (Uri.to_string uri)) fmt in @@ -209,7 +209,7 @@ end) : Internal_event.SINK with type t = t = struct let handle (type a) {output; lwt_bad_citizen_hack; filter; format; _} m ?(section = Internal_event.Section.empty) (v : unit -> a) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let module M = (val m : Internal_event.EVENT_DEFINITION with type t = a) in let now = Unix.gettimeofday () in let forced_event = v () in @@ -272,7 +272,7 @@ end) : Internal_event.SINK with type t = t = struct else return_unit let close {lwt_bad_citizen_hack; output; _} = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = List.iter_es (fun event_string -> output_one output event_string) diff --git a/src/lib_stdlib_unix/file_event_sink.ml b/src/lib_stdlib_unix/file_event_sink.ml index fb1f1a520346417deee93f25aa87efc258e784d3..49f798abe295c55e43c8f86a533ba3d5c3f5d3b7 100644 --- a/src/lib_stdlib_unix/file_event_sink.ml +++ b/src/lib_stdlib_unix/file_event_sink.ml @@ -281,7 +281,7 @@ module Sink_implementation : Internal_event.SINK with type t = t = struct let handle (type a) {path; lwt_bad_citizen_hack; event_filter} m ?(section = Internal_event.Section.empty) (v : unit -> a) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let module M = (val m : Internal_event.EVENT_DEFINITION with type t = a) in let now = Micro_seconds.now () in let (date, time) = Micro_seconds.date_string now in @@ -333,7 +333,7 @@ open Sink_implementation module Query = struct let with_file_kind dir p = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* kind = protect (fun () -> let* {Lwt_unix.st_kind; _} = @@ -348,7 +348,7 @@ module Query = struct return (`Special (k, p)) let fold_directory path ~init ~f = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* dirhandle = protect (fun () -> Lwt_result.ok @@ Lwt_unix.opendir path) in @@ -545,7 +545,7 @@ module Query = struct let fold ?on_unknown ?only_sections ?only_names ?(time_query = `All) uri ~init ~f = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let name_matches = match only_names with | None -> fun _ -> true diff --git a/src/lib_stdlib_unix/lwt_lock_file.ml b/src/lib_stdlib_unix/lwt_lock_file.ml index 290bd2e93346b55ed393a6fedcf3495cd423d544..6ef6c009c3a55a8298363b300d9cf7954df6db68 100644 --- a/src/lib_stdlib_unix/lwt_lock_file.ml +++ b/src/lib_stdlib_unix/lwt_lock_file.ml @@ -28,7 +28,7 @@ open Error_monad let try_with_lock ~when_locked ~filename f = protect (fun () -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let flags = let open Unix in [O_CLOEXEC; O_TRUNC; O_CREAT; O_WRONLY] @@ -44,7 +44,7 @@ let try_with_lock ~when_locked ~filename f = (function | Unix.Unix_error ((EAGAIN | EACCES | EDEADLK), _, _) -> return `Locked - | exn -> fail (Exn exn)) + | exn -> tzfail (Exn exn)) in match lock_status with | `Locked -> when_locked () diff --git a/src/lib_stdlib_unix/lwt_utils_unix.ml b/src/lib_stdlib_unix/lwt_utils_unix.ml index b0658e6965ac618807abfefc5194907c78516511..08dd519094db46ced0af37015d54481b8cf2f553 100644 --- a/src/lib_stdlib_unix/lwt_utils_unix.ml +++ b/src/lib_stdlib_unix/lwt_utils_unix.ml @@ -161,12 +161,12 @@ let rec create_dir ?(perm = 0o755) dir = | _ -> Stdlib.failwith "Not a directory" let safe_close fd = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt.catch (fun () -> let*! () = Lwt_unix.close fd in return_unit) - (fun exc -> fail (Exn exc)) + (fun exc -> tzfail (Exn exc)) let create_file ?(close_on_exec = true) ?(perm = 0o644) name content = let open Lwt_syntax in @@ -360,7 +360,7 @@ let with_open_in file task = (* This is to avoid file corruption *) let with_atomic_open_out ?(overwrite = true) ?temp_dir filename f = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let temp_file = Filename.temp_file ?temp_dir (Filename.basename filename) ".tmp" in diff --git a/src/lib_stdlib_unix/sys_info.ml b/src/lib_stdlib_unix/sys_info.ml index 370c9704e1185df415dcdda99c3bba7983388e17..bec8d4d3bedf2986156daf1614a7b21b9ad41cdc 100644 --- a/src/lib_stdlib_unix/sys_info.ml +++ b/src/lib_stdlib_unix/sys_info.ml @@ -63,7 +63,7 @@ let uname () = | exn -> Lwt.return_error (error_info "uname" (Printexc.to_string exn))) let page_size sysname = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let get_conf_process = match sysname with | Linux -> Ok ("getconf", [|"getconf"; "PAGE_SIZE"|]) diff --git a/src/lib_store/block_repr.ml b/src/lib_store/block_repr.ml index f3eb8546e0b4360e9ab93f7faf50950c87b2e521..41bad7b648471930d56a970b36080b066ab33da7 100644 --- a/src/lib_store/block_repr.ml +++ b/src/lib_store/block_repr.ml @@ -264,7 +264,7 @@ let block_metadata metadata = metadata.block_metadata let operations_metadata metadata = metadata.operations_metadata let check_block_consistency ?genesis_hash ?pred_block block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let block_header = header block in let block_hash = hash block in let result_hash = Block_header.hash block_header in diff --git a/src/lib_store/block_store.ml b/src/lib_store/block_store.ml index 0394d682005050305e37126d2da55ed8e52683aa..4e52993b328ad10ea1a801b924988c316f6a8095 100644 --- a/src/lib_store/block_store.ml +++ b/src/lib_store/block_store.ml @@ -178,7 +178,7 @@ let compute_predecessors block_store block = [distance] from the block with corresponding [hash] by every store iteratively. *) let get_hash block_store (Block (block_hash, offset)) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt_idle_waiter.task block_store.merge_scheduler (fun () -> let closest_power_two n = if n < 0 then assert false @@ -188,7 +188,7 @@ let get_hash block_store (Block (block_hash, offset)) = in (* actual predecessor function *) if offset = 0 then return_some block_hash - else if offset < 0 then fail (Wrong_predecessor (block_hash, offset)) + else if offset < 0 then tzfail (Wrong_predecessor (block_hash, offset)) else let rec loop block_hash offset = if offset = 1 then @@ -218,7 +218,7 @@ let get_hash block_store (Block (block_hash, offset)) = loop block_hash offset) let mem block_store key = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt_idle_waiter.task block_store.merge_scheduler (fun () -> let* o = get_hash block_store key in match o with @@ -240,7 +240,7 @@ let mem block_store key = predecessor_hash)) let read_block ~read_metadata block_store key_kind = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt_idle_waiter.task block_store.merge_scheduler (fun () -> (* Resolve the hash *) let* o = get_hash block_store key_kind in @@ -282,7 +282,7 @@ let read_block ~read_metadata block_store key_kind = return block) let read_block_metadata block_store key_kind = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt_idle_waiter.task block_store.merge_scheduler (fun () -> (* Resolve the hash *) let* o = get_hash block_store key_kind in @@ -316,7 +316,7 @@ let read_block_metadata block_store key_kind = level))) let store_block block_store block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = fail_when block_store.readonly Cannot_write_in_readonly in Lwt_idle_waiter.task block_store.merge_scheduler (fun () -> protect (fun () -> @@ -348,7 +348,7 @@ let check_blocks_consistency blocks = let cement_blocks ?(check_consistency = true) ~write_metadata block_store blocks = (* No need to lock *) - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Store_events.(emit start_cementing_blocks) () in let {cemented_store; _} = block_store in let are_blocks_consistent = check_blocks_consistency blocks in @@ -396,7 +396,7 @@ let read_predecessor_block_by_level_opt block_store ?(read_metadata = false) let read_predecessor_block_by_level block_store ?(read_metadata = false) ~head level = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let head_level = Block_repr.level head in let head_hash = Block_repr.hash head in let distance = Int32.(to_int (sub head_level level)) in @@ -405,15 +405,15 @@ let read_predecessor_block_by_level block_store ?(read_metadata = false) ~head in match o with | None -> - if distance < 0 then fail (Bad_level {head_level; given_level = level}) - else fail (Block_not_found {hash = head_hash; distance}) + if distance < 0 then tzfail (Bad_level {head_level; given_level = level}) + else tzfail (Block_not_found {hash = head_hash; distance}) | Some b -> return b (* TODO optimize this by reading chunks of contiguous data and filtering it afterwards? *) let read_block_range_in_floating_stores block_store ~ro_store ~rw_store ~head (low, high) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* high_block = read_predecessor_block_by_level block_store ~head high in let nb_blocks = Int32.(add one (sub high low) |> to_int) @@ -434,7 +434,7 @@ let read_block_range_in_floating_stores block_store ~ro_store ~rw_store ~head [target_offset] cannot be satisfied, the previous savepoint is returned.*) let expected_savepoint block_store ~target_offset = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let cemented_dir = Naming.cemented_blocks_dir block_store.chain_dir in let* metadata_table = Cemented_block_store.load_metadata_table cemented_dir in match metadata_table with @@ -465,7 +465,7 @@ let expected_savepoint block_store ~target_offset = [savepoint_candidate] block descriptor if it is valid. Returns the current savepoint otherwise. *) let available_savepoint block_store current_head savepoint_candidate = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let head_hash = Block_repr.hash current_head in let*! current_savepoint = savepoint block_store in let new_savepoint_level = @@ -481,7 +481,7 @@ let available_savepoint block_store current_head savepoint_candidate = in match o with | Some b -> return b - | None -> fail (Wrong_predecessor (head_hash, distance)) + | None -> tzfail (Wrong_predecessor (head_hash, distance)) in return (descriptor block) @@ -490,7 +490,7 @@ let available_savepoint block_store current_head savepoint_candidate = one needed and maintained available to export snapshot. That is to say, the block: lafl(head) - max_op_ttl(lafl). *) let preserved_block block_store current_head = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let head_hash = Block_repr.hash current_head in let* current_head_metadata_o = read_block_metadata block_store (Block (head_hash, 0)) @@ -507,7 +507,7 @@ let preserved_block block_store current_head = (* [infer_savepoint block_store current_head ~target_offset] returns the savepoint candidate for an history mode switch. *) let infer_savepoint block_store current_head ~target_offset = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* expected_savepoint_level = expected_savepoint block_store ~target_offset in @@ -543,12 +543,12 @@ let expected_caboose block_store ~target_offset = candidate for an history mode switch. *) let infer_caboose block_store savepoint current_head ~target_offset ~new_history_mode ~previous_history_mode = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match previous_history_mode with | History_mode.Archive -> ( match new_history_mode with | History_mode.Archive -> - fail + tzfail (Cannot_switch_history_mode { previous_mode = previous_history_mode; @@ -577,7 +577,7 @@ let infer_caboose block_store savepoint current_head ~target_offset in match o with | Some b -> return b - | None -> fail (Wrong_predecessor (head_hash, distance)) + | None -> tzfail (Wrong_predecessor (head_hash, distance)) in return (descriptor block) | None -> return savepoint) @@ -592,7 +592,7 @@ let infer_caboose block_store savepoint current_head ~target_offset let switch_history_mode block_store ~current_head ~previous_history_mode ~new_history_mode = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open History_mode in match (previous_history_mode, new_history_mode) with | (Full _, Rolling m) | (Rolling _, Rolling m) -> @@ -660,13 +660,13 @@ let switch_history_mode block_store ~current_head ~previous_history_mode let* () = write_caboose block_store new_caboose in return_unit | _ -> - fail + tzfail (Cannot_switch_history_mode {previous_mode = previous_history_mode; next_mode = new_history_mode}) let compute_new_savepoint block_store history_mode ~new_store ~min_level_to_preserve ~new_head ~cycles_to_cement = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in assert (cycles_to_cement <> []) ; let*! savepoint = Stored_data.get block_store.savepoint in match history_mode with @@ -771,12 +771,12 @@ let compute_new_savepoint block_store history_mode ~new_store shifted_savepoint_level in match o with - | None -> fail (Cannot_retrieve_savepoint shifted_savepoint_level) + | None -> tzfail (Cannot_retrieve_savepoint shifted_savepoint_level) | Some savepoint -> return (Block_repr.descriptor savepoint)) let compute_new_caboose block_store history_mode ~new_savepoint ~min_level_to_preserve ~new_head = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! caboose = Stored_data.get block_store.caboose in match history_mode with | History_mode.Archive | Full _ -> @@ -821,7 +821,7 @@ module BlocksLAFL = Set.Make (Int32) let update_floating_stores block_store ~history_mode ~ro_store ~rw_store ~new_store ~new_head ~new_head_lafl ~lowest_bound_to_preserve_in_floating ~cementing_highwatermark = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Store_events.(emit start_updating_floating_stores) () in let* lafl_block = read_predecessor_block_by_level block_store ~head:new_head new_head_lafl @@ -916,7 +916,7 @@ let update_floating_stores block_store ~history_mode ~ro_store ~rw_store in (* Return the range of cycles to cement. *) let rec loop acc pred = function - | [] -> fail (Cannot_cement_blocks `Empty) + | [] -> tzfail (Cannot_cement_blocks `Empty) | [h] -> assert (Compare.Int32.(h = new_head_lafl)) ; return (List.rev ((Int32.succ pred, h) :: acc)) @@ -961,7 +961,7 @@ let find_floating_store_by_kind block_store kind = (block_store.rw_floating_block_store :: block_store.ro_floating_block_stores) let move_floating_store block_store ~src:floating_store ~dst_kind = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let src_kind = Floating_block_store.kind floating_store in let* () = fail_when (src_kind = dst_kind) Wrong_floating_kind_swap in (* If the destination floating store exists, try closing it. *) @@ -985,7 +985,7 @@ let move_floating_store block_store ~src:floating_store ~dst_kind = (* This function must be called after the former [RO] and [RW] were merged together and that the new [RW] is in place. *) let move_all_floating_stores block_store ~new_ro_store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_dir = block_store.chain_dir in protect ~on_error:(fun err -> @@ -1027,7 +1027,7 @@ let move_all_floating_stores block_store ~new_ro_store = return_unit) let check_store_consistency block_store ~cementing_highwatermark = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Cemented_block_store.get_highest_cemented_level block_store.cemented_store with @@ -1048,7 +1048,7 @@ let check_store_consistency block_store ~cementing_highwatermark = lower bound.*) let compute_lowest_bound_to_preserve_in_floating block_store ~new_head ~new_head_metadata = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Safety check: is the highwatermark consistent with our highest cemented block *) let lafl = Block_repr.last_allowed_fork_level new_head_metadata in let* lafl_block = @@ -1073,7 +1073,7 @@ let compute_lowest_bound_to_preserve_in_floating block_store ~new_head | Some metadata -> Block_repr.max_operations_ttl metadata))) let instanciate_temporary_floating_store block_store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in protect ~on_error:(fun err -> (match block_store.ro_floating_block_stores with @@ -1108,7 +1108,7 @@ let instanciate_temporary_floating_store block_store = let create_merging_thread block_store ~history_mode ~old_ro_store ~old_rw_store ~new_head ~new_head_lafl ~lowest_bound_to_preserve_in_floating ~cementing_highwatermark = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Store_events.(emit start_merging_thread) () in let*! new_ro_store = Floating_block_store.init block_store.chain_dir ~readonly:false RO_TMP @@ -1216,7 +1216,7 @@ let create_merging_thread block_store ~history_mode ~old_ro_store ~old_rw_store let merge_stores block_store ~(on_error : tztrace -> unit tzresult Lwt.t) ~finalizer ~history_mode ~new_head ~new_head_metadata ~cementing_highwatermark = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = fail_when block_store.readonly Cannot_write_in_readonly in (* Do not allow multiple merges: force waiting for a potential previous merge. *) @@ -1333,7 +1333,7 @@ let get_merge_status block_store = | Lwt.Fail exn -> Merge_failed [Exn exn]) let merge_temporary_floating block_store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_dir = block_store.chain_dir in let*! () = List.iter_s @@ -1404,7 +1404,7 @@ let may_clean_cementing_artifacts block_store = | false -> Lwt.return_unit let may_recover_merge block_store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = fail_when block_store.readonly Cannot_write_in_readonly in let* () = Lwt_idle_waiter.force_idle block_store.merge_scheduler (fun () -> @@ -1421,7 +1421,7 @@ let may_recover_merge block_store = return_unit let load ?block_cache_limit chain_dir ~genesis_block ~readonly = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* cemented_store = Cemented_block_store.init chain_dir ~readonly in let*! ro_floating_block_store = Floating_block_store.init chain_dir ~readonly RO @@ -1483,7 +1483,7 @@ let load ?block_cache_limit chain_dir ~genesis_block ~readonly = return block_store let create ?block_cache_limit chain_dir ~genesis_block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* block_store = load chain_dir ?block_cache_limit ~genesis_block ~readonly:false in diff --git a/src/lib_store/cemented_block_store.ml b/src/lib_store/cemented_block_store.ml index c40f4d85186524e9b30a02f548fbee2b887ac922..777aada699507ecbd4e11c4cd88ddbe98965cc4e 100644 --- a/src/lib_store/cemented_block_store.ml +++ b/src/lib_store/cemented_block_store.ml @@ -80,7 +80,7 @@ let default_index_log_size = 10_000 let default_compression_level = 9 let create ~log_size cemented_blocks_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in protect (fun () -> let cemented_blocks_dir_path = Naming.dir_path cemented_blocks_dir in let cemented_blocks_metadata_dir = @@ -99,7 +99,7 @@ let create ~log_size cemented_blocks_dir = return_unit) (function | Failure s when s = "Not a directory" -> - fail + tzfail (Store_errors.Failed_to_init_cemented_block_store cemented_blocks_dir_path) | e -> Lwt.fail e) @@ -138,7 +138,7 @@ let compare_cemented_metadata ({start_level; _} : cemented_metadata_file) Compare.Int32.compare start_level start_level' let load_table cemented_blocks_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in protect (fun () -> let cemented_blocks_dir_path = Naming.dir_path cemented_blocks_dir in (* No need to check the existence of the cemented block @@ -183,7 +183,7 @@ let load_table cemented_blocks_dir = return_some cemented_files_array) let load_metadata_table cemented_blocks_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in protect (fun () -> let cemented_metadata_dir = Naming.cemented_blocks_metadata_dir cemented_blocks_dir @@ -244,7 +244,7 @@ let cemented_metadata_files cemented_block_store = load_metadata_table cemented_block_store.cemented_blocks_dir let load ~readonly ~log_size cemented_blocks_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let cemented_block_level_index = Cemented_block_level_index.v ~readonly @@ -271,7 +271,7 @@ let load ~readonly ~log_size cemented_blocks_dir = return cemented_store let init ?(log_size = default_index_log_size) chain_dir ~readonly = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let cemented_blocks_dir = Naming.cemented_blocks_dir chain_dir in let cemented_blocks_dir_path = Naming.dir_path cemented_blocks_dir in let*! b = Lwt_unix.file_exists cemented_blocks_dir_path in @@ -375,7 +375,7 @@ let get_cemented_block_hash cemented_store level = with Not_found -> None let read_block_metadata ?location cemented_store block_level = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let location = match location with | Some _ -> location @@ -414,7 +414,7 @@ let read_block_metadata ?location cemented_store block_level = (fun _ -> return_none)) let cement_blocks_metadata cemented_store blocks = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let cemented_metadata_dir = cemented_store.cemented_blocks_dir |> Naming.cemented_blocks_metadata_dir in @@ -432,7 +432,7 @@ let cement_blocks_metadata cemented_store blocks = (Block_repr.level (List.hd blocks |> WithExceptions.Option.get ~loc:__LOC__)) with - | None -> fail (Cannot_cement_blocks_metadata `Not_cemented) + | None -> tzfail (Cannot_cement_blocks_metadata `Not_cemented) | Some {file; _} -> let tmp_metadata_file_path = Naming.cemented_blocks_tmp_metadata_file cemented_metadata_dir file @@ -508,7 +508,7 @@ let get_highest_cemented_level cemented_store = None let get_cemented_block_by_level (cemented_store : t) ~read_metadata level = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match compute_location cemented_store level with | None -> return_none | Some ((filename, block_number) as location) -> @@ -530,7 +530,7 @@ let read_block_metadata cemented_store block_level = read_block_metadata cemented_store block_level let get_cemented_block_by_hash ~read_metadata (cemented_store : t) hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match get_cemented_block_level cemented_store hash with | None -> return_none | Some level -> @@ -543,7 +543,7 @@ let get_cemented_block_by_hash ~read_metadata (cemented_store : t) hash = and all blocks are expected to have metadata. *) let cement_blocks ?(check_consistency = true) (cemented_store : t) ~write_metadata (blocks : Block_repr.t list) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let nb_blocks = List.length blocks in let preamble_length = nb_blocks * offset_length in let* () = fail_when (nb_blocks = 0) (Cannot_cement_blocks `Empty) in @@ -750,7 +750,7 @@ let trigger_gc cemented_store history_mode = trigger_rolling_gc cemented_store cemented_blocks_files offset) let iter_cemented_file f ({file; _} as cemented_blocks_file) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in protect (fun () -> let file_path = Naming.file_path file in Lwt_io.with_file @@ -789,13 +789,13 @@ let iter_cemented_file f ({file; _} as cemented_blocks_file) = (fun exn -> Format.kasprintf (fun trace -> - fail (Inconsistent_cemented_file (file_path, trace))) + tzfail (Inconsistent_cemented_file (file_path, trace))) "%s" (Printexc.to_string exn)))) let check_indexes_consistency ?(post_step = fun () -> Lwt.return_unit) ?genesis_hash cemented_store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match cemented_store.cemented_blocks_files with | None -> return_unit | Some table -> diff --git a/src/lib_store/consistency.ml b/src/lib_store/consistency.ml index 3c41fa55c6695e514b3b2039981edda1501f66fc..6498cb0e68c4e8e8353c4250978150760433fdaf 100644 --- a/src/lib_store/consistency.ml +++ b/src/lib_store/consistency.ml @@ -47,7 +47,7 @@ open Store_errors the cementing_highwatermark is consistent with the cemented store. *) let check_cementing_highwatermark ~cementing_highwatermark block_store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let cemented_store = Block_store.cemented_block_store block_store in let highest_cemented_level = Cemented_block_store.get_highest_cemented_level cemented_store @@ -67,7 +67,7 @@ let check_cementing_highwatermark ~cementing_highwatermark block_store = | (None, None) -> return_unit let is_block_stored block_store (descriptor, expected_metadata, block_name) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* o = Block_store.read_block ~read_metadata:expected_metadata @@ -75,7 +75,7 @@ let is_block_stored block_store (descriptor, expected_metadata, block_name) = (Block (fst descriptor, 0)) in match o with - | None -> fail (Unexpected_missing_block {block_name}) + | None -> tzfail (Unexpected_missing_block {block_name}) | Some _block -> if expected_metadata then (* Force read the metadata of a block to avoid false negatives @@ -86,12 +86,12 @@ let is_block_stored block_store (descriptor, expected_metadata, block_name) = (Block (fst descriptor, 0)) in match o with - | None -> fail (Unexpected_missing_block_metadata {block_name}) + | None -> tzfail (Unexpected_missing_block_metadata {block_name}) | Some _ -> return_unit else return_unit let check_protocol_levels block_store ~caboose protocol_levels = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Protocol_levels.iter_es (fun proto_level {Protocol_levels.block = (hash, activation_level); protocol; _} -> @@ -115,7 +115,8 @@ let check_protocol_levels block_store ~caboose protocol_levels = match o with | Some _ -> return_unit | None -> - fail (Unexpected_missing_activation_block {block = hash; protocol})) + tzfail + (Unexpected_missing_activation_block {block = hash; protocol})) protocol_levels let check_invariant ~genesis ~caboose ~savepoint ~cementing_highwatermark @@ -150,7 +151,7 @@ let check_invariant ~genesis ~caboose ~savepoint ~cementing_highwatermark Hypothesis: an existing store is provided. *) let check_consistency chain_dir genesis = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Try loading all the block's data files *) let* genesis_data = Stored_data.load (Naming.genesis_block_file chain_dir) in let*! genesis_block = Stored_data.get genesis_data in @@ -235,7 +236,7 @@ let check_consistency chain_dir genesis = (fun () -> Block_store.close block_store) let fix_floating_stores chain_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let store_kinds = [Floating_block_store.RO; RW; RW_TMP; RO_TMP] in let*! (existing_floating_stores, incomplete_floating_stores) = List.partition_s @@ -263,7 +264,7 @@ let fix_floating_stores chain_dir = (* [fix_head chain_dir block_store genesis_block] iter through the floating blocks and set, as head, the fittest block found. *) let fix_head chain_dir block_store genesis_block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let floating_stores = Block_store.floating_block_stores block_store in let* blocks = List.map_es @@ -331,7 +332,7 @@ let fix_head chain_dir block_store genesis_block = in match o with | None -> - fail + tzfail (Corrupted_store (Inferred_head (Block_repr.hash inferred_head, Block_repr.level inferred_head))) @@ -462,7 +463,7 @@ let lowest_floating_blocks floating_stores = (* Reads and returns the inferred savepoint. *) let load_inferred_savepoint chain_dir block_store head savepoint_level = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* block = Block_store.read_block ~read_metadata:false @@ -490,11 +491,11 @@ let load_inferred_savepoint chain_dir block_store head savepoint_level = (* Assumption: the head is valid. Thus, at least the head (with metadata) must be a valid candidate for the savepoint. *) - fail (Corrupted_store Cannot_find_savepoint_candidate) + tzfail (Corrupted_store Cannot_find_savepoint_candidate) (* Reads and returns the inferred caboose. *) let load_inferred_caboose chain_dir block_store head caboose_level = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* block = Block_store.read_block ~read_metadata:false @@ -514,12 +515,12 @@ let load_inferred_caboose chain_dir block_store head caboose_level = Store_events.(emit fix_caboose (stored_caboose, inferred_caboose)) in return inferred_caboose - | None -> fail (Corrupted_store Cannot_find_caboose_candidate) + | None -> tzfail (Corrupted_store Cannot_find_caboose_candidate) (* Infers an returns both the savepoint and caboose to meet the invariants of the store. *) let infer_savepoint_and_caboose chain_dir block_store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let cemented_dir = Naming.cemented_blocks_dir chain_dir in let cemented_block_store = Block_store.cemented_block_store block_store in let cemented_block_files = @@ -559,7 +560,7 @@ let infer_savepoint_and_caboose chain_dir block_store = let* savepoint_level = match lowest_floating_with_metadata with | Some lvl -> return lvl - | None -> fail (Corrupted_store Cannot_find_floating_savepoint) + | None -> tzfail (Corrupted_store Cannot_find_floating_savepoint) in return (savepoint_level, caboose_level) | (None, None) -> @@ -571,12 +572,12 @@ let infer_savepoint_and_caboose chain_dir block_store = let* savepoint_level = match lowest_floating_with_metadata with | Some lvl -> return lvl - | None -> fail (Corrupted_store Cannot_find_floating_savepoint) + | None -> tzfail (Corrupted_store Cannot_find_floating_savepoint) in let* caboose_level = match lowest_floating with | Some lvl -> return lvl - | None -> fail (Corrupted_store Cannot_find_floating_caboose) + | None -> tzfail (Corrupted_store Cannot_find_floating_caboose) in return (savepoint_level, caboose_level) | (Some _, None) -> @@ -585,7 +586,7 @@ let infer_savepoint_and_caboose chain_dir block_store = assert false let load_genesis block_store genesis = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* block = Block_store.read_block ~read_metadata:true @@ -594,7 +595,7 @@ let load_genesis block_store genesis = in match block with | Some block -> return block - | None -> fail (Corrupted_store Missing_genesis) + | None -> tzfail (Corrupted_store Missing_genesis) (* [fix_savepoint_and_caboose chain_dir block_store head] Fix the savepoint by setting it to the lowest block with metadata. @@ -605,7 +606,7 @@ let load_genesis block_store genesis = Assumption: - block store is valid and available. *) let fix_savepoint_and_caboose ?history_mode chain_dir block_store head genesis = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match history_mode with | Some History_mode.Archive -> (* This case does not cover all the potential cases where the @@ -637,14 +638,14 @@ let fix_savepoint_and_caboose ?history_mode chain_dir block_store head genesis = - savepoint is valid, - block store is valid and available. *) let fix_checkpoint chain_dir block_store head = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let set_checkpoint head = let* head_lafl = match Block_repr.metadata head with | Some m -> return m.last_allowed_fork_level | None -> (*Assumption: head must have metadata *) - fail + tzfail (Corrupted_store (Inferred_head (Block_repr.hash head, Block_repr.level head))) in @@ -674,7 +675,7 @@ let fix_checkpoint chain_dir block_store head = (* If the head was reached and it has no metadata, the store is broken *) if Compare.Int32.(block_level = Block_repr.level head) then - fail (Corrupted_store Cannot_find_block_with_metadata) + tzfail (Corrupted_store Cannot_find_block_with_metadata) else (* Freshly imported rolling nodes may have deleted blocks at a level higher that the lafl of the current @@ -713,7 +714,7 @@ let fix_checkpoint chain_dir block_store head = - current head is valid and available. *) let fix_protocol_levels context_index block_store genesis genesis_header ~head ~savepoint = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Search in the cemented store*) let cemented_block_store = Block_store.cemented_block_store block_store in let cemented_block_files = @@ -961,7 +962,7 @@ let fix_protocol_levels context_index block_store genesis genesis_header ~head :: (List.rev cemented_protocol_levels @ floating_protocol_levels) in let corrupted_store head_proto_level head_hash = - fail + tzfail (Corrupted_store (Cannot_find_activation_block (head_hash, head_proto_level))) in @@ -1025,7 +1026,7 @@ let fix_protocol_levels context_index block_store genesis genesis_header ~head let fix_chain_state chain_dir block_store ~head ~cementing_highwatermark ~checkpoint ~savepoint:tmp_savepoint ~caboose:tmp_caboose ~alternate_heads ~forked_chains ~protocol_levels ~chain_config ~genesis ~genesis_context = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* By setting each stored data, we erase the previous content. *) let rec init_protocol_table protocol_table = function | [] -> protocol_table @@ -1211,7 +1212,7 @@ let fix_cementing_highwatermark chain_dir block_store = - context is valid and available - block store is valid and available *) let fix_consistency ?history_mode chain_dir context_index genesis = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Store_events.(emit fix_store ()) in (* We suppose that the genesis block is accessible *) let* genesis_data = diff --git a/src/lib_store/floating_block_store.ml b/src/lib_store/floating_block_store.ml index 5324125b9b6ac6fb11b934f68badc21325c2661a..7818039d675461fcd2a7ba3b0ea698730aa72a33 100644 --- a/src/lib_store/floating_block_store.ml +++ b/src/lib_store/floating_block_store.ml @@ -89,10 +89,10 @@ let read_block floating_store hash = | None -> Lwt.return_none let locked_write_block floating_store ~offset ~block ~predecessors = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* block_bytes = match Data_encoding.Binary.to_bytes_opt Block_repr.encoding block with - | None -> fail (Cannot_encode_block block.Block_repr.hash) + | None -> tzfail (Cannot_encode_block block.Block_repr.hash) | Some bytes -> return bytes in let block_length = Bytes.length block_bytes in @@ -123,7 +123,7 @@ let append_block ?(flush = true) floating_store predecessors let append_all floating_store (blocks : (Block_hash.t list * Block_repr.t) Seq.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt_idle_waiter.force_idle floating_store.scheduler (fun () -> let*! eof_offset = Lwt_unix.lseek floating_store.fd 0 Unix.SEEK_END in let* _last_offset = @@ -140,7 +140,7 @@ let append_all floating_store return_unit) let iter_s_raw_fd f fd = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! eof_offset = Lwt_unix.lseek fd 0 Unix.SEEK_END in let*! _file_start = Lwt_unix.lseek fd 0 Unix.SEEK_SET in let rec loop nb_bytes_left = @@ -265,7 +265,7 @@ let close {floating_block_index; fd; scheduler; _} = Lwt.return_unit) let append_floating_store ~from ~into = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in protect (fun () -> let* () = iter_with_pred_s @@ -377,7 +377,7 @@ let swap ~src ~dst = (* Call this function when full_integrity_check has failed. *) let fix_integrity chain_dir kind = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! b = full_integrity_check chain_dir kind in match b with | true -> (* Nothing to do *) return_unit diff --git a/src/lib_store/reconstruction.ml b/src/lib_store/reconstruction.ml index e6d8257886be23a1d6c8a115c2e9487b37d2dd30..30d0b738ccdbf5807013da1229f4148d6709f3e5 100644 --- a/src/lib_store/reconstruction.ml +++ b/src/lib_store/reconstruction.ml @@ -132,7 +132,7 @@ type metadata_status = Complete | Partial of Int32.t | Not_stored - there only exists a contiguous set of empty metadata *) let cemented_metadata_status cemented_store {Cemented_block_store.start_level; end_level; _} = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* o = Cemented_block_store.read_block_metadata cemented_store end_level in match o with | None -> return Not_stored @@ -194,7 +194,7 @@ let apply_context context_index chain_id ~user_activated_upgrades ~user_activated_protocol_overrides ~operation_metadata_size_limit ~predecessor_block_metadata_hash ~predecessor_ops_metadata_hash ~predecessor_block block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let block_header = Store.Block.header block in let operations = Store.Block.operations block in let predecessor_block_header = Store.Block.header predecessor_block in @@ -204,7 +204,7 @@ let apply_context context_index chain_id ~user_activated_upgrades match o with | Some ctxt -> return ctxt | None -> - fail + tzfail (Store_errors.Cannot_checkout_context (Store.Block.hash predecessor_block, context_hash)) in @@ -249,16 +249,16 @@ let apply_context context_index chain_id ~user_activated_upgrades (** Returns the protocol environment version of a given protocol level. *) let protocol_env_of_protocol_level chain_store protocol_level block_hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* protocol_hash = let*! o = Store.Chain.find_protocol chain_store ~protocol_level in match o with | Some ph -> return ph - | None -> fail (Store_errors.Cannot_find_protocol protocol_level) + | None -> tzfail (Store_errors.Cannot_find_protocol protocol_level) in match Registered_protocol.get protocol_hash with | None -> - fail + tzfail (Block_validator_errors.Unavailable_protocol {block = block_hash; protocol = protocol_hash}) | Some (module Proto) -> return Proto.environment_version @@ -295,7 +295,7 @@ let restore_block_contents chain_store block_protocol_env ~block_metadata {block with contents; metadata = Some metadata} let reconstruct_genesis_operations_metadata chain_store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! genesis_block = Store.Chain.genesis_block chain_store in let* { message; @@ -329,7 +329,7 @@ let reconstruct_genesis_operations_metadata chain_store = let reconstruct_chunk chain_store context_index ~user_activated_upgrades ~user_activated_protocol_overrides ~operation_metadata_size_limit ~start_level ~end_level = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_id = Store.Chain.chain_id chain_store in let rec loop level acc = if level > end_level then return List.(rev acc) @@ -413,7 +413,7 @@ let reconstruct_chunk chain_store context_index ~user_activated_upgrades loop start_level [] let store_chunk cemented_store chunk = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (lower_block, lower_env_version) = match List.hd chunk with | None -> failwith "Cannot read chunk to cement." @@ -442,7 +442,7 @@ let store_chunk cemented_store chunk = level in match o with - | None -> fail (Reconstruction_failure (Cannot_read_block_level level)) + | None -> tzfail (Reconstruction_failure (Cannot_read_block_level level)) | Some b -> ( match ( Block_repr.block_metadata_hash b, @@ -472,7 +472,7 @@ let store_chunk cemented_store chunk = block_chunk let gather_available_metadata chain_store ~start_level ~end_level = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let rec aux level acc = if level > end_level then return acc else @@ -491,7 +491,7 @@ let gather_available_metadata chain_store ~start_level ~end_level = let reconstruct_cemented chain_store context_index ~user_activated_upgrades ~user_activated_protocol_overrides ~operation_metadata_size_limit ~start_block_level = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let block_store = Store.Unsafe.get_block_store chain_store in let cemented_block_store = Block_store.cemented_block_store block_store in let chain_dir = Store.Chain.chain_dir chain_store in @@ -595,7 +595,7 @@ let reconstruct_cemented chain_store context_index ~user_activated_upgrades let reconstruct_floating chain_store context_index ~user_activated_upgrades ~user_activated_protocol_overrides ~operation_metadata_size_limit = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_id = Store.Chain.chain_id chain_store in let chain_dir = Store.Chain.chain_dir chain_store in let block_store = Store.Unsafe.get_block_store chain_store in @@ -672,7 +672,7 @@ let reconstruct_floating chain_store context_index ~user_activated_upgrades in match o with | None -> - fail + tzfail (Reconstruction_failure (Cannot_read_block_hash predecessor_hash)) @@ -776,13 +776,13 @@ let reconstruct_floating chain_store context_index ~user_activated_upgrades (* Only Full modes with any offset can be reconstructed *) let check_history_mode_compatibility chain_store savepoint genesis_block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Store.Chain.history_mode chain_store with | History_mode.(Full _) -> fail_when (snd savepoint = Store.Block.level genesis_block) (Reconstruction_failure Nothing_to_reconstruct) - | _ as history_mode -> fail (Cannot_reconstruct history_mode) + | _ as history_mode -> tzfail (Cannot_reconstruct history_mode) let restore_constants chain_store genesis_block head_lafl_block ~cementing_highwatermark = @@ -812,7 +812,7 @@ let restore_constants chain_store genesis_block head_lafl_block at the lowest non cemented cycle. Otherwise, the reconstruction starts at the genesis. *) let compute_start_level chain_store savepoint = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_dir = Store.Chain.chain_dir chain_store in let reconstruct_lockfile = Naming.reconstruction_lock_file chain_dir in let reconstruct_lockfile_path = Naming.file_path reconstruct_lockfile in diff --git a/src/lib_store/snapshots.ml b/src/lib_store/snapshots.ml index 8b095d71fb7db893975be2796cdd0c1473eaf452..22789f744eaa0d42f653581710874119e747c72b 100644 --- a/src/lib_store/snapshots.ml +++ b/src/lib_store/snapshots.ml @@ -603,10 +603,10 @@ module Version = struct (* Returns true if the given version is considered as legacy. *) let is_legacy version = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match List.assq_opt version supported_versions with | None -> - fail + tzfail (Inconsistent_version_import {expected = List.map fst supported_versions; got = version}) | Some `Legacy -> return_true @@ -774,7 +774,7 @@ let ensure_valid_tmp_snapshot_path snapshot_tmp_dir = (Cannot_create_tmp_export_directory (Naming.dir_path snapshot_tmp_dir)) let ensure_valid_export_path = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in function | Some path -> fail_when (Sys.file_exists path) (Invalid_export_path path) | None -> return_unit @@ -1348,7 +1348,7 @@ module Raw_exporter : EXPORTER = struct } let init snapshot_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Creates the requested export folder and its hierarchy *) let snapshot_tmp_dir = let tmp_dir = Naming.snapshot_dir ?snapshot_path:snapshot_dir () in @@ -1540,7 +1540,7 @@ module Raw_exporter : EXPORTER = struct clean_all paths let finalize t metadata = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let snapshot_filename = match t.snapshot_dir with | Some path -> path @@ -1571,7 +1571,7 @@ module Tar_exporter : EXPORTER = struct } let init snapshot_file = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Creates the requested export folder and its hierarchy *) let snapshot_tmp_dir = let tmp_dir = Naming.snapshot_dir ?snapshot_path:snapshot_file () in @@ -1764,7 +1764,7 @@ module Tar_exporter : EXPORTER = struct Onthefly.add_file_and_finalize t.tar ~file:src ~filename:dst let write_metadata t metadata = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let metadata_json = Data_encoding.Json.(construct metadata_encoding metadata) in @@ -1789,7 +1789,7 @@ module Tar_exporter : EXPORTER = struct clean_all paths let finalize t metadata = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let snapshot_filename = match t.snapshot_file with | Some path -> path @@ -1835,7 +1835,7 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct let copy_cemented_blocks snapshot_exporter ~should_filter_indexes (files : Cemented_block_store.cemented_blocks_file list) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Cemented_block_store in let nb_cycles = List.length files in (* Rebuild fresh indexes: cannot cp because of concurrent accesses *) @@ -1899,7 +1899,7 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct Lwt_utils_unix.write_bytes ~pos:0 ~len:(Bytes.length bytes) fd bytes let export_floating_blocks ~floating_ro_fd ~floating_rw_fd ~export_block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let ((limit_hash, limit_level) as export_block_descr) = Store.Block.descriptor export_block in @@ -1915,11 +1915,11 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct | Some (block, _length) -> return block | None -> (* No block to read *) - fail Empty_floating_store) + tzfail Empty_floating_store) in let first_block_level = Block_repr.level first_block in if Compare.Int32.(limit_level < first_block_level) then - fail + tzfail (Inconsistent_floating_store (export_block_descr, (Block_repr.hash first_block, first_block_level))) else @@ -1944,11 +1944,11 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct let* () = Floating_block_store.iter_s_raw_fd f floating_ro_fd in let*! _ = Lwt_unix.lseek floating_rw_fd 0 Unix.SEEK_SET in let* () = Floating_block_store.iter_s_raw_fd f floating_rw_fd in - fail (Missing_target_block export_block_descr)) + tzfail (Missing_target_block export_block_descr)) (function | Done -> return_unit | exn -> - fail (Cannot_read_floating_store (Printexc.to_string exn)))) + tzfail (Cannot_read_floating_store (Printexc.to_string exn)))) (fun () -> bpush#close ; Lwt.return_unit) @@ -2034,7 +2034,7 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct - at least max_op_ttl(target_block) headers must be available *) let check_export_block_validity chain_store block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let (block_hash, block_level) = Store.Block.descriptor block in let*! is_known = Store.Block.is_known_valid chain_store block_hash in let* () = @@ -2058,7 +2058,7 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct let*! o = Store.Block.read_predecessor_opt chain_store block in match o with | None -> - fail + tzfail (Invalid_export_block {block = Some block_hash; reason = `Not_enough_pred}) | Some pred_block -> return pred_block @@ -2078,7 +2078,7 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct let*! o = Store.Block.get_block_metadata_opt chain_store block in match o with | None -> - fail + tzfail (Invalid_export_block {block = Some block_hash; reason = `Pruned}) | Some block_metadata -> return block_metadata in @@ -2106,12 +2106,12 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct the future. In this particular case, the last allowed fork level of the current head is chosen. *) let retrieve_export_block chain_store block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* export_block = (match block with | `Genesis -> (* Exporting the genesis block does not make sense. *) - fail + tzfail (Invalid_export_block { block = Some (Store.Chain.genesis chain_store).Genesis.block; @@ -2122,7 +2122,7 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct non sense. Additionally, it is not allowed to export the caboose block. *) let*! (hash, _) = Store.Chain.caboose chain_store in - fail (Invalid_export_block {block = Some hash; reason = `Caboose}) + tzfail (Invalid_export_block {block = Some hash; reason = `Caboose}) | _ -> Store.Chain.block_of_identifier chain_store block) |> trace (Invalid_export_block {block = None; reason = `Unknown}) in @@ -2137,7 +2137,7 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct extra blocks. *) let compute_cemented_table_and_extra_cycle chain_store ~src_cemented_dir ~export_block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* o = Cemented_block_store.load_table src_cemented_dir in match o with | None -> return ([], None) @@ -2203,7 +2203,7 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct ~to_block:export_block in match o with - | None -> fail Cannot_retrieve_block_interval + | None -> tzfail Cannot_retrieve_block_interval | Some floating_blocks -> (* Don't forget to add the first block as [Chain_traversal.path] does not include the lower-bound @@ -2214,12 +2214,12 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct (* Ensures that the history mode requested to export is compatible with the current storage. *) let check_history_mode chain_store ~rolling = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match (Store.Chain.history_mode chain_store : History_mode.t) with | Archive | Full _ -> return_unit | Rolling _ when rolling -> return_unit | Rolling _ as stored -> - fail (Incompatible_history_mode {stored; requested = Full None}) + tzfail (Incompatible_history_mode {stored; requested = Full None}) let export_floating_block_stream snapshot_exporter floating_block_stream = let open Lwt_syntax in @@ -2242,7 +2242,7 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct return_ok_unit let export_rolling ~store_dir ~context_dir ~block ~rolling genesis = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let export_rolling_f chain_store = let* () = check_history_mode chain_store ~rolling in let* (export_block, pred_block, lowest_block_level_needed) = @@ -2268,7 +2268,7 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct ~to_block:pred_block in match o with - | None -> fail Cannot_retrieve_block_interval + | None -> tzfail Cannot_retrieve_block_interval | Some blocks -> (* Don't forget to add the first block as [Chain_traversal.path] does not include the @@ -2322,7 +2322,7 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct let export_full snapshot_exporter ~store_dir ~context_dir ~block ~rolling genesis = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let export_full_f chain_store = let* () = check_history_mode chain_store ~rolling in let* (export_block, pred_block, _lowest_block_level_needed) = @@ -2445,18 +2445,19 @@ module Make_snapshot_exporter (Exporter : EXPORTER) : Snapshot_exporter = struct (reading_thread, floating_block_stream) ) let ensure_valid_export_chain_dir store_path chain_id = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let store_dir = Naming.store_dir ~dir_path:store_path in let chain_dir = Naming.chain_dir store_dir chain_id in let*! b = Lwt_unix.file_exists (Naming.dir_path chain_dir) in match b with | true -> return_unit | false -> - fail (Invalid_chain_store_export (chain_id, Naming.dir_path store_dir)) + tzfail + (Invalid_chain_store_export (chain_id, Naming.dir_path store_dir)) let export ?snapshot_path ?(rolling = false) ~block ~store_dir ~context_dir ~chain_name ~on_disk genesis = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_id = Chain_id.of_block_hash genesis.Genesis.block in let* () = ensure_valid_export_chain_dir store_dir chain_id in let* snapshot_exporter = init snapshot_path in @@ -2621,7 +2622,7 @@ module Tar_loader : LOADER = struct Lwt.return {tar; snapshot_file; snapshot_tar} let load_snapshot_version t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let filename = Naming.(snapshot_version_file t.snapshot_tar |> file_path) in let*! o = let*! o = Onthefly.find_file t.tar ~filename in @@ -2637,10 +2638,10 @@ module Tar_loader : LOADER = struct in match o with | Some version -> return version - | None -> fail (Cannot_read {kind = `Version; path = filename}) + | None -> tzfail (Cannot_read {kind = `Version; path = filename}) let load_snapshot_metadata t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let filename = Naming.(snapshot_metadata_file t.snapshot_tar |> file_path) in @@ -2658,7 +2659,7 @@ module Tar_loader : LOADER = struct in match o with | Some metadata -> return metadata - | None -> fail (Cannot_read {kind = `Metadata; path = filename}) + | None -> tzfail (Cannot_read {kind = `Metadata; path = filename}) let load_snapshot_header t = let open Lwt_result_syntax in @@ -2775,16 +2776,16 @@ module Raw_importer : IMPORTER = struct ~snapshot_path:Naming.(t.snapshot_dir |> dir_path) let load_block_data t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let file = Naming.(snapshot_block_data_file t.snapshot_dir |> file_path) in let*! block_data = Lwt_utils_unix.read_file file in match Data_encoding.Binary.of_string_opt block_data_encoding block_data with | Some block_data -> return block_data - | None -> fail (Cannot_read {kind = `Block_data; path = file}) + | None -> tzfail (Cannot_read {kind = `Block_data; path = file}) let restore_context t context_index ~expected_context_hash ~nb_context_elements ~legacy ~in_memory = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let context_file_path = Naming.(snapshot_context_file t.snapshot_dir |> file_path) in @@ -2797,12 +2798,12 @@ module Raw_importer : IMPORTER = struct return fd) (function | Unix.Unix_error (e, _, _) -> - fail (Context.Cannot_open_file (Unix.error_message e)) + tzfail (Context.Cannot_open_file (Unix.error_message e)) | exc -> let msg = Printf.sprintf "unknown error: %s" (Printexc.to_string exc) in - fail (Context.Cannot_open_file msg)) + tzfail (Context.Cannot_open_file msg)) in Lwt.finalize (fun () -> @@ -2820,11 +2821,11 @@ module Raw_importer : IMPORTER = struct let*! stats = Lwt_unix.fstat fd in let total = stats.Lwt_unix.st_size in if current = total then return_unit - else fail (Context.Suspicious_file (total - current))) + else tzfail (Context.Suspicious_file (total - current))) (fun () -> Lwt_unix.close fd) let load_protocol_table t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let protocol_tbl_filename = Naming.(snapshot_protocol_levels_file t.snapshot_dir |> encoded_file_path) in @@ -2834,11 +2835,11 @@ module Raw_importer : IMPORTER = struct with | Some table -> return table | None -> - fail + tzfail (Cannot_read {kind = `Protocol_table; path = protocol_tbl_filename}) let load_and_validate_protocol_filenames t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let protocol_levels_file = Naming.snapshot_protocol_levels_file t.snapshot_dir in @@ -2865,11 +2866,11 @@ module Raw_importer : IMPORTER = struct (fun file -> match Protocol_hash.of_b58check_opt file with | Some ph -> return ph - | None -> fail (Invalid_protocol_file file)) + | None -> tzfail (Invalid_protocol_file file)) protocol_files let copy_and_validate_protocol t ~protocol_hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let src = Filename.concat (Naming.dir_path t.snapshot_protocol_dir) @@ -2883,7 +2884,7 @@ module Raw_importer : IMPORTER = struct let*! () = Lwt_utils_unix.copy_file ~src ~dst in let*! protocol_sources = Lwt_utils_unix.read_file dst in match Protocol.of_string protocol_sources with - | None -> fail (Cannot_decode_protocol protocol_hash) + | None -> tzfail (Cannot_decode_protocol protocol_hash) | Some p -> let hash = Protocol.hash p in fail_unless @@ -2915,7 +2916,7 @@ module Raw_importer : IMPORTER = struct else Lwt.return_unit let load_cemented_files t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let stream = Lwt_unix.files_of_directory (Naming.dir_path t.snapshot_cemented_dir) in @@ -2942,7 +2943,7 @@ module Raw_importer : IMPORTER = struct Int32.of_string_opt s <> None || Int32.of_string_opt e <> None | _ -> false in - if not is_valid then fail (Invalid_cemented_file file) + if not is_valid then tzfail (Invalid_cemented_file file) else return_true) files @@ -2954,7 +2955,7 @@ module Raw_importer : IMPORTER = struct return_ok_unit let restore_floating_blocks t genesis_hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let floating_blocks_file = Naming.(snapshot_floating_blocks_file t.snapshot_dir |> file_path) in @@ -2964,7 +2965,7 @@ module Raw_importer : IMPORTER = struct let*! fd = Lwt_unix.openfile floating_blocks_file Unix.[O_RDONLY] 0o444 in let (stream, bounded_push) = Lwt_stream.create_bounded 1000 in let rec loop ?pred_block nb_bytes_left = - if nb_bytes_left < 0 then fail Corrupted_floating_store + if nb_bytes_left < 0 then tzfail Corrupted_floating_store else if nb_bytes_left = 0 then return_unit else let*! (block, len_read) = Block_repr.read_next_block_exn fd in @@ -3044,7 +3045,7 @@ module Tar_importer : IMPORTER = struct ~snapshot_path:Naming.(t.snapshot_file |> file_path) let load_block_data t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let filename = Naming.(snapshot_block_data_file t.snapshot_tar |> file_path) in @@ -3059,17 +3060,17 @@ module Tar_importer : IMPORTER = struct in match o with | Some metadata -> return metadata - | None -> fail (Cannot_read {kind = `Block_data; path = filename}) + | None -> tzfail (Cannot_read {kind = `Block_data; path = filename}) let restore_context t context_index ~expected_context_hash ~nb_context_elements ~legacy ~in_memory = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let filename = Naming.(snapshot_context_file t.snapshot_tar |> file_path) in let* header = let*! o = Onthefly.get_file t.tar ~filename in match o with | Some header -> return header - | None -> fail (Cannot_read {kind = `Context; path = filename}) + | None -> tzfail (Cannot_read {kind = `Context; path = filename}) in let*! fd = Onthefly.read_raw t.tar header in Context.restore_context @@ -3081,7 +3082,7 @@ module Tar_importer : IMPORTER = struct ~in_memory let load_protocol_table t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let protocol_tbl_filename = Naming.(snapshot_protocol_levels_file t.snapshot_tar |> encoded_file_path) in @@ -3099,11 +3100,11 @@ module Tar_importer : IMPORTER = struct in return res | None -> - fail + tzfail (Cannot_read {kind = `Protocol_table; path = protocol_tbl_filename}) let load_and_validate_protocol_filenames t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let protocol_tbl_filename = Naming.(snapshot_protocol_levels_file t.snapshot_tar |> encoded_file_path) in @@ -3124,11 +3125,11 @@ module Tar_importer : IMPORTER = struct (fun file -> match Protocol_hash.of_b58check_opt file with | Some ph -> return ph - | None -> fail (Invalid_protocol_file file)) + | None -> tzfail (Invalid_protocol_file file)) protocol_files let copy_and_validate_protocol t ~protocol_hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let src = Filename.( concat @@ -3139,7 +3140,7 @@ module Tar_importer : IMPORTER = struct let*! o = Onthefly.get_file t.tar ~filename:src in match o with | Some file -> return file - | None -> fail (Cannot_read {kind = `Protocol; path = src}) + | None -> tzfail (Cannot_read {kind = `Protocol; path = src}) in let dst = Filename.( @@ -3150,7 +3151,7 @@ module Tar_importer : IMPORTER = struct let*! () = Onthefly.copy_to_file t.tar file ~dst in let*! protocol_sources = Lwt_utils_unix.read_file dst in match Protocol.of_string protocol_sources with - | None -> fail (Cannot_decode_protocol protocol_hash) + | None -> tzfail (Cannot_decode_protocol protocol_hash) | Some p -> let hash = Protocol.hash p in fail_unless @@ -3212,7 +3213,7 @@ module Tar_importer : IMPORTER = struct cemented_files) let restore_cemented_cycle t ~file = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let filename = Filename.( concat Naming.(cemented_blocks_dir t.snapshot_tar |> dir_path) file) @@ -3221,7 +3222,7 @@ module Tar_importer : IMPORTER = struct let*! o = Onthefly.get_file t.tar ~filename in match o with | Some file -> return file - | None -> fail (Cannot_read {kind = `Cemented_cycle; path = filename}) + | None -> tzfail (Cannot_read {kind = `Cemented_cycle; path = filename}) in let*! () = Onthefly.copy_to_file @@ -3235,7 +3236,7 @@ module Tar_importer : IMPORTER = struct return_unit let restore_floating_blocks t genesis_hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! o = Onthefly.get_file t.tar @@ -3248,7 +3249,7 @@ module Tar_importer : IMPORTER = struct let floating_blocks_file_fd = Onthefly.get_raw_input_fd t.tar in let (stream, bounded_push) = Lwt_stream.create_bounded 1000 in let rec loop ?pred_block nb_bytes_left = - if nb_bytes_left < 0L then fail Corrupted_floating_store + if nb_bytes_left < 0L then tzfail Corrupted_floating_store else if nb_bytes_left = 0L then return_unit else let*! (block, len_read) = @@ -3316,7 +3317,7 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct let restore_cemented_blocks ?(check_consistency = true) ~dst_chain_dir ~genesis_hash snapshot_importer = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Importer.restore_cemented_indexes snapshot_importer in let* cemented_files = Importer.load_cemented_files snapshot_importer in let nb_cemented_files = List.length cemented_files in @@ -3363,7 +3364,7 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct (Naming.file_path file |> Filename.basename) cemented_file) stored_cemented_files) - then fail (Missing_cemented_file cemented_file) + then tzfail (Missing_cemented_file cemented_file) else return_unit) (List.sort compare cemented_files) in @@ -3389,7 +3390,7 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct Importer.restore_floating_blocks snapshot_importer genesis_hash let restore_protocols snapshot_importer = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Import protocol table *) let* protocol_levels = Importer.load_protocol_table snapshot_importer in (* Retrieve protocol files *) @@ -3448,7 +3449,7 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct ~context_index ~user_activated_upgrades ~user_activated_protocol_overrides ~operation_metadata_size_limit ~legacy ~in_memory snapshot_metadata genesis chain_id = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Start by committing genesis *) let* genesis_ctxt_hash = Context.commit_genesis @@ -3500,7 +3501,7 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct let*! o = Context.checkout context_index pred_context_hash in match o with | Some ch -> return ch - | None -> fail (Inconsistent_context pred_context_hash) + | None -> tzfail (Inconsistent_context pred_context_hash) in let apply_environment = { @@ -3529,7 +3530,7 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct | Error errs -> Format.kasprintf (fun errs -> - fail + tzfail (Target_block_validation_failed (Block_header.hash block_header, errs))) "%a" @@ -3550,7 +3551,7 @@ module Make_snapshot_importer (Importer : IMPORTER) : Snapshot_importer = struct ~configured_history_mode ~user_activated_upgrades ~user_activated_protocol_overrides ~operation_metadata_size_limit ~in_memory (genesis : Genesis.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_id = Chain_id.of_block_hash genesis.Genesis.block in let*! snapshot_importer = init ~snapshot_path ~dst_store_dir chain_id in let dst_store_dir = Naming.dir_path dst_store_dir in @@ -3730,7 +3731,7 @@ end snapshot. We assume that a snapshot is valid if the medata can be read. *) let snapshot_file_kind ~snapshot_path = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let is_valid_uncompressed_snapshot file = let (module Loader) = (module Make_snapshot_loader (Tar_loader) : Snapshot_loader) @@ -3786,7 +3787,7 @@ let export ?snapshot_path export_format ?rolling ~block ~store_dir ~context_dir genesis let read_snapshot_header ~snapshot_path = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* kind = snapshot_file_kind ~snapshot_path in let (module Loader) = match kind with @@ -3800,7 +3801,7 @@ let import ~snapshot_path ?patch_context ?block ?check_consistency ~dst_store_dir ~dst_context_dir ~chain_name ~configured_history_mode ~user_activated_upgrades ~user_activated_protocol_overrides ~operation_metadata_size_limit ~in_memory genesis = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* kind = snapshot_file_kind ~snapshot_path in let (module Importer) = match kind with diff --git a/src/lib_store/store.ml b/src/lib_store/store.ml index 2df58fe45370a5321abd378805bcd4462e769689..c58bde8d52071fb5ed65f0860a0fd3bd87ae47fe 100644 --- a/src/lib_store/store.ml +++ b/src/lib_store/store.ml @@ -253,7 +253,7 @@ module Block = struct Block_hash.equal hash genesis.Genesis.block let read_block {block_store; _} ?(distance = 0) hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* o = Block_store.read_block ~read_metadata:false @@ -261,7 +261,7 @@ module Block = struct (Block (hash, distance)) in match o with - | None -> fail @@ Block_not_found {hash; distance} + | None -> tzfail @@ Block_not_found {hash; distance} | Some block -> return block let read_block_metadata ?(distance = 0) chain_store hash = @@ -288,11 +288,11 @@ module Block = struct | None -> Lwt.return_none) let get_block_metadata chain_store block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! o = get_block_metadata_opt chain_store block in match o with | Some metadata -> return metadata - | None -> fail (Block_metadata_not_found (Block_repr.hash block)) + | None -> tzfail (Block_metadata_not_found (Block_repr.hash block)) let read_block_opt chain_store ?(distance = 0) hash = let open Lwt_syntax in @@ -327,17 +327,17 @@ module Block = struct | None -> Lwt.return_none let read_predecessor_of_hash chain_store hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! o = read_predecessor_of_hash_opt chain_store hash in match o with | Some b -> return b - | None -> fail @@ Block_not_found {hash; distance = 0} + | None -> tzfail @@ Block_not_found {hash; distance = 0} let locked_read_block_by_level chain_store head level = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let distance = Int32.(to_int (sub (Block_repr.level head) level)) in if distance < 0 then - fail + tzfail (Bad_level { head_level = Block_repr.level head; @@ -367,11 +367,11 @@ module Block = struct | Some t -> t) let read_prechecked_block chain_store hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! o = read_prechecked_block_opt chain_store hash in match o with | Some b -> return b - | None -> fail (Block_not_found {hash; distance = 0}) + | None -> tzfail (Block_not_found {hash; distance = 0}) let check_metadata_list ~block_hash ~operations ~ops_metadata = fail_unless @@ -400,7 +400,7 @@ module Block = struct } )) let store_block chain_store ~block_header ~operations validation_result = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let { Block_validation.validation_store = { @@ -549,7 +549,7 @@ module Block = struct return_some block let store_prechecked_block chain_store ~hash ~block_header ~operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let operations_length = List.length operations in let validation_passes = block_header.Block_header.shell.validation_passes in let* () = @@ -592,12 +592,12 @@ module Block = struct Context.checkout context_index (Block_repr.context block) let context chain_store block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! o = context_opt chain_store block in match o with | Some context -> return context | None -> - fail + tzfail (Cannot_checkout_context (Block_repr.hash block, Block_repr.context block)) @@ -606,13 +606,13 @@ module Block = struct Context.exists context_index (Block_repr.context block) let testchain_status chain_store block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* context = let*! o = context_opt chain_store block in match o with | Some ctxt -> return ctxt | None -> - fail + tzfail (Cannot_checkout_context (Block_repr.hash block, Block_repr.context block)) in @@ -632,7 +632,7 @@ module Block = struct | Not_running -> return (status, None) let protocol_hash chain_store block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Shared.use chain_store.chain_state (fun chain_state -> let*! protocol_levels = Stored_data.get chain_state.protocol_levels_data @@ -641,7 +641,7 @@ module Block = struct let proto_level = Block_repr.proto_level block in match find proto_level protocol_levels with | Some {protocol; _} -> return protocol - | None -> fail (Cannot_find_protocol proto_level)) + | None -> tzfail (Cannot_find_protocol proto_level)) let protocol_hash_exn chain_store block = let open Lwt_syntax in @@ -661,8 +661,8 @@ module Block = struct Stored_data.get chain_state.invalid_blocks_data) let mark_invalid chain_store hash ~level errors = - let open Lwt_tzresult_syntax in - if is_genesis chain_store hash then fail Invalid_genesis_marking + let open Lwt_result_syntax in + if is_genesis chain_store hash then tzfail Invalid_genesis_marking else let* () = Shared.use chain_store.chain_state (fun chain_state -> @@ -894,7 +894,7 @@ module Chain = struct Shared.use chain_store.chain_state (fun {mempool; _} -> Lwt.return mempool) let block_of_identifier chain_store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let not_found () = fail_with_exn Not_found in function | `Genesis -> @@ -942,7 +942,7 @@ module Chain = struct | Error _ -> Lwt.return_none let set_mempool chain_store ~head mempool = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Shared.update_with chain_store.chain_state (fun chain_state -> let*! current_head_descr = Stored_data.get chain_state.current_head_data @@ -1265,7 +1265,7 @@ module Chain = struct let may_update_checkpoint_and_target chain_store ~new_head ~new_head_lafl ~checkpoint ~target = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let new_checkpoint = if Compare.Int32.(snd new_head_lafl > snd checkpoint) then new_head_lafl else checkpoint @@ -1281,7 +1281,7 @@ module Chain = struct | false -> (* Impossible: a block is not acceptable to be stored if it's not compatible with the target *) - fail Target_mismatch + tzfail Target_mismatch else return (new_checkpoint, Some target) let locked_determine_cementing_highwatermark chain_store chain_state head_lafl @@ -1340,7 +1340,7 @@ module Chain = struct return_unit let set_head chain_store new_head = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Shared.update_with chain_store.chain_state (fun chain_state -> (* The merge cannot finish until we release the lock on the chain state so its status cannot change while this @@ -1575,7 +1575,7 @@ module Chain = struct (* TODO (later) check if that's ok *) let locked_is_valid_for_checkpoint chain_store chain_state (given_checkpoint_hash, given_checkpoint_level) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let current_head = chain_state.current_head in let* current_head_metadata = Block.get_block_metadata chain_store current_head @@ -1611,7 +1611,7 @@ module Chain = struct (Block.hash current_head) in match o with - | None -> fail Missing_last_allowed_fork_level_block + | None -> tzfail Missing_last_allowed_fork_level_block | Some lafl_hash -> return (Block_hash.equal lafl_hash ancestor))) let is_valid_for_checkpoint chain_store given_checkpoint = @@ -1629,7 +1629,7 @@ module Chain = struct given_checkpoint) let best_known_head_for_checkpoint chain_store ~checkpoint = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let (_, checkpoint_level) = checkpoint in let*! current_head = current_head chain_store in let* valid = @@ -1665,7 +1665,7 @@ module Chain = struct heads let set_target chain_store new_target = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Block_store.await_merging chain_store.block_store in Shared.use chain_store.chain_state (fun chain_state -> let*! checkpoint = Stored_data.get chain_state.checkpoint_data in @@ -1675,7 +1675,7 @@ module Chain = struct in match b with | true -> return_unit - | false -> fail (Cannot_set_target new_target) + | false -> tzfail (Cannot_set_target new_target) else (* new_target > checkpoint *) let*! b = Block.is_known_valid chain_store (fst new_target) in @@ -1685,7 +1685,7 @@ module Chain = struct Block.locked_is_known_invalid chain_state (fst new_target) in match b with - | true -> fail (Cannot_set_target new_target) + | true -> tzfail (Cannot_set_target new_target) | false -> (* unknown block => new_target > all_heads *) (* Write future-block as target, [set_head] will @@ -1826,7 +1826,7 @@ module Chain = struct let create_chain_state ?target ~genesis_block ~genesis_protocol ~genesis_commit_info chain_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let genesis_proto_level = Block_repr.proto_level genesis_block in let ((_, genesis_level) as genesis_descr) = Block_repr.descriptor genesis_block @@ -1941,7 +1941,7 @@ module Chain = struct (* TODO add integrity check to ensure that files are present? *) (* Files are expected to be present *) let load_chain_state chain_dir block_store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* protocol_levels_data = Stored_data.load (Naming.protocol_levels_file chain_dir) in @@ -2009,11 +2009,11 @@ module Chain = struct } let get_commit_info index header = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in protect ~on_error:(fun err -> Format.kasprintf - (fun e -> fail (Missing_commit_info e)) + (fun e -> tzfail (Missing_commit_info e)) "%a" Error_monad.pp_print_trace err) @@ -2029,7 +2029,7 @@ module Chain = struct let create_chain_store ?block_cache_limit global_store chain_dir ?target ~chain_id ?(expiration = None) ?genesis_block ~genesis ~genesis_context history_mode = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Chain directory *) let genesis_block = match genesis_block with @@ -2084,7 +2084,7 @@ module Chain = struct let load_chain_store ?block_cache_limit global_store chain_dir ~chain_id ~readonly = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* chain_config_data = Stored_data.load (Naming.chain_config_file chain_dir) in @@ -2120,7 +2120,7 @@ module Chain = struct let*! head = current_head chain_store in let*! o = Block.get_block_metadata_opt chain_store head in match o with - | None -> fail Inconsistent_chain_store + | None -> tzfail Inconsistent_chain_store | Some metadata -> Shared.update_with chain_state (fun chain_state -> let*! (live_blocks, live_operations) = @@ -2167,7 +2167,7 @@ module Chain = struct let testchain_store {testchain_store; _} = testchain_store let locked_load_testchain chain_store chain_state ~chain_id = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let {forked_chains_data; active_testchain; _} = chain_state in match active_testchain with | Some testchain @@ -2193,7 +2193,7 @@ module Chain = struct let fork_testchain chain_store ~testchain_id ~forked_block ~genesis_hash ~genesis_header ~test_protocol ~expiration = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let forked_block_hash = Block.hash forked_block in let genesis_hash' = Context.compute_testchain_genesis forked_block_hash in assert (Block_hash.equal genesis_hash genesis_hash') ; @@ -2211,7 +2211,7 @@ module Chain = struct if Chain_id.equal testchain_store.chain_id testchain_id then ( assert (Block_hash.equal forked_block forked_block_hash) ; return (None, testchain)) - else fail (Cannot_fork_testchain testchain_id) + else tzfail (Cannot_fork_testchain testchain_id) | None -> let chain_dir = chain_store.chain_dir in let testchains_dir = Naming.testchains_dir chain_dir in @@ -2228,7 +2228,7 @@ module Chain = struct ~chain_id:testchain_id in match o with - | None -> fail (Cannot_load_testchain testchain_dir_path) + | None -> tzfail (Cannot_load_testchain testchain_dir_path) | Some testchain -> return ( Some {chain_state with active_testchain = Some testchain}, @@ -2302,7 +2302,7 @@ module Chain = struct (* Protocols *) let compute_commit_info chain_store block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let index = chain_store.global_store.context_index in protect ~on_error:(fun _ -> return_none) @@ -2311,7 +2311,7 @@ module Chain = struct return_some commit_info) let set_protocol_level chain_store ~protocol_level (block, protocol_hash) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Shared.locked_use chain_store.chain_state (fun {protocol_levels_data; _} -> let* commit_info_opt = compute_commit_info chain_store (Block.header block) @@ -2355,7 +2355,7 @@ module Chain = struct let may_update_protocol_level chain_store ?pred ?protocol_level (block, protocol_hash) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* pred = match pred with | None -> Block.read_predecessor chain_store block @@ -2377,7 +2377,7 @@ module Chain = struct else return_unit let may_update_ancestor_protocol_level chain_store ~head = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let head_proto_level = Block.proto_level head in let*! o = find_activation_block chain_store ~protocol_level:head_proto_level @@ -2497,7 +2497,7 @@ end let create_store ?block_cache_limit ~context_index ~chain_id ~genesis ~genesis_context ?(history_mode = History_mode.default) ~allow_testchains store_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let store_dir_path = Naming.dir_path store_dir in let*! () = Lwt_utils_unix.create_dir store_dir_path in let*! protocol_store = Protocol_store.init store_dir in @@ -2531,7 +2531,7 @@ let create_store ?block_cache_limit ~context_index ~chain_id ~genesis let load_store ?history_mode ?block_cache_limit store_dir ~context_index ~genesis ~chain_id ~allow_testchains ~readonly () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_dir = Naming.chain_dir store_dir chain_id in let* () = protect @@ -2612,7 +2612,7 @@ let main_chain_store store = let init ?patch_context ?commit_genesis ?history_mode ?(readonly = false) ?block_cache_limit ~store_dir ~context_dir ~allow_testchains genesis = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let store_dir = Naming.store_dir ~dir_path:store_dir in let chain_id = Chain_id.of_block_hash genesis.Genesis.block in let*! (context_index, commit_genesis) = @@ -2674,7 +2674,7 @@ let close_store global_store = Context.close global_store.context_index let may_switch_history_mode ~store_dir ~context_dir genesis ~new_history_mode = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let store_dir = Naming.store_dir ~dir_path:store_dir in let chain_id = Chain_id.of_block_hash genesis.Genesis.block in let chain_dir = Naming.chain_dir store_dir chain_id in @@ -2746,13 +2746,13 @@ let may_switch_history_mode ~store_dir ~context_dir genesis ~new_history_mode = let get_chain_store store chain_id = let chain_store = main_chain_store store in let rec loop chain_store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in if Chain_id.equal (Chain.chain_id chain_store) chain_id then return chain_store else Shared.use chain_store.chain_state (fun {active_testchain; _} -> match active_testchain with - | None -> fail (Validation_errors.Unknown_chain chain_id) + | None -> tzfail (Validation_errors.Unknown_chain chain_id) | Some {testchain_store; _} -> loop testchain_store) in loop chain_store @@ -3046,7 +3046,7 @@ module Unsafe = struct let open_for_snapshot_export ~store_dir ~context_dir genesis ~(locked_f : chain_store -> 'a tzresult Lwt.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let store_dir = Naming.store_dir ~dir_path:store_dir in let chain_id = Chain_id.of_block_hash genesis.Genesis.block in let chain_dir = Naming.chain_dir store_dir chain_id in @@ -3076,7 +3076,7 @@ module Unsafe = struct let restore_from_snapshot ?(notify = fun () -> Lwt.return_unit) store_dir ~genesis ~genesis_context_hash ~floating_blocks_stream ~new_head_with_metadata ~protocol_levels ~history_mode = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let chain_id = Chain_id.of_block_hash genesis.Genesis.block in let chain_dir = Naming.chain_dir store_dir chain_id in let genesis_block = diff --git a/src/lib_store/stored_data.ml b/src/lib_store/stored_data.ml index d815700322d88af8cfbabf96524c042cc6e6ac81..be9eeaeb36496b40c8b21ec315a659e0e1c45d31 100644 --- a/src/lib_store/stored_data.ml +++ b/src/lib_store/stored_data.ml @@ -90,13 +90,13 @@ let write_file encoded_file data = let write (Stored_data v) data = Lwt_idle_waiter.force_idle v.scheduler (fun () -> - if v.cache = data then Lwt_tzresult_syntax.return_unit + if v.cache = data then Lwt_result_syntax.return_unit else ( v.cache <- data ; write_file v.file data)) let create file data = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let file = file in let scheduler = Lwt_idle_waiter.create () in let* () = write_file file data in @@ -112,7 +112,7 @@ let update_with (Stored_data v) f = write_file v.file new_data)) let load file = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! o = if Naming.is_json_file file then read_json_file file else read_file file in @@ -120,7 +120,7 @@ let load file = | Some cache -> let scheduler = Lwt_idle_waiter.create () in return (Stored_data {cache; file; scheduler}) - | None -> fail (Missing_stored_data (Naming.encoded_file_path file)) + | None -> tzfail (Missing_stored_data (Naming.encoded_file_path file)) let init file ~initial_data = let open Lwt_syntax in diff --git a/src/lib_store/test/alpha_utils.ml b/src/lib_store/test/alpha_utils.ml index 76513140accb6b28ee72a44e6f6023172e76f9b4..4f0f31ad4367ffb9cfdcecdfa72af1c7fe195309 100644 --- a/src/lib_store/test/alpha_utils.ml +++ b/src/lib_store/test/alpha_utils.ml @@ -90,7 +90,7 @@ module Account = struct let activator_account = new_account () let find pkh = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Signature.Public_key_hash.Table.find known_accounts pkh with | Some v -> return v | None -> failwith "Missing account: %a" Signature.Public_key_hash.pp pkh @@ -118,7 +118,7 @@ module Account = struct |> WithExceptions.Option.get ~loc:__LOC__ let new_commitment ?seed () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let (pkh, pk, sk) = Signature.generate_key ?seed ~algo:Ed25519 () in let unactivated_account = {pkh; pk; sk} in let open Commitment in @@ -129,7 +129,7 @@ module Account = struct end let make_rpc_context ~chain_id ctxt block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let header = Store.Block.shell_header block in let ({ timestamp = predecessor_timestamp; @@ -356,7 +356,7 @@ end let protocol_param_key = ["protocol_parameters"] let check_constants_consistency constants = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Constants_repr in let {blocks_per_cycle; blocks_per_commitment; blocks_per_stake_snapshot; _} = constants @@ -459,7 +459,7 @@ let empty_operations = WithExceptions.List.init ~loc:__LOC__ nb_validation_passes (fun _ -> []) let apply ctxt chain_id ~policy ?(operations = empty_operations) pred = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* rpc_ctxt = make_rpc_context ~chain_id ctxt pred in let element_of_key ~chain_id ~predecessor_context ~predecessor_timestamp ~predecessor_level ~predecessor_fitness ~predecessor ~timestamp = @@ -594,7 +594,7 @@ let apply ctxt chain_id ~policy ?(operations = empty_operations) pred = let apply_and_store chain_store ?(synchronous_merge = true) ?policy ?(operations = empty_operations) pred = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* ctxt = Store.Block.context chain_store pred in let chain_id = Store.Chain.chain_id chain_store in let* ( block_header, diff --git a/src/lib_validation/block_validation.ml b/src/lib_validation/block_validation.ml index 5cf904c35c8b85c27ea2655681e81f0e3a3902ec..e73f8b76e3c64d1120598f5812f636f898178650 100644 --- a/src/lib_validation/block_validation.ml +++ b/src/lib_validation/block_validation.ml @@ -129,10 +129,10 @@ type result = { type apply_result = {result : result; cache : Environment_context.Context.cache} let check_proto_environment_version_increasing block_hash before after = - let open Tzresult_syntax in + let open Result_syntax in if Protocol.compare_version before after <= 0 then return_unit else - fail + tzfail (invalid_block block_hash (Invalid_protocol_environment_transition (before, after))) @@ -155,7 +155,7 @@ let update_testchain_status ctxt ~predecessor_hash timestamp = (Running {chain_id; genesis; protocol; expiration}) let init_test_chain ctxt forked_header = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! tc = Context.get_test_chain ctxt in match tc with | Not_running | Running _ -> assert false @@ -163,7 +163,7 @@ let init_test_chain ctxt forked_header = let* (module Proto_test) = match Registered_protocol.get protocol with | Some proto -> return proto - | None -> fail (Missing_test_protocol protocol) + | None -> tzfail (Missing_test_protocol protocol) in let test_ctxt = Shell_context.wrap_disk_context ctxt in let*! () = @@ -287,7 +287,7 @@ module Make (Proto : Registered_protocol.T) = struct let check_block_header ~(predecessor_block_header : Block_header.t) hash (block_header : Block_header.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = fail_unless (Int32.succ predecessor_block_header.shell.level @@ -324,19 +324,19 @@ module Make (Proto : Registered_protocol.T) = struct return_unit let parse_block_header block_hash (block_header : Block_header.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match Data_encoding.Binary.of_bytes_opt Proto.block_header_data_encoding block_header.protocol_data with - | None -> fail (invalid_block block_hash Cannot_parse_block_header) + | None -> tzfail (invalid_block block_hash Cannot_parse_block_header) | Some protocol_data -> return ({shell = block_header.shell; protocol_data} : Proto.block_header) let check_one_operation_quota block_hash pass ops quota = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = fail_unless (match quota.Tezos_protocol_environment.max_op with @@ -384,7 +384,7 @@ module Make (Proto : Registered_protocol.T) = struct let parse_operations block_hash operations = List.mapi_es (fun pass -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in List.map_es (fun op -> let op_hash = Operation.hash op in match @@ -393,7 +393,8 @@ module Make (Proto : Registered_protocol.T) = struct op.Operation.proto with | None -> - fail (invalid_block block_hash (Cannot_parse_operation op_hash)) + tzfail + (invalid_block block_hash (Cannot_parse_operation op_hash)) | Some protocol_data -> let op = {Proto.shell = op.shell; protocol_data} in let allowed_pass = Proto.acceptable_passes op in @@ -413,7 +414,7 @@ module Make (Proto : Registered_protocol.T) = struct See https://gitlab.com/tezos/tezos/-/issues/2716 *) let compute_metadata ~operation_metadata_size_limit proto_env_version block_data ops_metadata = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Block and operation metadata hashes are not required for environment V0. *) let should_include_metadata_hashes = @@ -477,7 +478,7 @@ module Make (Proto : Registered_protocol.T) = struct with exn -> trace Validation_errors.Cannot_serialize_operation_metadata - (fail (Exn exn)) + (tzfail (Exn exn)) in return (block_metadata, ops_metadata) @@ -486,7 +487,7 @@ module Make (Proto : Registered_protocol.T) = struct ~max_operations_ttl ~(predecessor_block_header : Block_header.t) ~predecessor_block_metadata_hash ~predecessor_ops_metadata_hash ~predecessor_context ~(block_header : Block_header.t) operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let block_hash = Block_header.hash block_header in match cached_result with | Some (({result; _} as cached_result), context) @@ -619,7 +620,7 @@ module Make (Proto : Registered_protocol.T) = struct else match Registered_protocol.get new_protocol with | None -> - fail + tzfail (Unavailable_protocol {block = block_hash; protocol = new_protocol}) | Some (module NewProto) -> @@ -723,20 +724,20 @@ module Make (Proto : Registered_protocol.T) = struct (** Doesn't depend on heavy [Registered_protocol.T] for testability. *) let safe_binary_of_bytes (encoding : 'a Data_encoding.t) (bytes : bytes) : 'a tzresult = - let open Tzresult_syntax in + let open Result_syntax in match Data_encoding.Binary.of_bytes_opt encoding bytes with - | None -> fail Parse_error + | None -> tzfail Parse_error | Some protocol_data -> return protocol_data let parse_unsafe (proto : bytes) : Proto.operation_data tzresult = safe_binary_of_bytes Proto.operation_data_encoding proto let parse (raw : Operation.t) = - let open Tzresult_syntax in + let open Result_syntax in let hash = Operation.hash raw in let size = Data_encoding.Binary.length Operation.encoding raw in if size > Proto.max_operation_data_length then - fail (Oversized_operation {size; max = Proto.max_operation_data_length}) + tzfail (Oversized_operation {size; max = Proto.max_operation_data_length}) else let* protocol_data = parse_unsafe raw.proto in return {hash; raw; protocol_data} @@ -748,7 +749,7 @@ module Make (Proto : Registered_protocol.T) = struct ~(predecessor_shell_header : Block_header.shell_header) ~predecessor_hash ~predecessor_max_operations_ttl ~predecessor_block_metadata_hash ~predecessor_ops_metadata_hash ~operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let context = predecessor_context in let*! context = update_testchain_status context ~predecessor_hash timestamp @@ -768,7 +769,7 @@ module Make (Proto : Registered_protocol.T) = struct match predecessor_block_metadata_hash with | None -> if should_metadata_be_present then - fail (Missing_block_metadata_hash predecessor_hash) + tzfail (Missing_block_metadata_hash predecessor_hash) else return context | Some hash -> Lwt_result.ok @@ -778,7 +779,7 @@ module Make (Proto : Registered_protocol.T) = struct match predecessor_ops_metadata_hash with | None -> if should_metadata_be_present then - fail (Missing_operation_metadata_hashes predecessor_hash) + tzfail (Missing_operation_metadata_hashes predecessor_hash) else return context | Some hash -> Lwt_result.ok @@ -925,7 +926,7 @@ module Make (Proto : Registered_protocol.T) = struct else match Registered_protocol.get protocol with | None -> - fail + tzfail (Block_validator_errors.Unavailable_protocol {block = predecessor_hash; protocol}) | Some (module NewProto) -> @@ -987,7 +988,7 @@ module Make (Proto : Registered_protocol.T) = struct let precheck block_hash chain_id ~(predecessor_block_header : Block_header.t) ~predecessor_block_hash ~predecessor_context ~cache ~(block_header : Block_header.t) operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = check_block_header ~predecessor_block_header block_hash block_header in @@ -1042,7 +1043,7 @@ module Make (Proto : Registered_protocol.T) = struct end let assert_no_duplicate_operations block_hash live_operations operations = - let open Tzresult_syntax in + let open Result_syntax in let exception Duplicate of block_error in try return @@ -1054,10 +1055,10 @@ let assert_no_duplicate_operations block_hash live_operations operations = else Operation_hash.Set.add oph live_operations)) live_operations operations) - with Duplicate err -> fail (invalid_block block_hash err) + with Duplicate err -> tzfail (invalid_block block_hash err) let assert_operation_liveness block_hash live_blocks operations = - let open Tzresult_syntax in + let open Result_syntax in let exception Outdated of block_error in try return @@ -1074,7 +1075,7 @@ let assert_operation_liveness block_hash live_blocks operations = in raise (Outdated error))) operations) - with Outdated err -> fail (invalid_block block_hash err) + with Outdated err -> tzfail (invalid_block block_hash err) (* Maybe this function should be moved somewhere else since it used once by [Block_validator_process] *) @@ -1109,12 +1110,12 @@ let apply ?cached_result predecessor_ops_metadata_hash; predecessor_context; } ~cache block_hash block_header operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! pred_protocol_hash = Context.get_protocol predecessor_context in let* (module Proto) = match Registered_protocol.get pred_protocol_hash with | None -> - fail + tzfail (Unavailable_protocol {block = block_hash; protocol = pred_protocol_hash}) | Some p -> return p @@ -1136,7 +1137,7 @@ let apply ?cached_result operations let apply ?cached_result c ~cache block_header operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let block_hash = Block_header.hash block_header in let*! r = (* The cache might be inconsistent with the context. By forcing @@ -1169,18 +1170,18 @@ let apply ?cached_result c ~cache block_header operations = in match r with | Error (Exn (Unix.Unix_error (errno, fn, msg)) :: _) -> - fail (System_error {errno = Unix.error_message errno; fn; msg}) + tzfail (System_error {errno = Unix.error_message errno; fn; msg}) | (Ok _ | Error _) as res -> Lwt.return res let precheck ~chain_id ~predecessor_block_header ~predecessor_block_hash ~predecessor_context ~cache block_header operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let block_hash = Block_header.hash block_header in let*! pred_protocol_hash = Context.get_protocol predecessor_context in let* (module Proto) = match Registered_protocol.get pred_protocol_hash with | None -> - fail + tzfail (Unavailable_protocol {block = block_hash; protocol = pred_protocol_hash}) | Some p -> return p @@ -1200,7 +1201,7 @@ let preapply ~chain_id ~user_activated_upgrades ~protocol_data ~live_blocks ~live_operations ~predecessor_context ~predecessor_shell_header ~predecessor_hash ~predecessor_max_operations_ttl ~predecessor_block_metadata_hash ~predecessor_ops_metadata_hash operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! protocol = Context.get_protocol predecessor_context in let* (module Proto) = match Registered_protocol.get protocol with @@ -1248,7 +1249,7 @@ let preapply ~chain_id ~user_activated_upgrades ~protocol_data ~live_blocks ~live_operations ~predecessor_context ~predecessor_shell_header ~predecessor_hash ~predecessor_max_operations_ttl ~predecessor_block_metadata_hash ~predecessor_ops_metadata_hash operations = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! r = preapply ~chain_id @@ -1269,5 +1270,5 @@ let preapply ~chain_id ~user_activated_upgrades in match r with | Error (Exn (Unix.Unix_error (errno, fn, msg)) :: _) -> - fail (System_error {errno = Unix.error_message errno; fn; msg}) + tzfail (System_error {errno = Unix.error_message errno; fn; msg}) | (Ok _ | Error _) as res -> Lwt.return res diff --git a/src/lib_validation/external_validation.ml b/src/lib_validation/external_validation.ml index f546f39a4938d1721914039ab5d7f7b15bdec23d..bf97c9524fd314faefb5421ad7f4df4084d27449 100644 --- a/src/lib_validation/external_validation.ml +++ b/src/lib_validation/external_validation.ml @@ -423,7 +423,7 @@ let create_socket ~canceler = Lwt.return socket let create_socket_listen ~canceler ~max_requests ~socket_path = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! socket = create_socket ~canceler in let* () = Lwt.catch @@ -434,7 +434,7 @@ let create_socket_listen ~canceler ~max_requests ~socket_path = | Unix.Unix_error (ENAMETOOLONG, _, _) -> (* Unix.ENAMETOOLONG (Filename too long (POSIX.1-2001)) can be thrown if the given directory has a too long path. *) - fail + tzfail Block_validator_errors.( Validation_process_failed (Socket_path_too_long socket_path)) | Unix.Unix_error (EACCES, _, _) -> @@ -442,12 +442,12 @@ let create_socket_listen ~canceler ~max_requests ~socket_path = thrown when the given directory has wrong access rights. Unix.EPERM (Operation not permitted (POSIX.1-2001)) should not be thrown in this case. *) - fail + tzfail Block_validator_errors.( Validation_process_failed (Socket_path_wrong_permission socket_path)) | exn -> - fail + tzfail (Block_validator_errors.Validation_process_failed (Cannot_run_external_validator (Printexc.to_string exn)))) in diff --git a/src/lib_workers/worker.ml b/src/lib_workers/worker.ml index db7e2a610511230b3be96d1fc5081f8262b9a032..308233d7f8af6c1cc35dd5cd970d474dd22dde0e 100644 --- a/src/lib_workers/worker.ml +++ b/src/lib_workers/worker.ml @@ -321,7 +321,7 @@ struct (function | Lwt_dropbox.Closed -> let name = Format.asprintf "%a" Name.pp w.name in - Lwt_tzresult_syntax.fail (Closed {base = base_name; name}) + Lwt_result_syntax.tzfail (Closed {base = base_name; name}) | exn -> (* [Lwt_dropbox.put] can only raise [Closed] which is caught above. We don't want to catch any other exception but we cannot use an @@ -385,7 +385,7 @@ struct t with Lwt_pipe.Closed -> let name = Format.asprintf "%a" Name.pp w.name in - Lwt_tzresult_syntax.fail (Closed {base = base_name; name})) + Lwt_result_syntax.tzfail (Closed {base = base_name; name})) | Bounded_buffer message_queue -> let (t, u) = Lwt.wait () in Lwt.try_bind @@ -395,7 +395,7 @@ struct (function | Lwt_pipe.Closed -> let name = Format.asprintf "%a" Name.pp w.name in - Lwt_tzresult_syntax.fail (Closed {base = base_name; name}) + Lwt_result_syntax.tzfail (Closed {base = base_name; name}) | exn -> raise exn) let pending_requests (type a) (w : a queue t) = @@ -428,7 +428,7 @@ struct let name = Format.asprintf "%a" Name.pp w.name in Lwt.wakeup_later u - (Tzresult_syntax.fail (Closed {base = base_name; name})) + (Result_syntax.tzfail (Closed {base = base_name; name})) | (_, Message (_, None)) -> () in let close_queue message_queue = @@ -565,7 +565,7 @@ struct recursive call to this [loop] at which point this call to [protect] fails immediately with [Canceled]. *) Lwt.bind - Lwt_tzresult_syntax.( + Lwt_result_syntax.( let* popped = protect ~canceler:w.canceler (fun () -> Lwt_result.ok @@ pop w) in @@ -690,7 +690,7 @@ struct } in Nametbl.add table.instances name w ; - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let started = if id_name = base_name then None else Some name_s in let*! () = lwt_emit w (Started started) in let* state = Handlers.on_launch w name parameters in diff --git a/src/proto_010_PtGRANAD/lib_client_commands/client_proto_stresstest_commands.ml b/src/proto_010_PtGRANAD/lib_client_commands/client_proto_stresstest_commands.ml index 9742ccd1ad76fef2c3e7d4de64ac55f0e6df3006..2c4bfc752c8f08ae56e875b6f00392deb4a131ba 100644 --- a/src/proto_010_PtGRANAD/lib_client_commands/client_proto_stresstest_commands.ml +++ b/src/proto_010_PtGRANAD/lib_client_commands/client_proto_stresstest_commands.ml @@ -316,7 +316,7 @@ let generate_fresh_source pool rng = let heads_iter (cctxt : Protocol_client_context.full) (f : Block_hash.t * Tezos_base.Block_header.t -> unit Lwt.t) : unit tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Error_monad.protect (fun () -> let* (heads_stream, stopper) = Shell_services.Monitor.heads cctxt `Main in diff --git a/src/proto_011_PtHangz2/lib_client/test/test_client_proto_contracts.ml b/src/proto_011_PtHangz2/lib_client/test/test_client_proto_contracts.ml index 226aebcc45fef79b6a6a9de66f37da6c1b96bc29..bfc8133374dc4cf97d6850feb445eb4ee017459d 100644 --- a/src/proto_011_PtHangz2/lib_client/test/test_client_proto_contracts.ml +++ b/src/proto_011_PtHangz2/lib_client/test/test_client_proto_contracts.ml @@ -57,7 +57,7 @@ class mock_wallet (entities : string) : Tezos_client_base.Client_context.wallet fun _alias_name _list _encoding -> failwith "mock_wallet:write" method last_modification_time : string -> float option tzresult Lwt.t = - fun _ -> Lwt_tzresult_syntax.return_none + fun _ -> Lwt_result_syntax.return_none end (** diff --git a/src/proto_011_PtHangz2/lib_client_commands/client_proto_stresstest_commands.ml b/src/proto_011_PtHangz2/lib_client_commands/client_proto_stresstest_commands.ml index 9742ccd1ad76fef2c3e7d4de64ac55f0e6df3006..2c4bfc752c8f08ae56e875b6f00392deb4a131ba 100644 --- a/src/proto_011_PtHangz2/lib_client_commands/client_proto_stresstest_commands.ml +++ b/src/proto_011_PtHangz2/lib_client_commands/client_proto_stresstest_commands.ml @@ -316,7 +316,7 @@ let generate_fresh_source pool rng = let heads_iter (cctxt : Protocol_client_context.full) (f : Block_hash.t * Tezos_base.Block_header.t -> unit Lwt.t) : unit tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Error_monad.protect (fun () -> let* (heads_stream, stopper) = Shell_services.Monitor.heads cctxt `Main in diff --git a/src/proto_012_Psithaca/lib_client/test/test_client_proto_contracts.ml b/src/proto_012_Psithaca/lib_client/test/test_client_proto_contracts.ml index 226aebcc45fef79b6a6a9de66f37da6c1b96bc29..bfc8133374dc4cf97d6850feb445eb4ee017459d 100644 --- a/src/proto_012_Psithaca/lib_client/test/test_client_proto_contracts.ml +++ b/src/proto_012_Psithaca/lib_client/test/test_client_proto_contracts.ml @@ -57,7 +57,7 @@ class mock_wallet (entities : string) : Tezos_client_base.Client_context.wallet fun _alias_name _list _encoding -> failwith "mock_wallet:write" method last_modification_time : string -> float option tzresult Lwt.t = - fun _ -> Lwt_tzresult_syntax.return_none + fun _ -> Lwt_result_syntax.return_none end (** diff --git a/src/proto_012_Psithaca/lib_client_commands/client_proto_stresstest_commands.ml b/src/proto_012_Psithaca/lib_client_commands/client_proto_stresstest_commands.ml index b9e4fbba98d814abb42770400c1d9a6e5511e36f..9661293389522bba51c6fe6d8e083f3163322333 100644 --- a/src/proto_012_Psithaca/lib_client_commands/client_proto_stresstest_commands.ml +++ b/src/proto_012_Psithaca/lib_client_commands/client_proto_stresstest_commands.ml @@ -316,7 +316,7 @@ let generate_fresh_source pool rng = let heads_iter (cctxt : Protocol_client_context.full) (f : Block_hash.t * Tezos_base.Block_header.t -> unit Lwt.t) : unit tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Error_monad.protect (fun () -> let* (heads_stream, stopper) = Shell_services.Monitor.heads cctxt `Main in diff --git a/src/proto_012_Psithaca/lib_delegate/liquidity_baking_vote_file.ml b/src/proto_012_Psithaca/lib_delegate/liquidity_baking_vote_file.ml index e0b051037b00613bc4324a59873e8bcfa74cfcfb..a3d3473efbd83e72c3ba85526666eb9565efb3aa 100644 --- a/src/proto_012_Psithaca/lib_delegate/liquidity_baking_vote_file.ml +++ b/src/proto_012_Psithaca/lib_delegate/liquidity_baking_vote_file.ml @@ -126,7 +126,7 @@ let () = Block_vote_file_missing_liquidity_baking_escape_vote file_path) let traced_option_to_result ~error = - Option.fold ~some:ok ~none:(Tzresult_syntax.fail error) + Option.fold ~some:ok ~none:(Result_syntax.tzfail error) let check_file_exists file = if Sys.file_exists file then Result.return_unit diff --git a/src/proto_012_Psithaca/lib_delegate/test/mockup_simulator/faked_client_context.ml b/src/proto_012_Psithaca/lib_delegate/test/mockup_simulator/faked_client_context.ml index 11be0238871cc9835a24f24fd634a78612c2b45a..3843e921d577e1a2bbb793f97af060f04a73a97d 100644 --- a/src/proto_012_Psithaca/lib_delegate/test/mockup_simulator/faked_client_context.ml +++ b/src/proto_012_Psithaca/lib_delegate/test/mockup_simulator/faked_client_context.ml @@ -138,7 +138,7 @@ class faked_wallet ~base_dir ~filesystem : Client_context.wallet = return_unit method last_modification_time : string -> float option tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in fun alias_name -> let filename = self#filename alias_name in let file = String.Hashtbl.find_opt filesystem filename in diff --git a/src/proto_012_Psithaca/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_012_Psithaca/lib_delegate/test/mockup_simulator/mockup_simulator.ml index 9bf5b42d601fa78a25f3eb1a03850bdfeba96e32..cb61231de37f8bf9fc62d105e140d107210325f5 100644 --- a/src/proto_012_Psithaca/lib_delegate/test/mockup_simulator/mockup_simulator.ml +++ b/src/proto_012_Psithaca/lib_delegate/test/mockup_simulator/mockup_simulator.ml @@ -1077,7 +1077,7 @@ let run ?(config = default_config) bakers_spec = Lwt.pick [ timeout_process (); - Lwt_tzresult_syntax.join + Lwt_result_syntax.tzjoin (take_third (List.fold_left (fun (i, delegates_acc, ms) (n, user_hooks) -> diff --git a/src/proto_012_Psithaca/lib_protocol/test/helpers/transfers.ml b/src/proto_012_Psithaca/lib_protocol/test/helpers/transfers.ml index 2817680a26aa8a2ff352e2b57b33be06edcc99f3..78557fb568492dd2e053f89bf92261aa58b3d9c8 100644 --- a/src/proto_012_Psithaca/lib_protocol/test/helpers/transfers.ml +++ b/src/proto_012_Psithaca/lib_protocol/test/helpers/transfers.ml @@ -29,7 +29,7 @@ open Test_tez let transfer_and_check_balances ?(with_burn = false) ~loc b ?(fee = Tez.zero) ?expect_failure src dst amount = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*? amount_fee = fee +? amount in let* bal_src = Context.Contract.balance (I b) src in let* bal_dst = Context.Contract.balance (I b) dst in diff --git a/src/proto_012_Psithaca/lib_protocol/test/unit/test_saturation.ml b/src/proto_012_Psithaca/lib_protocol/test/unit/test_saturation.ml index c57d4a1c4288603293329bb6b9fb72cee52a54c7..39853e842a644c33ca69fbf41caf3947ec32083f 100644 --- a/src/proto_012_Psithaca/lib_protocol/test/unit/test_saturation.ml +++ b/src/proto_012_Psithaca/lib_protocol/test/unit/test_saturation.ml @@ -195,7 +195,7 @@ let encoding encoder () = (x' :> int) x)))) in - Error_monad.Lwt_tzresult_syntax.join + Error_monad.Lwt_result_syntax.tzjoin (List.map check_encode_decode [0; 7373737373; max_int - 1]) let tests = diff --git a/src/proto_013_PtJakart/bin_sc_rollup_node/configuration.ml b/src/proto_013_PtJakart/bin_sc_rollup_node/configuration.ml index 5608d3760e36466a32c421ed7f8e86c831703ff8..03afc2912ec5e373d6b9561f8809495cf5c4d7c6 100644 --- a/src/proto_013_PtJakart/bin_sc_rollup_node/configuration.ml +++ b/src/proto_013_PtJakart/bin_sc_rollup_node/configuration.ml @@ -68,6 +68,6 @@ let save config = Lwt_utils_unix.Json.write_file (filename config) json let load ~data_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let+ json = Lwt_utils_unix.Json.read_file (relative_filename data_dir) in Data_encoding.Json.destruct encoding json diff --git a/src/proto_013_PtJakart/bin_sc_rollup_node/daemon.ml b/src/proto_013_PtJakart/bin_sc_rollup_node/daemon.ml index 2d018efae927354f47cd64173acb7b171bd4bdc9..2f9c6e8e772e3b476865d9276566ffc55b96ee1e 100644 --- a/src/proto_013_PtJakart/bin_sc_rollup_node/daemon.ml +++ b/src/proto_013_PtJakart/bin_sc_rollup_node/daemon.ml @@ -24,7 +24,7 @@ (*****************************************************************************) let on_layer_1_chain_event cctxt store chain_event = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = Inbox.update cctxt store chain_event in let*! () = Layer1.processed chain_event in return () @@ -52,7 +52,7 @@ let install_finalizer store rpc_server = Tezos_base_unix.Internal_event_unix.close () let run ~data_dir (cctxt : Protocol_client_context.full) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let start () = let*! () = Event.starting_node () in let* configuration = Configuration.load ~data_dir in diff --git a/src/proto_013_PtJakart/bin_sc_rollup_node/inbox.ml b/src/proto_013_PtJakart/bin_sc_rollup_node/inbox.ml index 30315b50b01820460fd2639ffd0ce8fdabc12699..b0848b535a1741aca05977796c4b6e0a3f44373d 100644 --- a/src/proto_013_PtJakart/bin_sc_rollup_node/inbox.ml +++ b/src/proto_013_PtJakart/bin_sc_rollup_node/inbox.ml @@ -65,7 +65,7 @@ module State = struct end let get_messages cctxt head rollup = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Block_services in let+ operations = Operations.operations cctxt ~chain:`Main ~block:(`Level (snd head)) () @@ -118,7 +118,7 @@ let process_head cctxt store Layer1.(Head {level; hash = head_hash} as head) = return_unit let update cctxt store chain_event = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Layer1 in Lwt.map Environment.wrap_tzresult @@ diff --git a/src/proto_013_PtJakart/bin_sc_rollup_node/layer1.ml b/src/proto_013_PtJakart/bin_sc_rollup_node/layer1.ml index 720fd809e3824384826bbfe49082756994822e2c..eb2ea3b67496f7c5095dee378c2e877b39238d64 100644 --- a/src/proto_013_PtJakart/bin_sc_rollup_node/layer1.ml +++ b/src/proto_013_PtJakart/bin_sc_rollup_node/layer1.ml @@ -260,7 +260,7 @@ let catch_up cctxt store chain last_seen_head new_head = | Some predecessor -> aux [] predecessor let chain_events cctxt store chain = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let on_head (hash, (block_header : Tezos_base.Block_header.t)) = let level = block_header.shell.level in let new_head = Head {hash; level} in @@ -279,7 +279,7 @@ let chain_events cctxt store chain = let check_sc_rollup_address_exists sc_rollup_address (cctxt : Protocol_client_context.full) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* kind_opt = RPC.Sc_rollup.kind cctxt (cctxt#chain, cctxt#block) sc_rollup_address () in @@ -292,7 +292,7 @@ let check_sc_rollup_address_exists sc_rollup_address return_unit let start configuration (cctxt : Protocol_client_context.full) store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Layer1_event.starting () in let* () = check_sc_rollup_address_exists configuration.sc_rollup_address cctxt diff --git a/src/proto_013_PtJakart/bin_tx_rollup_node/RPC.ml b/src/proto_013_PtJakart/bin_tx_rollup_node/RPC.ml index 3d0d85c702cfa26bc3207b929ded0205463df374..82e3439b6e4b99de4db201c46dc9a587363e7a7c 100644 --- a/src/proto_013_PtJakart/bin_tx_rollup_node/RPC.ml +++ b/src/proto_013_PtJakart/bin_tx_rollup_node/RPC.ml @@ -138,7 +138,7 @@ module Arg = struct end module Block = struct - open Lwt_tzresult_syntax + open Lwt_result_syntax let path = RPC_path.(open_root) @@ -213,7 +213,7 @@ module Block = struct end module Context_RPC = struct - open Lwt_tzresult_syntax + open Lwt_result_syntax let path = RPC_path.open_root diff --git a/src/proto_013_PtJakart/bin_tx_rollup_node/batcher.ml b/src/proto_013_PtJakart/bin_tx_rollup_node/batcher.ml index 16dfaba14a0a308f4523fe839cef5f1ccb455971..c2ce94eddf823c9319435aa0d791c1b5e741077f 100644 --- a/src/proto_013_PtJakart/bin_tx_rollup_node/batcher.ml +++ b/src/proto_013_PtJakart/bin_tx_rollup_node/batcher.ml @@ -195,7 +195,7 @@ let init cctxt ~rollup ~signer index parameters = let register_transaction ?(eager_batch = false) ?(apply = true) state (tr : L2_transaction.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt_mutex.with_lock state.lock @@ fun () -> let batch = Tx_rollup_l2_batch.V1. @@ -215,7 +215,7 @@ let register_transaction ?(eager_batch = false) ?(apply = true) state return new_context | Batch_V1.Batch_result {results = [(_tr, Transaction_failure {reason; _})]; _} -> - fail (Environment.wrap_tzerror reason) + tzfail (Environment.wrap_tzerror reason) | _ -> return context in context diff --git a/src/proto_013_PtJakart/bin_tx_rollup_node/stores.ml b/src/proto_013_PtJakart/bin_tx_rollup_node/stores.ml index b2443cd7841a07bf5e8a0c311b1739f355e374ba..c7792994beee102cf2c0b303aebee5ac336f352b 100644 --- a/src/proto_013_PtJakart/bin_tx_rollup_node/stores.ml +++ b/src/proto_013_PtJakart/bin_tx_rollup_node/stores.ml @@ -388,10 +388,10 @@ module L2_block_store = struct Cache.find_or_replace store.cache hash read_from_disk let locked_write_block store ~offset ~block ~hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* block_bytes = match Data_encoding.Binary.to_bytes_opt L2_blocks_file.encoding block with - | None -> fail (Cannot_encode_block hash) + | None -> tzfail (Cannot_encode_block hash) | Some bytes -> return bytes in let block_length = Bytes.length block_bytes in @@ -562,13 +562,13 @@ struct (Bytes.unsafe_of_string bytes) let write store x = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! res = Lwt_utils_unix.with_atomic_open_out ~overwrite:true store.file @@ fun fd -> let* block_bytes = match Data_encoding.Binary.to_bytes_opt S.encoding x with - | None -> fail (Cannot_encode_data S.name) + | None -> tzfail (Cannot_encode_data S.name) | Some bytes -> return bytes in let*! () = Lwt_utils_unix.write_bytes fd block_bytes in @@ -576,7 +576,7 @@ struct in match res with | Ok res -> Lwt.return res - | Error _ -> fail (Cannot_write_file S.name) + | Error _ -> tzfail (Cannot_write_file S.name) let init ~data_dir = let file = Filename.Infix.(Node_data.store_dir data_dir // S.name) in diff --git a/src/proto_013_PtJakart/lib_client/test/test_client_proto_contracts.ml b/src/proto_013_PtJakart/lib_client/test/test_client_proto_contracts.ml index 226aebcc45fef79b6a6a9de66f37da6c1b96bc29..bfc8133374dc4cf97d6850feb445eb4ee017459d 100644 --- a/src/proto_013_PtJakart/lib_client/test/test_client_proto_contracts.ml +++ b/src/proto_013_PtJakart/lib_client/test/test_client_proto_contracts.ml @@ -57,7 +57,7 @@ class mock_wallet (entities : string) : Tezos_client_base.Client_context.wallet fun _alias_name _list _encoding -> failwith "mock_wallet:write" method last_modification_time : string -> float option tzresult Lwt.t = - fun _ -> Lwt_tzresult_syntax.return_none + fun _ -> Lwt_result_syntax.return_none end (** diff --git a/src/proto_013_PtJakart/lib_delegate/liquidity_baking_vote_file.ml b/src/proto_013_PtJakart/lib_delegate/liquidity_baking_vote_file.ml index e23b2934b9e68048ae2b1e96432fac8636af0028..da49a169c1b0d273580c47b399b4757d76534f9e 100644 --- a/src/proto_013_PtJakart/lib_delegate/liquidity_baking_vote_file.ml +++ b/src/proto_013_PtJakart/lib_delegate/liquidity_baking_vote_file.ml @@ -135,7 +135,7 @@ let () = Block_vote_file_missing_liquidity_baking_toggle_vote file_path) let traced_option_to_result ~error = - Option.fold ~some:ok ~none:(Tzresult_syntax.fail error) + Option.fold ~some:ok ~none:(Result_syntax.tzfail error) let check_file_exists file = if Sys.file_exists file then Result.return_unit diff --git a/src/proto_013_PtJakart/lib_delegate/test/mockup_simulator/faked_client_context.ml b/src/proto_013_PtJakart/lib_delegate/test/mockup_simulator/faked_client_context.ml index 1d06e59cefcf433d8ef6652114da2a145bec75f8..0483265b3328e71979da8de221b361e0c6b459ef 100644 --- a/src/proto_013_PtJakart/lib_delegate/test/mockup_simulator/faked_client_context.ml +++ b/src/proto_013_PtJakart/lib_delegate/test/mockup_simulator/faked_client_context.ml @@ -138,7 +138,7 @@ class faked_wallet ~base_dir ~filesystem : Client_context.wallet = return_unit method last_modification_time : string -> float option tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in fun alias_name -> let filename = self#filename alias_name in let file = String.Hashtbl.find_opt filesystem filename in diff --git a/src/proto_013_PtJakart/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_013_PtJakart/lib_delegate/test/mockup_simulator/mockup_simulator.ml index 028e2060437ea72131adc2030ead5d27d46700f5..e361018fd87cb8c85d1cf15fbf9daea5a90ae672 100644 --- a/src/proto_013_PtJakart/lib_delegate/test/mockup_simulator/mockup_simulator.ml +++ b/src/proto_013_PtJakart/lib_delegate/test/mockup_simulator/mockup_simulator.ml @@ -1125,7 +1125,7 @@ let run ?(config = default_config) bakers_spec = Lwt.pick [ timeout_process (); - Lwt_tzresult_syntax.join + Lwt_result_syntax.tzjoin (take_third (List.fold_left (fun (i, delegates_acc, ms) (n, user_hooks) -> diff --git a/src/proto_013_PtJakart/lib_protocol/test/helpers/transfers.ml b/src/proto_013_PtJakart/lib_protocol/test/helpers/transfers.ml index 2817680a26aa8a2ff352e2b57b33be06edcc99f3..78557fb568492dd2e053f89bf92261aa58b3d9c8 100644 --- a/src/proto_013_PtJakart/lib_protocol/test/helpers/transfers.ml +++ b/src/proto_013_PtJakart/lib_protocol/test/helpers/transfers.ml @@ -29,7 +29,7 @@ open Test_tez let transfer_and_check_balances ?(with_burn = false) ~loc b ?(fee = Tez.zero) ?expect_failure src dst amount = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*? amount_fee = fee +? amount in let* bal_src = Context.Contract.balance (I b) src in let* bal_dst = Context.Contract.balance (I b) dst in diff --git a/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_block_time_instructions.ml b/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_block_time_instructions.ml index 221d12cf5cdfe8c4eb224d115d03af22e9fec9c2..ac8de4e6e97b5da3d03afc9eb5df8570f7865b4c 100644 --- a/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_block_time_instructions.ml +++ b/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_block_time_instructions.ml @@ -36,13 +36,13 @@ open Protocol open Alpha_context let context_with_constants constants = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (block, _contracts) = Context.init_with_constants constants 1 in let+ incremental = Incremental.begin_construction block in Incremental.alpha_ctxt incremental let test_min_block_time () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* context = context_with_constants Default_parameters.constants_mainnet in let* (result, _) = Contract_helpers.run_script diff --git a/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_accounting.ml b/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_accounting.ml index 18025e9d0590f8ad98bc0aa3b3e1cfc56178e8aa..1a717ac3f0ac33e9985bf40a9bbf98b6882e8aa1 100644 --- a/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_accounting.ml +++ b/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_accounting.ml @@ -52,7 +52,7 @@ let assert_fail_with ~loc ~msg f = | Error _ -> failwith "Expected a single error at %s." loc let string_list_of_ex_token_diffs ctxt token_diffs = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let accum (xs, ctxt) (Ticket_token.Ex_token {ticketer; contents_type; contents}, amount) = let* (x, ctxt) = @@ -80,7 +80,7 @@ let string_list_of_ex_token_diffs ctxt token_diffs = return (List.rev xs, ctxt) let make_ex_token ctxt ~ticketer ~type_exp ~content_exp = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in wrap @@ let*? (Script_ir_translator.Ex_comparable_ty contents_type, ctxt) = let node = Micheline.root @@ Expr.from_string type_exp in @@ -94,7 +94,7 @@ let make_ex_token ctxt ~ticketer ~type_exp ~content_exp = return (Ticket_token.Ex_token {ticketer; contents_type; contents}, ctxt) let assert_equal_ticket_diffs ~loc ctxt given expected = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (ctxt, tbs1) = List.fold_left_map_es (fun ctxt ((ticketer, content), delta) -> @@ -116,7 +116,7 @@ let assert_equal_ticket_diffs ~loc ctxt given expected = (List.sort String.compare tbs2) let updates_of_key_values ctxt ~key_type ~value_type key_values = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in List.fold_right_es (fun (key, value) (kvs, ctxt) -> let* (key_hash, ctxt) = @@ -158,7 +158,7 @@ let make_alloc big_map_id alloc updates = (Update {init = Lazy_storage.Alloc alloc; updates}) let init () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (block, contracts) = Context.init 1 in let source = WithExceptions.Option.get ~loc:__LOC__ @@ List.hd contracts in let* (operation, originated) = @@ -182,7 +182,7 @@ let init_for_operation () = (baker, src1, block) let two_ticketers block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* ctxt = Incremental.begin_construction block >|=? Incremental.alpha_ctxt in @@ -197,7 +197,7 @@ let ticket_list_script = |} let setup ctxt ~key_type ~value_type entries = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (ctxt, big_map_id) = wrap @@ Big_map.fresh ~temporary:false ctxt in let* (updates, ctxt) = updates_of_key_values @@ -226,7 +226,7 @@ let setup ctxt ~key_type ~value_type entries = return (alloc, big_map_id, ctxt) let new_big_map ctxt contract ~key_type ~value_type entries = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (alloc, big_map_id, ctxt) = setup ctxt ~key_type ~value_type entries in let storage = Expr.from_string "{}" in let* ctxt = @@ -235,19 +235,19 @@ let new_big_map ctxt contract ~key_type ~value_type entries = return (big_map_id, ctxt) let alloc_diff ctxt ~key_type ~value_type entries = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (allocations, _, ctxt) = setup ctxt ~key_type ~value_type entries in return (allocations, ctxt) let remove_diff ctxt contract ~key_type ~value_type ~existing_entries = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (big_map_id, ctxt) = new_big_map ctxt contract ~key_type ~value_type existing_entries in return (Lazy_storage.make Lazy_storage.Kind.Big_map big_map_id Remove, ctxt) let copy_diff ctxt contract ~key_type ~value_type ~existing_entries ~updates = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (big_map_id, ctxt) = new_big_map ctxt contract ~key_type ~value_type existing_entries in @@ -264,7 +264,7 @@ let copy_diff ctxt contract ~key_type ~value_type ~existing_entries ~updates = let existing_diff ctxt contract ~key_type ~value_type ~existing_entries ~updates = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (big_map_id, ctxt) = new_big_map ctxt contract ~key_type ~value_type existing_entries in @@ -279,7 +279,7 @@ let existing_diff ctxt contract ~key_type ~value_type ~existing_entries ~updates ctxt ) let empty_big_map ctxt ~key_type ~value_type = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (ctxt, big_map_id) = wrap @@ Big_map.fresh ~temporary:false ctxt in return @@ -293,7 +293,7 @@ let empty_big_map ctxt ~key_type ~value_type = ctxt ) let make_big_map ctxt contract ~key_type ~value_type entries = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (big_map_id, ctxt) = new_big_map ctxt contract ~key_type ~value_type entries @@ -309,7 +309,7 @@ let make_big_map ctxt contract ~key_type ~value_type entries = ctxt ) let originate_script block ~script ~storage ~src ~baker ~forges_tickets = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let code = Expr.toplevel_from_string script in let storage = Expr.from_string storage in let script = @@ -331,7 +331,7 @@ let originate_script block ~script ~storage ~src ~baker ~forges_tickets = Incremental.finalize_block incr >|=? fun block -> (destination, script, block) let origination_operation ctxt ~src ~script ~orig_contract = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* ( Script_ir_translator.Ex_script (Script { @@ -369,7 +369,7 @@ let origination_operation ctxt ~src ~script ~orig_contract = return (operation, ctxt) let originate block ~src ~baker ~script ~storage ~forges_tickets = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (orig_contract, script, block) = originate_script block ~script ~storage ~src ~baker ~forges_tickets in @@ -379,7 +379,7 @@ let originate block ~src ~baker ~script ~storage ~forges_tickets = return (orig_contract, script, incr) let transfer_operation ctxt ~src ~destination ~arg_type ~arg = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (params_node, ctxt) = wrap (Script_ir_translator.unparse_data @@ -432,7 +432,7 @@ let type_has_tickets ctxt ty = (** Test that adding a ticket to a lazy storage diff is picked up. *) let assert_ticket_diffs ctxt ~loc ~arg_type ~storage_type ~arg ~old_storage ~new_storage ~lazy_storage_diff expected = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*? (arg_type_has_tickets, ctxt) = type_has_tickets ctxt arg_type in let*? (storage_type_has_tickets, ctxt) = type_has_tickets ctxt storage_type in let* (ticket_diff, ctxt) = @@ -452,7 +452,7 @@ let assert_ticket_diffs ctxt ~loc ~arg_type ~storage_type ~arg ~old_storage assert_equal_ticket_diffs ~loc ctxt ticket_diffs expected let assert_balance ctxt ~loc key expected = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (balance, _) = wrap @@ Ticket_balance.get_balance ctxt key in match (balance, expected) with | (Some b, Some eb) -> Assert.equal_int ~loc (Z.to_int b) eb @@ -473,7 +473,7 @@ let string_ticket ticketer contents amount = Script_typed_ir.{ticketer; contents; amount} let string_ticket_token ticketer content = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let contents = Result.value_f ~default:(fun _ -> assert false) @@ Alpha_context.Script_string.of_string content @@ -484,7 +484,7 @@ let string_ticket_token ticketer content = {ticketer; contents_type = Script_typed_ir.string_key; contents}) let test_diffs_empty () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (_contract, ctxt) = init () in let*? int_ticket_big_map_ty = @@ -508,7 +508,7 @@ let test_diffs_empty () = (** Test that sending one ticket as an argument, when the new storage is empty results in an negative diff. *) let test_diffs_tickets_in_args () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (_contract, ctxt) = init () in let arg = string_ticket "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1 in @@ -526,7 +526,7 @@ let test_diffs_tickets_in_args () = (** Test adding a ticket to the args, which is also accounted for in the new storage, results in an empty diff. *) let test_diffs_tickets_in_args_and_storage () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (_contract, ctxt) = init () in let arg = string_ticket "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1 in assert_ticket_diffs @@ -543,7 +543,7 @@ let test_diffs_tickets_in_args_and_storage () = (** Test that adding two tickets in the args, and only one new ticket in the storage results in a negative diff. *) let test_diffs_drop_one_ticket () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (_contract, ctxt) = init () in let arg = boxed_list @@ -572,7 +572,7 @@ let test_diffs_drop_one_ticket () = (** Test that adding a new ticket to the storage results in a positive balance. *) let test_diffs_adding_new_ticket_to_storage () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (_contract, ctxt) = init () in let new_storage = boxed_list [string_ticket "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1] @@ -591,7 +591,7 @@ let test_diffs_adding_new_ticket_to_storage () = (** Test that removing one ticket from the storage results in a negative diff. *) let test_diffs_remove_from_storage () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (_contract, ctxt) = init () in let old_storage = boxed_list @@ -619,7 +619,7 @@ let test_diffs_remove_from_storage () = (* Test adding ticket through lazy-storage diff results in a positive diff. *) let test_diffs_lazy_storage_alloc () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (_contract, ctxt) = init () in let*? int_ticket_big_map_ty = @@ -653,7 +653,7 @@ let test_diffs_lazy_storage_alloc () = (* Test removing a big map containing a ticket results in a negative diff. *) let test_diffs_remove_from_big_map () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (contract, ctxt) = init () in let*? int_ticket_big_map_ty = @@ -689,7 +689,7 @@ let test_diffs_remove_from_big_map () = (** Test copying a big-map. *) let test_diffs_copy_big_map () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (contract, ctxt) = init () in let*? int_ticket_big_map_ty = @@ -738,7 +738,7 @@ let test_diffs_copy_big_map () = (** Test that adding and removing items from an existing big-map results yield corresponding ticket-token diffs. *) let test_diffs_add_to_existing_big_map () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (contract, ctxt) = init () in let*? int_ticket_big_map_ty = @@ -802,7 +802,7 @@ let test_diffs_add_to_existing_big_map () = (** Test a combination of updates. *) let test_diffs_args_storage_and_lazy_diffs () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (contract, ctxt) = init () in let*? int_ticket_big_map_ty = @@ -893,7 +893,7 @@ let test_diffs_args_storage_and_lazy_diffs () = (** Test that attempting to transfer a ticket that exceeds the budget fails. *) let test_update_invalid_transfer () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, src, block) = init_for_operation () in let* (destination, _script, incr) = originate @@ -927,7 +927,7 @@ let test_update_invalid_transfer () = (** Test that adding more tickets created by the [self] contract is valid and results in a balance update. *) let test_update_ticket_self_diff () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, src, block) = init_for_operation () in let* (self, _script, incr) = originate @@ -963,7 +963,7 @@ let test_update_ticket_self_diff () = (* Test that sending tickets to self succeed (there are no budget constraints). *) let test_update_self_ticket_transfer () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, self, block) = init_for_operation () in let* (ticket_receiver, _script, incr) = originate @@ -1022,7 +1022,7 @@ let test_update_self_ticket_transfer () = (** Test that transferring a ticket that does not exceed the budget succeeds. *) let test_update_valid_transfer () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, self, block) = init_for_operation () in let* (destination, _script, incr) = originate @@ -1084,7 +1084,7 @@ let test_update_valid_transfer () = (** Test that transferring a ticket to itself is allowed and does not impact the balance. *) let test_update_transfer_tickets_to_self () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, src, block) = init_for_operation () in let* (self, _script, incr) = originate @@ -1143,7 +1143,7 @@ let test_update_transfer_tickets_to_self () = (** Test that attempting to originate a contract with tickets that exceed the budget fails. *) let test_update_invalid_origination () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, src, block) = init_for_operation () in let* (destination, script, incr) = let storage = @@ -1180,7 +1180,7 @@ let test_update_invalid_origination () = (** Test update valid origination. *) let test_update_valid_origination () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, self, block) = init_for_operation () in let ticketer = "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" in assert (ticketer <> Contract.to_b58check self) ; @@ -1237,7 +1237,7 @@ let test_update_valid_origination () = assert_balance ~loc:__LOC__ ctxt red_originated_token_hash (Some 1) let test_update_self_origination () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, self, block) = init_for_operation () in let ticketer = Contract.to_b58check self in let* (originated, script, incr) = @@ -1276,7 +1276,7 @@ let test_update_self_origination () = (** Test ticket-token map of list with duplicates. *) let test_ticket_token_map_of_list_with_duplicates () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, src, block) = init_for_operation () in let* (self, _script, incr) = originate diff --git a/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_balance.ml b/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_balance.ml index 31a9cc3f96a4b53336545579c5b025f6df8eb735..4e95525f0e1642f26b5d8990e06d74d0a12152b6 100644 --- a/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_balance.ml +++ b/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_balance.ml @@ -34,7 +34,7 @@ open Protocol open Alpha_context -open Lwt_tzresult_syntax +open Lwt_result_syntax let wrap m = m >|= Environment.wrap_tzresult diff --git a/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_manager.ml b/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_manager.ml index 252e84bb0df6c05b475c6b16e75170a234aca7a6..7bb0f500951d527985ea7d1b50825ca4911ab25a 100644 --- a/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_manager.ml +++ b/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_manager.ml @@ -40,7 +40,7 @@ open Protocol open Alpha_context -open Lwt_tzresult_syntax +open Lwt_result_syntax let wrap m = m >|= Environment.wrap_tzresult diff --git a/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml b/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml index 183c07137406caebf571d1881ac17ae44a596d6b..25c3b57d806a4f8821d9bbb46a50b2e75ff56bf7 100644 --- a/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml +++ b/src/proto_013_PtJakart/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml @@ -283,7 +283,7 @@ let originate block ~src ~baker ~script ~storage ~forges_tickets = return (orig_contract, incr) let transfer_operation ~incr ~src ~destination ~parameters_ty ~parameters = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let ctxt = Incremental.alpha_ctxt incr in let* (params_node, ctxt) = wrap @@ -319,7 +319,7 @@ let transfer_operation ~incr ~src ~destination ~parameters_ty ~parameters = let transfer_operation_to_tx_rollup ~incr ~src ~parameters_ty ~parameters ~tx_rollup = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let ctxt = Incremental.alpha_ctxt incr in let* (params_node, ctxt) = wrap @@ -393,7 +393,7 @@ let make_tickets ts = return {elements; length = List.length elements} let transfer_tickets_operation ~incr ~src ~destination tickets = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*? parameters_ty = Environment.wrap_tzresult list_ticket_string_ty in let* parameters = wrap @@ make_tickets tickets in transfer_operation ~incr ~src ~destination ~parameters_ty ~parameters @@ -1093,7 +1093,7 @@ let test_transfer_big_map_with_tickets () = ~storage:"{}" ~forges_tickets:false in - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*? value_type = Environment.wrap_tzresult @@ ticket_t Micheline.dummy_location string_key in @@ -1144,7 +1144,7 @@ let test_transfer_big_map_with_tickets () = (** Test transfer a ticket to a tx_rollup. *) let test_tx_rollup_deposit_one_ticket () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (_baker, src, block) = init ~tx_rollup_enable:true () in let* ticketer = one_ticketer block in let* incr = Incremental.begin_construction block in diff --git a/src/proto_013_PtJakart/lib_protocol/test/integration/operations/test_sc_rollup.ml b/src/proto_013_PtJakart/lib_protocol/test/integration/operations/test_sc_rollup.ml index 7e43cd100edaf1b1c3adf673fd77079de81d165c..468484621844aed64f221c45ae5b891fb922bd55 100644 --- a/src/proto_013_PtJakart/lib_protocol/test/integration/operations/test_sc_rollup.ml +++ b/src/proto_013_PtJakart/lib_protocol/test/integration/operations/test_sc_rollup.ml @@ -34,7 +34,7 @@ open Protocol open Alpha_context -open Lwt_tzresult_syntax +open Lwt_result_syntax exception Sc_rollup_test_error of string diff --git a/src/proto_013_PtJakart/lib_protocol/test/integration/test_storage_functions.ml b/src/proto_013_PtJakart/lib_protocol/test/integration/test_storage_functions.ml index b1d22bc8848136c3191f5220aba8f9a189285603..c0fa687b72a7cfd3c72e7114084b1e647bc5aed0 100644 --- a/src/proto_013_PtJakart/lib_protocol/test/integration/test_storage_functions.ml +++ b/src/proto_013_PtJakart/lib_protocol/test/integration/test_storage_functions.ml @@ -97,7 +97,7 @@ let wrap m = m >|= Environment.wrap_tzresult This test checks that it is possible to add values to a Carbonated_data_set_storage and iterate over them. *) let test_fold_keys_unaccounted () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* ctxt = Context.default_raw_context () in let* (ctxt, _) = wrap (Table.init ctxt 1) in let* (ctxt, _) = wrap (Table.init ctxt 2) in diff --git a/src/proto_013_PtJakart/lib_protocol/test/pbt/test_bitset.ml b/src/proto_013_PtJakart/lib_protocol/test/pbt/test_bitset.ml index e61b7b2c98cc17af4cfe57343e770a12f42a0f2e..56c84b4d69446b0c3f695222ab7272a51645ec45 100644 --- a/src/proto_013_PtJakart/lib_protocol/test/pbt/test_bitset.ml +++ b/src/proto_013_PtJakart/lib_protocol/test/pbt/test_bitset.ml @@ -55,7 +55,7 @@ let test_get_set (c, ofs) = List.for_all (fun ofs' -> let res = - let open Tzresult_syntax in + let open Result_syntax in let* c' = add c ofs in let* v = mem c ofs' in let* v' = mem c' ofs' in diff --git a/src/proto_013_PtJakart/lib_protocol/test/unit/test_gas_monad.ml b/src/proto_013_PtJakart/lib_protocol/test/unit/test_gas_monad.ml index 281a092abc60e6ba9633044637ac333d2aaff40f..27a82fe49119451e124eb35e62c921149d273ba3 100644 --- a/src/proto_013_PtJakart/lib_protocol/test/unit/test_gas_monad.ml +++ b/src/proto_013_PtJakart/lib_protocol/test/unit/test_gas_monad.ml @@ -54,7 +54,7 @@ let assert_equal_gas ~loc g1 g2 = let assert_inner_errors ~loc ctxt gas_monad ~errors ~remaining_gas = match GM.run ctxt gas_monad with | Ok (Error e, ctxt) -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = Assert.assert_equal_list ~loc @@ -73,7 +73,7 @@ let assert_inner_errors ~loc ctxt gas_monad ~errors ~remaining_gas = let assert_success ~loc ctxt gas_monad ~result ~remaining_gas = match GM.run ctxt gas_monad with | Ok (Ok x, ctxt) -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = Assert.equal_int ~loc x result in assert_equal_gas ~loc diff --git a/src/proto_013_PtJakart/lib_protocol/test/unit/test_saturation.ml b/src/proto_013_PtJakart/lib_protocol/test/unit/test_saturation.ml index f0d2898d75226c3ffca960304492e54bd1b077fa..0cf2633314ca37c9a3339bedbbfded3cfe7324a5 100644 --- a/src/proto_013_PtJakart/lib_protocol/test/unit/test_saturation.ml +++ b/src/proto_013_PtJakart/lib_protocol/test/unit/test_saturation.ml @@ -212,7 +212,7 @@ let encoding encoder () = (x' :> int) x)))) in - Error_monad.Lwt_tzresult_syntax.join + Error_monad.Lwt_result_syntax.tzjoin (List.map check_encode_decode [0; 7373737373; max_int - 1]) let tests = diff --git a/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml b/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml index d22c873edb53d179e90b73203b40a033ac1cceed..a408a513ad5b689ed80b6e3a771f23271cb0e583 100644 --- a/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml +++ b/src/proto_alpha/bin_sc_rollup_node/RPC_server.ml @@ -28,18 +28,18 @@ open Tezos_rpc_http open Tezos_rpc_http_server let get_head_exn store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! head = Layer1.current_head_hash store in match head with None -> failwith "No head" | Some head -> return head let get_state_exn store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* head = get_head_exn store in let*! state = Store.PVMState.find store head in match state with None -> failwith "No state" | Some state -> return state let get_state_info_exn store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* head = get_head_exn store in let*! state = Store.StateInfo.get store head in return state @@ -50,7 +50,7 @@ module Common = struct dir (Sc_rollup_services.current_num_messages ()) (fun () () -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* state_info = get_state_info_exn store in return state_info.num_messages) @@ -86,7 +86,7 @@ module Common = struct dir (Sc_rollup_services.current_ticks ()) (fun () () -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* state = get_state_info_exn store in return state.num_ticks) @@ -118,7 +118,7 @@ module Make (PVM : Pvm.S) = struct dir (Sc_rollup_services.current_total_ticks ()) (fun () () -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* state = get_state_exn store in let*! tick = PVM.get_tick state in return tick) @@ -128,7 +128,7 @@ module Make (PVM : Pvm.S) = struct dir (Sc_rollup_services.current_state_hash ()) (fun () () -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* state = get_state_exn store in let*! hash = PVM.state_hash state in return hash) @@ -138,7 +138,7 @@ module Make (PVM : Pvm.S) = struct dir (Sc_rollup_services.current_status ()) (fun () () -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* state = get_state_exn store in let*! status = PVM.get_status state in return (PVM.string_of_status status)) diff --git a/src/proto_alpha/bin_sc_rollup_node/configuration.ml b/src/proto_alpha/bin_sc_rollup_node/configuration.ml index f2d58fec18dbc4a1bd370ce69e6968edf98e9d23..87efa1268dd2edb98dc6432c0bdafb89df34308b 100644 --- a/src/proto_alpha/bin_sc_rollup_node/configuration.ml +++ b/src/proto_alpha/bin_sc_rollup_node/configuration.ml @@ -120,6 +120,6 @@ let save config = Lwt_utils_unix.Json.write_file (filename config) json let load ~data_dir = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let+ json = Lwt_utils_unix.Json.read_file (relative_filename data_dir) in Data_encoding.Json.destruct encoding json diff --git a/src/proto_alpha/bin_sc_rollup_node/constants.ml b/src/proto_alpha/bin_sc_rollup_node/constants.ml index d27f249ea1d4177f872399b499c957a0e14c6a10..2a87644c72c210bd79666b9128f6808d5efb479c 100644 --- a/src/proto_alpha/bin_sc_rollup_node/constants.ml +++ b/src/proto_alpha/bin_sc_rollup_node/constants.ml @@ -46,14 +46,14 @@ let (set_sc_rollup_node_operator, get_sc_rollup_node_operator) = make_ref () let (set_sc_rollup_initial_level, get_sc_rollup_initial_level) = make_ref () let get_operator_keys cctxt = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let pkh = get_sc_rollup_node_operator () in let+ (_, pk, sk) = Client_keys.get_key cctxt pkh in (pkh, pk, sk) let init (cctxt : Protocol_client_context.full) sc_rollup_address sc_rollup_node_operator = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in set_sc_rollup_address sc_rollup_address ; set_sc_rollup_node_operator sc_rollup_node_operator ; let+ initial_level = diff --git a/src/proto_alpha/bin_sc_rollup_node/daemon.ml b/src/proto_alpha/bin_sc_rollup_node/daemon.ml index 374a640164dfb04e16cec8a9bcb9c2f17e3f87ae..65898fde90ddd3f65dda9bcc6fee3bd4784fb701 100644 --- a/src/proto_alpha/bin_sc_rollup_node/daemon.ml +++ b/src/proto_alpha/bin_sc_rollup_node/daemon.ml @@ -24,7 +24,7 @@ (*****************************************************************************) let on_layer_1_chain_event cctxt store chain_event = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = Inbox.update cctxt store chain_event in let* () = Interpreter.Arith.update store chain_event in let*! () = Layer1.processed chain_event in @@ -53,7 +53,7 @@ let install_finalizer store rpc_server = Tezos_base_unix.Internal_event_unix.close () let run ~data_dir (cctxt : Protocol_client_context.full) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let start () = let*! () = Event.starting_node () in let* configuration = Configuration.load ~data_dir in diff --git a/src/proto_alpha/bin_sc_rollup_node/inbox.ml b/src/proto_alpha/bin_sc_rollup_node/inbox.ml index 2bc6a17c5b7a514b5658c023ba1471b073f3ad98..3eac00dd96ada17fe2ae9bbf86b4af66d17934c0 100644 --- a/src/proto_alpha/bin_sc_rollup_node/inbox.ml +++ b/src/proto_alpha/bin_sc_rollup_node/inbox.ml @@ -57,7 +57,7 @@ module State = struct end let get_messages cctxt head rollup = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Block_services in let+ operations = Operations.operations cctxt ~chain:`Main ~block:(`Level (snd head)) () @@ -110,7 +110,7 @@ let process_head cctxt store Layer1.(Head {level; hash = head_hash} as head) = return_unit let update cctxt store chain_event = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Layer1 in Lwt.map Environment.wrap_tzresult @@ diff --git a/src/proto_alpha/bin_sc_rollup_node/interpreter.ml b/src/proto_alpha/bin_sc_rollup_node/interpreter.ml index c8acc3d7ad8d88456528941a6605f85dd9252409..6a563fda3476d6afaf943836efaba6f575a8715d 100644 --- a/src/proto_alpha/bin_sc_rollup_node/interpreter.ml +++ b/src/proto_alpha/bin_sc_rollup_node/interpreter.ml @@ -65,7 +65,7 @@ module Make (PVM : Pvm.S) : S = struct (** [transition_pvm store predecessor_hash hash] runs a PVM at the previous state from block [predecessor_hash] by consuming as many messages as possible from block [hash]. *) let transition_pvm store predecessor_hash hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in (* Retrieve the previous PVM state from store. *) let*! predecessor_state = Store.PVMState.find store predecessor_hash in let* predecessor_state = @@ -118,13 +118,13 @@ module Make (PVM : Pvm.S) : S = struct (** [process_head store head] runs the PVM for the given head. *) let process_head store (Layer1.Head {hash; _} as head) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! predecessor_hash = Layer1.predecessor store head in transition_pvm store predecessor_hash hash (** [update store chain_event] reacts to an event on the chain. *) let update store chain_event = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in match chain_event with | Layer1.SameBranch {intermediate_heads; new_head} -> let* () = List.iter_es (process_head store) intermediate_heads in @@ -133,7 +133,7 @@ module Make (PVM : Pvm.S) : S = struct (** [start store] initializes the [store] with the needed state. *) let start store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Store.PVMState.init_s store Layer1.genesis_hash (fun () -> PVM.initial_state diff --git a/src/proto_alpha/bin_sc_rollup_node/layer1.ml b/src/proto_alpha/bin_sc_rollup_node/layer1.ml index 720fd809e3824384826bbfe49082756994822e2c..eb2ea3b67496f7c5095dee378c2e877b39238d64 100644 --- a/src/proto_alpha/bin_sc_rollup_node/layer1.ml +++ b/src/proto_alpha/bin_sc_rollup_node/layer1.ml @@ -260,7 +260,7 @@ let catch_up cctxt store chain last_seen_head new_head = | Some predecessor -> aux [] predecessor let chain_events cctxt store chain = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let on_head (hash, (block_header : Tezos_base.Block_header.t)) = let level = block_header.shell.level in let new_head = Head {hash; level} in @@ -279,7 +279,7 @@ let chain_events cctxt store chain = let check_sc_rollup_address_exists sc_rollup_address (cctxt : Protocol_client_context.full) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* kind_opt = RPC.Sc_rollup.kind cctxt (cctxt#chain, cctxt#block) sc_rollup_address () in @@ -292,7 +292,7 @@ let check_sc_rollup_address_exists sc_rollup_address return_unit let start configuration (cctxt : Protocol_client_context.full) store = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! () = Layer1_event.starting () in let* () = check_sc_rollup_address_exists configuration.sc_rollup_address cctxt diff --git a/src/proto_alpha/bin_sc_rollup_node/main_sc_rollup_node_alpha.ml b/src/proto_alpha/bin_sc_rollup_node/main_sc_rollup_node_alpha.ml index 9a39f1e81f228ba68c66d25a54c947235b781020..9719e8ffe81dc7d53ed9b17217106c455aeddc4f 100644 --- a/src/proto_alpha/bin_sc_rollup_node/main_sc_rollup_node_alpha.ml +++ b/src/proto_alpha/bin_sc_rollup_node/main_sc_rollup_node_alpha.ml @@ -33,7 +33,7 @@ let sc_rollup_address_param = | Some addr -> return addr)) let sc_rollup_node_operator_param = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Clic.param ~name:"node-operator" ~desc:"Public key hash of the the smart-contract rollup node operator" diff --git a/src/proto_alpha/bin_tx_rollup_node/RPC.ml b/src/proto_alpha/bin_tx_rollup_node/RPC.ml index 68385d33c41b9aeaeae4eca21ffca42da9cdad0f..a052b0faa2ee39fc08b334ab327c5af12d9a46d8 100644 --- a/src/proto_alpha/bin_tx_rollup_node/RPC.ml +++ b/src/proto_alpha/bin_tx_rollup_node/RPC.ml @@ -158,7 +158,7 @@ module Arg = struct end module Block = struct - open Lwt_tzresult_syntax + open Lwt_result_syntax let path = RPC_path.(open_root) @@ -312,7 +312,7 @@ module Block = struct end module Context_RPC = struct - open Lwt_tzresult_syntax + open Lwt_result_syntax let path = RPC_path.open_root diff --git a/src/proto_alpha/bin_tx_rollup_node/batcher.ml b/src/proto_alpha/bin_tx_rollup_node/batcher.ml index 5463e75a7001ce3be17cb1aca269acd91bf23ff1..dfe644b2689c13eefc7f14d7bcdb7063ccf638ed 100644 --- a/src/proto_alpha/bin_tx_rollup_node/batcher.ml +++ b/src/proto_alpha/bin_tx_rollup_node/batcher.ml @@ -185,7 +185,7 @@ let on_batch state = return_unit let on_register state ~apply (tr : L2_transaction.t) = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in Lwt_mutex.with_lock state.lock @@ fun () -> let batch = Tx_rollup_l2_batch.V1. @@ -212,7 +212,7 @@ let on_register state ~apply (tr : L2_transaction.t) = return new_context | Batch_V1.Batch_result {results = [(_tr, Transaction_failure {reason; _})]; _} -> - fail (Environment.wrap_tzerror reason) + tzfail (Environment.wrap_tzerror reason) | _ -> return context in context diff --git a/src/proto_alpha/bin_tx_rollup_node/stores.ml b/src/proto_alpha/bin_tx_rollup_node/stores.ml index 7c5da92a414b16b07ec53cebd4c63b6ff606ddb4..5a46f0cb0ea015ea5790b73eaf2caef90a4109e7 100644 --- a/src/proto_alpha/bin_tx_rollup_node/stores.ml +++ b/src/proto_alpha/bin_tx_rollup_node/stores.ml @@ -387,10 +387,10 @@ module L2_block_store = struct Cache.find_or_replace store.cache hash read_from_disk let locked_write_block store ~offset ~block ~hash = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* block_bytes = match Data_encoding.Binary.to_bytes_opt L2_blocks_file.encoding block with - | None -> fail (Cannot_encode_block hash) + | None -> tzfail (Cannot_encode_block hash) | Some bytes -> return bytes in let block_length = Bytes.length block_bytes in @@ -561,13 +561,13 @@ struct (Bytes.unsafe_of_string bytes) let write store x = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*! res = Lwt_utils_unix.with_atomic_open_out ~overwrite:true store.file @@ fun fd -> let* block_bytes = match Data_encoding.Binary.to_bytes_opt S.encoding x with - | None -> fail (Cannot_encode_data S.name) + | None -> tzfail (Cannot_encode_data S.name) | Some bytes -> return bytes in let*! () = Lwt_utils_unix.write_bytes fd block_bytes in @@ -575,7 +575,7 @@ struct in match res with | Ok res -> Lwt.return res - | Error _ -> fail (Cannot_write_file S.name) + | Error _ -> tzfail (Cannot_write_file S.name) let init ~data_dir = let file = Filename.Infix.(Node_data.store_dir data_dir // S.name) in diff --git a/src/proto_alpha/lib_client/test/test_client_proto_contracts.ml b/src/proto_alpha/lib_client/test/test_client_proto_contracts.ml index 226aebcc45fef79b6a6a9de66f37da6c1b96bc29..bfc8133374dc4cf97d6850feb445eb4ee017459d 100644 --- a/src/proto_alpha/lib_client/test/test_client_proto_contracts.ml +++ b/src/proto_alpha/lib_client/test/test_client_proto_contracts.ml @@ -57,7 +57,7 @@ class mock_wallet (entities : string) : Tezos_client_base.Client_context.wallet fun _alias_name _list _encoding -> failwith "mock_wallet:write" method last_modification_time : string -> float option tzresult Lwt.t = - fun _ -> Lwt_tzresult_syntax.return_none + fun _ -> Lwt_result_syntax.return_none end (** diff --git a/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml index 01b2b0a0c2c6470e018ae8632d3d7fc2ccb392c4..ec3e8bfa1787704244b32dd4d321280cf10b8a41 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml @@ -360,7 +360,7 @@ let generate_fresh_source state = let heads_iter (cctxt : Protocol_client_context.full) (f : Block_hash.t * Tezos_base.Block_header.t -> unit tzresult Lwt.t) : (unit tzresult Lwt.t * RPC_context.stopper) tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (heads_stream, stopper) = Shell_services.Monitor.heads cctxt `Main in let rec loop () : unit tzresult Lwt.t = let*! block_hash_and_header = Lwt_stream.get heads_stream in diff --git a/src/proto_alpha/lib_delegate/liquidity_baking_vote_file.ml b/src/proto_alpha/lib_delegate/liquidity_baking_vote_file.ml index e23b2934b9e68048ae2b1e96432fac8636af0028..da49a169c1b0d273580c47b399b4757d76534f9e 100644 --- a/src/proto_alpha/lib_delegate/liquidity_baking_vote_file.ml +++ b/src/proto_alpha/lib_delegate/liquidity_baking_vote_file.ml @@ -135,7 +135,7 @@ let () = Block_vote_file_missing_liquidity_baking_toggle_vote file_path) let traced_option_to_result ~error = - Option.fold ~some:ok ~none:(Tzresult_syntax.fail error) + Option.fold ~some:ok ~none:(Result_syntax.tzfail error) let check_file_exists file = if Sys.file_exists file then Result.return_unit diff --git a/src/proto_alpha/lib_delegate/test/mockup_simulator/faked_client_context.ml b/src/proto_alpha/lib_delegate/test/mockup_simulator/faked_client_context.ml index 1d06e59cefcf433d8ef6652114da2a145bec75f8..0483265b3328e71979da8de221b361e0c6b459ef 100644 --- a/src/proto_alpha/lib_delegate/test/mockup_simulator/faked_client_context.ml +++ b/src/proto_alpha/lib_delegate/test/mockup_simulator/faked_client_context.ml @@ -138,7 +138,7 @@ class faked_wallet ~base_dir ~filesystem : Client_context.wallet = return_unit method last_modification_time : string -> float option tzresult Lwt.t = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in fun alias_name -> let filename = self#filename alias_name in let file = String.Hashtbl.find_opt filesystem filename in diff --git a/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml index 028e2060437ea72131adc2030ead5d27d46700f5..e361018fd87cb8c85d1cf15fbf9daea5a90ae672 100644 --- a/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml +++ b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml @@ -1125,7 +1125,7 @@ let run ?(config = default_config) bakers_spec = Lwt.pick [ timeout_process (); - Lwt_tzresult_syntax.join + Lwt_result_syntax.tzjoin (take_third (List.fold_left (fun (i, delegates_acc, ms) (n, user_hooks) -> diff --git a/src/proto_alpha/lib_protocol/test/helpers/transfers.ml b/src/proto_alpha/lib_protocol/test/helpers/transfers.ml index 2817680a26aa8a2ff352e2b57b33be06edcc99f3..78557fb568492dd2e053f89bf92261aa58b3d9c8 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/transfers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/transfers.ml @@ -29,7 +29,7 @@ open Test_tez let transfer_and_check_balances ?(with_burn = false) ~loc b ?(fee = Tez.zero) ?expect_failure src dst amount = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*? amount_fee = fee +? amount in let* bal_src = Context.Contract.balance (I b) src in let* bal_dst = Context.Contract.balance (I b) dst in diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_block_time_instructions.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_block_time_instructions.ml index f2f5f2446fef2897b47f86978718a3a6390c1c25..09ae3ed90c6dc2fd0e2ada6188284ea05cfc101c 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_block_time_instructions.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_block_time_instructions.ml @@ -36,13 +36,13 @@ open Protocol open Alpha_context let context_with_constants constants = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (block, _contracts) = Context.init_with_constants constants 1 in let+ incremental = Incremental.begin_construction block in Incremental.alpha_ctxt incremental let test_min_block_time () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* context = context_with_constants Default_parameters.constants_mainnet in let* (result, _) = Contract_helpers.run_script diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml index b5927986155f7a8b952e05a618d5eae4a703bf72..16e5ec3b593842715a949b89d00f894ebced6ea4 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml @@ -52,7 +52,7 @@ let assert_fail_with ~loc ~msg f = | Error _ -> failwith "Expected a single error at %s." loc let string_list_of_ex_token_diffs ctxt token_diffs = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let accum (xs, ctxt) (Ticket_token.Ex_token {ticketer; contents_type; contents}, amount) = let* (x, ctxt) = @@ -80,7 +80,7 @@ let string_list_of_ex_token_diffs ctxt token_diffs = return (List.rev xs, ctxt) let make_ex_token ctxt ~ticketer ~type_exp ~content_exp = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in wrap @@ let*? (Script_ir_translator.Ex_comparable_ty contents_type, ctxt) = let node = Micheline.root @@ Expr.from_string type_exp in @@ -94,7 +94,7 @@ let make_ex_token ctxt ~ticketer ~type_exp ~content_exp = return (Ticket_token.Ex_token {ticketer; contents_type; contents}, ctxt) let assert_equal_ticket_diffs ~loc ctxt given expected = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (ctxt, tbs1) = List.fold_left_map_es (fun ctxt ((ticketer, content), delta) -> @@ -116,7 +116,7 @@ let assert_equal_ticket_diffs ~loc ctxt given expected = (List.sort String.compare tbs2) let updates_of_key_values ctxt ~key_type ~value_type key_values = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in List.fold_right_es (fun (key, value) (kvs, ctxt) -> let* (key_hash, ctxt) = @@ -158,7 +158,7 @@ let make_alloc big_map_id alloc updates = (Update {init = Lazy_storage.Alloc alloc; updates}) let init () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (block, contracts) = Context.init 1 in let source = WithExceptions.Option.get ~loc:__LOC__ @@ List.hd contracts in let* (operation, originated) = @@ -182,7 +182,7 @@ let init_for_operation () = (baker, src1, block) let two_ticketers block = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* ctxt = Incremental.begin_construction block >|=? Incremental.alpha_ctxt in @@ -197,7 +197,7 @@ let ticket_list_script = |} let setup ctxt ~key_type ~value_type entries = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (ctxt, big_map_id) = wrap @@ Big_map.fresh ~temporary:false ctxt in let* (updates, ctxt) = updates_of_key_values @@ -226,7 +226,7 @@ let setup ctxt ~key_type ~value_type entries = return (alloc, big_map_id, ctxt) let new_big_map ctxt contract ~key_type ~value_type entries = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (alloc, big_map_id, ctxt) = setup ctxt ~key_type ~value_type entries in let storage = Expr.from_string "{}" in let* ctxt = @@ -235,19 +235,19 @@ let new_big_map ctxt contract ~key_type ~value_type entries = return (big_map_id, ctxt) let alloc_diff ctxt ~key_type ~value_type entries = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (allocations, _, ctxt) = setup ctxt ~key_type ~value_type entries in return (allocations, ctxt) let remove_diff ctxt contract ~key_type ~value_type ~existing_entries = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (big_map_id, ctxt) = new_big_map ctxt contract ~key_type ~value_type existing_entries in return (Lazy_storage.make Lazy_storage.Kind.Big_map big_map_id Remove, ctxt) let copy_diff ctxt contract ~key_type ~value_type ~existing_entries ~updates = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (big_map_id, ctxt) = new_big_map ctxt contract ~key_type ~value_type existing_entries in @@ -264,7 +264,7 @@ let copy_diff ctxt contract ~key_type ~value_type ~existing_entries ~updates = let existing_diff ctxt contract ~key_type ~value_type ~existing_entries ~updates = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (big_map_id, ctxt) = new_big_map ctxt contract ~key_type ~value_type existing_entries in @@ -279,7 +279,7 @@ let existing_diff ctxt contract ~key_type ~value_type ~existing_entries ~updates ctxt ) let empty_big_map ctxt ~key_type ~value_type = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (ctxt, big_map_id) = wrap @@ Big_map.fresh ~temporary:false ctxt in return @@ -293,7 +293,7 @@ let empty_big_map ctxt ~key_type ~value_type = ctxt ) let make_big_map ctxt contract ~key_type ~value_type entries = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (big_map_id, ctxt) = new_big_map ctxt contract ~key_type ~value_type entries @@ -309,7 +309,7 @@ let make_big_map ctxt contract ~key_type ~value_type entries = ctxt ) let originate_script block ~script ~storage ~src ~baker ~forges_tickets = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let code = Expr.toplevel_from_string script in let storage = Expr.from_string storage in let script = @@ -331,7 +331,7 @@ let originate_script block ~script ~storage ~src ~baker ~forges_tickets = Incremental.finalize_block incr >|=? fun block -> (destination, script, block) let origination_operation ctxt ~src ~script ~orig_contract = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* ( Script_ir_translator.Ex_script (Script { @@ -369,7 +369,7 @@ let origination_operation ctxt ~src ~script ~orig_contract = return (operation, ctxt) let originate block ~src ~baker ~script ~storage ~forges_tickets = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (orig_contract, script, block) = originate_script block ~script ~storage ~src ~baker ~forges_tickets in @@ -379,7 +379,7 @@ let originate block ~src ~baker ~script ~storage ~forges_tickets = return (orig_contract, script, incr) let transfer_operation ctxt ~src ~destination ~arg_type ~arg = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (params_node, ctxt) = wrap (Script_ir_translator.unparse_data @@ -432,7 +432,7 @@ let type_has_tickets ctxt ty = (** Test that adding a ticket to a lazy storage diff is picked up. *) let assert_ticket_diffs ctxt ~loc ~arg_type ~storage_type ~arg ~old_storage ~new_storage ~lazy_storage_diff expected = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*? (arg_type_has_tickets, ctxt) = type_has_tickets ctxt arg_type in let*? (storage_type_has_tickets, ctxt) = type_has_tickets ctxt storage_type in let* (ticket_diff, ctxt) = @@ -452,7 +452,7 @@ let assert_ticket_diffs ctxt ~loc ~arg_type ~storage_type ~arg ~old_storage assert_equal_ticket_diffs ~loc ctxt ticket_diffs expected let assert_balance ctxt ~loc key expected = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (balance, _) = wrap @@ Ticket_balance.get_balance ctxt key in match (balance, expected) with | (Some b, Some eb) -> Assert.equal_int ~loc (Z.to_int b) eb @@ -473,7 +473,7 @@ let string_ticket ticketer contents amount = Script_typed_ir.{ticketer; contents; amount} let string_ticket_token ticketer content = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let contents = Result.value_f ~default:(fun _ -> assert false) @@ Script_string.of_string content @@ -484,7 +484,7 @@ let string_ticket_token ticketer content = {ticketer; contents_type = Script_typed_ir.string_t; contents}) let test_diffs_empty () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (_contract, ctxt) = init () in let*? int_ticket_big_map_ty = @@ -508,7 +508,7 @@ let test_diffs_empty () = (** Test that sending one ticket as an argument, when the new storage is empty results in an negative diff. *) let test_diffs_tickets_in_args () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (_contract, ctxt) = init () in let arg = string_ticket "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1 in @@ -526,7 +526,7 @@ let test_diffs_tickets_in_args () = (** Test adding a ticket to the args, which is also accounted for in the new storage, results in an empty diff. *) let test_diffs_tickets_in_args_and_storage () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (_contract, ctxt) = init () in let arg = string_ticket "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1 in assert_ticket_diffs @@ -543,7 +543,7 @@ let test_diffs_tickets_in_args_and_storage () = (** Test that adding two tickets in the args, and only one new ticket in the storage results in a negative diff. *) let test_diffs_drop_one_ticket () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (_contract, ctxt) = init () in let arg = boxed_list @@ -572,7 +572,7 @@ let test_diffs_drop_one_ticket () = (** Test that adding a new ticket to the storage results in a positive balance. *) let test_diffs_adding_new_ticket_to_storage () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (_contract, ctxt) = init () in let new_storage = boxed_list [string_ticket "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1] @@ -591,7 +591,7 @@ let test_diffs_adding_new_ticket_to_storage () = (** Test that removing one ticket from the storage results in a negative diff. *) let test_diffs_remove_from_storage () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (_contract, ctxt) = init () in let old_storage = boxed_list @@ -619,7 +619,7 @@ let test_diffs_remove_from_storage () = (* Test adding ticket through lazy-storage diff results in a positive diff. *) let test_diffs_lazy_storage_alloc () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (_contract, ctxt) = init () in let*? int_ticket_big_map_ty = @@ -653,7 +653,7 @@ let test_diffs_lazy_storage_alloc () = (* Test removing a big map containing a ticket results in a negative diff. *) let test_diffs_remove_from_big_map () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (contract, ctxt) = init () in let*? int_ticket_big_map_ty = @@ -689,7 +689,7 @@ let test_diffs_remove_from_big_map () = (** Test copying a big-map. *) let test_diffs_copy_big_map () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (contract, ctxt) = init () in let*? int_ticket_big_map_ty = @@ -738,7 +738,7 @@ let test_diffs_copy_big_map () = (** Test that adding and removing items from an existing big-map results yield corresponding ticket-token diffs. *) let test_diffs_add_to_existing_big_map () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (contract, ctxt) = init () in let*? int_ticket_big_map_ty = @@ -802,7 +802,7 @@ let test_diffs_add_to_existing_big_map () = (** Test a combination of updates. *) let test_diffs_args_storage_and_lazy_diffs () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let open Script_typed_ir in let* (contract, ctxt) = init () in let*? int_ticket_big_map_ty = @@ -893,7 +893,7 @@ let test_diffs_args_storage_and_lazy_diffs () = (** Test that attempting to transfer a ticket that exceeds the budget fails. *) let test_update_invalid_transfer () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, src, block) = init_for_operation () in let* (destination, _script, incr) = originate @@ -927,7 +927,7 @@ let test_update_invalid_transfer () = (** Test that adding more tickets created by the [self] contract is valid and results in a balance update. *) let test_update_ticket_self_diff () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, src, block) = init_for_operation () in let* (self, _script, incr) = originate @@ -963,7 +963,7 @@ let test_update_ticket_self_diff () = (* Test that sending tickets to self succeed (there are no budget constraints). *) let test_update_self_ticket_transfer () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, self, block) = init_for_operation () in let* (ticket_receiver, _script, incr) = originate @@ -1022,7 +1022,7 @@ let test_update_self_ticket_transfer () = (** Test that transferring a ticket that does not exceed the budget succeeds. *) let test_update_valid_transfer () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, self, block) = init_for_operation () in let* (destination, _script, incr) = originate @@ -1084,7 +1084,7 @@ let test_update_valid_transfer () = (** Test that transferring a ticket to itself is allowed and does not impact the balance. *) let test_update_transfer_tickets_to_self () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, src, block) = init_for_operation () in let* (self, _script, incr) = originate @@ -1143,7 +1143,7 @@ let test_update_transfer_tickets_to_self () = (** Test that attempting to originate a contract with tickets that exceed the budget fails. *) let test_update_invalid_origination () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, src, block) = init_for_operation () in let* (destination, script, incr) = let storage = @@ -1180,7 +1180,7 @@ let test_update_invalid_origination () = (** Test update valid origination. *) let test_update_valid_origination () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, self, block) = init_for_operation () in let ticketer = "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" in assert (ticketer <> Contract.to_b58check self) ; @@ -1237,7 +1237,7 @@ let test_update_valid_origination () = assert_balance ~loc:__LOC__ ctxt red_originated_token_hash (Some 1) let test_update_self_origination () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, self, block) = init_for_operation () in let ticketer = Contract.to_b58check self in let* (originated, script, incr) = @@ -1276,7 +1276,7 @@ let test_update_self_origination () = (** Test ticket-token map of list with duplicates. *) let test_ticket_token_map_of_list_with_duplicates () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (baker, src, block) = init_for_operation () in let* (self, _script, incr) = originate diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_balance.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_balance.ml index ca33275908f7d2de61f3329141d0d666a5ddf75b..80c808710a9101055884bf7f32bdb3f216eec8d6 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_balance.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_balance.ml @@ -34,7 +34,7 @@ open Protocol open Alpha_context -open Lwt_tzresult_syntax +open Lwt_result_syntax let wrap m = m >|= Environment.wrap_tzresult diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml index 252e84bb0df6c05b475c6b16e75170a234aca7a6..7bb0f500951d527985ea7d1b50825ca4911ab25a 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml @@ -40,7 +40,7 @@ open Protocol open Alpha_context -open Lwt_tzresult_syntax +open Lwt_result_syntax let wrap m = m >|= Environment.wrap_tzresult diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml index f9f07b9491bc6a5470168c221fbd0cd2d35f9f83..924b502223d8344f97b28efd0303580e395f83ec 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml @@ -283,7 +283,7 @@ let originate block ~src ~baker ~script ~storage ~forges_tickets = return (orig_contract, incr) let transfer_operation ~incr ~src ~destination ~parameters_ty ~parameters = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let ctxt = Incremental.alpha_ctxt incr in let* (params_node, ctxt) = wrap @@ -319,7 +319,7 @@ let transfer_operation ~incr ~src ~destination ~parameters_ty ~parameters = let transfer_operation_to_tx_rollup ~incr ~src ~parameters_ty ~parameters ~tx_rollup = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let ctxt = Incremental.alpha_ctxt incr in let* (params_node, ctxt) = wrap @@ -393,7 +393,7 @@ let make_tickets ts = return {elements; length = List.length elements} let transfer_tickets_operation ~incr ~src ~destination tickets = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*? parameters_ty = Environment.wrap_tzresult list_ticket_string_ty in let* parameters = wrap @@ make_tickets tickets in transfer_operation ~incr ~src ~destination ~parameters_ty ~parameters @@ -1093,7 +1093,7 @@ let test_transfer_big_map_with_tickets () = ~storage:"{}" ~forges_tickets:false in - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let*? value_type = Environment.wrap_tzresult @@ ticket_t Micheline.dummy_location string_t in @@ -1144,7 +1144,7 @@ let test_transfer_big_map_with_tickets () = (** Test transfer a ticket to a tx_rollup. *) let test_tx_rollup_deposit_one_ticket () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* (_baker, src, block) = init ~tx_rollup_enable:true () in let* ticketer = one_ticketer block in let* incr = Incremental.begin_construction block in diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml index 7e43cd100edaf1b1c3adf673fd77079de81d165c..468484621844aed64f221c45ae5b891fb922bd55 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml @@ -34,7 +34,7 @@ open Protocol open Alpha_context -open Lwt_tzresult_syntax +open Lwt_result_syntax exception Sc_rollup_test_error of string diff --git a/src/proto_alpha/lib_protocol/test/integration/test_storage_functions.ml b/src/proto_alpha/lib_protocol/test/integration/test_storage_functions.ml index b1d22bc8848136c3191f5220aba8f9a189285603..c0fa687b72a7cfd3c72e7114084b1e647bc5aed0 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_storage_functions.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_storage_functions.ml @@ -97,7 +97,7 @@ let wrap m = m >|= Environment.wrap_tzresult This test checks that it is possible to add values to a Carbonated_data_set_storage and iterate over them. *) let test_fold_keys_unaccounted () = - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* ctxt = Context.default_raw_context () in let* (ctxt, _) = wrap (Table.init ctxt 1) in let* (ctxt, _) = wrap (Table.init ctxt 2) in diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_bitset.ml b/src/proto_alpha/lib_protocol/test/pbt/test_bitset.ml index e61b7b2c98cc17af4cfe57343e770a12f42a0f2e..56c84b4d69446b0c3f695222ab7272a51645ec45 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_bitset.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_bitset.ml @@ -55,7 +55,7 @@ let test_get_set (c, ofs) = List.for_all (fun ofs' -> let res = - let open Tzresult_syntax in + let open Result_syntax in let* c' = add c ofs in let* v = mem c ofs' in let* v' = mem c' ofs' in diff --git a/src/proto_alpha/lib_protocol/test/unit/test_gas_monad.ml b/src/proto_alpha/lib_protocol/test/unit/test_gas_monad.ml index 281a092abc60e6ba9633044637ac333d2aaff40f..27a82fe49119451e124eb35e62c921149d273ba3 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_gas_monad.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_gas_monad.ml @@ -54,7 +54,7 @@ let assert_equal_gas ~loc g1 g2 = let assert_inner_errors ~loc ctxt gas_monad ~errors ~remaining_gas = match GM.run ctxt gas_monad with | Ok (Error e, ctxt) -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = Assert.assert_equal_list ~loc @@ -73,7 +73,7 @@ let assert_inner_errors ~loc ctxt gas_monad ~errors ~remaining_gas = let assert_success ~loc ctxt gas_monad ~result ~remaining_gas = match GM.run ctxt gas_monad with | Ok (Ok x, ctxt) -> - let open Lwt_tzresult_syntax in + let open Lwt_result_syntax in let* () = Assert.equal_int ~loc x result in assert_equal_gas ~loc diff --git a/src/proto_alpha/lib_protocol/test/unit/test_saturation.ml b/src/proto_alpha/lib_protocol/test/unit/test_saturation.ml index f0d2898d75226c3ffca960304492e54bd1b077fa..0cf2633314ca37c9a3339bedbbfded3cfe7324a5 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_saturation.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_saturation.ml @@ -212,7 +212,7 @@ let encoding encoder () = (x' :> int) x)))) in - Error_monad.Lwt_tzresult_syntax.join + Error_monad.Lwt_result_syntax.tzjoin (List.map check_encode_decode [0; 7373737373; max_int - 1]) let tests =