diff --git a/CHANGES.rst b/CHANGES.rst index 83f06a6a21bd9de0b7ef61e8707a6accd200ba76..7f42b26a5c07d3b5d5e7c701cfad88092aa468f2 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 ------------ diff --git a/src/proto_alpha/lib_delegate/baking_commands.ml b/src/proto_alpha/lib_delegate/baking_commands.ml index 4b9a271bbc0656ad3d2c8026fac2253453403015..7c91b2cd0b58d295094eb1828a66a45c7e35262a 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.ml +++ b/src/proto_alpha/lib_delegate/baking_commands.ml @@ -355,9 +355,16 @@ 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 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,26 @@ let accuser_commands () = command ~group ~desc:"Launch the accuser daemon" - (args3 pidfile_arg Client_proto_args.preserved_levels_arg keep_alive_arg) + (args5 + pidfile_arg + Client_proto_args.preserved_levels_arg + keep_alive_arg + dal_node_endpoint_arg + dal_slot_index_arg) (prefixes ["run"] @@ stop) - (fun (pidfile, preserved_levels, keep_alive) cctxt -> + (fun ( pidfile, + preserved_levels, + keep_alive, + dal_node_endpoint, + dal_slot_index ) + cctxt -> may_lock_pidfile pidfile @@ fun () -> Client_daemon.Accuser.run cctxt ~chain:cctxt#chain ~preserved_levels - ~keep_alive); + ~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 49a3cb5aeafeda71f0288a1c2548b72a4fd768a0..6a75524e3d8db7b71c500a624bf72df8d2f47094 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,14 +101,43 @@ type 'a state = { mutable ops_stream : ops_stream; (* operatons stream stopper. Used when a q new *) mutable ops_stream_stopper : unit -> unit; + dal : dal_config 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 ?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; @@ -113,6 +149,7 @@ let create_state ~preserved_levels blocks_stream ops_stream ops_stream_stopper = blocks_stream; ops_stream; ops_stream_stopper; + dal; } (* We choose a previous offset (5 blocks from head) to ensure that the @@ -551,14 +588,16 @@ 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 + ?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 diff --git a/src/proto_alpha/lib_delegate/client_baking_denunciation.mli b/src/proto_alpha/lib_delegate/client_baking_denunciation.mli index 46e784d132b49cef5f5e031d1d41bc55161c493a..65fafefd5752bb2914d5a4d2229f6276e61c9cf1 100644 --- a/src/proto_alpha/lib_delegate/client_baking_denunciation.mli +++ b/src/proto_alpha/lib_delegate/client_baking_denunciation.mli @@ -26,6 +26,8 @@ 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 f63ab6e2db236ae991f557e017ddcaf6f6326a9f..52eac647d096e6a8ac0f845b47b83e64af1562ba 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 ?dal_slot_index () = let open Lwt_result_syntax in let process () = let*! () = @@ -194,6 +194,8 @@ module Accuser = struct Client_baking_denunciation.create 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 bd24247fda99c5201fdb1ff8a1fae0b3dffebfea..639b2105d780878d4b8f6d60e9a93333717730a2 100644 --- a/src/proto_alpha/lib_delegate/client_daemon.mli +++ b/src/proto_alpha/lib_delegate/client_daemon.mli @@ -54,6 +54,9 @@ module Accuser : sig chain:Chain_services.chain -> preserved_levels:int -> keep_alive:bool -> + ?dal_node_endpoint:Uri.t -> + ?dal_slot_index:int -> + unit -> unit tzresult Lwt.t end