From 4d34d8d40189db787256a3dc4415856302b4f08b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Fri, 14 Feb 2025 17:10:54 +0100 Subject: [PATCH 1/6] DAL/Types: A specific encoding for Span used with RPCs --- src/lib_dal_node_services/types.ml | 7 +++++++ src/lib_dal_node_services/types.mli | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/lib_dal_node_services/types.ml b/src/lib_dal_node_services/types.ml index 4fbcdd922fbf..29ece620d8b7 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 41001d39c2f5..7e7ba203c123 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 -- GitLab From d256c3af03ab620b5c955640d9e2b668c97590ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Fri, 14 Feb 2025 16:48:48 +0100 Subject: [PATCH 2/6] DAL/Node: Add a service for reconnections --- src/lib_dal_node_services/services.ml | 21 +++++++++++++++++++++ src/lib_dal_node_services/services.mli | 9 +++++++++ 2 files changed, 30 insertions(+) diff --git a/src/lib_dal_node_services/services.ml b/src/lib_dal_node_services/services.ml index a22f77493e28..9af693ed9d36 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 1cd224d67ae5..6f7c89017e97 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 -- GitLab From af83be78232778d99cf62122616434a9b7149092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Fri, 14 Feb 2025 16:50:08 +0100 Subject: [PATCH 3/6] Gossipsub/Worker: Implement a way to get reconnection delays --- src/lib_gossipsub/gossipsub_intf.ml | 5 +++++ src/lib_gossipsub/gossipsub_worker.ml | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/lib_gossipsub/gossipsub_intf.ml b/src/lib_gossipsub/gossipsub_intf.ml index ca9a3cf25815..b0396e803e87 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 cfb52f29ed93..3ccb3aa7737b 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)) -- GitLab From 8994f205b727bf65cb2cdca81a3583a690557648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Fri, 14 Feb 2025 16:50:23 +0100 Subject: [PATCH 4/6] DAL/Node: Add a wrapper to get reconnection delays --- src/bin_dal_node/node_context.ml | 3 +++ src/bin_dal_node/node_context.mli | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/bin_dal_node/node_context.ml b/src/bin_dal_node/node_context.ml index 037b6dfa776f..dec52e007bb6 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 628bb67694ce..2a5e0c37a6f1 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 -- GitLab From eac1ed2c3c9a09e709a2470c2818b16e46df2975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Fri, 14 Feb 2025 16:50:36 +0100 Subject: [PATCH 5/6] DAL/Node: Register and implement the new `reconnections` RPC --- src/bin_dal_node/RPC_server.ml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bin_dal_node/RPC_server.ml b/src/bin_dal_node/RPC_server.ml index c7452d336591..60f1eafb06ea 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 -- GitLab From 234bb7d09ca3654f8380def42310d7701caead0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Fri, 14 Feb 2025 17:33:28 +0100 Subject: [PATCH 6/6] Tezt/Tests: Update regression tests --- .../dal.ml/Alpha- Testing DAL node (dal node list RPCs).out | 3 +++ .../dal.ml/Parisc- Testing DAL node (dal node list RPCs).out | 3 +++ .../dal.ml/Quebec- Testing DAL node (dal node list RPCs).out | 3 +++ 3 files changed, 9 insertions(+) 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 0b3b3d7c41a5..abedf9de0e57 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 0b3b3d7c41a5..abedf9de0e57 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 0b3b3d7c41a5..abedf9de0e57 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 -- GitLab