Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/compatible' into georgeee/proof-…
Browse files Browse the repository at this point in the history
…cache-tag-19-decouple-mina-block-types
  • Loading branch information
georgeee committed Feb 6, 2025
2 parents 057ad38 + 1b3457d commit dc75457
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 83 deletions.
18 changes: 17 additions & 1 deletion buildkite/scripts/connect/connect-to-network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ for ((i=1;i<=$num_status_retries;i++)); do
done

# Check that the daemon has connected to peers and is still up after 2 mins
sleep $WAIT_AFTER_FINAL_CHECK
sleep "$WAIT_AFTER_FINAL_CHECK"
mina client status
if [ "$(mina advanced get-peers | wc -l)" -gt 0 ]; then
echo "Found some peers"
Expand All @@ -65,3 +65,19 @@ else
exit 1
fi

# Check network id
NETWORK_ID=$(curl 'http://localhost:3085/graphql' \
-H 'accept: application/json' \
-H 'content-type: application/json' \
--data-raw '{"query":"query MyQuery {\n networkID\n}\n","variables":null,"operationName":"MyQuery"}' \
| jq -r .data.networkID)

EXPECTED_NETWORK=mina:$NETWORK_NAME

if [[ "$NETWORK_ID" == "$EXPECTED_NETWORK" ]]; then
echo "Network id correct ($NETWORK_ID)"
else
echo "Network id incorrect (expected: $EXPECTED_NETWORK got: $NETWORK_ID)"
exit 1
fi

2 changes: 1 addition & 1 deletion src/app/heap_usage/values.ml
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ let staged_ledger_diff =
}
|json}
in
Staged_ledger_diff.of_yojson json |> Result.ok_or_failwith
Staged_ledger_diff.Stable.Latest.of_yojson json |> Result.ok_or_failwith

