From c6cc33c040df1ef800e88d01dd26ecc0e7dc084e Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 9 Oct 2024 11:57:48 +0200 Subject: [PATCH 1/4] Alpha/Accuser: add a --dal-node optional argument --- .../lib_delegate/baking_commands.ml | 14 +++++++++---- .../client_baking_denunciation.ml | 21 ++++++++++++++++--- .../client_baking_denunciation.mli | 1 + src/proto_alpha/lib_delegate/client_daemon.ml | 3 ++- .../lib_delegate/client_daemon.mli | 2 ++ 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/proto_alpha/lib_delegate/baking_commands.ml b/src/proto_alpha/lib_delegate/baking_commands.ml index 4b9a271bbc06..6144fed072aa 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.ml +++ b/src/proto_alpha/lib_delegate/baking_commands.ml @@ -355,7 +355,7 @@ let dal_node_endpoint_arg = Tezos_clic.arg ~long:"dal-node" ~placeholder:"uri" - ~doc:"endpoint of the DAL node, e.g. 'http://localhost:8933'" + ~doc:"endpoint of the DAL node, e.g. 'http://localhost:10732'" (Tezos_clic.parameter (fun _ s -> return @@ Uri.of_string s)) let block_count_arg = @@ -849,13 +849,19 @@ let accuser_commands () = command ~group ~desc:"Launch the accuser daemon" - (args3 pidfile_arg Client_proto_args.preserved_levels_arg keep_alive_arg) + (args4 + pidfile_arg + Client_proto_args.preserved_levels_arg + keep_alive_arg + dal_node_endpoint_arg) (prefixes ["run"] @@ stop) - (fun (pidfile, preserved_levels, keep_alive) cctxt -> + (fun (pidfile, preserved_levels, keep_alive, dal_node_endpoint) cctxt -> may_lock_pidfile pidfile @@ fun () -> Client_daemon.Accuser.run cctxt ~chain:cctxt#chain ~preserved_levels - ~keep_alive); + ~keep_alive + ?dal_node_endpoint + ()); ] diff --git a/src/proto_alpha/lib_delegate/client_baking_denunciation.ml b/src/proto_alpha/lib_delegate/client_baking_denunciation.ml index 49a3cb5aeafe..47c2c020333e 100644 --- a/src/proto_alpha/lib_delegate/client_baking_denunciation.ml +++ b/src/proto_alpha/lib_delegate/client_baking_denunciation.ml @@ -94,9 +94,22 @@ type 'a state = { mutable ops_stream : ops_stream; (* operatons stream stopper. Used when a q new *) mutable ops_stream_stopper : unit -> unit; + (* the DAL node RPC context, if a DAL node endpoint was given *) + dal_node_rpc_ctxt : Tezos_rpc.Context.generic option; } -let create_state ~preserved_levels blocks_stream ops_stream ops_stream_stopper = +let create_dal_node_rpc_ctxt endpoint = + let open Tezos_rpc_http_client_unix in + let rpc_config = + {Tezos_rpc_http_client_unix.RPC_client_unix.default_config with endpoint} + in + let media_types = + Tezos_rpc_http.Media_type.Command_line.of_command_line rpc_config.media_type + in + new RPC_client_unix.http_ctxt rpc_config media_types + +let create_state ~preserved_levels ?dal_node_endpoint blocks_stream ops_stream + ops_stream_stopper = let clean_frequency = max 1 (preserved_levels / 10) in let validators_rights = Validators_cache.create (preserved_levels + 2) in (* We keep rights for [preserved_levels] in the past, and 2 levels in the @@ -113,6 +126,7 @@ let create_state ~preserved_levels blocks_stream ops_stream ops_stream_stopper = blocks_stream; ops_stream; ops_stream_stopper; + dal_node_rpc_ctxt = Option.map create_dal_node_rpc_ctxt dal_node_endpoint; } (* We choose a previous offset (5 blocks from head) to ensure that the @@ -551,14 +565,15 @@ let start_ops_monitor cctxt = ~outdated:false () -let create (cctxt : #Protocol_client_context.full) ?canceler ~preserved_levels - valid_blocks_stream = +let create (cctxt : #Protocol_client_context.full) ?canceler ?dal_node_endpoint + ~preserved_levels valid_blocks_stream = let open Lwt_result_syntax in let*! () = B_Events.(emit daemon_setup) name in let* ops_stream, ops_stream_stopper = start_ops_monitor cctxt in let*! state = create_state ~preserved_levels + ?dal_node_endpoint valid_blocks_stream ops_stream ops_stream_stopper diff --git a/src/proto_alpha/lib_delegate/client_baking_denunciation.mli b/src/proto_alpha/lib_delegate/client_baking_denunciation.mli index 46e784d132b4..afc3f2d8c63c 100644 --- a/src/proto_alpha/lib_delegate/client_baking_denunciation.mli +++ b/src/proto_alpha/lib_delegate/client_baking_denunciation.mli @@ -26,6 +26,7 @@ val create : #Protocol_client_context.full -> ?canceler:Lwt_canceler.t -> + ?dal_node_endpoint:Uri.t -> preserved_levels:int -> Client_baking_blocks.block_info tzresult Lwt_stream.t -> unit tzresult Lwt.t diff --git a/src/proto_alpha/lib_delegate/client_daemon.ml b/src/proto_alpha/lib_delegate/client_daemon.ml index f63ab6e2db23..c3775084806b 100644 --- a/src/proto_alpha/lib_delegate/client_daemon.ml +++ b/src/proto_alpha/lib_delegate/client_daemon.ml @@ -165,7 +165,7 @@ end module Accuser = struct let run (cctxt : #Protocol_client_context.full) ~chain ~preserved_levels - ~keep_alive = + ~keep_alive ?dal_node_endpoint () = let open Lwt_result_syntax in let process () = let*! () = @@ -194,6 +194,7 @@ module Accuser = struct Client_baking_denunciation.create cctxt ~canceler + ?dal_node_endpoint ~preserved_levels valid_blocks_stream in diff --git a/src/proto_alpha/lib_delegate/client_daemon.mli b/src/proto_alpha/lib_delegate/client_daemon.mli index bd24247fda99..e9e9588bbcfa 100644 --- a/src/proto_alpha/lib_delegate/client_daemon.mli +++ b/src/proto_alpha/lib_delegate/client_daemon.mli @@ -54,6 +54,8 @@ module Accuser : sig chain:Chain_services.chain -> preserved_levels:int -> keep_alive:bool -> + ?dal_node_endpoint:Uri.t -> + unit -> unit tzresult Lwt.t end -- GitLab From 98385096f2414163df57d23b3da5d213fa800335 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Sat, 11 Jan 2025 18:46:53 +0100 Subject: [PATCH 2/4] Alpha/Accuser: add --dal-slot-index optional argument --- .../lib_delegate/baking_commands.ml | 20 ++++++++++++++++--- .../client_baking_denunciation.ml | 2 +- .../client_baking_denunciation.mli | 1 + src/proto_alpha/lib_delegate/client_daemon.ml | 3 ++- .../lib_delegate/client_daemon.mli | 1 + 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_delegate/baking_commands.ml b/src/proto_alpha/lib_delegate/baking_commands.ml index 6144fed072aa..7c91b2cd0b58 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.ml +++ b/src/proto_alpha/lib_delegate/baking_commands.ml @@ -358,6 +358,13 @@ let dal_node_endpoint_arg = ~doc:"endpoint of the DAL node, e.g. 'http://localhost:10732'" (Tezos_clic.parameter (fun _ s -> return @@ Uri.of_string s)) +let dal_slot_index_arg = + Tezos_clic.arg + ~long:"dal-slot-index" + ~placeholder:"DAL slot index" + ~doc:"the DAL slot index to track" + @@ Client_proto_args.non_negative_parameter () + let block_count_arg = Tezos_clic.default_arg ~long:"count" @@ -849,13 +856,19 @@ let accuser_commands () = command ~group ~desc:"Launch the accuser daemon" - (args4 + (args5 pidfile_arg Client_proto_args.preserved_levels_arg keep_alive_arg - dal_node_endpoint_arg) + dal_node_endpoint_arg + dal_slot_index_arg) (prefixes ["run"] @@ stop) - (fun (pidfile, preserved_levels, keep_alive, dal_node_endpoint) cctxt -> + (fun ( pidfile, + preserved_levels, + keep_alive, + dal_node_endpoint, + dal_slot_index ) + cctxt -> may_lock_pidfile pidfile @@ fun () -> Client_daemon.Accuser.run cctxt @@ -863,5 +876,6 @@ let accuser_commands () = ~preserved_levels ~keep_alive ?dal_node_endpoint + ?dal_slot_index ()); ] diff --git a/src/proto_alpha/lib_delegate/client_baking_denunciation.ml b/src/proto_alpha/lib_delegate/client_baking_denunciation.ml index 47c2c020333e..a401a02fa0cb 100644 --- a/src/proto_alpha/lib_delegate/client_baking_denunciation.ml +++ b/src/proto_alpha/lib_delegate/client_baking_denunciation.ml @@ -566,7 +566,7 @@ let start_ops_monitor cctxt = () let create (cctxt : #Protocol_client_context.full) ?canceler ?dal_node_endpoint - ~preserved_levels valid_blocks_stream = + ?dal_slot_index:_ ~preserved_levels valid_blocks_stream = let open Lwt_result_syntax in let*! () = B_Events.(emit daemon_setup) name in let* ops_stream, ops_stream_stopper = start_ops_monitor cctxt in diff --git a/src/proto_alpha/lib_delegate/client_baking_denunciation.mli b/src/proto_alpha/lib_delegate/client_baking_denunciation.mli index afc3f2d8c63c..65fafefd5752 100644 --- a/src/proto_alpha/lib_delegate/client_baking_denunciation.mli +++ b/src/proto_alpha/lib_delegate/client_baking_denunciation.mli @@ -27,6 +27,7 @@ val create : #Protocol_client_context.full -> ?canceler:Lwt_canceler.t -> ?dal_node_endpoint:Uri.t -> + ?dal_slot_index:int -> preserved_levels:int -> Client_baking_blocks.block_info tzresult Lwt_stream.t -> unit tzresult Lwt.t diff --git a/src/proto_alpha/lib_delegate/client_daemon.ml b/src/proto_alpha/lib_delegate/client_daemon.ml index c3775084806b..52eac647d096 100644 --- a/src/proto_alpha/lib_delegate/client_daemon.ml +++ b/src/proto_alpha/lib_delegate/client_daemon.ml @@ -165,7 +165,7 @@ end module Accuser = struct let run (cctxt : #Protocol_client_context.full) ~chain ~preserved_levels - ~keep_alive ?dal_node_endpoint () = + ~keep_alive ?dal_node_endpoint ?dal_slot_index () = let open Lwt_result_syntax in let process () = let*! () = @@ -195,6 +195,7 @@ module Accuser = struct cctxt ~canceler ?dal_node_endpoint + ?dal_slot_index ~preserved_levels valid_blocks_stream in diff --git a/src/proto_alpha/lib_delegate/client_daemon.mli b/src/proto_alpha/lib_delegate/client_daemon.mli index e9e9588bbcfa..639b2105d780 100644 --- a/src/proto_alpha/lib_delegate/client_daemon.mli +++ b/src/proto_alpha/lib_delegate/client_daemon.mli @@ -55,6 +55,7 @@ module Accuser : sig preserved_levels:int -> keep_alive:bool -> ?dal_node_endpoint:Uri.t -> + ?dal_slot_index:int -> unit -> unit tzresult Lwt.t end -- GitLab From 4598d2f5634b630db4cc89b72fe03a7dbf24b77b Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Sat, 11 Jan 2025 18:48:23 +0100 Subject: [PATCH 3/4] Alpha/Accuser: store the slot index in the state --- .../client_baking_denunciation.ml | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/proto_alpha/lib_delegate/client_baking_denunciation.ml b/src/proto_alpha/lib_delegate/client_baking_denunciation.ml index a401a02fa0cb..6a75524e3d8d 100644 --- a/src/proto_alpha/lib_delegate/client_baking_denunciation.ml +++ b/src/proto_alpha/lib_delegate/client_baking_denunciation.ml @@ -68,6 +68,13 @@ type recorded_consensus_operations = { preattestation : Kind.preattestation recorded_consensus; } +type dal_config = { + (* the DAL node RPC context, if a DAL node endpoint was given *) + rpc_ctxt : Tezos_rpc.Context.generic; + (* the DAL node RPC context, if a DAL node endpoint was given *) + slot_index : int; (* the DAL slot index to track *) +} + type 'a state = { (* Validators rights for the last preserved levels *) validators_rights : public_key_hash Slot.Map.t Validators_cache.t; @@ -94,8 +101,7 @@ type 'a state = { mutable ops_stream : ops_stream; (* operatons stream stopper. Used when a q new *) mutable ops_stream_stopper : unit -> unit; - (* the DAL node RPC context, if a DAL node endpoint was given *) - dal_node_rpc_ctxt : Tezos_rpc.Context.generic option; + dal : dal_config option; } let create_dal_node_rpc_ctxt endpoint = @@ -108,13 +114,30 @@ let create_dal_node_rpc_ctxt endpoint = in new RPC_client_unix.http_ctxt rpc_config media_types -let create_state ~preserved_levels ?dal_node_endpoint blocks_stream ops_stream - ops_stream_stopper = +let create_state ~preserved_levels ?dal_node_endpoint ?dal_slot_index + blocks_stream ops_stream ops_stream_stopper = + let open Lwt_result_syntax in let clean_frequency = max 1 (preserved_levels / 10) in let validators_rights = Validators_cache.create (preserved_levels + 2) in (* We keep rights for [preserved_levels] in the past, and 2 levels in the future from [highest_level_encountered] *) - Lwt.return + let* dal = + match (dal_node_endpoint, dal_slot_index) with + | None, None -> return_none + | Some endpoint, Some slot_index -> + return_some {rpc_ctxt = create_dal_node_rpc_ctxt endpoint; slot_index} + | Some _, None -> + (* TODO-POC: proper error message *) + failwith + "If a DAL node endpoint is given, then a slot index needs to be \ + provided as well" + | None, Some _ -> + (* TODO-POC: proper error message *) + failwith + "If a DAL slot index is given, then DAL node endpoint needs to be \ + provided as well" + in + return { validators_rights; consensus_operations_table = HLevel.create preserved_levels; @@ -126,7 +149,7 @@ let create_state ~preserved_levels ?dal_node_endpoint blocks_stream ops_stream blocks_stream; ops_stream; ops_stream_stopper; - dal_node_rpc_ctxt = Option.map create_dal_node_rpc_ctxt dal_node_endpoint; + dal; } (* We choose a previous offset (5 blocks from head) to ensure that the @@ -566,14 +589,15 @@ let start_ops_monitor cctxt = () let create (cctxt : #Protocol_client_context.full) ?canceler ?dal_node_endpoint - ?dal_slot_index:_ ~preserved_levels valid_blocks_stream = + ?dal_slot_index ~preserved_levels valid_blocks_stream = let open Lwt_result_syntax in let*! () = B_Events.(emit daemon_setup) name in let* ops_stream, ops_stream_stopper = start_ops_monitor cctxt in - let*! state = + let* state = create_state ~preserved_levels ?dal_node_endpoint + ?dal_slot_index valid_blocks_stream ops_stream ops_stream_stopper -- GitLab From ef893ab188ac62d3eedb014e2e2e4ec5426d8fd4 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Mon, 13 Jan 2025 08:10:50 +0100 Subject: [PATCH 4/4] CHANGES: update --- CHANGES.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 83f06a6a21bd..7f42b26a5c07 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -52,6 +52,11 @@ Baker Accuser ------- +- Added two new optional arguments ``--dal-node `` and + ``--dal-slot-index `` (both or none should be provided) to allow + the accuser to connected to a DAL node that monitor the given slot index for + traps. (MR :gl:`!16186`) + Proxy Server ------------ -- GitLab