From 04465e3ac63723106a94d2e95d85e51d99568a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Tue, 30 Jan 2018 11:08:56 +0100 Subject: [PATCH] Proto_sigs: split the deprecated module `Tezos_data` --- src/lib_base/protocol_environment.ml | 14 +- .../jbuild_embedded_protocol_template | 3 +- src/lib_protocol_compiler/packer.ml | 1 - src/lib_protocol_environment_sigs/jbuild | 6 +- .../sigs_packer/sigs_packer.ml | 1 - .../v1/block_header.mli | 33 +++++ .../v1/fitness.mli | 10 +- .../v1/operation.mli | 25 ++++ .../v1/protocol.mli | 31 +++++ src/lib_protocol_environment_sigs/v1/s.mli | 46 +++++++ .../v1/tezos_data.mli | 123 ------------------ src/lib_protocol_updater/updater.ml | 8 +- src/lib_protocol_updater/updater.mli | 8 +- .../lib_protocol/src/block_header_repr.ml | 8 +- .../lib_protocol/src/block_header_repr.mli | 4 +- .../lib_protocol/src/operation_repr.ml | 2 + .../lib_protocol/src/operation_repr.mli | 2 + .../lib_protocol/src/services_registration.ml | 2 +- .../lib_protocol/src/tezos_context.mli | 6 +- 19 files changed, 172 insertions(+), 161 deletions(-) create mode 100644 src/lib_protocol_environment_sigs/v1/block_header.mli create mode 100644 src/lib_protocol_environment_sigs/v1/operation.mli create mode 100644 src/lib_protocol_environment_sigs/v1/protocol.mli create mode 100644 src/lib_protocol_environment_sigs/v1/s.mli diff --git a/src/lib_base/protocol_environment.ml b/src/lib_base/protocol_environment.ml index 15a6f6a58..dfcfffaf1 100644 --- a/src/lib_base/protocol_environment.ml +++ b/src/lib_base/protocol_environment.ml @@ -56,21 +56,17 @@ module Make(Param : sig val name: string end)() = struct module Make_Blake2B = Blake2B.Make end module Blake2B = Blake2B - module Tezos_data = struct - module type DATA = S.T - module type HASHABLE_DATA = S.HASHABLE - module Fitness = Fitness - module Operation = Operation - module Block_header = Block_header - module Protocol = Protocol - end + module S = S + module Fitness = Fitness + module Operation = Operation + module Block_header = Block_header + module Protocol = Protocol module RPC_arg = RPC_arg module RPC_path = RPC_path module RPC_query = RPC_query module RPC_service = RPC_service module RPC_answer = RPC_answer module RPC_directory = RPC_directory - module Fitness = Fitness module Error_monad = struct type error_category = [ `Branch | `Temporary | `Permanent ] include Error_monad.Make() diff --git a/src/lib_protocol_compiler/jbuild_embedded_protocol_template b/src/lib_protocol_compiler/jbuild_embedded_protocol_template index 3e5ae8cbf..bfd5a87c4 100644 --- a/src/lib_protocol_compiler/jbuild_embedded_protocol_template +++ b/src/lib_protocol_compiler/jbuild_embedded_protocol_template @@ -48,8 +48,7 @@ let () = Format.kasprintf Jbuild_plugin.V1.send {| -warn-error -a+8 -open Tezos_embedded_protocol_environment_%s__Environment -open Error_monad - -open Hash - -open Tezos_data)) + -open Hash)) (modules (:standard \ Environment Registerer)))) (library diff --git a/src/lib_protocol_compiler/packer.ml b/src/lib_protocol_compiler/packer.ml index 858b4498b..cfa56ec72 100644 --- a/src/lib_protocol_compiler/packer.ml +++ b/src/lib_protocol_compiler/packer.ml @@ -45,7 +45,6 @@ let opened_modules = [ "Error_monad" ; "Hash" ; "Logging" ; - "Tezos_data" ; ] let dump oc files = diff --git a/src/lib_protocol_environment_sigs/jbuild b/src/lib_protocol_environment_sigs/jbuild index 710815932..599dd9de3 100644 --- a/src/lib_protocol_environment_sigs/jbuild +++ b/src/lib_protocol_environment_sigs/jbuild @@ -45,8 +45,12 @@ v1/ed25519.mli ;; Tezos specifics + v1/s.mli v1/micheline.mli - v1/tezos_data.mli + v1/block_header.mli + v1/fitness.mli + v1/operation.mli + v1/protocol.mli v1/context.mli v1/updater.mli diff --git a/src/lib_protocol_environment_sigs/sigs_packer/sigs_packer.ml b/src/lib_protocol_environment_sigs/sigs_packer/sigs_packer.ml index eb1d9750e..3e9ca9069 100644 --- a/src/lib_protocol_environment_sigs/sigs_packer/sigs_packer.ml +++ b/src/lib_protocol_environment_sigs/sigs_packer/sigs_packer.ml @@ -25,7 +25,6 @@ let opened_modules = [ "Pervasives" ; "Error_monad" ; "Hash" ; - "Tezos_data" ; ] let include_mli oc file = diff --git a/src/lib_protocol_environment_sigs/v1/block_header.mli b/src/lib_protocol_environment_sigs/v1/block_header.mli new file mode 100644 index 000000000..395345b8a --- /dev/null +++ b/src/lib_protocol_environment_sigs/v1/block_header.mli @@ -0,0 +1,33 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2017. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +type shell_header = { + level: Int32.t ; + (** The number of preceding block in this chain, i.e. the genesis + has level 0. *) + proto_level: int ; + (** The number of preceding protocol change in the chain (modulo 256), + i.e the genesis has proto_level 0. *) + predecessor: Block_hash.t ; + timestamp: Time.t ; + validation_passes: int ; + operations_hash: Operation_list_list_hash.t ; + fitness: MBytes.t list ; + context: Context_hash.t ; +} + +val shell_header_encoding: shell_header Data_encoding.t + +type t = { + shell: shell_header ; + proto: MBytes.t ; +} + +include S.HASHABLE with type t := t + and type hash := Block_hash.t diff --git a/src/lib_protocol_environment_sigs/v1/fitness.mli b/src/lib_protocol_environment_sigs/v1/fitness.mli index 6734fbd4e..042fb64d2 100644 --- a/src/lib_protocol_environment_sigs/v1/fitness.mli +++ b/src/lib_protocol_environment_sigs/v1/fitness.mli @@ -7,10 +7,6 @@ (* *) (**************************************************************************) -type fitness = MBytes.t list - -val compare: fitness -> fitness -> int -val pp: Format.formatter -> fitness -> unit -val to_string: fitness -> string - -val encoding: fitness Data_encoding.t +(** The fitness of a block is defined as a list of bytes, + compared in a lexicographical order (longer list are greater). *) +include S.T with type t = MBytes.t list diff --git a/src/lib_protocol_environment_sigs/v1/operation.mli b/src/lib_protocol_environment_sigs/v1/operation.mli new file mode 100644 index 000000000..3c45c6b3c --- /dev/null +++ b/src/lib_protocol_environment_sigs/v1/operation.mli @@ -0,0 +1,25 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2017. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +(** Tezos operations. *) + +type shell_header = { + branch: Block_hash.t ; + (** The operation is only valid in a branch containing the + block [branch]. *) +} +val shell_header_encoding: shell_header Data_encoding.t + +type t = { + shell: shell_header ; + proto: MBytes.t ; +} + +include S.HASHABLE with type t := t + and type hash := Operation_hash.t diff --git a/src/lib_protocol_environment_sigs/v1/protocol.mli b/src/lib_protocol_environment_sigs/v1/protocol.mli new file mode 100644 index 000000000..6b266b248 --- /dev/null +++ b/src/lib_protocol_environment_sigs/v1/protocol.mli @@ -0,0 +1,31 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2017. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +type t = { + expected_env: env_version ; + components: component list ; +} + +(** An OCaml source component of a protocol implementation. *) +and component = { + (* The OCaml module name. *) + name : string ; + (* The OCaml interface source code *) + interface : string option ; + (* The OCaml source code *) + implementation : string ; +} + +and env_version = V1 + +val component_encoding: component Data_encoding.t +val env_version_encoding: env_version Data_encoding.t + +include S.HASHABLE with type t := t + and type hash := Protocol_hash.t diff --git a/src/lib_protocol_environment_sigs/v1/s.mli b/src/lib_protocol_environment_sigs/v1/s.mli new file mode 100644 index 000000000..f05fc3a88 --- /dev/null +++ b/src/lib_protocol_environment_sigs/v1/s.mli @@ -0,0 +1,46 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2017. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +(** Generic interface for a datatype with comparison, pretty-printer + and serialization functions. *) +module type T = sig + + type t + + val compare: t -> t -> int + val equal: t -> t -> bool + + val (=): t -> t -> bool + val (<>): t -> t -> bool + val (<): t -> t -> bool + val (<=): t -> t -> bool + val (>=): t -> t -> bool + val (>): t -> t -> bool + val min: t -> t -> t + val max: t -> t -> t + + val pp: Format.formatter -> t -> unit + + val encoding: t Data_encoding.t + val to_bytes: t -> MBytes.t + val of_bytes: MBytes.t -> t option + +end + +(** Generic interface for a datatype with comparison, pretty-printer, + serialization functions and a hashing function. *) +module type HASHABLE = sig + + include T + + type hash + val hash: t -> hash + val hash_raw: MBytes.t -> hash + +end diff --git a/src/lib_protocol_environment_sigs/v1/tezos_data.mli b/src/lib_protocol_environment_sigs/v1/tezos_data.mli index f632f3d90..6ec18bc60 100644 --- a/src/lib_protocol_environment_sigs/v1/tezos_data.mli +++ b/src/lib_protocol_environment_sigs/v1/tezos_data.mli @@ -1,128 +1,5 @@ -(**************************************************************************) -(* *) -(* Copyright (c) 2014 - 2017. *) -(* Dynamic Ledger Solutions, Inc. *) -(* *) -(* All rights reserved. No warranty, explicit or implicit, provided. *) -(* *) -(**************************************************************************) - -(** Tezos Protocol Environment - Basic data structures *) - -(** Generic interface for a datatype with comparison, pretty-printer - and serialization functions. *) -module type DATA = sig - - type t - - val compare: t -> t -> int - val equal: t -> t -> bool - - val (=): t -> t -> bool - val (<>): t -> t -> bool - val (<): t -> t -> bool - val (<=): t -> t -> bool - val (>=): t -> t -> bool - val (>): t -> t -> bool - val min: t -> t -> t - val max: t -> t -> t - - val pp: Format.formatter -> t -> unit - - val encoding: t Data_encoding.t - val to_bytes: t -> MBytes.t - val of_bytes: MBytes.t -> t option - -end - -(** Generic interface for a datatype with comparison, pretty-printer, - serialization functions and a hashing function. *) -module type HASHABLE_DATA = sig - - include DATA - - type hash - val hash: t -> hash - val hash_raw: MBytes.t -> hash - -end - -(** The fitness of a block is defined as a list of bytes, - compared in a lexicographical order (longer list are greater). *) -module Fitness : DATA with type t = MBytes.t list - -(** Tezos operations. *) -module Operation : sig - - type shell_header = { - branch: Block_hash.t ; - (** The operation is only valid in a branch containing the - block [branch]. *) - } - val shell_header_encoding: shell_header Data_encoding.t - - type t = { - shell: shell_header ; - proto: MBytes.t ; - } - - include HASHABLE_DATA with type t := t - and type hash := Operation_hash.t - -end - -module Block_header : sig - - type shell_header = { - level: Int32.t ; - (** The number of preceding block in this chain, i.e. the genesis - has level 0. *) - proto_level: int ; - (** The number of preceding protocol change in the chain (modulo 256), - i.e the genesis has proto_level 0. *) - predecessor: Block_hash.t ; - timestamp: Time.t ; - validation_passes: int ; - operations_hash: Operation_list_list_hash.t ; - fitness: MBytes.t list ; - context: Context_hash.t ; - } - - val shell_header_encoding: shell_header Data_encoding.t - - type t = { - shell: shell_header ; - proto: MBytes.t ; - } - - include HASHABLE_DATA with type t := t - and type hash := Block_hash.t - -end module Protocol : sig - type t = { - expected_env: env_version ; - components: component list ; - } - - (** An OCaml source component of a protocol implementation. *) - and component = { - (* The OCaml module name. *) - name : string ; - (* The OCaml interface source code *) - interface : string option ; - (* The OCaml source code *) - implementation : string ; - } - - and env_version = V1 - - val component_encoding: component Data_encoding.t - val env_version_encoding: env_version Data_encoding.t - - include HASHABLE_DATA with type t := t - and type hash := Protocol_hash.t end diff --git a/src/lib_protocol_updater/updater.ml b/src/lib_protocol_updater/updater.ml index f70cc0e46..21adf6a5a 100644 --- a/src/lib_protocol_updater/updater.ml +++ b/src/lib_protocol_updater/updater.ml @@ -105,10 +105,10 @@ module Node_protocol_environment_sigs = struct and type Context.t = Context.t and type Time.t = Time.t and type MBytes.t = MBytes.t - and type Tezos_data.Operation.shell_header = Operation.shell_header - and type Tezos_data.Operation.t = Operation.t - and type Tezos_data.Block_header.shell_header = Block_header.shell_header - and type Tezos_data.Block_header.t = Block_header.t + and type Operation.shell_header = Operation.shell_header + and type Operation.t = Operation.t + and type Block_header.shell_header = Block_header.shell_header + and type Block_header.t = Block_header.t and type 'a RPC_directory.t = 'a RPC_directory.t and type Updater.validation_result = validation_result and type Updater.rpc_context = rpc_context diff --git a/src/lib_protocol_updater/updater.mli b/src/lib_protocol_updater/updater.mli index 3a9398f4f..30491da58 100644 --- a/src/lib_protocol_updater/updater.mli +++ b/src/lib_protocol_updater/updater.mli @@ -95,10 +95,10 @@ module Node_protocol_environment_sigs : sig and type Context.t = Context.t and type Time.t = Time.t and type MBytes.t = MBytes.t - and type Tezos_data.Operation.shell_header = Operation.shell_header - and type Tezos_data.Operation.t = Operation.t - and type Tezos_data.Block_header.shell_header = Block_header.shell_header - and type Tezos_data.Block_header.t = Block_header.t + and type Operation.shell_header = Operation.shell_header + and type Operation.t = Operation.t + and type Block_header.shell_header = Block_header.shell_header + and type Block_header.t = Block_header.t and type 'a RPC_directory.t = 'a RPC_directory.t and type Updater.validation_result = validation_result and type Updater.rpc_context = rpc_context diff --git a/src/proto_alpha/lib_protocol/src/block_header_repr.ml b/src/proto_alpha/lib_protocol/src/block_header_repr.ml index 439cbe2a6..f9be91667 100644 --- a/src/proto_alpha/lib_protocol/src/block_header_repr.ml +++ b/src/proto_alpha/lib_protocol/src/block_header_repr.ml @@ -26,11 +26,11 @@ and proto_header = { type block_header = t -type raw = Tezos_data.Block_header.t -type shell_header = Tezos_data.Block_header.shell_header +type raw = Block_header.t +type shell_header = Block_header.shell_header -let raw_encoding = Tezos_data.Block_header.encoding -let shell_header_encoding = Tezos_data.Block_header.shell_header_encoding +let raw_encoding = Block_header.encoding +let shell_header_encoding = Block_header.shell_header_encoding let proto_header_encoding = let open Data_encoding in diff --git a/src/proto_alpha/lib_protocol/src/block_header_repr.mli b/src/proto_alpha/lib_protocol/src/block_header_repr.mli index 964ed7fb5..eab364253 100644 --- a/src/proto_alpha/lib_protocol/src/block_header_repr.mli +++ b/src/proto_alpha/lib_protocol/src/block_header_repr.mli @@ -24,8 +24,8 @@ and proto_header = { type block_header = t -type raw = Tezos_data.Block_header.t -type shell_header = Tezos_data.Block_header.shell_header +type raw = Block_header.t +type shell_header = Block_header.shell_header val encoding: block_header Data_encoding.encoding val raw_encoding: raw Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/src/operation_repr.ml b/src/proto_alpha/lib_protocol/src/operation_repr.ml index e875241da..a374fea33 100644 --- a/src/proto_alpha/lib_protocol/src/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/src/operation_repr.ml @@ -413,3 +413,5 @@ let parse_proto bytes = | None -> fail Cannot_parse_operation include Encoding + +let hash_raw = Operation.hash diff --git a/src/proto_alpha/lib_protocol/src/operation_repr.mli b/src/proto_alpha/lib_protocol/src/operation_repr.mli index 690720c5d..98cdc56a3 100644 --- a/src/proto_alpha/lib_protocol/src/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/src/operation_repr.mli @@ -92,6 +92,8 @@ type error += Cannot_parse_operation (* `Branch *) val encoding: operation Data_encoding.t +val hash_raw: raw -> Operation_hash.t + val parse: Operation_hash.t -> Operation.t -> operation tzresult diff --git a/src/proto_alpha/lib_protocol/src/services_registration.ml b/src/proto_alpha/lib_protocol/src/services_registration.ml index 2cb325e4d..5b80b938e 100644 --- a/src/proto_alpha/lib_protocol/src/services_registration.ml +++ b/src/proto_alpha/lib_protocol/src/services_registration.ml @@ -533,7 +533,7 @@ let parse_operations ctxt () (operations, check) = map_s begin fun raw -> begin Lwt.return - (Operation.parse (Tezos_data.Operation.hash raw) raw) >>=? fun op -> + (Operation.parse (Operation.hash_raw raw) raw) >>=? fun op -> begin match check with | Some true -> check_signature ctxt op.signature op.shell op.contents | Some false | None -> return () diff --git a/src/proto_alpha/lib_protocol/src/tezos_context.mli b/src/proto_alpha/lib_protocol/src/tezos_context.mli index 16b6cbd32..407e37d5b 100644 --- a/src/proto_alpha/lib_protocol/src/tezos_context.mli +++ b/src/proto_alpha/lib_protocol/src/tezos_context.mli @@ -605,6 +605,8 @@ module Operation : sig type t = operation val encoding: operation Data_encoding.t + val hash_raw: raw -> Operation_hash.t + type error += Cannot_parse_operation (* `Branch *) val parse: Operation_hash.t -> Operation.t -> operation tzresult @@ -641,8 +643,8 @@ module Block_header : sig type block_header = t - type raw = Tezos_data.Block_header.t - type shell_header = Tezos_data.Block_header.shell_header + type raw = Block_header.t + type shell_header = Block_header.shell_header val hash: block_header -> Block_hash.t val hash_raw: raw -> Block_hash.t