Skip to content

Commit

Permalink
Decouple Mina_block.{Stable.Latest.t, t}
Browse files Browse the repository at this point in the history
Remove `Stable.Latest.t = t` from interfaces. This is a preparation step
for removing the equality in the implementation as well.
  • Loading branch information
georgeee committed Jan 21, 2025
1 parent 8c5a8c3 commit e43844d
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/app/archive/lib/diff.ml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ module Builder = struct
(Time.diff account_created_time accounts_accessed_time) ) )
] ;
Transition_frontier.Breadcrumb_added
{ block = block_with_hash
{ block = With_hash.map ~f:Mina_block.unwrap block_with_hash
; accounts_accessed
; accounts_created
; tokens_used
Expand Down
1 change: 1 addition & 0 deletions src/app/archive/lib/processor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4708,6 +4708,7 @@ let run pool reader ~genesis_constants ~constraint_constants ~logger
{ block; accounts_accessed; accounts_created; tokens_used; _ } ) -> (
let add_block = Block.add_if_doesn't_exist ~constraint_constants in
let hash = State_hash.With_state_hashes.state_hash in
let block = With_hash.map ~f:Mina_block.generate block in
match%bind
add_block_aux ~logger ~genesis_constants ~pool ~delete_older_than
~hash ~add_block ~accounts_accessed ~accounts_created ~tokens_used
Expand Down
3 changes: 2 additions & 1 deletion src/app/cli/src/init/test_ledger_application.ml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ let test ~privkey_path ~ledger_path ?prev_block_path ~first_partition_slots
let prev_block =
Binable.of_string (module Mina_block.Stable.Latest) prev_block_data
in
Mina_block.header prev_block |> Mina_block.Header.protocol_state
Mina_block.Stable.Latest.header prev_block
|> Mina_block.Header.protocol_state
in
let consensus_constants =
Consensus.Constants.create ~constraint_constants
Expand Down
2 changes: 1 addition & 1 deletion src/app/delegation_verify/delegation_verify.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module Make_verifier (Source : Submission.Data_source) = struct
verify_snark_work ~verify_transaction_snarks ~proof ~message
else return ()
in
let header = Mina_block.header block in
let header = Mina_block.Stable.Latest.header block in
let protocol_state = Mina_block.Header.protocol_state header in
let consensus_state =
Mina_state.Protocol_state.consensus_state protocol_state
Expand Down
4 changes: 2 additions & 2 deletions src/app/delegation_verify/known_blocks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end

module Deferred_block = struct
type t =
{ block : Mina_block.t Deferred.Or_error.t
{ block : Mina_block.Stable.Latest.t Deferred.Or_error.t
; valid : unit Deferred.Or_error.t (* Raises if block is invalid. *)
}

Expand All @@ -26,7 +26,7 @@ module Deferred_block = struct
Deferred.create compute

let verify_block ~verify_blockchain_snarks block =
let header = Mina_block.header block in
let header = Mina_block.Stable.Latest.header block in
let open Mina_block.Header in
verify_blockchain_snarks
[ (protocol_state header, protocol_state_proof header) ]
Expand Down
13 changes: 7 additions & 6 deletions src/app/dump_blocks/encoding.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Core
type t = Json | Binary

type 'a content =
| Block : Mina_block.t content
| Block : Mina_block.Stable.Latest.t content
| Precomputed : Mina_block.Precomputed.t content

let append_newline s = s ^ "\n"
Expand All @@ -13,7 +13,7 @@ let block_of_breadcrumb ?with_parent_statehash breadcrumb =
let block = Frontier_base.Breadcrumb.block breadcrumb in
match with_parent_statehash with
| None ->
block
block |> Mina_block.unwrap
| Some hash ->
let previous_state_hash = Mina_base.State_hash.of_base58_check_exn hash in
let h = header block in
Expand All @@ -28,7 +28,7 @@ let block_of_breadcrumb ?with_parent_statehash breadcrumb =
~current_protocol_version:(Header.current_protocol_version h)
()
in
Mina_block.create ~header ~body:(body block)
Mina_block.create ~header ~body:(body block) |> Mina_block.unwrap

module type S = sig
type t
Expand All @@ -43,8 +43,8 @@ module type S = sig
val of_string : string -> t
end

module Binary_block : S with type t = Mina_block.t = struct
type t = Mina_block.t
module Binary_block : S with type t = Mina_block.Stable.Latest.t = struct
type t = Mina_block.Stable.Latest.t

let name = "binary"

Expand All @@ -71,7 +71,8 @@ let precomputed_of_breadcrumb ?with_parent_statehash breadcrumb =
let block = block_of_breadcrumb ?with_parent_statehash breadcrumb in
let staged_ledger = Transition_frontier.Breadcrumb.staged_ledger breadcrumb in
let scheduled_time =
Mina_block.(Header.protocol_state @@ header block)
Mina_block.Stable.Latest.header block
|> Mina_block.Header.protocol_state
|> Mina_state.Protocol_state.blockchain_state
|> Mina_state.Blockchain_state.timestamp
in
Expand Down
16 changes: 10 additions & 6 deletions src/lib/best_tip_prover/wrap_for_block.ml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
let map ~f
let to_header_data ~to_header
{ Proof_carrying_data.proof = merkle_list, root_unverified
; data = best_tip_unverified
} =
{ Proof_carrying_data.proof = (merkle_list, to_header root_unverified)
; data = to_header best_tip_unverified
}

let map ~f
( { Proof_carrying_data.proof = _, root_unverified
; data = best_tip_unverified
} as pcd ) =
let%map.Async_kernel.Deferred.Or_error ( `Root root_header
, `Best_tip best_tip_header ) =
f
{ Proof_carrying_data.proof =
(merkle_list, Mina_block.header root_unverified)
; data = Mina_block.header best_tip_unverified
}
f (to_header_data ~to_header:Mina_block.header pcd)
in
let root =
Mina_block.Validation.with_body root_header
Expand Down
8 changes: 7 additions & 1 deletion src/lib/bootstrap_controller/bootstrap_controller.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,19 @@ let on_transition ({ context = (module Context); _ } as t) ~sender
$error" ;
Deferred.return `Ignored
| Ok peer_root_with_proof -> (
let pcd =
peer_root_with_proof.data
|> Proof_carrying_data.map ~f:Mina_block.generate
|> Proof_carrying_data.map_proof
~f:(Tuple2.map_snd ~f:Mina_block.generate)
in
match%bind
Best_tip_prover.Wrap_for_block.map
~f:
(Sync_handler.Root.verify
~context:(module Context)
~verifier:t.verifier candidate_consensus_state )
peer_root_with_proof.data
pcd
with
| Ok (`Root root, `Best_tip best_tip) ->
if done_syncing_root root_sync_ledger then return `Ignored
Expand Down
8 changes: 6 additions & 2 deletions src/lib/gossip_net/libp2p.ml
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,10 @@ module Make (Rpc_interface : RPC_INTERFACE) :
~fn:(fun (env, vc) ->
match Envelope.Incoming.data env with
| Message.Latest.T.New_state state ->
let state_cached = Mina_block.generate state in
Sinks.Block_sink.push sink_block
( `Block (Envelope.Incoming.map ~f:(const state) env)
( `Block
(Envelope.Incoming.map ~f:(const state_cached) env)
, `Time_received (Block_time.now config.time_controller)
, `Valid_cb vc )
| Message.Latest.T.Transaction_pool_diff
Expand Down Expand Up @@ -951,7 +953,9 @@ module Make (Rpc_interface : RPC_INTERFACE) :
guard_topic ?origin_topic v1_topic_block pfs.publish_v1_block
(Mina_block.header state)
in
guard_topic ?origin_topic v0_topic pfs.publish_v0 (Message.New_state state)
let state_unwrapped = Mina_block.unwrap state in
guard_topic ?origin_topic v0_topic pfs.publish_v0
(Message.New_state state_unwrapped)

let broadcast_transaction_pool_diff ?origin_topic ?(nonce = 0) t diff =
let pfs = !(t.publish_functions) in
Expand Down
3 changes: 1 addition & 2 deletions src/lib/gossip_net/message.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ open Network_peer
module Master = struct
module T = struct
type msg =
| New_state of Mina_block.t
| New_state of Mina_block.Stable.Latest.t
| Snark_pool_diff of
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
6 changes: 5 additions & 1 deletion src/lib/ledger_catchup/normal_catchup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ let download_transitions ~target_hash ~logger ~trust_system ~network
~hash_data:
(Fn.compose Mina_state.Protocol_state.hashes
(Fn.compose Mina_block.Header.protocol_state
Mina_block.header ) ) )
Mina_block.Stable.Latest.header ) ) )
in
if not @@ verify_against_hashes hashed_transitions hashes then (
let error_msg =
Expand Down Expand Up @@ -820,6 +820,10 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~verifier ~network
else
download_transitions ~logger ~trust_system ~network
~preferred_peer ~hashes_of_missing_transitions ~target_hash
>>| List.map
~f:
(Envelope.Incoming.map
~f:(With_hash.map ~f:Mina_block.generate) )
in
[%log debug]
~metadata:[ ("target_hash", State_hash.to_yojson target_hash) ]
Expand Down
3 changes: 2 additions & 1 deletion src/lib/ledger_catchup/super_catchup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,8 @@ let run_catchup ~context:(module Context : CONTEXT) ~trust_system ~verifier
in
Mina_networking.get_transition_chain
~heartbeat_timeout:(Time_ns.Span.of_sec sec)
~timeout:(Time.Span.of_sec sec) network peer (List.map hs ~f:fst) )
~timeout:(Time.Span.of_sec sec) network peer (List.map hs ~f:fst)
|> Deferred.Or_error.map ~f:(List.map ~f:Mina_block.generate) )
~peers:(fun () -> Mina_networking.peers network)
~knowledge_context:
(Broadcast_pipe.map best_tip_r
Expand Down
20 changes: 15 additions & 5 deletions src/lib/mina_block/block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ open Mina_state

[%%versioned
module Stable = struct
[@@@no_toplevel_latest_type]

module V2 = struct
type t =
{ header : Header.Stable.V2.t
Expand All @@ -18,7 +20,8 @@ module Stable = struct

type nonrec t = t

type 'a creator = header:Header.t -> body:Staged_ledger_diff.Body.t -> 'a
type 'a creator =
header:Header.t -> body:Staged_ledger_diff.Body.Stable.Latest.t -> 'a

let map_creator c ~f ~header ~body = f (c ~header ~body)

Expand All @@ -40,6 +43,10 @@ module Stable = struct
end
end]

type t = Stable.Latest.t =
{ header : Header.t; body : Staged_ledger_diff.Body.t }
[@@deriving fields]

type with_hash = t State_hash.With_state_hashes.t

let to_yojson t =
Expand All @@ -60,8 +67,7 @@ let to_yojson t =
~default:"<None>" ~f:Protocol_version.to_string ) )
]