let merkle_path
~(constraint_constants : Genesis_constants.Constraint_constants.t) =
Expand Down
6 changes: 3 additions & 3 deletions src/lib/block_producer/block_producer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ let generate_next_state ~proof_cache_db ~commit_id ~zkapp_cmd_limit
, `String
(Staged_ledger.Staged_ledger_error.to_string e) )
; ( "diff"
, Staged_ledger_diff.With_valid_signatures_and_proofs
.to_yojson diff )
, Staged_ledger_diff.Stable.Latest.to_yojson
@@ Staged_ledger_diff.forget diff )
]
"Error applying the diff $diff: $error"
| Error e ->
Expand Down Expand Up @@ -526,7 +526,7 @@ let handle_block_production_errors ~logger ~rejected_blocks_logger
in
let metadata =
[ ("error", Error_json.error_to_yojson e)
; ("diff", Staged_ledger_diff.to_yojson staged_ledger_diff)
; ("diff", Staged_ledger_diff.Stable.Latest.to_yojson staged_ledger_diff)
]
in
[%log error] ~metadata msg ;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mina_block/internal_transition.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type t = Stable.Latest.t =
; prover_state : Consensus.Data.Prover_state.t
; staged_ledger_diff : Staged_ledger_diff.t
}
[@@deriving sexp, fields, to_yojson]
[@@deriving fields]

let create ~snark_transition ~ledger_proof ~prover_state ~staged_ledger_diff =
{ Stable.Latest.snark_transition
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mina_block/precomputed_block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module T = struct
{ scheduled_time : Block_time.t
; protocol_state : Protocol_state.value
; protocol_state_proof : Proof.t
; staged_ledger_diff : Staged_ledger_diff.t
; staged_ledger_diff : Staged_ledger_diff.Stable.Latest.t
; delta_transition_chain_proof :
Frozen_ledger_hash.t * Frozen_ledger_hash.t list
; protocol_version : Protocol_version.t
Expand Down
11 changes: 7 additions & 4 deletions src/lib/mina_lmdb_storage/block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,13 @@ let%test_module "Block storage tests" =
let id = match id_ with `Ok a -> a | _ -> failwith "unexpected" in
[%log info] "Push message received" ;
[%test_eq: String.t] (Consensus.Body_reference.to_raw_string body_ref) id ;
[%test_eq:
( Mina_block.Body.t
, [ `Invalid_structure of Error.t | `Non_full | `Tx_failed ] )
Result.t] (Ok body) (read_body db body_ref)
let body' =
read_body db body_ref
|> function
| Ok a -> a | Error _ -> failwith "unexpected failure to read_body"
in
if not (Mina_block.Body.Stable.Latest.equal body body') then
failwith "Retrieved body not equal to original body"

let%test_unit "Write many blocks" =
let n = 300 in
Expand Down
14 changes: 3 additions & 11 deletions src/lib/staged_ledger/staged_ledger.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,6 @@ module T = struct
{ commands_rev : User_command.Valid.t Sequence.t
; completed_work : Transaction_snark_work.Checked.t Sequence.t
}
[@@deriving sexp_of]

let add_user_command t uc =
{ t with
Expand Down Expand Up @@ -1354,7 +1353,6 @@ module T = struct
; is_coinbase_receiver_new : bool
; logger : (Logger.t[@sexp.opaque])
}
[@@deriving sexp_of]

let coinbase_ft (cw : Transaction_snark_work.Checked.t) =
let fee = Transaction_snark_work.Checked.fee cw in
Expand Down Expand Up @@ -3772,11 +3770,9 @@ let%test_module "staged ledger tests" =
let work = List.hd_exn (List.drop work_done 1) in
assert_same_fee single work.fee )
| _ ->
failwith
(sprintf
!"Incorrect coinbase in the diff %{sexp: \
Staged_ledger_diff.t}"
diff )
failwith @@ "Incorrect coinbase in the diff "
^ ( Staged_ledger_diff.Stable.Latest.to_yojson diff
|> Yojson.Safe.to_string )
in
(diff, List.tl_exn proofs_available_left) )
in
Expand Down Expand Up @@ -4381,10 +4377,6 @@ let%test_module "staged ledger tests" =
.commands diff )
= 1 ) ;
let f, s = diff.diff in
[%log info] "Diff %s"
( Staged_ledger_diff.With_valid_signatures_and_proofs
.to_yojson diff
|> Yojson.Safe.to_string ) ;
let failed_command =
With_status.
{ data = invalid_command
Expand Down
21 changes: 4 additions & 17 deletions src/lib/staged_ledger_diff/body.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@ end
module Make_str (A : Wire_types.Concrete) = struct
[%%versioned
module Stable = struct
[@@@no_toplevel_latest_type]

module V1 = struct
type t = A.V1.t = { staged_ledger_diff : Diff.Stable.V2.t }
[@@deriving equal, compare, sexp, fields]
[@@deriving equal, fields, sexp]

let to_latest = Fn.id

let to_yojson _ = `String "<opaque>"

module Creatable = struct
let id = "block_body"

type nonrec t = t

let sexp_of_t = sexp_of_t

let t_of_sexp = t_of_sexp

type 'a creator = Diff.Stable.Latest.t -> 'a

let map_creator c ~f staged_ledger_diff = f (c staged_ledger_diff)
Expand All @@ -38,21 +34,12 @@ module Make_str (A : Wire_types.Concrete) = struct
Allocation_functor.Intf.Output.Basic_intf
with type t := t
and type 'a creator := 'a Creatable.creator )

include (
Allocation_functor.Make.Sexp
(Creatable) :
Allocation_functor.Intf.Output.Sexp_intf
with type t := t
and type 'a creator := 'a Creatable.creator )
end
end]

type t = Stable.Latest.t

[%%define_locally
Stable.Latest.
(create, to_yojson, sexp_of_t, t_of_sexp, equal, compare, staged_ledger_diff)]
[%%define_locally Stable.Latest.(create, staged_ledger_diff)]

let to_binio_bigstring b =
let sz = Stable.V1.bin_size_t b in
Expand Down
4 changes: 2 additions & 2 deletions src/lib/staged_ledger_diff/body_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ module type Full = sig
[@@@no_toplevel_latest_type]

module V1 : sig
type t [@@deriving equal, compare, sexp, to_yojson, bin_io]
type t [@@deriving equal, sexp]
end
end]

type t = Stable.Latest.t [@@deriving equal, compare, sexp, to_yojson]
type t = Stable.Latest.t

val create : Diff.t -> t

