diff --git a/src/bin_dal_node/RPC_server.ml b/src/bin_dal_node/RPC_server.ml index c7452d336591e1488f82a6d7bbe5d41384b539e5..60f1eafb06eabc5c5fd5edbcee6d796b218f92e3 100644 --- a/src/bin_dal_node/RPC_server.ml +++ b/src/bin_dal_node/RPC_server.ml @@ -511,6 +511,10 @@ module P2P = struct ?ignore_bootstrap_topics ctxt + let get_reconnection_delays ctxt () () = + let open Lwt_result_syntax in + return @@ Node_context.P2P.Gossipsub.get_reconnection_delays ctxt + let get_scores ctxt () () = let open Lwt_result_syntax in return @@ Node_context.P2P.Gossipsub.get_scores ctxt @@ -615,6 +619,10 @@ let register : Tezos_rpc.Directory.register0 Services.P2P.Gossipsub.get_connections (P2P.Gossipsub.get_connections ~ignore_bootstrap_topics:true ctxt) + |> add_service + Tezos_rpc.Directory.register0 + Services.P2P.Gossipsub.get_reconnection_delays + (P2P.Gossipsub.get_reconnection_delays ctxt) |> add_service Tezos_rpc.Directory.register0 Services.P2P.Gossipsub.get_scores diff --git a/src/bin_dal_node/node_context.ml b/src/bin_dal_node/node_context.ml index 037b6dfa776fb022f939625851bcda699f7b36c7..dec52e007bb6710f446c28598f5bdbf7fac753d1 100644 --- a/src/bin_dal_node/node_context.ml +++ b/src/bin_dal_node/node_context.ml @@ -331,6 +331,9 @@ module P2P = struct state.connections [] + let get_reconnection_delays {gs_worker; _} = + Gossipsub.Worker.reconnection_delays gs_worker + let get_scores {gs_worker; _} = let state = Gossipsub.Worker.state gs_worker in Gossipsub.Worker.GS.Peer.Map.fold diff --git a/src/bin_dal_node/node_context.mli b/src/bin_dal_node/node_context.mli index 628bb67694ce005127bfb93409dd5ba5acd3400c..2a5e0c37a6f1646febcbcdd9af473f349360bf65 100644 --- a/src/bin_dal_node/node_context.mli +++ b/src/bin_dal_node/node_context.mli @@ -289,6 +289,9 @@ module P2P : sig t -> (Types.Peer.t * Types.Gossipsub.connection) list + (** [get_reconnection_delays t] returns the reconnections delays for unreachable points. *) + val get_reconnection_delays : t -> (Types.Point.t * Types.Span.t) list + (** [get_scores t] returns the score of peers with a known score. *) val get_scores : t -> (Types.Peer.t * Types.Score.t) list diff --git a/src/lib_dal_node_services/services.ml b/src/lib_dal_node_services/services.ml index a22f77493e28304e6b921906a000fccafa424797..9af693ed9d363a70fb568e9c2d668d66f8d20355 100644 --- a/src/lib_dal_node_services/services.ml +++ b/src/lib_dal_node_services/services.ml @@ -579,6 +579,27 @@ module P2P = struct (req "connection" Gossipsub.connection_encoding))) (open_root / "connections") + let get_reconnection_delays : + < meth : [`GET] + ; input : unit + ; output : (Point.t * Span.t) list + ; prefix : unit + ; params : unit + ; query : unit > + service = + Tezos_rpc.Service.get_service + ~description: + "For each unreachable point, retrieve the time remaining until the \ + next reconnection attempt." + ~query:Tezos_rpc.Query.empty + ~output: + Data_encoding.( + list + (obj2 + (req "point" Point.encoding) + (req "delay" Span.rpc_encoding))) + (open_root / "reconnection_delays") + let get_scores : < meth : [`GET] ; input : unit diff --git a/src/lib_dal_node_services/services.mli b/src/lib_dal_node_services/services.mli index 1cd224d67ae50b7a9229072416136f0e7914c20e..6f7c89017e97dd7c4dae47c2b345d5c18a4c716b 100644 --- a/src/lib_dal_node_services/services.mli +++ b/src/lib_dal_node_services/services.mli @@ -332,6 +332,15 @@ module P2P : sig ; query : unit > service + val get_reconnection_delays : + < meth : [`GET] + ; input : unit + ; output : (Types.Point.t * Types.Span.t) list + ; prefix : unit + ; params : unit + ; query : unit > + service + val get_scores : < meth : [`GET] ; input : unit diff --git a/src/lib_dal_node_services/types.ml b/src/lib_dal_node_services/types.ml index 4fbcdd922fbfde2bea99615e58ded4f2b604c436..29ece620d8b70f87ebd4adc276dec52818af209b 100644 --- a/src/lib_dal_node_services/types.ml +++ b/src/lib_dal_node_services/types.ml @@ -260,6 +260,13 @@ module Span = struct let pp = Ptime.Span.pp + let rpc_encoding : t Data_encoding.t = + let open Data_encoding in + conv + (fun span -> Format.asprintf "%a" Ptime.Span.pp span) + (fun _ -> Stdlib.failwith "This is only used for encoding") + Data_encoding.string + let encoding : t Data_encoding.t = let open Data_encoding in (* We limit the size of a {!Span.t} value to 2 bytes. It is sufficient for the diff --git a/src/lib_dal_node_services/types.mli b/src/lib_dal_node_services/types.mli index 41001d39c2f5af9b9a8c59bdc88e630fbb81149b..7e7ba203c1239410e0d29b969a1af767323ec5f3 100644 --- a/src/lib_dal_node_services/types.mli +++ b/src/lib_dal_node_services/types.mli @@ -165,6 +165,8 @@ module Span : sig include COMPARABLE with type t := t + val rpc_encoding : t Data_encoding.t + val zero : t val of_int_s : int -> t diff --git a/src/lib_gossipsub/gossipsub_intf.ml b/src/lib_gossipsub/gossipsub_intf.ml index ca9a3cf258152841e1dcbd7f4e641f4f5958978f..b0396e803e87ef2acf575c763a2ec47300671a96 100644 --- a/src/lib_gossipsub/gossipsub_intf.ml +++ b/src/lib_gossipsub/gossipsub_intf.ml @@ -1219,6 +1219,11 @@ module type WORKER = sig to be processed by the worker. *) val input_events_stream : t -> event Stream.t + (** [reconnection_delays t] returns the points that are currently + unreachable with the span before the next attempt to reconnect + to them. *) + val reconnection_delays : t -> (Point.t * GS.Span.t) list + (** [is_subscribed t topic] checks whether [topic] is in the mesh of [t]. *) val is_subscribed : t -> GS.Topic.t -> bool diff --git a/src/lib_gossipsub/gossipsub_worker.ml b/src/lib_gossipsub/gossipsub_worker.ml index cfb52f29ed93bb080ea5d2c7cfe2043b14ee08ff..3ccb3aa7737bd2d06677799c67a4e7ec3e9a5cf0 100644 --- a/src/lib_gossipsub/gossipsub_worker.ml +++ b/src/lib_gossipsub/gossipsub_worker.ml @@ -954,6 +954,19 @@ module Make (C : Gossipsub_intf.WORKER_CONFIGURATION) : let input_events_stream t = t.state.events_stream + let reconnection_delays {state = {unreachable_points; gossip_state; _}; _} = + let heartbeat_span = View.((view gossip_state).limits.heartbeat_interval) in + let View.{heartbeat_ticks; _} = View.(view gossip_state) in + unreachable_points |> Point.Map.to_seq + |> Seq.map (fun (point, next_heartbeat_reconnection_tick) -> + let how_many_ticks_left = + Int64.(sub next_heartbeat_reconnection_tick heartbeat_ticks) + |> Int64.to_int + in + let span = GS.Span.mul heartbeat_span how_many_ticks_left in + (point, span)) + |> List.of_seq + let is_subscribed t topic = GS.Introspection.(has_joined topic (view t.state.gossip_state)) diff --git a/tezt/tests/expected/dal.ml/Alpha- Testing DAL node (dal node list RPCs).out b/tezt/tests/expected/dal.ml/Alpha- Testing DAL node (dal node list RPCs).out index 0b3b3d7c41a573d9e6c2af2c10adff654e45c34a..abedf9de0e57fa8d7deca34513f9322d80404c39 100644 --- a/tezt/tests/expected/dal.ml/Alpha- Testing DAL node (dal node list RPCs).out +++ b/tezt/tests/expected/dal.ml/Alpha- Testing DAL node (dal node list RPCs).out @@ -37,6 +37,9 @@ Available services: connected peers and the remote peers subscribed to that topic. If the 'subscribed' flag is given, then restrict the output to the topics this peer is subscribed to. + - GET /p2p/gossipsub/reconnection_delays + For each unreachable point, retrieve the time remaining until the + next reconnection attempt. - GET /p2p/gossipsub/scores Get the scores of the peers with a known score. - GET /p2p/gossipsub/slot_indexes/peers diff --git a/tezt/tests/expected/dal.ml/Parisc- Testing DAL node (dal node list RPCs).out b/tezt/tests/expected/dal.ml/Parisc- Testing DAL node (dal node list RPCs).out index 0b3b3d7c41a573d9e6c2af2c10adff654e45c34a..abedf9de0e57fa8d7deca34513f9322d80404c39 100644 --- a/tezt/tests/expected/dal.ml/Parisc- Testing DAL node (dal node list RPCs).out +++ b/tezt/tests/expected/dal.ml/Parisc- Testing DAL node (dal node list RPCs).out @@ -37,6 +37,9 @@ Available services: connected peers and the remote peers subscribed to that topic. If the 'subscribed' flag is given, then restrict the output to the topics this peer is subscribed to. + - GET /p2p/gossipsub/reconnection_delays + For each unreachable point, retrieve the time remaining until the + next reconnection attempt. - GET /p2p/gossipsub/scores Get the scores of the peers with a known score. - GET /p2p/gossipsub/slot_indexes/peers diff --git a/tezt/tests/expected/dal.ml/Quebec- Testing DAL node (dal node list RPCs).out b/tezt/tests/expected/dal.ml/Quebec- Testing DAL node (dal node list RPCs).out index 0b3b3d7c41a573d9e6c2af2c10adff654e45c34a..abedf9de0e57fa8d7deca34513f9322d80404c39 100644 --- a/tezt/tests/expected/dal.ml/Quebec- Testing DAL node (dal node list RPCs).out +++ b/tezt/tests/expected/dal.ml/Quebec- Testing DAL node (dal node list RPCs).out @@ -37,6 +37,9 @@ Available services: connected peers and the remote peers subscribed to that topic. If the 'subscribed' flag is given, then restrict the output to the topics this peer is subscribed to. + - GET /p2p/gossipsub/reconnection_delays + For each unreachable point, retrieve the time remaining until the + next reconnection attempt. - GET /p2p/gossipsub/scores Get the scores of the peers with a known score. - GET /p2p/gossipsub/slot_indexes/peers