[%%define_locally
Stable.Latest.(create, header, body)]
let create ~header ~body = { header; body }

let wrap_with_hash block =
With_hash.of_data block
Expand All @@ -75,10 +81,10 @@ let timestamp block =

let transactions ~constraint_constants block =
let consensus_state =
block |> header |> Header.protocol_state |> Protocol_state.consensus_state
Header.protocol_state block.header |> Protocol_state.consensus_state
in
let staged_ledger_diff =
block |> body |> Staged_ledger_diff.Body.staged_ledger_diff
Staged_ledger_diff.Body.staged_ledger_diff block.body
in
let coinbase_receiver =
Consensus.Data.Consensus_state.coinbase_receiver consensus_state
Expand All @@ -98,3 +104,7 @@ let account_ids_accessed ~constraint_constants t =
|> List.concat
|> List.dedup_and_sort
~compare:[%compare: Account_id.t * [ `Accessed | `Not_accessed ]]

let generate = Fn.id

let unwrap = Fn.id
10 changes: 9 additions & 1 deletion src/lib/mina_block/block.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ module Stable : sig

module V2 : sig
type t [@@deriving equal]

val header : t -> Header.Stable.V2.t

val body : t -> Staged_ledger_diff.Body.Stable.V1.t
end
end]

type t = Stable.Latest.t [@@deriving to_yojson]
type t [@@deriving to_yojson]