Expand Down
40 changes: 23 additions & 17 deletions src/lib/staged_ledger_diff/diff.ml
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ module Make_str (A : Wire_types.Concrete) = struct
( Transaction_snark_work.Stable.V2.t
, User_command.Stable.V2.t With_status.Stable.V2.t )
Pre_diff_two.Stable.V2.t
[@@deriving equal, compare, sexp, yojson]
[@@deriving equal, sexp, yojson]

let to_latest = Fn.id
end
end]

type t = Stable.Latest.t [@@deriving equal, compare, sexp, yojson]
type t = Stable.Latest.t
end

module Pre_diff_with_at_most_one_coinbase = struct
Expand All @@ -188,13 +188,13 @@ module Make_str (A : Wire_types.Concrete) = struct
( Transaction_snark_work.Stable.V2.t
, User_command.Stable.V2.t With_status.Stable.V2.t )
Pre_diff_one.Stable.V2.t
[@@deriving equal, compare, sexp, yojson]
[@@deriving equal, sexp, yojson]

let to_latest = Fn.id
end
end]

type t = Stable.Latest.t [@@deriving equal, compare, sexp, yojson]
type t = Stable.Latest.t
end

module Diff = struct
Expand All @@ -206,13 +206,13 @@ module Make_str (A : Wire_types.Concrete) = struct
type t =
Pre_diff_with_at_most_two_coinbase.Stable.V2.t
* Pre_diff_with_at_most_one_coinbase.Stable.V2.t option
[@@deriving equal, compare, sexp, yojson]
[@@deriving equal, sexp, yojson]

let to_latest = Fn.id
end
end]

type t = Stable.Latest.t [@@deriving equal, compare, sexp, yojson]
type t = Stable.Latest.t
end

[%%versioned
Expand All @@ -221,34 +221,30 @@ module Make_str (A : Wire_types.Concrete) = struct

module V2 = struct
type t = A.V2.t = { diff : Diff.Stable.V2.t }
[@@deriving equal, compare, sexp, yojson]
[@@deriving equal, sexp, yojson]

let to_latest = Fn.id
end
end]

type t = Stable.Latest.t = { diff : Diff.t }
[@@deriving equal, compare, sexp, yojson, fields]
type t = Stable.Latest.t = { diff : Diff.t } [@@deriving fields]

module With_valid_signatures_and_proofs = struct
type pre_diff_with_at_most_two_coinbase =
( Transaction_snark_work.Checked.t
, User_command.Valid.t With_status.t )
Pre_diff_two.t
[@@deriving compare, sexp, to_yojson]

type pre_diff_with_at_most_one_coinbase =
( Transaction_snark_work.Checked.t
, User_command.Valid.t With_status.t )
Pre_diff_one.t
[@@deriving compare, sexp, to_yojson]

type diff =
pre_diff_with_at_most_two_coinbase
* pre_diff_with_at_most_one_coinbase option
[@@deriving compare, sexp, to_yojson]

type t = { diff : diff } [@@deriving compare, sexp, to_yojson]
type t = { diff : diff }

let empty_diff : t =
{ diff =
Expand Down Expand Up @@ -297,20 +293,17 @@ module Make_str (A : Wire_types.Concrete) = struct
( Transaction_snark_work.t
, User_command.Valid.t With_status.t )
Pre_diff_two.t
[@@deriving compare, sexp, to_yojson]

type pre_diff_with_at_most_one_coinbase =
( Transaction_snark_work.t
, User_command.Valid.t With_status.t )
Pre_diff_one.t
[@@deriving compare, sexp, to_yojson]

type diff =
pre_diff_with_at_most_two_coinbase
* pre_diff_with_at_most_one_coinbase option
[@@deriving compare, sexp, to_yojson]

type t = { diff : diff } [@@deriving compare, sexp, to_yojson]
type t = { diff : diff }

let coinbase
~(constraint_constants : Genesis_constants.Constraint_constants.t)
Expand Down Expand Up @@ -461,6 +454,19 @@ module Make_str (A : Wire_types.Concrete) = struct
}
, None )
}

let is_empty = function
| { diff =
( { completed_works = []
; commands = []
; coinbase = At_most_two.Zero
; internal_command_statuses = []
}
, None )
} ->
true
| _ ->
false
end

include Wire_types.Make (Make_sig) (Make_str)
Loading

0 comments on commit dc75457

Please sign in to comment.