From f8a8bfc1fa91986865eb964b201c3495cf972b5d Mon Sep 17 00:00:00 2001 From: James Deikun Date: Wed, 13 Jun 2018 16:31:10 -0400 Subject: [PATCH 1/8] initial service definitions for client RPC --- .gitlab-ci.yml | 89 +++++++------- .../lib_delegate/tezos-baking-alpha.opam | 3 + src/proto_alpha/lib_delegate_services/dune | 18 +++ .../lib_delegate_services/event_queues.ml | 116 ++++++++++++++++++ .../lib_delegate_services/event_queues.mli | 70 +++++++++++ .../tezos-baking-alpha-services.opam | 23 ++++ 6 files changed, 277 insertions(+), 42 deletions(-) create mode 100644 src/proto_alpha/lib_delegate_services/dune create mode 100644 src/proto_alpha/lib_delegate_services/event_queues.ml create mode 100644 src/proto_alpha/lib_delegate_services/event_queues.mli create mode 100644 src/proto_alpha/lib_delegate_services/tezos-baking-alpha-services.opam diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d83fee4c4fbc..dabed691c657 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -398,126 +398,131 @@ opam:38:tezos-protocol-genesis: variables: package: tezos-protocol-genesis -opam:39:ocplib-resto-json: - <<: *opam_definition - variables: - package: ocplib-resto-json - -opam:40:tezos-protocol-updater: +opam:39:tezos-protocol-updater: <<: *opam_definition variables: package: tezos-protocol-updater -opam:41:tezos-p2p: +opam:40:tezos-p2p: <<: *opam_definition variables: package: tezos-p2p -opam:42:tezos-baking-alpha-commands: +opam:41:ocplib-resto-json: <<: *opam_definition variables: - package: tezos-baking-alpha-commands + package: ocplib-resto-json -opam:43:tezos-client-alpha-commands: +opam:42:tezos-baking-alpha-commands: <<: *opam_definition variables: - package: tezos-client-alpha-commands + package: tezos-baking-alpha-commands -opam:44:tezos-client-base-unix: +opam:43:tezos-client-base-unix: <<: *opam_definition variables: package: tezos-client-base-unix -opam:45:tezos-client-genesis: +opam:44:tezos-client-genesis: <<: *opam_definition variables: package: tezos-client-genesis -opam:46:ocplib-ezresto: - <<: *opam_definition - variables: - package: ocplib-ezresto - -opam:47:tezos-embedded-protocol-alpha: +opam:45:tezos-embedded-protocol-alpha: <<: *opam_definition variables: package: tezos-embedded-protocol-alpha -opam:48:tezos-embedded-protocol-demo: +opam:46:tezos-embedded-protocol-demo: <<: *opam_definition variables: package: tezos-embedded-protocol-demo -opam:49:tezos-embedded-protocol-genesis: +opam:47:tezos-embedded-protocol-genesis: <<: *opam_definition variables: package: tezos-embedded-protocol-genesis -opam:50:tezos-shell: +opam:48:tezos-shell: <<: *opam_definition variables: package: tezos-shell -opam:51:tezos-endorser-alpha-commands: +opam:49:tezos-client-alpha-commands: <<: *opam_definition variables: - package: tezos-endorser-alpha-commands + package: tezos-client-alpha-commands -opam:52:tezos-client: +opam:50:ocplib-ezresto: <<: *opam_definition variables: - package: tezos-client + package: ocplib-ezresto -opam:53:ocplib-ezresto-directory: +opam:51:tezos-baking-alpha-services: <<: *opam_definition variables: - package: ocplib-ezresto-directory + package: tezos-baking-alpha-services -opam:54:tezos-accuser-alpha: +opam:52:tezos-accuser-alpha: <<: *opam_definition variables: package: tezos-accuser-alpha -opam:55:tezos-endorser-alpha: +opam:53:tezos-baker-alpha: <<: *opam_definition variables: - package: tezos-endorser-alpha + package: tezos-baker-alpha -opam:56:tezos-accuser-alpha-commands: +opam:54:ocplib-json-typed-browser: <<: *opam_definition variables: - package: tezos-accuser-alpha-commands + package: ocplib-json-typed-browser -opam:57:tezos-baker-alpha: +opam:55:tezos-protocol-demo: <<: *opam_definition variables: - package: tezos-baker-alpha + package: tezos-protocol-demo -opam:58:tezos-protocol-demo: +opam:56:tezos-node: <<: *opam_definition variables: - package: tezos-protocol-demo + package: tezos-node -opam:59:tezos-signer: +opam:57:tezos-signer: <<: *opam_definition variables: package: tezos-signer -opam:60:tezos-node: +opam:58:tezos-endorser-alpha-commands: <<: *opam_definition variables: - package: tezos-node + package: tezos-endorser-alpha-commands -opam:61:ocplib-json-typed-browser: +opam:59:tezos-client: <<: *opam_definition variables: - package: ocplib-json-typed-browser + package: tezos-client + +opam:60:tezos-endorser-alpha: + <<: *opam_definition + variables: + package: tezos-endorser-alpha + +opam:61:tezos-accuser-alpha-commands: + <<: *opam_definition + variables: + package: tezos-accuser-alpha-commands opam:62:tezos-baker-alpha-commands: <<: *opam_definition variables: package: tezos-baker-alpha-commands +opam:63:ocplib-ezresto-directory: + <<: *opam_definition + variables: + package: ocplib-ezresto-directory + ##END_OPAM## diff --git a/src/proto_alpha/lib_delegate/tezos-baking-alpha.opam b/src/proto_alpha/lib_delegate/tezos-baking-alpha.opam index 87e71ee1c037..fbcdb76282e8 100644 --- a/src/proto_alpha/lib_delegate/tezos-baking-alpha.opam +++ b/src/proto_alpha/lib_delegate/tezos-baking-alpha.opam @@ -13,9 +13,12 @@ depends: [ "tezos-protocol-environment" "tezos-protocol-alpha" "tezos-shell-services" + "tezos-baking-alpha-services" "tezos-client-base" "tezos-client-commands" "tezos-client-alpha" + "tezos-rpc-http" + "tezos-stdlib-unix" "tezos-node" { test } "tezos-client-genesis" { test } "tezos-client-base-unix" { test } diff --git a/src/proto_alpha/lib_delegate_services/dune b/src/proto_alpha/lib_delegate_services/dune new file mode 100644 index 000000000000..ba7e68257a04 --- /dev/null +++ b/src/proto_alpha/lib_delegate_services/dune @@ -0,0 +1,18 @@ +(library + (name tezos_baking_alpha_services) + (public_name tezos-baking-alpha-services) + (libraries tezos-base + tezos-protocol-environment + tezos-protocol-alpha + tezos-client-base + tezos-client-alpha) + (flags (:standard -w +27@8 + -safe-string + -open Tezos_base__TzPervasives + -open Tezos_client_base + -open Tezos_client_alpha))) + +(alias + (name runtest_indent) + (deps (glob_files *.ml{,i})) + (action (run bash %{libexec:tezos-stdlib:test-ocp-indent.sh} %{deps}))) diff --git a/src/proto_alpha/lib_delegate_services/event_queues.ml b/src/proto_alpha/lib_delegate_services/event_queues.ml new file mode 100644 index 000000000000..083f458df821 --- /dev/null +++ b/src/proto_alpha/lib_delegate_services/event_queues.ml @@ -0,0 +1,116 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +open Proto_alpha +open Alpha_context + +module type EVENT = sig + type t + val name: string + val capacity: int + val encoding: t Data_encoding.t +end + +module Error_event = struct + let name = "errors" + let capacity = 20 + type t = { + message: string ; + trace: error list ; + } + let encoding = let open Data_encoding in + conv + (fun { message ; trace } -> + ( message , trace )) + (fun ( message , trace ) -> + { message ; trace }) + (obj2 + (req "message" string) + (req "trace" (list error_encoding))) +end + +module Baked_event = struct + let name = "baked" + let capacity = 20 + type t = { + hash: Block_hash.t ; + signed_header: MBytes.t ; + operations: Tezos_base.Operation.t list list; + } + let encoding = let open Data_encoding in + conv + (fun { hash ; signed_header ; operations } -> + ( hash , signed_header , operations )) + (fun ( hash , signed_header , operations ) -> + { hash ; signed_header ; operations }) + (obj3 + (req "hash" Block_hash.encoding) + (req "signed_header" bytes) + (req "operations" (list (list (dynamic_size Tezos_base.Operation.encoding))))) +end + +module Endorsement_event = struct + let name = "endorsed" + let capacity = 20 + type t = { + hash: Block_hash.t ; + level: Raw_level.t ; + slot: int ; + delegate: public_key_hash ; + name: string ; + oph: Operation_hash.t ; + } + let encoding = let open Data_encoding in + conv + (fun { hash ; level ; slot ; delegate ; name ; oph } -> + ( hash , level , slot , delegate , name , oph )) + (fun ( hash , level , slot , delegate , name , oph ) -> + { hash ; level ; slot ; delegate ; name ; oph }) + (obj6 + (req "hash" Block_hash.encoding) + (req "level" Raw_level.encoding) + (req "slot" int31) + (req "delegate" Signature.Public_key_hash.encoding) + (req "name" string) + (req "oph" Operation_hash.encoding)) +end + +module Accusation_event = struct + let name = "accused" + let capacity = 20 + type t = Tezos_base.Operation.t + let encoding = Data_encoding.dynamic_size Tezos_base.Operation.encoding +end + +module Block_event = struct + type t = Block_hash.t * Block_header.t + let encoding = let open Data_encoding in + (merge_objs + (obj1 + (req "hash" Block_hash.encoding)) + Block_header.encoding) + let capacity = 20 + let name = "seen" +end diff --git a/src/proto_alpha/lib_delegate_services/event_queues.mli b/src/proto_alpha/lib_delegate_services/event_queues.mli new file mode 100644 index 000000000000..97699391d1a2 --- /dev/null +++ b/src/proto_alpha/lib_delegate_services/event_queues.mli @@ -0,0 +1,70 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +open Proto_alpha +open Alpha_context + +module type EVENT = sig + type t + val name: string + val capacity: int + val encoding: t Data_encoding.t +end + +module Error_event : sig + type t = { + message: string ; + trace: error list ; + } + include EVENT with type t := t +end + +module Baked_event : sig + type t = { + hash: Block_hash.t ; + signed_header: MBytes.t ; + operations: Tezos_base.Operation.t list list; + } + include EVENT with type t := t +end + +module Endorsement_event : sig + type t = { + hash: Block_hash.t ; + level: Raw_level.t ; + slot: int ; + delegate: public_key_hash ; + name: string ; + oph: Operation_hash.t ; + } + include EVENT with type t := t +end + +module Accusation_event : sig + type t = Tezos_base.Operation.t + include EVENT with type t := t +end + +module Block_event : EVENT with type t = Block_hash.t * Block_header.t diff --git a/src/proto_alpha/lib_delegate_services/tezos-baking-alpha-services.opam b/src/proto_alpha/lib_delegate_services/tezos-baking-alpha-services.opam new file mode 100644 index 000000000000..5c14f97d3844 --- /dev/null +++ b/src/proto_alpha/lib_delegate_services/tezos-baking-alpha-services.opam @@ -0,0 +1,23 @@ +opam-version: "1.2" +version: "dev" +maintainer: "contact@tezos.com" +authors: [ "Tezos devteam" ] +homepage: "https://www.tezos.com/" +bug-reports: "https://gitlab.com/tezos/tezos/issues" +dev-repo: "https://gitlab.com/tezos/tezos.git" +license: "MIT" +depends: [ + "ocamlfind" { build } + "dune" { build & = "1.0.1" } + "tezos-base" + "tezos-protocol-environment" + "tezos-protocol-alpha" + "tezos-client-base" + "tezos-client-alpha" +] +build: [ + [ "dune" "build" "-p" name "-j" jobs ] +] +build-test: [ + [ "dune" "runtest" "-p" name "-j" jobs ] +] -- GitLab From 4e3b298d460e409141baa12f6f6f592e14f04e81 Mon Sep 17 00:00:00 2001 From: James Deikun Date: Fri, 15 Jun 2018 15:34:01 -0400 Subject: [PATCH 2/8] hook up events for seen blocks --- .../lib_delegate/client_baking_blocks.ml | 13 ++++++++----- .../lib_delegate/client_baking_blocks.mli | 2 ++ .../lib_delegate_services/event_queues.ml | 16 ++++++++-------- .../lib_delegate_services/event_queues.mli | 5 ++--- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/proto_alpha/lib_delegate/client_baking_blocks.ml b/src/proto_alpha/lib_delegate/client_baking_blocks.ml index d40cc2c55b2d..dbaad5f63c2e 100644 --- a/src/proto_alpha/lib_delegate/client_baking_blocks.ml +++ b/src/proto_alpha/lib_delegate/client_baking_blocks.ml @@ -61,19 +61,22 @@ let info cctxt ?(chain = `Main) block = cctxt ~chain ~block () >>=? fun shell_header -> raw_info cctxt ~chain hash shell_header -let monitor_valid_blocks cctxt ?chains ?protocols ~next_protocols () = +let monitor_valid_blocks cctxt ?(report=ignore) ?chains ?protocols ~next_protocols () = Monitor_services.valid_blocks cctxt ?chains ?protocols ?next_protocols () >>=? fun (block_stream, _stop) -> return (Lwt_stream.map_s - (fun ((chain, block), { Tezos_base.Block_header.shell }) -> - raw_info cctxt ~chain:(`Hash chain) block shell) + (fun ((chain, block), data) -> + report (block, data) ; + raw_info cctxt ~chain:(`Hash chain) block data.Tezos_base.Block_header.shell) block_stream) -let monitor_heads cctxt ~next_protocols chain = +let monitor_heads cctxt ?(report=ignore) ~next_protocols chain = Monitor_services.heads cctxt ?next_protocols chain >>=? fun (block_stream, _stop) -> return (Lwt_stream.map_s - (fun (block, { Tezos_base.Block_header.shell }) -> raw_info cctxt ~chain block shell) + (fun (block, data) -> + report (block, data) ; + raw_info cctxt ~chain block data.Tezos_base.Block_header.shell) block_stream) let blocks_from_current_cycle cctxt ?(chain = `Main) block ?(offset = 0l) () = diff --git a/src/proto_alpha/lib_delegate/client_baking_blocks.mli b/src/proto_alpha/lib_delegate/client_baking_blocks.mli index b92795bda581..4d988ac7cb10 100644 --- a/src/proto_alpha/lib_delegate/client_baking_blocks.mli +++ b/src/proto_alpha/lib_delegate/client_baking_blocks.mli @@ -47,6 +47,7 @@ val info: val monitor_valid_blocks: #Proto_alpha.rpc_context -> + ?report:(Block_hash.t * Tezos_base.Block_header.t -> unit) -> ?chains:Chain_services.chain list -> ?protocols:Protocol_hash.t list -> next_protocols:Protocol_hash.t list option -> @@ -54,6 +55,7 @@ val monitor_valid_blocks: val monitor_heads: #Proto_alpha.rpc_context -> + ?report:(Block_hash.t * Tezos_base.Block_header.t -> unit) -> next_protocols:Protocol_hash.t list option -> Chain_services.chain -> block_info tzresult Lwt_stream.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_delegate_services/event_queues.ml b/src/proto_alpha/lib_delegate_services/event_queues.ml index 083f458df821..02ff0c5812aa 100644 --- a/src/proto_alpha/lib_delegate_services/event_queues.ml +++ b/src/proto_alpha/lib_delegate_services/event_queues.ml @@ -24,7 +24,6 @@ (*****************************************************************************) open Proto_alpha -open Alpha_context module type EVENT = sig type t @@ -76,9 +75,9 @@ module Endorsement_event = struct let capacity = 20 type t = { hash: Block_hash.t ; - level: Raw_level.t ; + level: Alpha_context.Raw_level.t ; slot: int ; - delegate: public_key_hash ; + delegate: Signature.Public_key_hash.t ; name: string ; oph: Operation_hash.t ; } @@ -90,7 +89,7 @@ module Endorsement_event = struct { hash ; level ; slot ; delegate ; name ; oph }) (obj6 (req "hash" Block_hash.encoding) - (req "level" Raw_level.encoding) + (req "level" Alpha_context.Raw_level.encoding) (req "slot" int31) (req "delegate" Signature.Public_key_hash.encoding) (req "name" string) @@ -107,10 +106,11 @@ end module Block_event = struct type t = Block_hash.t * Block_header.t let encoding = let open Data_encoding in - (merge_objs - (obj1 - (req "hash" Block_hash.encoding)) - Block_header.encoding) + dynamic_size + (merge_objs + (obj1 + (req "hash" Block_hash.encoding)) + Block_header.encoding) let capacity = 20 let name = "seen" end diff --git a/src/proto_alpha/lib_delegate_services/event_queues.mli b/src/proto_alpha/lib_delegate_services/event_queues.mli index 97699391d1a2..3760497fc19e 100644 --- a/src/proto_alpha/lib_delegate_services/event_queues.mli +++ b/src/proto_alpha/lib_delegate_services/event_queues.mli @@ -24,7 +24,6 @@ (*****************************************************************************) open Proto_alpha -open Alpha_context module type EVENT = sig type t @@ -53,9 +52,9 @@ end module Endorsement_event : sig type t = { hash: Block_hash.t ; - level: Raw_level.t ; + level: Alpha_context.Raw_level.t ; slot: int ; - delegate: public_key_hash ; + delegate: Signature.Public_key_hash.t ; name: string ; oph: Operation_hash.t ; } -- GitLab From 873bed392bd9d6a7a869d948aff1bf5b0305c00b Mon Sep 17 00:00:00 2001 From: James Deikun Date: Fri, 15 Jun 2018 17:18:36 -0400 Subject: [PATCH 3/8] capture baked block events --- src/proto_alpha/lib_delegate/client_baking_forge.ml | 6 ++++++ src/proto_alpha/lib_delegate/client_daemon.ml | 2 ++ src/proto_alpha/lib_delegate/logging.ml | 1 + src/proto_alpha/lib_delegate/logging.mli | 3 ++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_delegate/client_baking_forge.ml b/src/proto_alpha/lib_delegate/client_baking_forge.ml index 3f09c777f39a..372ca3a18fdd 100644 --- a/src/proto_alpha/lib_delegate/client_baking_forge.ml +++ b/src/proto_alpha/lib_delegate/client_baking_forge.ml @@ -135,6 +135,12 @@ let inject_block src_sk shell_header priority seed_nonce_hash >>=? fun signed_header -> Shell_services.Injection.block cctxt ?force ~chain signed_header operations >>=? fun block_hash -> + lwt_log_info Tag.DSL.(fun f -> + f "Client_baking_forge.inject_block: inject %a" + -% t event "inject_baked_block" + -% a Block_hash.Logging.tag block_hash + -% t signed_header_tag signed_header + -% t operations_tag operations) >>= fun () -> return block_hash type error += diff --git a/src/proto_alpha/lib_delegate/client_daemon.ml b/src/proto_alpha/lib_delegate/client_daemon.ml index b8cacf2addf0..f897cf5ed061 100644 --- a/src/proto_alpha/lib_delegate/client_daemon.ml +++ b/src/proto_alpha/lib_delegate/client_daemon.ml @@ -23,6 +23,8 @@ (* *) (*****************************************************************************) +include Tezos_stdlib.Logging.Make_semantic(struct let name = "client.daemon" end) + let await_bootstrapped_node (cctxt: #Proto_alpha.full) = (* Waiting for the node to be synchronized *) cctxt#message "Waiting for the node to be synchronized with its \ diff --git a/src/proto_alpha/lib_delegate/logging.ml b/src/proto_alpha/lib_delegate/logging.ml index 191f0fff2608..acc7301b0e65 100644 --- a/src/proto_alpha/lib_delegate/logging.ml +++ b/src/proto_alpha/lib_delegate/logging.ml @@ -35,6 +35,7 @@ let current_slots_tag = Tag.def ~doc:"Number of baking slots that can be baked a let future_slots_tag = Tag.def ~doc:"Number of baking slots in the foreseeable future but not yet bakeable" "future_slots" Format.pp_print_int let timespan_tag = Tag.def ~doc:"Time in seconds" "timespan" (fun fmt i -> Format.fprintf fmt "%Lds" i) +let signed_header_tag = Tag.def ~doc:"Signed header" "signed_header" MBytes.pp_hex let operations_tag = Tag.def ~doc:"Block Operations" "operations" (Format.pp_print_list ~pp_sep:(fun ppf () -> Format.fprintf ppf "+") diff --git a/src/proto_alpha/lib_delegate/logging.mli b/src/proto_alpha/lib_delegate/logging.mli index 868594ee9c55..822537b553a0 100644 --- a/src/proto_alpha/lib_delegate/logging.mli +++ b/src/proto_alpha/lib_delegate/logging.mli @@ -32,7 +32,8 @@ val current_slots_tag : int Tag.def val future_slots_tag : int Tag.def val timespan_tag : int64 Tag.def -val operations_tag : Proto_alpha.Alpha_context.Operation.raw list list Tag.def +val signed_header_tag : MBytes.t Tag.def +val operations_tag : Tezos_base.Operation.t list list Tag.def val bake_op_count_tag : int Tag.def val endorsement_slot_tag : int Tag.def val endorsement_slots_tag : int list Tag.def -- GitLab From a71e71f64794086726a94248fa48b4950d49a65e Mon Sep 17 00:00:00 2001 From: dbornside Date: Mon, 18 Jun 2018 11:21:31 -0400 Subject: [PATCH 4/8] monitor errors in baking --- src/proto_alpha/lib_delegate_services/event_queues.ml | 4 ++-- src/proto_alpha/lib_delegate_services/event_queues.mli | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_delegate_services/event_queues.ml b/src/proto_alpha/lib_delegate_services/event_queues.ml index 02ff0c5812aa..94a6732fad7c 100644 --- a/src/proto_alpha/lib_delegate_services/event_queues.ml +++ b/src/proto_alpha/lib_delegate_services/event_queues.ml @@ -36,7 +36,7 @@ module Error_event = struct let name = "errors" let capacity = 20 type t = { - message: string ; + message: string option ; trace: error list ; } let encoding = let open Data_encoding in @@ -46,7 +46,7 @@ module Error_event = struct (fun ( message , trace ) -> { message ; trace }) (obj2 - (req "message" string) + (opt "message" string) (req "trace" (list error_encoding))) end diff --git a/src/proto_alpha/lib_delegate_services/event_queues.mli b/src/proto_alpha/lib_delegate_services/event_queues.mli index 3760497fc19e..36169c1a64af 100644 --- a/src/proto_alpha/lib_delegate_services/event_queues.mli +++ b/src/proto_alpha/lib_delegate_services/event_queues.mli @@ -34,7 +34,7 @@ end module Error_event : sig type t = { - message: string ; + message: string option ; trace: error list ; } include EVENT with type t := t -- GitLab From a15de419ba53e85b229365344e084cf3460d1e8e Mon Sep 17 00:00:00 2001 From: James Deikun Date: Wed, 5 Sep 2018 15:57:55 -0400 Subject: [PATCH 5/8] report endorsements --- .../lib_delegate/client_baking_endorsement.ml | 1 + .../lib_delegate_services/event_queues.ml | 12 +++++------- .../lib_delegate_services/event_queues.mli | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/proto_alpha/lib_delegate/client_baking_endorsement.ml b/src/proto_alpha/lib_delegate/client_baking_endorsement.ml index 4759717a5b86..f899677da374 100644 --- a/src/proto_alpha/lib_delegate/client_baking_endorsement.ml +++ b/src/proto_alpha/lib_delegate/client_baking_endorsement.ml @@ -137,6 +137,7 @@ let endorse_for_delegate cctxt block delegate = -% a Block_hash.Logging.tag hash -% a level_tag level -% s Client_keys.Logging.tag name + -% t Signature.Public_key_hash.Logging.tag delegate -% a Operation_hash.Logging.tag oph) >>= fun () -> return_unit diff --git a/src/proto_alpha/lib_delegate_services/event_queues.ml b/src/proto_alpha/lib_delegate_services/event_queues.ml index 94a6732fad7c..bc1e6cb854a5 100644 --- a/src/proto_alpha/lib_delegate_services/event_queues.ml +++ b/src/proto_alpha/lib_delegate_services/event_queues.ml @@ -76,21 +76,19 @@ module Endorsement_event = struct type t = { hash: Block_hash.t ; level: Alpha_context.Raw_level.t ; - slot: int ; delegate: Signature.Public_key_hash.t ; name: string ; oph: Operation_hash.t ; } let encoding = let open Data_encoding in conv - (fun { hash ; level ; slot ; delegate ; name ; oph } -> - ( hash , level , slot , delegate , name , oph )) - (fun ( hash , level , slot , delegate , name , oph ) -> - { hash ; level ; slot ; delegate ; name ; oph }) - (obj6 + (fun { hash ; level ; delegate ; name ; oph } -> + ( hash , level , delegate , name , oph )) + (fun ( hash , level , delegate , name , oph ) -> + { hash ; level ; delegate ; name ; oph }) + (obj5 (req "hash" Block_hash.encoding) (req "level" Alpha_context.Raw_level.encoding) - (req "slot" int31) (req "delegate" Signature.Public_key_hash.encoding) (req "name" string) (req "oph" Operation_hash.encoding)) diff --git a/src/proto_alpha/lib_delegate_services/event_queues.mli b/src/proto_alpha/lib_delegate_services/event_queues.mli index 36169c1a64af..9a98a3b36168 100644 --- a/src/proto_alpha/lib_delegate_services/event_queues.mli +++ b/src/proto_alpha/lib_delegate_services/event_queues.mli @@ -53,7 +53,6 @@ module Endorsement_event : sig type t = { hash: Block_hash.t ; level: Alpha_context.Raw_level.t ; - slot: int ; delegate: Signature.Public_key_hash.t ; name: string ; oph: Operation_hash.t ; -- GitLab From 8cf6859d1ab9a1aa4c78c8afea62102fa21717f6 Mon Sep 17 00:00:00 2001 From: James Deikun Date: Wed, 5 Sep 2018 16:44:11 -0400 Subject: [PATCH 6/8] report denunciations --- .../lib_delegate/client_baking_denunciation.ml | 2 ++ src/proto_alpha/lib_delegate/logging.ml | 3 +++ src/proto_alpha/lib_delegate/logging.mli | 2 ++ .../lib_delegate_services/event_queues.ml | 15 +++++++++++++-- .../lib_delegate_services/event_queues.mli | 6 +++++- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_delegate/client_baking_denunciation.ml b/src/proto_alpha/lib_delegate/client_baking_denunciation.ml index 6b00e84b9349..162cc49682ff 100644 --- a/src/proto_alpha/lib_delegate/client_baking_denunciation.ml +++ b/src/proto_alpha/lib_delegate/client_baking_denunciation.ml @@ -113,6 +113,7 @@ let process_endorsements (cctxt : #Proto_alpha.full) state ~chain lwt_log_notice Tag.DSL.(fun f -> f "Double endorsement evidence injected %a" -% t event "double_endorsement_denounced" + -% t signed_operation_tag bytes -% a Operation_hash.Logging.tag op_hash) >>= fun () -> return @@ HLevel.replace state.endorsements_table level (Delegate_Map.add delegate new_endorsement map) @@ -166,6 +167,7 @@ let process_block (cctxt : #Proto_alpha.full) state ~chain (header : Alpha_block lwt_log_notice Tag.DSL.(fun f -> f "Double baking evidence injected %a" -% t event "double_baking_denounced" + -% t signed_operation_tag bytes -% a Operation_hash.Logging.tag op_hash) >>= fun () -> return @@ HLevel.replace state.blocks_table level (Delegate_Map.add baker hash map) diff --git a/src/proto_alpha/lib_delegate/logging.ml b/src/proto_alpha/lib_delegate/logging.ml index acc7301b0e65..47e6ea06457d 100644 --- a/src/proto_alpha/lib_delegate/logging.ml +++ b/src/proto_alpha/lib_delegate/logging.ml @@ -36,6 +36,7 @@ let future_slots_tag = Tag.def ~doc:"Number of baking slots in the foreseeable f let timespan_tag = Tag.def ~doc:"Time in seconds" "timespan" (fun fmt i -> Format.fprintf fmt "%Lds" i) let signed_header_tag = Tag.def ~doc:"Signed header" "signed_header" MBytes.pp_hex +let signed_operation_tag = Tag.def ~doc:"Signed operation" "signed_operation" MBytes.pp_hex let operations_tag = Tag.def ~doc:"Block Operations" "operations" (Format.pp_print_list ~pp_sep:(fun ppf () -> Format.fprintf ppf "+") @@ -52,5 +53,7 @@ let level_tag = Tag.def ~doc:"Level" "level" Raw_level.pp let worker_tag = Tag.def ~doc:"Worker in which event occurred" "worker" Format.pp_print_text +let operation_tag = Tag.def ~doc:"Operation" "operation" Tezos_base.Operation.pp + let conflicting_endorsements_tag = Tag.def ~doc:"Two conflicting endorsements signed by the same key" "conflicting_endorsements" Format.( fun ppf (a,b) -> fprintf ppf "%a / %a" Operation_hash.pp (Operation.hash a) Operation_hash.pp (Operation.hash b)) diff --git a/src/proto_alpha/lib_delegate/logging.mli b/src/proto_alpha/lib_delegate/logging.mli index 822537b553a0..0ed82d42c6a6 100644 --- a/src/proto_alpha/lib_delegate/logging.mli +++ b/src/proto_alpha/lib_delegate/logging.mli @@ -33,6 +33,7 @@ val future_slots_tag : int Tag.def val timespan_tag : int64 Tag.def val signed_header_tag : MBytes.t Tag.def +val signed_operation_tag : MBytes.t Tag.def val operations_tag : Tezos_base.Operation.t list list Tag.def val bake_op_count_tag : int Tag.def val endorsement_slot_tag : int Tag.def @@ -41,6 +42,7 @@ val denounced_endorsements_slots_tag : int list Tag.def val denouncement_source_tag : string Tag.def val level_tag : Proto_alpha.Alpha_context.Raw_level.t Tag.def val worker_tag : string Tag.def +val operation_tag : Tezos_base.Operation.t Tag.def open Proto_alpha.Alpha_context val conflicting_endorsements_tag : (Kind.endorsement operation * Kind.endorsement operation) Tag.def diff --git a/src/proto_alpha/lib_delegate_services/event_queues.ml b/src/proto_alpha/lib_delegate_services/event_queues.ml index bc1e6cb854a5..11f6d4ceaa8f 100644 --- a/src/proto_alpha/lib_delegate_services/event_queues.ml +++ b/src/proto_alpha/lib_delegate_services/event_queues.ml @@ -97,8 +97,19 @@ end module Accusation_event = struct let name = "accused" let capacity = 20 - type t = Tezos_base.Operation.t - let encoding = Data_encoding.dynamic_size Tezos_base.Operation.encoding + type t = { + sin : string ; + oph : Operation_hash.t ; + raw : MBytes.t ; + } + let encoding = let open Data_encoding in + conv + (fun { sin ; oph ; raw } -> ( sin , oph , raw )) + (fun ( sin , oph , raw ) -> { sin ; oph ; raw }) + (obj3 + (req "sin" string) + (req "oph" Operation_hash.encoding) + (req "raw" bytes)) end module Block_event = struct diff --git a/src/proto_alpha/lib_delegate_services/event_queues.mli b/src/proto_alpha/lib_delegate_services/event_queues.mli index 9a98a3b36168..719282754d3e 100644 --- a/src/proto_alpha/lib_delegate_services/event_queues.mli +++ b/src/proto_alpha/lib_delegate_services/event_queues.mli @@ -61,7 +61,11 @@ module Endorsement_event : sig end module Accusation_event : sig - type t = Tezos_base.Operation.t + type t = { + sin: string ; + oph: Operation_hash.t ; + raw: MBytes.t ; + } include EVENT with type t := t end -- GitLab From 81a313267bcf17e67dca0a5308c9b8a1d7dd9a44 Mon Sep 17 00:00:00 2001 From: James Deikun Date: Mon, 10 Sep 2018 16:03:57 -0400 Subject: [PATCH 7/8] =?UTF-8?q?Address=20comments=20from=20Rapha=C3=ABl=20?= =?UTF-8?q?Proust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/proto_alpha/lib_delegate_services/event_queues.mli | 1 + 1 file changed, 1 insertion(+) diff --git a/src/proto_alpha/lib_delegate_services/event_queues.mli b/src/proto_alpha/lib_delegate_services/event_queues.mli index 719282754d3e..bfdeebbf618c 100644 --- a/src/proto_alpha/lib_delegate_services/event_queues.mli +++ b/src/proto_alpha/lib_delegate_services/event_queues.mli @@ -25,6 +25,7 @@ open Proto_alpha +(** Parameters defining an inspectable, named stream of events. *) module type EVENT = sig type t val name: string -- GitLab From 52977cf4e2bbe9a71d7f46722e7529bb002311e4 Mon Sep 17 00:00:00 2001 From: James Deikun Date: Mon, 10 Sep 2018 21:38:39 -0400 Subject: [PATCH 8/8] report nonce revelations --- .../lib_delegate/client_baking_revelation.ml | 11 +++++++++- src/proto_alpha/lib_delegate/logging.ml | 3 +++ src/proto_alpha/lib_delegate/logging.mli | 3 +++ .../lib_delegate_services/event_queues.ml | 20 +++++++++++++++++++ .../lib_delegate_services/event_queues.mli | 9 +++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_delegate/client_baking_revelation.ml b/src/proto_alpha/lib_delegate/client_baking_revelation.ml index 068d0010ad6c..f80421179f30 100644 --- a/src/proto_alpha/lib_delegate/client_baking_revelation.ml +++ b/src/proto_alpha/lib_delegate/client_baking_revelation.ml @@ -34,7 +34,16 @@ let inject_seed_nonce_revelation rpc_config ?(chain = `Main) block ?async nonces Alpha_services.Forge.seed_nonce_revelation rpc_config (chain, block) ~branch ~level ~nonce () >>=? fun bytes -> let bytes = Signature.concat bytes Signature.zero in - Shell_services.Injection.operation rpc_config ?async ~chain bytes) + Shell_services.Injection.operation rpc_config ?async ~chain bytes >>=? fun oph -> + lwt_debug Tag.DSL.(fun f -> + f "Revealing nonce %a from level %a at chain %a, block %a with operation %a" + -% t event "reveal_nonce" + -% a Logging.nonce_tag nonce + -% a Logging.level_tag level + -% a Logging.chain_tag chain + -% a Logging.block_tag block + -% a Operation_hash.Logging.tag oph) >>= fun () -> + return oph) nonces >>=? fun ophs -> return ophs diff --git a/src/proto_alpha/lib_delegate/logging.ml b/src/proto_alpha/lib_delegate/logging.ml index 47e6ea06457d..3b8247f775c3 100644 --- a/src/proto_alpha/lib_delegate/logging.ml +++ b/src/proto_alpha/lib_delegate/logging.ml @@ -50,6 +50,9 @@ let denounced_endorsements_slots_tag = Tag.def ~doc:"Endorsement Slots" "denounc let denouncement_source_tag = Tag.def ~doc:"Denounce Source" "source" Format.pp_print_text let level_tag = Tag.def ~doc:"Level" "level" Raw_level.pp +let nonce_tag = Tag.def ~doc:"Nonce" "nonce" Data_encoding.Json.(fun ppf nonce -> pp ppf (construct Nonce.encoding nonce)) +let chain_tag = Tag.def ~doc:"Chain selector" "chain" Format.(fun ppf chain -> pp_print_string ppf @@ Block_services.chain_to_string chain) +let block_tag = Tag.def ~doc:"Block selector" "block" Format.(fun ppf block -> pp_print_string ppf @@ Block_services.to_string block) let worker_tag = Tag.def ~doc:"Worker in which event occurred" "worker" Format.pp_print_text diff --git a/src/proto_alpha/lib_delegate/logging.mli b/src/proto_alpha/lib_delegate/logging.mli index 0ed82d42c6a6..b653daf02195 100644 --- a/src/proto_alpha/lib_delegate/logging.mli +++ b/src/proto_alpha/lib_delegate/logging.mli @@ -41,6 +41,9 @@ val endorsement_slots_tag : int list Tag.def val denounced_endorsements_slots_tag : int list Tag.def val denouncement_source_tag : string Tag.def val level_tag : Proto_alpha.Alpha_context.Raw_level.t Tag.def +val nonce_tag : Proto_alpha.Alpha_context.Nonce.t Tag.def +val chain_tag : Block_services.chain Tag.def +val block_tag : Block_services.block Tag.def val worker_tag : string Tag.def val operation_tag : Tezos_base.Operation.t Tag.def diff --git a/src/proto_alpha/lib_delegate_services/event_queues.ml b/src/proto_alpha/lib_delegate_services/event_queues.ml index 11f6d4ceaa8f..4a2ddc915f15 100644 --- a/src/proto_alpha/lib_delegate_services/event_queues.ml +++ b/src/proto_alpha/lib_delegate_services/event_queues.ml @@ -70,6 +70,26 @@ module Baked_event = struct (req "operations" (list (list (dynamic_size Tezos_base.Operation.encoding))))) end +module Revelation_event = struct + let name = "revealed" + let capacity = 20 + type t = { + nonce: Alpha_context.Nonce.t ; + level: Alpha_context.Raw_level.t ; + oph: Operation_hash.t ; + } + let encoding = let open Data_encoding in + conv + (fun { nonce ; level ; oph } -> + ( nonce , level , oph )) + (fun ( nonce , level , oph ) -> + { nonce ; level ; oph }) + (obj3 + (req "nonce" Alpha_context.Nonce.encoding) + (req "level" Alpha_context.Raw_level.encoding) + (req "oph" Operation_hash.encoding)) +end + module Endorsement_event = struct let name = "endorsed" let capacity = 20 diff --git a/src/proto_alpha/lib_delegate_services/event_queues.mli b/src/proto_alpha/lib_delegate_services/event_queues.mli index bfdeebbf618c..edf19e5857d1 100644 --- a/src/proto_alpha/lib_delegate_services/event_queues.mli +++ b/src/proto_alpha/lib_delegate_services/event_queues.mli @@ -50,6 +50,15 @@ module Baked_event : sig include EVENT with type t := t end +module Revelation_event : sig + type t = { + nonce: Alpha_context.Nonce.t ; + level: Alpha_context.Raw_level.t ; + oph : Operation_hash.t ; + } + include EVENT with type t := t +end + module Endorsement_event : sig type t = { hash: Block_hash.t ; -- GitLab