Skip to content

Commit 953ed42

Browse files
authoredFeb 28, 2024··
Merge pull request #15241 from MinaProtocol/joaosreis/node-stats-simplified-develop
2 parents e2f8673 + 4836fc4 commit 953ed42

File tree

4 files changed

+76
-12
lines changed

4 files changed

+76
-12
lines changed
 

‎src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,10 @@ let setup_daemon logger =
540540
and node_error_url =
541541
flag "--node-error-url" ~aliases:[ "node-error-url" ] (optional string)
542542
~doc:"URL of the node error collection service"
543+
and simplified_node_stats =
544+
flag "--simplified-node-stats"
545+
~aliases:[ "simplified-node-stats" ]
546+
no_arg ~doc:"whether to report simplified node stats (default: false)"
543547
and contact_info =
544548
flag "--contact-info" ~aliases:[ "contact-info" ] (optional string)
545549
~doc:
@@ -1415,7 +1419,8 @@ Pass one of -peer, -peer-list-file, -seed, -peer-list-url.|} ;
14151419
~start_filtered_logs ~upload_blocks_to_gcloud
14161420
~block_reward_threshold ~uptime_url ~uptime_submitter_keypair
14171421
~uptime_send_node_commit ~stop_time ~node_status_url
1418-
~graphql_control_port:itn_graphql_port () )
1422+
~graphql_control_port:itn_graphql_port ~simplified_node_stats
1423+
() )
14191424
in
14201425
{ mina
14211426
; client_trustlist

‎src/lib/mina_lib/config.ml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type t =
5656
; upload_blocks_to_gcloud : bool
5757
; block_reward_threshold : Currency.Amount.t option [@default None]
5858
; node_status_url : string option [@default None]
59+
; simplified_node_stats : bool [@default false]
5960
; uptime_url : Uri.t option [@default None]
6061
; uptime_submitter_keypair : Keypair.t option [@default None]
6162
; uptime_send_node_commit : bool [@default false]

‎src/lib/mina_lib/mina_lib.ml

+27-9
Original file line numberDiff line numberDiff line change
@@ -1327,15 +1327,33 @@ let start t =
13271327
let () =
13281328
match t.config.node_status_url with
13291329
| Some node_status_url ->
1330-
Node_status_service.start ~logger:t.config.logger ~node_status_url
1331-
~network:t.components.net
1332-
~transition_frontier:t.components.transition_frontier
1333-
~sync_status:t.sync_status ~chain_id:t.config.chain_id
1334-
~addrs_and_ports:t.config.gossip_net_params.addrs_and_ports
1335-
~start_time:t.config.start_time
1336-
~slot_duration:
1337-
(Block_time.Span.to_time_span
1338-
t.config.precomputed_values.consensus_constants.slot_duration_ms )
1330+
if t.config.simplified_node_stats then
1331+
let block_producer_public_key_base58 =
1332+
Option.map ~f:(fun (_, pk) ->
1333+
Public_key.Compressed.to_base58_check pk )
1334+
@@ Keypair.And_compressed_pk.Set.choose
1335+
t.config.block_production_keypairs
1336+
in
1337+
Node_status_service.start_simplified ~logger:t.config.logger
1338+
~node_status_url ~network:t.components.net
1339+
~chain_id:t.config.chain_id
1340+
~addrs_and_ports:t.config.gossip_net_params.addrs_and_ports
1341+
~slot_duration:
1342+
(Block_time.Span.to_time_span
1343+
t.config.precomputed_values.consensus_constants
1344+
.slot_duration_ms )
1345+
~block_producer_public_key_base58
1346+
else
1347+
Node_status_service.start ~logger:t.config.logger ~node_status_url
1348+
~network:t.components.net
1349+
~transition_frontier:t.components.transition_frontier
1350+
~sync_status:t.sync_status ~chain_id:t.config.chain_id
1351+
~addrs_and_ports:t.config.gossip_net_params.addrs_and_ports
1352+
~start_time:t.config.start_time
1353+
~slot_duration:
1354+
(Block_time.Span.to_time_span
1355+
t.config.precomputed_values.consensus_constants
1356+
.slot_duration_ms )
13391357
| None ->
13401358
()
13411359
in

‎src/lib/node_status_service/node_status_service.ml

+42-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,22 @@ type node_status_data =
8787
}
8888
[@@deriving to_yojson]
8989

90-
let send_node_status_data ~logger ~url node_status_data =
90+
module Simplified = struct
91+
type t =
92+
{ max_observed_block_height : int
93+
; commit_hash : string
94+
; git_branch : string
95+
; chain_id : string
96+
; peer_id : string
97+
; peer_count : int
98+
; timestamp : string
99+
; block_producer_public_key : string option
100+
}
101+
[@@deriving to_yojson]
102+
end
103+
104+
let send_node_status_data (type data) ~logger ~url (node_status_data : data)
105+
(node_status_data_to_yojson : data -> Yojson.Safe.t) =
91106
let node_status_json = node_status_data_to_yojson node_status_data in
92107
let json = `Assoc [ ("data", node_status_json) ] in
93108
let headers =
@@ -398,9 +413,34 @@ let start ~logger ~node_status_url ~transition_frontier ~sync_status ~chain_id
398413
reset_gauges () ;
399414
send_node_status_data ~logger
400415
~url:(Uri.of_string node_status_url)
401-
node_status_data
416+
node_status_data node_status_data_to_yojson
402417
| Error e ->
403418
[%log info]
404419
~metadata:[ ("error", `String (Error.to_string_hum e)) ]
405420
"Failed to get bandwidth info from libp2p" ;
406421
Deferred.unit )
422+
423+
let start_simplified ~logger ~node_status_url ~chain_id ~network
424+
~addrs_and_ports ~slot_duration ~block_producer_public_key_base58 =
425+
[%log info] "Starting simplified node status service using URL $url"
426+
~metadata:[ ("url", `String node_status_url) ] ;
427+
let five_slots = Time.Span.scale slot_duration 5. in
428+
every ~start:(after five_slots) ~continue_on_error:true five_slots
429+
@@ fun () ->
430+
don't_wait_for
431+
@@ let%bind peers = Mina_networking.peers network in
432+
let node_status_data =
433+
{ Simplified.max_observed_block_height =
434+
!Mina_metrics.Transition_frontier.max_blocklength_observed
435+
; commit_hash = Mina_version.commit_id
436+
; git_branch = Mina_version.branch
437+
; chain_id
438+
; peer_id = (Node_addrs_and_ports.to_peer_exn addrs_and_ports).peer_id
439+
; peer_count = List.length peers
440+
; timestamp = Rfc3339_time.get_rfc3339_time ()
441+
; block_producer_public_key = block_producer_public_key_base58
442+
}
443+
in
444+
send_node_status_data ~logger
445+
~url:(Uri.of_string node_status_url)
446+
node_status_data Simplified.to_yojson

0 commit comments

Comments
 (0)
Please sign in to comment.