type with_hash = t State_hash.With_state_hashes.t

Expand Down Expand Up @@ -39,3 +43,7 @@ val account_ids_accessed :
constraint_constants:Genesis_constants.Constraint_constants.t
-> t
-> (Account_id.t * [ `Accessed | `Not_accessed ]) list

val generate : Stable.Latest.t -> t

val unwrap : t -> Stable.Latest.t
2 changes: 1 addition & 1 deletion src/lib/mina_block/validated_block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ let header t = t |> forget |> With_hash.data |> Block.header

let body t = t |> forget |> With_hash.data |> Block.body

let unwrap = Fn.id
let unwrap ((b, v) : t) : Stable.Latest.t = (With_hash.map ~f:Block.unwrap b, v)
20 changes: 12 additions & 8 deletions src/lib/mina_networking/mina_networking.mli
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module Rpcs : sig
module Get_transition_chain : sig
type query = State_hash.t list

type response = Mina_block.t list option
type response = Mina_block.Stable.Latest.t list option
end

module Get_transition_chain_proof : sig
Expand All @@ -86,8 +86,8 @@ module Rpcs : sig
(Consensus.Data.Consensus_state.Value.t, State_hash.t) With_hash.t

type response =
( Mina_block.t
, State_body_hash.t list * Mina_block.t )
( Mina_block.Stable.Latest.t
, State_body_hash.t list * Mina_block.Stable.Latest.t )
Proof_carrying_data.t
option
end
Expand All @@ -103,8 +103,8 @@ module Rpcs : sig
type query = unit

