From b618522c987959ff86e55960fd2555755c59237f Mon Sep 17 00:00:00 2001 From: georgeee Date: Thu, 20 Feb 2025 19:42:45 +0000 Subject: [PATCH 1/3] Add Mina_block.to_logging_yojson --- src/lib/mina_block/block.ml | 10 +++++----- src/lib/mina_block/block.mli | 4 +++- src/lib/mina_block/validated_block.ml | 4 +++- src/lib/transition_handler/block_sink.ml | 4 +++- src/lib/transition_handler/catchup_scheduler.ml | 3 ++- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/lib/mina_block/block.ml b/src/lib/mina_block/block.ml index aad9ed67d74..b2933591653 100644 --- a/src/lib/mina_block/block.ml +++ b/src/lib/mina_block/block.ml @@ -47,21 +47,21 @@ type t = Stable.Latest.t = type with_hash = t State_hash.With_state_hashes.t -let to_yojson t = +let to_logging_yojson header : Yojson.Safe.t = `Assoc [ ( "protocol_state" - , Protocol_state.value_to_yojson (Header.protocol_state t.header) ) + , Protocol_state.value_to_yojson (Header.protocol_state header) ) ; ("protocol_state_proof", `String "") ; ("staged_ledger_diff", `String "") ; ("delta_transition_chain_proof", `String "") ; ( "current_protocol_version" , `String - (Protocol_version.to_string - (Header.current_protocol_version t.header) ) ) + (Protocol_version.to_string (Header.current_protocol_version header)) + ) ; ( "proposed_protocol_version" , `String (Option.value_map - (Header.proposed_protocol_version_opt t.header) + (Header.proposed_protocol_version_opt header) ~default:"" ~f:Protocol_version.to_string ) ) ] diff --git a/src/lib/mina_block/block.mli b/src/lib/mina_block/block.mli index cd52834f253..5b71512dfdb 100644 --- a/src/lib/mina_block/block.mli +++ b/src/lib/mina_block/block.mli @@ -10,7 +10,9 @@ module Stable : sig end end] -type t = Stable.Latest.t [@@deriving to_yojson] +type t = Stable.Latest.t + +val to_logging_yojson : Header.t -> Yojson.Safe.t type with_hash = t State_hash.With_state_hashes.t diff --git a/src/lib/mina_block/validated_block.ml b/src/lib/mina_block/validated_block.ml index 6cc280af77a..68680829a75 100644 --- a/src/lib/mina_block/validated_block.ml +++ b/src/lib/mina_block/validated_block.ml @@ -22,7 +22,9 @@ type t = * State_hash.t Mina_stdlib.Nonempty_list.t let to_yojson (block_with_hashes, _) = - State_hash.With_state_hashes.to_yojson Block.to_yojson block_with_hashes + State_hash.With_state_hashes.to_yojson + (Fn.compose Block.to_logging_yojson Block.header) + block_with_hashes let lift (b, v) = match v with diff --git a/src/lib/transition_handler/block_sink.ml b/src/lib/transition_handler/block_sink.ml index ecad7d1d2d7..298dfd494f2 100644 --- a/src/lib/transition_handler/block_sink.ml +++ b/src/lib/transition_handler/block_sink.ml @@ -129,7 +129,9 @@ let push sink (b_or_h, `Time_received tm, `Valid_cb cb) = let metadata = match b_or_h with | `Block b_env -> - [ ("block", Mina_block.to_yojson @@ Envelope.Incoming.data b_env) + [ ( "block" + , Mina_block.to_logging_yojson @@ Mina_block.header + @@ Envelope.Incoming.data b_env ) ] | `Header h_env -> [ ( "header" diff --git a/src/lib/transition_handler/catchup_scheduler.ml b/src/lib/transition_handler/catchup_scheduler.ml index 4173095250c..baae2d3250b 100644 --- a/src/lib/transition_handler/catchup_scheduler.ml +++ b/src/lib/transition_handler/catchup_scheduler.ml @@ -219,7 +219,8 @@ let make_timeout t transition_with_hash duration = ; ( "duration" , `Int (Block_time.Span.to_ms duration |> Int64.to_int_trunc) ) ; ( "cached_transition" - , With_hash.data transition_with_hash |> Mina_block.to_yojson ) + , With_hash.data transition_with_hash + |> Mina_block.header |> Mina_block.to_logging_yojson ) ] "Timed out waiting for the parent of $cached_transition after \ $duration ms, signalling a catchup job" ; From 20cb6e9b92b4335bf68e7071587f7ac0a1d939cf Mon Sep 17 00:00:00 2001 From: georgeee Date: Thu, 20 Feb 2025 19:44:42 +0000 Subject: [PATCH 2/3] Small refactoring of block_sink.ml --- src/lib/transition_handler/block_sink.ml | 38 ++++++++++-------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/lib/transition_handler/block_sink.ml b/src/lib/transition_handler/block_sink.ml index 298dfd494f2..abcf31f0d13 100644 --- a/src/lib/transition_handler/block_sink.ml +++ b/src/lib/transition_handler/block_sink.ml @@ -67,14 +67,13 @@ let push sink (b_or_h, `Time_received tm, `Valid_cb cb) = in let sender, header, txs_opt = match b_or_h with - | `Block b_env -> - ( Envelope.Incoming.sender b_env - , Mina_block.header (Envelope.Incoming.data b_env) - , Some - ( Envelope.Incoming.data b_env - |> Mina_block.transactions ~constraint_constants ) ) - | `Header h_env -> - (Envelope.Incoming.sender h_env, Envelope.Incoming.data h_env, None) + | `Block { Envelope.Incoming.data = block; sender; _ } -> + let transactions = + Mina_block.transactions ~constraint_constants block + in + (sender, Mina_block.header block, Some transactions) + | `Header { Envelope.Incoming.data = header; sender; _ } -> + (sender, header, None) in let state_hash = (Mina_block.Header.protocol_state header |> Protocol_state.hashes) @@ -128,15 +127,12 @@ let push sink (b_or_h, `Time_received tm, `Valid_cb cb) = ( if log_gossip_heard then let metadata = match b_or_h with - | `Block b_env -> + | `Block { Envelope.Incoming.data = block; _ } -> [ ( "block" - , Mina_block.to_logging_yojson @@ Mina_block.header - @@ Envelope.Incoming.data b_env ) - ] - | `Header h_env -> - [ ( "header" - , Mina_block.Header.to_yojson @@ Envelope.Incoming.data h_env ) + , Mina_block.to_logging_yojson @@ Mina_block.header block ) ] + | `Header { Envelope.Incoming.data = header; _ } -> + [ ("header", Mina_block.Header.to_yojson header) ] in [%str_log info] ~metadata (Block_received { state_hash; sender }) ) ; Mina_net2.Validation_callback.set_message_type cb `Block ; @@ -159,16 +155,12 @@ let push sink (b_or_h, `Time_received tm, `Valid_cb cb) = Writer.write writer (b_or_h, `Time_received tm, `Valid_cb cb) in let exists_well_formedness_errors = - match b_or_h with - | `Header _ -> + match txs_opt with + | None -> + (* It's a header *) (* TODO make sure this check is executed at a later point when body is received *) false - | `Block block_env -> - let transactions = - Mina_block.transactions - (Envelope.Incoming.data block_env) - ~constraint_constants - in + | Some transactions -> List.exists transactions ~f:(fun txn -> match Mina_transaction.Transaction.check_well_formedness From 9d1cca1346180c560a8d037a0e86ad52dcdaffbc Mon Sep 17 00:00:00 2001 From: georgeee Date: Fri, 21 Feb 2025 21:41:19 +0000 Subject: [PATCH 3/3] Remove useless yojson derivations --- src/lib/gossip_net/message.ml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/gossip_net/message.ml b/src/lib/gossip_net/message.ml index 855a0365a3c..2e574c92782 100644 --- a/src/lib/gossip_net/message.ml +++ b/src/lib/gossip_net/message.ml @@ -11,7 +11,6 @@ module Master = struct Snark_pool.Resource_pool.Diff.t Network_pool.With_nonce.t | Transaction_pool_diff of Transaction_pool.Resource_pool.Diff.t Network_pool.With_nonce.t - [@@deriving to_yojson] type snark_pool_diff_msg = Snark_pool.Resource_pool.Diff.t