Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactoring of mina_block.ml and block_sink.ml #16653

Open
wants to merge 4 commits into
base: compatible
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/lib/gossip_net/message.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions src/lib/mina_block/block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<opaque>")
; ("staged_ledger_diff", `String "<opaque>")
; ("delta_transition_chain_proof", `String "<opaque>")
; ( "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:"<None>" ~f:Protocol_version.to_string ) )
]

Expand Down
4 changes: 3 additions & 1 deletion src/lib/mina_block/block.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion src/lib/mina_block/validated_block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 16 additions & 22 deletions src/lib/transition_handler/block_sink.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -128,13 +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", Mina_block.to_yojson @@ Envelope.Incoming.data b_env)
]
| `Header h_env ->
[ ( "header"
, Mina_block.Header.to_yojson @@ Envelope.Incoming.data h_env )
| `Block { Envelope.Incoming.data = block; _ } ->
[ ( "block"
, 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 ;
Expand All @@ -157,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
Expand Down
3 changes: 2 additions & 1 deletion src/lib/transition_handler/catchup_scheduler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ;
Expand Down