type response =
( Mina_block.t
, State_body_hash.t list * Mina_block.t )
( Mina_block.Stable.Latest.t
, State_body_hash.t list * Mina_block.Stable.Latest.t )
Proof_carrying_data.t
option
end
Expand Down Expand Up @@ -187,7 +187,9 @@ val get_ancestry :
t
-> Peer.Id.t
-> (Consensus.Data.Consensus_state.Value.t, State_hash.t) With_hash.t
-> (Mina_block.t, State_body_hash.t list * Mina_block.t) Proof_carrying_data.t
-> ( Mina_block.Stable.Latest.t
, State_body_hash.t list * Mina_block.Stable.Latest.t )
Proof_carrying_data.t
Envelope.Incoming.t
Deferred.Or_error.t

Expand All @@ -196,7 +198,9 @@ val get_best_tip :
-> ?timeout:Time.Span.t
-> t
-> Network_peer.Peer.t
-> (Mina_block.t, State_body_hash.t list * Mina_block.t) Proof_carrying_data.t
-> ( Mina_block.Stable.Latest.t
, State_body_hash.t list * Mina_block.Stable.Latest.t )
Proof_carrying_data.t
Deferred.Or_error.t

val get_transition_chain_proof :
Expand All @@ -213,7 +217,7 @@ val get_transition_chain :
-> t
-> Network_peer.Peer.t
-> State_hash.t list
-> Mina_block.t list Deferred.Or_error.t
-> Mina_block.Stable.Latest.t list Deferred.Or_error.t

val get_staged_ledger_aux_and_pending_coinbases_at_hash :
t
Expand Down
Loading

0 comments on commit e43844d

Please sign in to comment.