diff --git a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml index 2e055d80158..562cdff488b 100644 --- a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml +++ b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml @@ -540,6 +540,10 @@ let setup_daemon logger = and node_error_url = flag "--node-error-url" ~aliases:[ "node-error-url" ] (optional string) ~doc:"URL of the node error collection service" + and simplified_node_stats = + flag "--simplified-node-stats" + ~aliases:[ "simplified-node-stats" ] + no_arg ~doc:"whether to report simplified node stats (default: false)" and contact_info = flag "--contact-info" ~aliases:[ "contact-info" ] (optional string) ~doc: @@ -1415,7 +1419,8 @@ Pass one of -peer, -peer-list-file, -seed, -peer-list-url.|} ; ~start_filtered_logs ~upload_blocks_to_gcloud ~block_reward_threshold ~uptime_url ~uptime_submitter_keypair ~uptime_send_node_commit ~stop_time ~node_status_url - ~graphql_control_port:itn_graphql_port () ) + ~graphql_control_port:itn_graphql_port ~simplified_node_stats + () ) in { mina ; client_trustlist diff --git a/src/lib/mina_lib/config.ml b/src/lib/mina_lib/config.ml index 264d1b4eeb0..2512042fe9d 100644 --- a/src/lib/mina_lib/config.ml +++ b/src/lib/mina_lib/config.ml @@ -56,6 +56,7 @@ type t = ; upload_blocks_to_gcloud : bool ; block_reward_threshold : Currency.Amount.t option [@default None] ; node_status_url : string option [@default None] + ; simplified_node_stats : bool [@default false] ; uptime_url : Uri.t option [@default None] ; uptime_submitter_keypair : Keypair.t option [@default None] ; uptime_send_node_commit : bool [@default false] diff --git a/src/lib/mina_lib/mina_lib.ml b/src/lib/mina_lib/mina_lib.ml index 65220ae9892..51120886167 100644 --- a/src/lib/mina_lib/mina_lib.ml +++ b/src/lib/mina_lib/mina_lib.ml @@ -1327,15 +1327,33 @@ let start t = let () = match t.config.node_status_url with | Some node_status_url -> - Node_status_service.start ~logger:t.config.logger ~node_status_url - ~network:t.components.net - ~transition_frontier:t.components.transition_frontier - ~sync_status:t.sync_status ~chain_id:t.config.chain_id - ~addrs_and_ports:t.config.gossip_net_params.addrs_and_ports - ~start_time:t.config.start_time - ~slot_duration: - (Block_time.Span.to_time_span - t.config.precomputed_values.consensus_constants.slot_duration_ms ) + if t.config.simplified_node_stats then + let block_producer_public_key_base58 = + Option.map ~f:(fun (_, pk) -> + Public_key.Compressed.to_base58_check pk ) + @@ Keypair.And_compressed_pk.Set.choose + t.config.block_production_keypairs + in + Node_status_service.start_simplified ~logger:t.config.logger + ~node_status_url ~network:t.components.net + ~chain_id:t.config.chain_id + ~addrs_and_ports:t.config.gossip_net_params.addrs_and_ports + ~slot_duration: + (Block_time.Span.to_time_span + t.config.precomputed_values.consensus_constants + .slot_duration_ms ) + ~block_producer_public_key_base58 + else + Node_status_service.start ~logger:t.config.logger ~node_status_url + ~network:t.components.net + ~transition_frontier:t.components.transition_frontier + ~sync_status:t.sync_status ~chain_id:t.config.chain_id + ~addrs_and_ports:t.config.gossip_net_params.addrs_and_ports + ~start_time:t.config.start_time + ~slot_duration: + (Block_time.Span.to_time_span + t.config.precomputed_values.consensus_constants + .slot_duration_ms ) | None -> () in diff --git a/src/lib/node_status_service/node_status_service.ml b/src/lib/node_status_service/node_status_service.ml index 72e1ecd46c8..666f036a0c8 100644 --- a/src/lib/node_status_service/node_status_service.ml +++ b/src/lib/node_status_service/node_status_service.ml @@ -87,7 +87,22 @@ type node_status_data = } [@@deriving to_yojson] -let send_node_status_data ~logger ~url node_status_data = +module Simplified = struct + type t = + { max_observed_block_height : int + ; commit_hash : string + ; git_branch : string + ; chain_id : string + ; peer_id : string + ; peer_count : int + ; timestamp : string + ; block_producer_public_key : string option + } + [@@deriving to_yojson] +end + +let send_node_status_data (type data) ~logger ~url (node_status_data : data) + (node_status_data_to_yojson : data -> Yojson.Safe.t) = let node_status_json = node_status_data_to_yojson node_status_data in let json = `Assoc [ ("data", node_status_json) ] in let headers = @@ -398,9 +413,34 @@ let start ~logger ~node_status_url ~transition_frontier ~sync_status ~chain_id reset_gauges () ; send_node_status_data ~logger ~url:(Uri.of_string node_status_url) - node_status_data + node_status_data node_status_data_to_yojson | Error e -> [%log info] ~metadata:[ ("error", `String (Error.to_string_hum e)) ] "Failed to get bandwidth info from libp2p" ; Deferred.unit ) + +let start_simplified ~logger ~node_status_url ~chain_id ~network + ~addrs_and_ports ~slot_duration ~block_producer_public_key_base58 = + [%log info] "Starting simplified node status service using URL $url" + ~metadata:[ ("url", `String node_status_url) ] ; + let five_slots = Time.Span.scale slot_duration 5. in + every ~start:(after five_slots) ~continue_on_error:true five_slots + @@ fun () -> + don't_wait_for + @@ let%bind peers = Mina_networking.peers network in + let node_status_data = + { Simplified.max_observed_block_height = + !Mina_metrics.Transition_frontier.max_blocklength_observed + ; commit_hash = Mina_version.commit_id + ; git_branch = Mina_version.branch + ; chain_id + ; peer_id = (Node_addrs_and_ports.to_peer_exn addrs_and_ports).peer_id + ; peer_count = List.length peers + ; timestamp = Rfc3339_time.get_rfc3339_time () + ; block_producer_public_key = block_producer_public_key_base58 + } + in + send_node_status_data ~logger + ~url:(Uri.of_string node_status_url) + node_status_data Simplified.to_yojson