diff --git a/src/app/archive/lib/processor.ml b/src/app/archive/lib/processor.ml index 1cea2428381..922547d5117 100644 --- a/src/app/archive/lib/processor.ml +++ b/src/app/archive/lib/processor.ml @@ -2079,7 +2079,7 @@ module User_command = struct in let memo = ps.memo |> Signed_command_memo.to_base58_check in let hash = - Transaction_hash.hash_command (Zkapp_command ps) + Transaction_hash.hash_wrapped_zkapp_command ps |> Transaction_hash.to_base58_check in Mina_caqti.select_insert_into_cols ~select:("id", Caqti_type.int) diff --git a/src/app/archive/lib/test.ml b/src/app/archive/lib/test.ml index 3c09f79f977..cdc6a2fc25f 100644 --- a/src/app/archive/lib/test.ml +++ b/src/app/archive/lib/test.ml @@ -134,7 +134,9 @@ let%test_module "Archive node unit tests" = @@ fun () -> Async.Quickcheck.async_test ~sexp_of:[%sexp_of: User_command.t] user_command_signed_gen ~f:(fun user_command -> - let transaction_hash = Transaction_hash.hash_command user_command in + let transaction_hash = + Transaction_hash.hash_wrapped_command user_command + in match%map let open Deferred.Result.Let_syntax in let%bind user_command_id = @@ -164,7 +166,9 @@ let%test_module "Archive node unit tests" = @@ fun () -> Async.Quickcheck.async_test ~trials:20 ~sexp_of:[%sexp_of: User_command.t] user_command_zkapp_gen ~f:(fun user_command -> - let transaction_hash = Transaction_hash.hash_command user_command in + let transaction_hash = + Transaction_hash.hash_wrapped_command user_command + in match user_command with | Signed_command _ -> failwith "zkapp_gen failed" 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 729f7579eb8..d020256b8b3 100644 --- a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml +++ b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml @@ -1381,6 +1381,9 @@ let replay_blocks ~itn_features logger = block | Error err -> failwithf "Could not read block: %s" err () ) + | Some "sexp" -> + fun line -> + Sexp.of_string_conv_exn line Mina_block.Precomputed.t_of_sexp | _ -> failwith "Expected one of 'json', 'sexp' for -format flag" in @@ -1625,7 +1628,7 @@ let internal_commands ~itn_features logger = in let spec = [%of_sexp: - ( Transaction_witness.t + ( Transaction_witness.Stable.Latest.t , Ledger_proof.t ) Snark_work_lib.Work.Single.Spec.t] sexp in diff --git a/src/app/cli/src/init/client.ml b/src/app/cli/src/init/client.ml index 39c55a4a02a..be8a4dcb686 100644 --- a/src/app/cli/src/init/client.ml +++ b/src/app/cli/src/init/client.ml @@ -336,12 +336,24 @@ let verify_receipt = ~doc:"TOKEN_ID The token ID for the account" (optional_with_default Token_id.default Cli_lib.Arg_type.token_id) in + let legacy_json_flag = + flag "--legacy" no_arg + ~doc:"Use legacy json format (zkapp command with hashes)" + in let config_files = Cli_lib.Flag.config_files in Command.async ~summary:"Verify a receipt of a sent payment" (Cli_lib.Background_daemon.rpc_init - (Args.zip5 config_files payment_path_flag proof_path_flag address_flag - token_flag ) - ~f:(fun port (config_files, payment_path, proof_path, pk, token_id) -> + (Args.zip6 config_files payment_path_flag proof_path_flag address_flag + token_flag legacy_json_flag ) + ~f:(fun + port + ( config_files + , payment_path + , proof_path + , pk + , token_id + , use_legacy_json ) + -> let%bind compile_config = load_compile_config config_files in let account_id = Account_id.create pk token_id in let dispatch_result = @@ -350,22 +362,40 @@ let verify_receipt = read_json payment_path ~flag:"payment-path" in let%bind proof_json = read_json proof_path ~flag:"proof-path" in + let of_payment_json = + if use_legacy_json then + Fn.compose + (Result.map ~f:User_command.unwrap) + User_command.of_yojson + else User_command.Stable.Latest.of_yojson + in + let of_proof_json = + let unwrap_proof = + Tuple2.map_snd ~f:(List.map ~f:User_command.unwrap) + in + if use_legacy_json then + Fn.compose + (Result.map ~f:unwrap_proof) + [%of_yojson: Receipt.Chain_hash.t * User_command.t list] + else + [%of_yojson: + Receipt.Chain_hash.t * User_command.Stable.Latest.t list] + in let to_deferred_or_error result ~error = Result.map_error result ~f:(fun s -> Error.of_string (sprintf "%s: %s" error s) ) |> Deferred.return in let%bind payment = - User_command.of_yojson payment_json - |> to_deferred_or_error - ~error: - (sprintf "Payment file %s has invalid json format" - payment_path ) + to_deferred_or_error + ~error: + (sprintf "Payment file %s has invalid json format" payment_path) + (of_payment_json payment_json) and proof = - [%of_yojson: Receipt.Chain_hash.t * User_command.t list] proof_json - |> to_deferred_or_error - ~error: - (sprintf "Proof file %s has invalid json format" proof_path) + to_deferred_or_error + ~error: + (sprintf "Proof file %s has invalid json format" proof_path) + (of_proof_json proof_json) in Daemon_rpcs.Client.dispatch ~compile_config Verify_proof.rpc (account_id, payment, proof) @@ -2205,7 +2235,8 @@ let receipt_chain_hash = in let receipt_elt = let _txn_commitment, full_txn_commitment = - Zkapp_command.get_transaction_commitments zkapp_cmd + Zkapp_command.get_transaction_commitments + (Zkapp_command.generate zkapp_cmd) in Receipt.Zkapp_command_elt.Zkapp_command_commitment full_txn_commitment diff --git a/src/app/cli/src/init/itn.ml b/src/app/cli/src/init/itn.ml index 2b689266e19..6b6da5244f3 100644 --- a/src/app/cli/src/init/itn.ml +++ b/src/app/cli/src/init/itn.ml @@ -181,12 +181,13 @@ let create_accounts ~(genesis_constants : Genesis_constants.t) Transaction_snark.For_tests.multiple_transfers ~constraint_constants multispec ) in + (* TODO do not compute hashes and remoive Zkapp_command.unwrap *) let zkapps_batches = List.chunks_of zkapps ~length:zkapps_per_block in Deferred.List.iter zkapps_batches ~f:(fun zkapps_batch -> Format.printf "Processing batch of %d zkApps@." (List.length zkapps_batch) ; List.iteri zkapps_batch ~f:(fun i zkapp -> let txn_hash = - Transaction_hash.hash_command (Zkapp_command zkapp) + Transaction_hash.hash_wrapped_zkapp_command zkapp |> Transaction_hash.to_base58_check in Format.printf " zkApp %d, transaction hash: %s@." i txn_hash ; @@ -220,7 +221,9 @@ let create_accounts ~(genesis_constants : Genesis_constants.t) balance_change_str ) ) ; let%bind res = Daemon_rpcs.Client.dispatch ~compile_config - Daemon_rpcs.Send_zkapp_commands.rpc zkapps_batch port + Daemon_rpcs.Send_zkapp_commands.rpc + (List.map ~f:Zkapp_command.unwrap zkapps_batch) + port in ( match res with | Ok res_inner -> ( diff --git a/src/app/dump_blocks/dump_blocks.ml b/src/app/dump_blocks/dump_blocks.ml index 99285855f68..8ecc364d923 100644 --- a/src/app/dump_blocks/dump_blocks.ml +++ b/src/app/dump_blocks/dump_blocks.ml @@ -20,10 +20,14 @@ let mk_io : type a. a Encoding.content -> Encoding.t io -> a codec io = { io with encoding = ( match (content, io.encoding) with + | Precomputed, Sexp -> + (module Sexp_precomputed) | Precomputed, Json -> (module Json_precomputed) | Precomputed, Binary -> (module Binary_precomputed) + | Block, Sexp -> + (module Sexp_block) | Block, Json -> failwith "Json encoding for full blocks not supported." | Block, Binary -> @@ -36,8 +40,10 @@ let encoded_block = | [ encoding; filename ] -> { encoding = ( match String.lowercase encoding with + | "sexp" -> + Encoding.Sexp | "json" -> - Encoding.Json + Json | "bin" | "binary" -> Binary | _ -> @@ -92,7 +98,10 @@ let f (type a) ?parent (outputs : a codec io list) make_breadcrumb = output_block content output ) ; clean_up_persistent_root ~frontier ) -let default_outputs = [ { encoding = Encoding.Json; filename = "-" } ] +let default_outputs = + [ { encoding = Encoding.Sexp; filename = "-" } + ; { encoding = Encoding.Json; filename = "-" } + ] let command = Command.basic diff --git a/src/app/dump_blocks/encoding.ml b/src/app/dump_blocks/encoding.ml index 7d27f1dccbe..1aabd0a20d4 100644 --- a/src/app/dump_blocks/encoding.ml +++ b/src/app/dump_blocks/encoding.ml @@ -1,6 +1,6 @@ open Core -type t = Json | Binary +type t = Sexp | Json | Binary type 'a content = | Block : Mina_block.Stable.Latest.t content @@ -43,6 +43,19 @@ module type S = sig val of_string : string -> t end +module Sexp_block : S with type t = Mina_block.Stable.Latest.t = struct + type t = Mina_block.Stable.Latest.t + + let name = "sexp" + + let of_breadcrumb = block_of_breadcrumb + + let to_string b = + Mina_block.Stable.Latest.sexp_of_t b |> Sexp.to_string |> append_newline + + let of_string s = Sexp.of_string s |> Mina_block.Stable.Latest.t_of_sexp +end + module Binary_block : S with type t = Mina_block.Stable.Latest.t = struct type t = Mina_block.Stable.Latest.t @@ -80,6 +93,19 @@ let precomputed_of_breadcrumb ?with_parent_statehash breadcrumb = ~scheduled_time (Breadcrumb.block_with_hash breadcrumb) +module Sexp_precomputed : S with type t = Mina_block.Precomputed.t = struct + type t = Mina_block.Precomputed.t + + let name = "sexp" + + let of_breadcrumb = precomputed_of_breadcrumb + + let to_string b = + Mina_block.Precomputed.sexp_of_t b |> Sexp.to_string |> append_newline + + let of_string s = Sexp.of_string s |> Mina_block.Precomputed.t_of_sexp +end + module Json_precomputed : S with type t = Mina_block.Precomputed.t = struct type t = Mina_block.Precomputed.t diff --git a/src/app/test_executive/zkapps.ml b/src/app/test_executive/zkapps.ml index f095a91e871..a6a2b73e824 100644 --- a/src/app/test_executive/zkapps.ml +++ b/src/app/test_executive/zkapps.ml @@ -767,6 +767,40 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct zkapp_command_insufficient_fee "Insufficient fee" ) in let%bind () = wait_for t (Wait_condition.blocks_to_be_produced 1) in + let%bind.Deferred () = + (* Wait for the start of the next slot, attempting to submit all commands + within the same slot. + In particular, this has the goal of reducing flakiness around the + 'insufficient replace fee' test, which becomes an 'invalid nonce' + failure if the first transaction has already been included. + + Note that this *isn't* redundant with the block waiting above, because + the block will be produced part-way through a slot, and will further + take us some time to receive the message about that block production + due to polling. + *) + let next_slot_time = + let genesis_timestamp = + constants.genesis_constants.protocol.genesis_state_timestamp + |> Int64.to_float |> Time.Span.of_ms |> Time.of_span_since_epoch + in + let block_duration_ms = + constants.constraint_constants.block_window_duration_ms + |> Int.to_float + in + let current_slot_span_ms = + Time.(diff (now ()) genesis_timestamp) |> Time.Span.to_ms + in + let target_slot = + block_duration_ms /. current_slot_span_ms |> Float.round_up + in + let target_slot_span_ms = + target_slot *. current_slot_span_ms |> Time.Span.of_ms + in + Time.add genesis_timestamp target_slot_span_ms + in + after Time.(diff (now ()) next_slot_time) + in (* Won't be accepted until the previous transactions are applied *) let%bind () = section_hard "Send a zkApp transaction to update all fields" @@ -775,16 +809,16 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct zkapp_command_update_all ) in let%bind () = - section_hard "Send a zkapp with an invalid proof" + section_hard "Send a zkapp with an insufficient replace fee" (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) - zkapp_command_invalid_proof "Invalid_proof" ) + zkapp_command_insufficient_replace_fee "Insufficient_replace_fee" ) in let%bind () = - section_hard "Send a zkapp with an insufficient replace fee" + section_hard "Send a zkapp with an invalid proof" (send_invalid_zkapp ~logger (Network.Node.get_ingress_uri node) - zkapp_command_insufficient_replace_fee "Insufficient_replace_fee" ) + zkapp_command_invalid_proof "Invalid_proof" ) in let%bind () = section_hard "Send a zkApp transaction with an invalid nonce" diff --git a/src/app/zkapp_test_transaction/lib/commands.ml b/src/app/zkapp_test_transaction/lib/commands.ml index 11670e5602e..80f66f331f6 100644 --- a/src/app/zkapp_test_transaction/lib/commands.ml +++ b/src/app/zkapp_test_transaction/lib/commands.ml @@ -5,7 +5,7 @@ module Ledger = Mina_ledger.Ledger let underToCamel s = String.lowercase s |> Mina_graphql.Reflection.underToCamel -let graphql_zkapp_command (zkapp_command : Zkapp_command.t) = +let graphql_zkapp_command (zkapp_command : Zkapp_command.Stable.Latest.t) = sprintf {| mutation MyMutation { @@ -42,6 +42,26 @@ let get_second_pass_ledger_mask ~ledger ~constraint_constants ~global_slot in second_pass_ledger +let print_witnesses ~constraint_constants ~proof_level witnesses = + let module T = Transaction_snark.Make (struct + let constraint_constants = constraint_constants + + let proof_level = proof_level + end) in + Async.Deferred.List.iter (List.rev witnesses) + ~f:(fun (witness, spec, statement) -> + printf "%s" + (sprintf + !"current witness \ + %{sexp:(Transaction_witness.Zkapp_command_segment_witness.Stable.Latest.t \ + * Transaction_snark.Zkapp_command_segment.Basic.t * \ + Transaction_snark.Statement.With_sok.t) }%!" + ( Transaction_witness.Zkapp_command_segment_witness.unwrap witness + , spec + , statement ) ) ; + Deferred.ignore_m + @@ T.of_zkapp_command_segment_exn ~statement ~witness ~spec ) + let gen_proof ?(zkapp_account = None) (zkapp_command : Zkapp_command.t) ~(genesis_constants : Genesis_constants.t) ~(proof_level : Genesis_constants.Proof_level.t) @@ -56,7 +76,6 @@ let gen_proof ?(zkapp_account = None) (zkapp_command : Zkapp_command.t) (Account.create id Currency.Balance.(of_mina_int_exn 1_000)) |> Or_error.ok_exn in - let open Async.Deferred.Let_syntax in let%bind () = Option.value_map zkapp_account ~default:(Deferred.return ()) ~f:(fun pk -> let `VK vk, `Prover _ = Lazy.force @@ vk_and_prover in @@ -121,30 +140,11 @@ let gen_proof ?(zkapp_account = None) (zkapp_command : Zkapp_command.t) , zkapp_command ) ] in - let module T = Transaction_snark.Make (struct - let constraint_constants = constraint_constants - - let proof_level = proof_level - end) in - let%map _ = - Async.Deferred.List.fold ~init:((), ()) (List.rev witnesses) - ~f:(fun _ ((witness, spec, statement) as w) -> - printf "%s" - (sprintf - !"current witness \ - %{sexp:(Transaction_witness.Zkapp_command_segment_witness.t * \ - Transaction_snark.Zkapp_command_segment.Basic.t * \ - Transaction_snark.Statement.With_sok.t) }%!" - w ) ; - let%map _ = T.of_zkapp_command_segment_exn ~statement ~witness ~spec in - ((), ()) ) - in - () + print_witnesses ~constraint_constants ~proof_level witnesses let generate_zkapp_txn (keypair : Signature_lib.Keypair.t) (ledger : Ledger.t) ~zkapp_kp ~(genesis_constants : Genesis_constants.t) ~proof_level ~constraint_constants = - let open Deferred.Let_syntax in let receiver = Quickcheck.random_value Signature_lib.Public_key.Compressed.gen in @@ -184,7 +184,7 @@ let generate_zkapp_txn (keypair : Signature_lib.Keypair.t) (ledger : Ledger.t) printf "ZkApp transaction yojson: %s\n\n%!" (Zkapp_command.to_yojson zkapp_command |> Yojson.Safe.to_string) ; printf "(ZkApp transaction graphQL input %s\n\n%!" - (graphql_zkapp_command zkapp_command) ; + (graphql_zkapp_command @@ Zkapp_command.unwrap zkapp_command) ; printf "Updated accounts\n" ; let%bind accounts = Ledger.to_list ledger in List.iter accounts ~f:(fun acc -> @@ -224,26 +224,7 @@ let generate_zkapp_txn (keypair : Signature_lib.Keypair.t) (ledger : Ledger.t) , zkapp_command ) ] in - let open Async.Deferred.Let_syntax in - let module T = Transaction_snark.Make (struct - let constraint_constants = constraint_constants - - let proof_level = proof_level - end) in - let%map _ = - Async.Deferred.List.fold ~init:((), ()) (List.rev witnesses) - ~f:(fun _ ((witness, spec, statement) as w) -> - printf "%s" - (sprintf - !"current witness \ - %{sexp:(Transaction_witness.Zkapp_command_segment_witness.t * \ - Transaction_snark.Zkapp_command_segment.Basic.t * \ - Transaction_snark.Statement.With_sok.t) }%!" - w ) ; - let%map _ = T.of_zkapp_command_segment_exn ~statement ~witness ~spec in - ((), ()) ) - in - () + print_witnesses ~constraint_constants ~proof_level witnesses module App_state = struct type t = Snark_params.Tick.Field.t @@ -286,8 +267,10 @@ module Util = struct printf "Zkapp transaction yojson:\n %s\n\n%!" (Zkapp_command.to_yojson zkapp_command |> Yojson.Safe.to_string) ; printf "Zkapp transaction graphQL input %s\n\n%!" - (graphql_zkapp_command zkapp_command) ) - else printf "%s\n%!" (graphql_zkapp_command zkapp_command) + (graphql_zkapp_command @@ Zkapp_command.unwrap zkapp_command) ) + else + printf "%s\n%!" + (graphql_zkapp_command @@ Zkapp_command.unwrap zkapp_command) let memo = Option.value_map ~default:Signed_command_memo.empty ~f:(fun m -> @@ -761,7 +744,7 @@ let%test_module "ZkApps test transaction" = io_field "sendZkapp" ~typ:(non_null string) ~args:Arg.[ arg "input" ~typ:(non_null typ) ] ~doc:"sample query" - ~resolve:(fun _ () (zkapp_command' : Zkapp_command.t) -> + ~resolve:(fun _ () (zkapp_command' : Zkapp_command.Stable.Latest.t) -> let ok_fee_payer = print_diff_yojson ~path:[ "fee_payer" ] (Account_update.Fee_payer.to_yojson zkapp_command.fee_payer) @@ -808,7 +791,7 @@ let%test_module "ZkApps test transaction" = match user_cmd with | Zkapp_command p -> let p = Zkapp_command.Valid.forget p in - let q = graphql_zkapp_command p in + let q = graphql_zkapp_command (Zkapp_command.unwrap p) in Async.Thread_safe.block_on_async_exn (fun () -> match%map hit_server p q with | Ok _res -> diff --git a/src/lib/crypto/kimchi_bindings/stubs/Cargo.toml b/src/lib/crypto/kimchi_bindings/stubs/Cargo.toml index b2db36f6951..0c24b9ac52e 100644 --- a/src/lib/crypto/kimchi_bindings/stubs/Cargo.toml +++ b/src/lib/crypto/kimchi_bindings/stubs/Cargo.toml @@ -13,31 +13,31 @@ crate-type = ["lib", "staticlib"] [dependencies] array-init = "2.0.0" -rmp-serde = "1.1.2" libc = "0.2.62" num-bigint = { version = "0.4.4", features = [ "rand", "serde" ] } +# ocaml-specific +ocaml = { version = "0.22.2", features = ["no-caml-startup"] } +ocaml-gen = "0.1.5" +once_cell = "1.10.0" paste = "1.0.5" rand = "0.8.5" rayon = "1.5.0" +rmp-serde = "1.1.2" serde = "1.0.130" serde_json = "1.0.103" sprs = { version = "0.11.0", features = ["multi_thread"] } -once_cell = "1.10.0" # arkworks -ark-ff = { version = "0.4.2", features = ["parallel", "asm"] } -ark-serialize = "0.4.2" ark-ec = { version = "0.4.2", features = ["parallel"] } +ark-ff = { version = "0.4.2", features = ["parallel", "asm"] } ark-poly = { version = "0.4.2", features = ["parallel"] } +ark-serialize = "0.4.2" # proof-systems -poly-commitment = { path = "../../proof-systems/poly-commitment", features = ["ocaml_types"] } groupmap = { path = "../../proof-systems/groupmap" } +kimchi = { path = "../../proof-systems/kimchi", features = ["ocaml_types"] } mina-curves = { path = "../../proof-systems/curves" } -o1-utils = { path = "../../proof-systems/utils" } mina-poseidon = { path = "../../proof-systems/poseidon" } -kimchi = { path = "../../proof-systems/kimchi", features = ["ocaml_types"] } +o1-utils = { path = "../../proof-systems/utils" } +poly-commitment = { path = "../../proof-systems/poly-commitment", features = ["ocaml_types"] } -# ocaml-specific -ocaml = { version = "0.22.2", features = ["no-caml-startup"] } -ocaml-gen = "0.1.5" diff --git a/src/lib/crypto/kimchi_bindings/stubs/src/caml/caml_pointer.rs b/src/lib/crypto/kimchi_bindings/stubs/src/caml/caml_pointer.rs index 55629e74c40..ac4a1cac9bb 100644 --- a/src/lib/crypto/kimchi_bindings/stubs/src/caml/caml_pointer.rs +++ b/src/lib/crypto/kimchi_bindings/stubs/src/caml/caml_pointer.rs @@ -12,8 +12,8 @@ macro_rules! impl_caml_pointer { } extern "C" fn caml_pointer_compare(_: ocaml::Raw, _: ocaml::Raw) -> i32 { - // Always return equal. We can use this for sanity checks, and anything else using this - // would be broken anyway. + // Always return equal. We can use this for sanity checks, and + // anything else using this would be broken anyway. 0 } } @@ -49,12 +49,14 @@ macro_rules! impl_caml_pointer { unsafe { // Wholely unsafe, Batman! // We would use [`get_mut_unchecked`] here, but it is nightly-only. - // Instead, we get coerce our constant pointer to a mutable pointer, in the knowledge - // that - // * all of our mutations called from OCaml are blocking, so we won't have multiple - // live mutable references live simultaneously, and - // * the underlying pointer is in the correct state to be mutable, since we can call - // [`get_mut_unchecked`] in nightly, or can call [`get_mut`] and unwrap if this is + // Instead, we get coerce our constant pointer to a mutable + // pointer, in the knowledge that + // * all of our mutations called from OCaml are blocking, so + // we won't have multiple live mutable references live + // simultaneously, and + // * the underlying pointer is in the correct state to be + // mutable, since we can call [`get_mut_unchecked`] in + // nightly, or can call [`get_mut`] and unwrap if this is // the only live reference. &mut *(((&*self.0) as *const Self::Target) as *mut Self::Target) } diff --git a/src/lib/crypto/kimchi_bindings/stubs/src/lagrange_basis.rs b/src/lib/crypto/kimchi_bindings/stubs/src/lagrange_basis.rs index a132e142621..e68e246ae30 100644 --- a/src/lib/crypto/kimchi_bindings/stubs/src/lagrange_basis.rs +++ b/src/lib/crypto/kimchi_bindings/stubs/src/lagrange_basis.rs @@ -42,7 +42,6 @@ fn add_lagrange_basis_with_cache>( } if let Some(basis) = cache.load_lagrange_basis_from_cache(srs.g.len(), &domain) { srs.lagrange_bases.get_or_generate(n, || basis); - return; } else { let basis = srs.get_lagrange_basis(domain); cache.cache_lagrange_basis(srs.g.len(), &domain, basis); @@ -81,7 +80,7 @@ mod cache { &self, srs_length: usize, domain: &D, - basis: &Vec>, + basis: &[PolyComm], ); } @@ -100,10 +99,9 @@ mod cache { } } - /* - The FileCache implementation uses a directory as a cache for the Lagrange basis hash map -- - i.e every file corresponds to a Lagrange basis for a given G-basis and domain size. - */ + // The FileCache implementation uses a directory as a cache for the Lagrange + // basis hash map -- i.e every file corresponds to a Lagrange basis for a + // given G-basis and domain size. impl LagrangeCache for FileCache { type CacheKey = PathBuf; @@ -115,7 +113,7 @@ mod cache { self.cache_dir.clone().join(format!( "lagrange_basis_{:}-{:}", srs_length, - domain.size().to_string() + domain.size() )) } @@ -126,14 +124,13 @@ mod cache { ) -> Option>> { let cache_key = self.lagrange_basis_cache_key(srs_length, domain); if Path::exists(&cache_key) { - let f = File::open(cache_key.clone()).expect(&format!( - "Missing lagrange basis cache file {:?}", - cache_key - )); - let basis: Vec> = rmp_serde::decode::from_read(f).expect(&format!( - "Error decoding lagrange cache file {:?}", - cache_key - )); + let f = File::open(cache_key.clone()).unwrap_or_else(|_| { + panic!("Missing lagrange basis cache file {:?}", cache_key) + }); + let basis: Vec> = + rmp_serde::decode::from_read(f).unwrap_or_else(|_| { + panic!("Error decoding lagrange cache file {:?}", cache_key) + }); Some(basis) } else { None @@ -144,26 +141,22 @@ mod cache { &self, srs_length: usize, domain: &D, - basis: &Vec>, + basis: &[PolyComm], ) { let cache_key = self.lagrange_basis_cache_key(srs_length, domain); - if Path::exists(&cache_key) { - return; - } else { - let mut f = File::create(cache_key.clone()).expect(&format!( - "Error creating lagrabnge basis cache file {:?}", - cache_key - )); - rmp_serde::encode::write(&mut f, basis).expect(&format!( - "Error encoding lagrange basis to file {:?}", - cache_key - )); + if !Path::exists(&cache_key) { + let mut f = File::create(cache_key.clone()).unwrap_or_else(|_| { + panic!("Error creating lagrabnge basis cache file {:?}", cache_key) + }); + rmp_serde::encode::write(&mut f, basis).unwrap_or_else(|_| { + panic!("Error encoding lagrange basis to file {:?}", cache_key) + }); } } } - // The following two caches are all that we need for mina tests. These will not be initialized unless they are - // explicitly called. + // The following two caches are all that we need for mina tests. These will + // not be initialized unless they are explicitly called. static VESTA_FILE_CACHE: Lazy> = Lazy::new(|| { let cache_base_dir: String = env::var("LAGRANGE_CACHE_DIR").expect("LAGRANGE_CACHE_DIR missing in env"); @@ -175,7 +168,7 @@ mod cache { }); pub fn get_vesta_file_cache() -> &'static FileCache { - &*VESTA_FILE_CACHE + &VESTA_FILE_CACHE } static PALLAS_FILE_CACHE: Lazy> = Lazy::new(|| { @@ -189,6 +182,6 @@ mod cache { }); pub fn get_pallas_file_cache() -> &'static FileCache { - &*PALLAS_FILE_CACHE + &PALLAS_FILE_CACHE } } diff --git a/src/lib/crypto/kimchi_bindings/stubs/src/linearization.rs b/src/lib/crypto/kimchi_bindings/stubs/src/linearization.rs index 4ca294fd6cf..5e3dc5a5543 100644 --- a/src/lib/crypto/kimchi_bindings/stubs/src/linearization.rs +++ b/src/lib/crypto/kimchi_bindings/stubs/src/linearization.rs @@ -44,8 +44,8 @@ pub fn linearization_strings( mut index_terms, } = linearization.linearize(evaluated_cols).unwrap(); - // HashMap deliberately uses an unstable order; here we sort to ensure that the output is - // consistent when printing. + // HashMap deliberately uses an unstable order; here we sort to ensure that + // the output is consistent when printing. index_terms.sort_by(|(x, _), (y, _)| x.cmp(y)); let constant = constant_term.ocaml_str(); diff --git a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fp_plonk_proof.rs b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fp_plonk_proof.rs index 23816ccf39c..2af8e66431d 100644 --- a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fp_plonk_proof.rs +++ b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fp_plonk_proof.rs @@ -662,7 +662,8 @@ pub fn caml_pasta_fp_plonk_proof_example_with_ffadd( for _ in 0..4 { CircuitGate::extend_multi_range_check(&mut gates, &mut curr_row); } - // Connect the witnesses of the addition to the corresponding range checks + // Connect the witnesses of the addition to the corresponding range + // checks gates.connect_ffadd_range_checks(1, Some(4), Some(8), 12); // Connect the bound check range checks gates.connect_ffadd_range_checks(2, None, None, 16); @@ -701,7 +702,8 @@ pub fn caml_pasta_fp_plonk_proof_example_with_ffadd( witness }; - // not sure if theres a smarter way instead of the double unwrap, but should be fine in the test + // not sure if theres a smarter way instead of the double unwrap, but should + // be fine in the test let cs = ConstraintSystem::::create(gates) .public(num_public_inputs) .build() @@ -762,7 +764,8 @@ pub fn caml_pasta_fp_plonk_proof_example_with_xor( None, )); } - // 1 XOR of 128 bits. This will create 8 Xor16 gates and a Generic final gate with all zeros. + // 1 XOR of 128 bits. This will create 8 Xor16 gates and a Generic final + // gate with all zeros. CircuitGate::::extend_xor_gadget(&mut gates, 128); // connect public inputs to the inputs of the XOR gates.connect_cell_pair((0, 0), (2, 0)); @@ -789,7 +792,8 @@ pub fn caml_pasta_fp_plonk_proof_example_with_xor( cols }; - // not sure if theres a smarter way instead of the double unwrap, but should be fine in the test + // not sure if theres a smarter way instead of the double unwrap, but should + // be fine in the test let cs = ConstraintSystem::::create(gates) .public(num_public_inputs) .build() @@ -882,7 +886,8 @@ pub fn caml_pasta_fp_plonk_proof_example_with_rot( cols }; - // not sure if theres a smarter way instead of the double unwrap, but should be fine in the test + // not sure if theres a smarter way instead of the double unwrap, but should + // be fine in the test let cs = ConstraintSystem::::create(gates) .public(num_public_inputs) .build() diff --git a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_proof.rs b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_proof.rs index 14be39c2269..3323f137d4a 100644 --- a/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_proof.rs +++ b/src/lib/crypto/kimchi_bindings/stubs/src/pasta_fq_plonk_proof.rs @@ -78,12 +78,17 @@ pub fn caml_pasta_fq_plonk_proof_create( // public input let public_input = witness[0][0..index.cs.public].to_vec(); - // NB: This method is designed only to be used by tests. However, since creating a new reference will cause `drop` to be called on it once we are done with it. Since `drop` calls `caml_shutdown` internally, we *really, really* do not want to do this, but we have no other way to get at the active runtime. - // TODO: There's actually a way to get a handle to the runtime as a function argument. Switch - // to doing this instead. + // NB: This method is designed only to be used by tests. However, since + // creating a new reference will cause `drop` to be called on it once we are + // done with it. Since `drop` calls `caml_shutdown` internally, we *really, + // really* do not want to do this, but we have no other way to get at the + // active runtime. + // TODO: There's actually a way to get a handle to the runtime as a function + // argument. Switch to doing this instead. let runtime = unsafe { ocaml::Runtime::recover_handle() }; - // Release the runtime lock so that other threads can run using it while we generate the proof. + // Release the runtime lock so that other threads can run using it while we + // generate the proof. runtime.releasing_runtime(|| { let group_map = GroupMap::::setup(); let proof = ProverProof::create_recursive::< diff --git a/src/lib/crypto/kimchi_bindings/stubs/src/projective.rs b/src/lib/crypto/kimchi_bindings/stubs/src/projective.rs index 2eac668905a..b4128250d66 100644 --- a/src/lib/crypto/kimchi_bindings/stubs/src/projective.rs +++ b/src/lib/crypto/kimchi_bindings/stubs/src/projective.rs @@ -68,7 +68,8 @@ macro_rules! impl_projective { #[ocaml_gen::func] #[ocaml::func] pub fn [](i: ocaml::Int) -> $GroupProjective { - // We only care about entropy here, so we force a conversion i32 -> u32. + // We only care about entropy here, so we force a conversion i32 + // -> u32. let i: u64 = (i as u32).into(); let mut rng: StdRng = rand::SeedableRng::seed_from_u64(i); let proj: $Projective = UniformRand::rand(&mut rng); diff --git a/src/lib/crypto/kimchi_bindings/wasm/Cargo.toml b/src/lib/crypto/kimchi_bindings/wasm/Cargo.toml index 438b73d0e29..c91df7756c5 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/Cargo.toml +++ b/src/lib/crypto/kimchi_bindings/wasm/Cargo.toml @@ -14,9 +14,30 @@ crate-type = ["cdylib"] ################################# Dependencies ################################ [dependencies] +array-init = "2.0.0" +base64 = "0.13.0" +console_error_panic_hook = { version = "0.1.6" } +getrandom = { version = "0.2", features = ["js"] } +js-sys = "0.3" +libc = "0.2.62" +num-bigint = { version = "0.4.0" } +once_cell = "1.10.0" +paste = "1.0.5" +# Version for proc-macro2 needs to be 1.0.60+ to be compatible with newer rust versions +# https://github.com/rust-lang/rust/issues/113152 +proc-macro2 = { version = "=1.0.66", features = ["default", "proc-macro"] } +quote = "1.0.31" +rand = { version = "0.8.0" } +rayon = { version = "1" } +rmp-serde = "1.0.0" +sprs = { version = "0.11.0" } +spmc = { version = "0.3.0" } +serde = "1.0.171" +serde_json = "1.0.103" +serde_with = ">=2.1.0" +serde-wasm-bindgen = ">=0.4" # Strictly enforcing 0.2.87 wasm-bindgen = { version = "=0.2.87" } -console_error_panic_hook = { version = "0.1.6" } web-sys = { version = "0.3.35", features = [ "Window", "Document", @@ -26,42 +47,19 @@ web-sys = { version = "0.3.35", features = [ "Element", ] } -once_cell = "1.10.0" -libc = "0.2.62" - # arkworks -ark-ff = { version = "0.4.2", features = ["parallel", "asm"] } -ark-serialize = "0.4.2" ark-ec = { version = "0.4.2", features = ["parallel"] } +ark-ff = { version = "0.4.2", features = ["parallel", "asm"] } ark-poly = { version = "0.4.2", features = ["parallel"] } +ark-serialize = "0.4.2" # proof-systems -poly-commitment = { path = "../../proof-systems/poly-commitment" } groupmap = { path = "../../proof-systems/groupmap" } +kimchi = { path = "../../proof-systems/kimchi", features = ["wasm_types"] } mina-curves = { path = "../../proof-systems/curves" } -o1-utils = { path = "../../proof-systems/utils" } mina-poseidon = { path = "../../proof-systems/poseidon" } -kimchi = { path = "../../proof-systems/kimchi", features = ["wasm_types"] } - -array-init = "2.0.0" -base64 = "0.13.0" -getrandom = { version = "0.2", features = ["js"] } -num-bigint = { version = "0.4.0" } -paste = "1.0.5" -rand = { version = "0.8.0" } -rayon = { version = "1" } -rmp-serde = "1.0.0" -sprs = { version = "0.11.0" } -spmc = { version = "0.3.0" } -serde = "1.0.171" -serde_json = "1.0.103" -serde_with = ">=2.1.0" -serde-wasm-bindgen = ">=0.4" -js-sys = "0.3" -# Version for proc-macro2 needs to be 1.0.60+ to be compatible with newer rust versions -# https://github.com/rust-lang/rust/issues/113152 -proc-macro2 = { version = "=1.0.66", features = ["default", "proc-macro"] } -quote = "1.0.31" +o1-utils = { path = "../../proof-systems/utils" } +poly-commitment = { path = "../../proof-systems/poly-commitment" } [dev-dependencies] wasm-bindgen-test = ">=0.3.0" diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/arkworks/bigint_256.rs b/src/lib/crypto/kimchi_bindings/wasm/src/arkworks/bigint_256.rs index 3c97b9e7170..9fd2e7aa2d0 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/arkworks/bigint_256.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/arkworks/bigint_256.rs @@ -38,9 +38,7 @@ impl IntoWasmAbi for WasmBigInteger256 { type Abi = as FromWasmAbi>::Abi; fn into_abi(self) -> Self::Abi { let mut bytes: Vec = vec![]; - (&mut bytes) - .write_all(self.0.to_bytes_le().as_slice()) - .unwrap(); + bytes.write_all(self.0.to_bytes_le().as_slice()).unwrap(); bytes.into_abi() } } diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fp_plonk_index.rs b/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fp_plonk_index.rs index 9cbe1e15513..94bcaeb445a 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fp_plonk_index.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fp_plonk_index.rs @@ -44,7 +44,7 @@ pub struct WasmPastaFpLookupTable { impl From for LookupTable { fn from(wasm_lt: WasmPastaFpLookupTable) -> LookupTable { LookupTable { - id: wasm_lt.id.into(), + id: wasm_lt.id, data: wasm_lt.data.0, } } diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fq_plonk_index.rs b/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fq_plonk_index.rs index ec8640781c6..79b40801be5 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fq_plonk_index.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fq_plonk_index.rs @@ -41,7 +41,7 @@ pub struct WasmPastaFqLookupTable { impl From for LookupTable { fn from(wasm_lt: WasmPastaFqLookupTable) -> LookupTable { LookupTable { - id: wasm_lt.id.into(), + id: wasm_lt.id, data: wasm_lt.data.0, } } diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/plonk_verifier_index.rs b/src/lib/crypto/kimchi_bindings/wasm/src/plonk_verifier_index.rs index def0114de61..bdeaca366c5 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/plonk_verifier_index.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/plonk_verifier_index.rs @@ -603,7 +603,7 @@ macro_rules! impl_verification_key { evals: evals.clone(), shifts: shifts.clone(), lookup_index: lookup_index.clone(), - zk_rows: zk_rows, + zk_rows, } } @@ -737,7 +737,7 @@ macro_rules! impl_verification_key { xor, lookup, range_check: range_check0 || range_check1 || rot, - foreign_field_mul: foreign_field_mul, + foreign_field_mul, }; FeatureFlags { diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/poseidon.rs b/src/lib/crypto/kimchi_bindings/wasm/src/poseidon.rs index cf1564460f5..378505665a6 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/poseidon.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/poseidon.rs @@ -15,7 +15,7 @@ pub fn caml_pasta_fp_poseidon_block_cipher( ) -> WasmFlatVector { let mut state_vec: Vec = state.into_iter().map(Into::into).collect(); poseidon_block_cipher::( - &mina_poseidon::pasta::fp_kimchi::static_params(), + mina_poseidon::pasta::fp_kimchi::static_params(), &mut state_vec, ); state_vec @@ -33,7 +33,7 @@ pub fn caml_pasta_fq_poseidon_block_cipher( ) -> WasmFlatVector { let mut state_vec: Vec = state.into_iter().map(Into::into).collect(); poseidon_block_cipher::( - &mina_poseidon::pasta::fq_kimchi::static_params(), + mina_poseidon::pasta::fq_kimchi::static_params(), &mut state_vec, ); state_vec diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/srs.rs b/src/lib/crypto/kimchi_bindings/wasm/src/srs.rs index 2b33c56d59f..81ba96d0ad3 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/srs.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/srs.rs @@ -226,8 +226,8 @@ pub mod fp { #[wasm_bindgen] pub fn caml_fp_srs_get(srs: &WasmFpSrs) -> WasmVector { // return a vector which consists of h, then all the gs - let mut h_and_gs: Vec = vec![srs.0.h.clone().into()]; - h_and_gs.extend(srs.0.g.iter().map(|x: &G| WasmG::from(x.clone()))); + let mut h_and_gs: Vec = vec![srs.0.h.into()]; + h_and_gs.extend(srs.0.g.iter().map(|x: &G| WasmG::from(*x))); h_and_gs.into() } @@ -285,7 +285,7 @@ pub mod fp { EvaluationDomain::::new(domain_size as usize).expect("invalid domain size"); srs.get_lagrange_basis(domain) }); - basis.into_iter().map(Into::into).collect() + basis.iter().map(Into::into).collect() } } @@ -306,8 +306,8 @@ pub mod fq { #[wasm_bindgen] pub fn caml_fq_srs_get(srs: &WasmFqSrs) -> WasmVector { // return a vector which consists of h, then all the gs - let mut h_and_gs: Vec = vec![srs.0.h.clone().into()]; - h_and_gs.extend(srs.0.g.iter().map(|x: &G| WasmG::from(x.clone()))); + let mut h_and_gs: Vec = vec![srs.0.h.into()]; + h_and_gs.extend(srs.0.g.iter().map(|x: &G| WasmG::from(*x))); h_and_gs.into() } @@ -365,6 +365,6 @@ pub mod fq { EvaluationDomain::::new(domain_size as usize).expect("invalid domain size"); srs.get_lagrange_basis(domain) }); - basis.into_iter().map(Into::into).collect() + basis.iter().map(Into::into).collect() } } diff --git a/src/lib/filtered_external_transition/filtered_external_transition.ml b/src/lib/filtered_external_transition/filtered_external_transition.ml index f530cead99b..5f5038926f4 100644 --- a/src/lib/filtered_external_transition/filtered_external_transition.ml +++ b/src/lib/filtered_external_transition/filtered_external_transition.ml @@ -18,6 +18,8 @@ end module Transactions = struct [%%versioned module Stable = struct + [@@@no_toplevel_latest_type] + module V2 = struct type t = { commands : @@ -55,6 +57,8 @@ end [%%versioned module Stable = struct + [@@@no_toplevel_latest_type] + module V2 = struct type t = { creator : Public_key.Compressed.Stable.V1.t @@ -69,6 +73,15 @@ module Stable = struct end end] +type t = Stable.Latest.t = + { creator : Public_key.Compressed.t + ; winner : Public_key.Compressed.t + ; protocol_state : Protocol_state.t + ; transactions : Transactions.Stable.Latest.t + ; snark_jobs : Transaction_snark_work.Info.t list + ; proof : Proof.t + } + let participants { transactions = { commands; fee_transfers; _ }; creator; winner; _ } = let open Account_id.Set in @@ -102,7 +115,8 @@ let participant_pks in add (add (union user_command_set fee_transfer_participants) creator) winner -let commands { transactions = { Transactions.commands; _ }; _ } = commands +let commands { transactions = { Transactions.Stable.Latest.commands; _ }; _ } = + commands let validate_transactions block = let consensus_state = @@ -143,13 +157,13 @@ let of_transition block tracked_participants let transactions = List.fold calculated_transactions ~init: - { Transactions.commands = [] + { Transactions.Stable.Latest.commands = [] ; fee_transfers = [] ; coinbase = Currency.Amount.zero ; coinbase_receiver = None } ~f:(fun acc_transactions -> function | { data = Command command; status } -> ( - let command = (command :> User_command.t) in + let command = User_command.unwrap command in let should_include_transaction command participants = List.exists (User_command.accounts_referenced command) ~f:(fun account_id -> diff --git a/src/lib/graphql_lib/transaction/graphql_scalars.ml b/src/lib/graphql_lib/transaction/graphql_scalars.ml index c4ac1536fd5..e18bc672235 100644 --- a/src/lib/graphql_lib/transaction/graphql_scalars.ml +++ b/src/lib/graphql_lib/transaction/graphql_scalars.ml @@ -49,7 +49,9 @@ let%test_module "Roundtrip tests" = let%test_module "TransactionId" = ( module struct module TransactionId_gen = struct - include Mina_transaction.Transaction_id.User_command + include Mina_base.User_command.Stable.Latest + + let gen = Mina_base.User_command.gen end include Make_test (TransactionId) (TransactionId_gen) diff --git a/src/lib/integration_test_lib/graphql_requests.ml b/src/lib/integration_test_lib/graphql_requests.ml index adde8f2066c..33cea272508 100644 --- a/src/lib/integration_test_lib/graphql_requests.ml +++ b/src/lib/integration_test_lib/graphql_requests.ml @@ -748,7 +748,8 @@ let send_zkapp_batch ~logger node_uri let open Deferred.Or_error.Let_syntax in let zkapp_commands_json = List.map zkapp_commands ~f:(fun zkapp_command -> - Mina_base.Zkapp_command.to_json zkapp_command |> Yojson.Safe.to_basic ) + Zkapp_command.unwrap zkapp_command + |> Mina_base.Zkapp_command.to_json |> Yojson.Safe.to_basic ) |> Array.of_list in let send_zkapp_graphql () = diff --git a/src/lib/integration_test_lib/wait_condition.ml b/src/lib/integration_test_lib/wait_condition.ml index 492f09f0d1f..500e202df69 100644 --- a/src/lib/integration_test_lib/wait_condition.ml +++ b/src/lib/integration_test_lib/wait_condition.ml @@ -280,9 +280,10 @@ struct } let zkapp_to_be_included_in_frontier ~has_failures ~zkapp_command = + (* TODO: do not use unwrap, instead avoid computing hashes on the level above *) + let zkapp_command = Zkapp_command.unwrap zkapp_command in let txn_hash = - Mina_transaction.Transaction_hash.hash_command - (Zkapp_command zkapp_command) + Mina_transaction.Transaction_hash.hash_zkapp_command zkapp_command in let check () _node (breadcrumb_added : Event_type.Breadcrumb_added.t) = let zkapp_opt = @@ -298,12 +299,15 @@ struct ~metadata: [ ("state_hash", State_hash.to_yojson breadcrumb_added.state_hash) ; ("txn_hash", Mina_transaction.Transaction_hash.to_yojson txn_hash) - ; ("txn", Zkapp_command.to_yojson zkapp_command) + ; ("txn", Zkapp_command.Stable.Latest.to_yojson zkapp_command) ] ; [%log' debug (Logger.create ())] "wait_condition check, zkapp_to_be_included_in_frontier, \ zkapp_command: $zkapp_command " - ~metadata:[ ("zkapp_command", Zkapp_command.to_yojson zkapp_command) ] ; + ~metadata: + [ ( "zkapp_command" + , Zkapp_command.Stable.Latest.to_yojson zkapp_command ) + ] ; [%log' debug (Logger.create ())] "wait_condition check, zkapp_to_be_included_in_frontier, user_commands \ from breadcrumb: $tx_hashes state_hash: $state_hash" diff --git a/src/lib/mina_base/test/fee_related_test.ml b/src/lib/mina_base/test/fee_related_test.ml index cd3ccc132d5..e850effde45 100644 --- a/src/lib/mina_base/test/fee_related_test.ml +++ b/src/lib/mina_base/test/fee_related_test.ml @@ -12,19 +12,18 @@ let feepayer_body_generator = Zkapp_command.gen let test_fee () = Quickcheck.test ~trials:50 feepayer_body_generator ~f:(fun x -> - [%test_eq: Currency.Fee.t] x.fee_payer.body.fee - Zkapp_command.(fee @@ of_wire x) ) + [%test_eq: Currency.Fee.t] x.fee_payer.body.fee @@ Zkapp_command.fee x ) let fee_payer_account_update () = Quickcheck.test ~trials:50 feepayer_body_generator ~f:(fun x -> [%test_eq: Account_update.Fee_payer.t] x.fee_payer - Zkapp_command.(fee_payer_account_update @@ of_wire x) ) + @@ Zkapp_command.fee_payer_account_update x ) let fee_payer_pk () = Quickcheck.test ~trials:50 feepayer_body_generator ~f:(fun x -> [%test_eq: Signature_lib.Public_key.Compressed.t] x.fee_payer.body.public_key - Zkapp_command.(fee_payer_pk @@ of_wire x) ) + @@ Zkapp_command.fee_payer_pk x ) let fee_excess () = Quickcheck.test ~trials:50 feepayer_body_generator ~f:(fun x -> @@ -34,4 +33,4 @@ let fee_excess () = ; fee_token_r = Token_id.default ; fee_excess_r = Currency.Fee.Signed.zero } - Zkapp_command.(fee_excess @@ of_wire x) ) + @@ Zkapp_command.fee_excess x ) diff --git a/src/lib/mina_base/test/helpers/zkapp_cmd_builder.ml b/src/lib/mina_base/test/helpers/zkapp_cmd_builder.ml index 9937f0c1829..ac5ee0ec036 100644 --- a/src/lib/mina_base/test/helpers/zkapp_cmd_builder.ml +++ b/src/lib/mina_base/test/helpers/zkapp_cmd_builder.ml @@ -237,11 +237,10 @@ let build_zkapp_cmd ?valid_until ~fee transactions : let open State.Let_syntax in let%bind body = fee_payer_body ?valid_until fee in let%map updates = State.concat_map_m ~f:mk_updates transactions in - Zkapp_command. - { fee_payer = { body; authorization = Signature.dummy } - ; account_updates = updates - ; memo = Signed_command_memo.dummy - } + { Zkapp_command.Poly.fee_payer = { body; authorization = Signature.dummy } + ; account_updates = updates + ; memo = Signed_command_memo.dummy + } let zkapp_cmd ?valid_until ~noncemap ~fee transactions = Monad_lib.State.eval_state diff --git a/src/lib/mina_base/test/zkapp_command_test.ml b/src/lib/mina_base/test/zkapp_command_test.ml index 2deb78a2c70..824460b56e0 100644 --- a/src/lib/mina_base/test/zkapp_command_test.ml +++ b/src/lib/mina_base/test/zkapp_command_test.ml @@ -98,12 +98,12 @@ let account_update_or_stack_of_zkapp_command_list () = zkapp_command_list_4 let wire_embedded_in_t () = - let module Wire = Stable.Latest.Wire in + let module Wire = Stable.Latest in Quickcheck.test ~trials:10 ~shrinker:Wire.shrinker Wire.gen ~f:(fun w -> - [%test_eq: Wire.t] (to_wire (of_wire w)) w ) + [%test_eq: Wire.t] (unwrap (generate w)) w ) let wire_embedded_in_graphql () = - let module Wire = Stable.Latest.Wire in + let module Wire = Stable.Latest in Quickcheck.test ~shrinker:Wire.shrinker Wire.gen ~f:(fun w -> [%test_eq: Wire.t] (Wire.of_graphql_repr (Wire.to_graphql_repr w)) w ) @@ -119,10 +119,13 @@ end = struct let full = deriver @@ Fd.o () let json_roundtrip_dummy () = - let dummy = Lazy.force dummy in - [%test_eq: t] dummy (dummy |> Fd.to_json full |> Fd.of_json full) + let dummy = Lazy.force dummy |> Zkapp_command.unwrap in + [%test_eq: Stable.Latest.t] dummy + (dummy |> Fd.to_json full |> Fd.of_json full) let full_circuit () = Run_in_thread.block_on_async_exn - @@ fun () -> Fields_derivers_zkapps.Test.Loop.run full (Lazy.force dummy) + @@ fun () -> + Fields_derivers_zkapps.Test.Loop.run full + (Zkapp_command.unwrap @@ Lazy.force dummy) end diff --git a/src/lib/mina_base/user_command.ml b/src/lib/mina_base/user_command.ml index 952d290ee74..fb5dcfcd7d2 100644 --- a/src/lib/mina_base/user_command.ml +++ b/src/lib/mina_base/user_command.ml @@ -75,6 +75,8 @@ let gen = Gen.to_signed_command gen_signed [%%versioned module Stable = struct + [@@@no_toplevel_latest_type] + module V2 = struct type t = (Signed_command.Stable.V2.t, Zkapp_command.Stable.V1.t) Poly.Stable.V2.t @@ -84,13 +86,31 @@ module Stable = struct end end] -let to_base64 : t -> string = function +type t = (Signed_command.t, Zkapp_command.t) Poly.t +[@@deriving sexp, compare, equal, hash, yojson] + +let generate : Stable.Latest.t -> t = function + | Signed_command sc -> + Signed_command sc + | Zkapp_command zc -> + Zkapp_command (Zkapp_command.generate zc) + +let unwrap : t -> Stable.Latest.t = function + | Signed_command sc -> + Signed_command sc + | Zkapp_command zc -> + Zkapp_command (Zkapp_command.unwrap zc) + +type ('a, 'b) with_forest = + (Signed_command.t, ('a, 'b) Zkapp_command.with_forest) Poly.t + +let to_base64 : Stable.Latest.t -> string = function | Signed_command sc -> Signed_command.to_base64 sc | Zkapp_command zc -> Zkapp_command.to_base64 zc -let of_base64 s : t Or_error.t = +let of_base64 s : Stable.Latest.t Or_error.t = match Signed_command.of_base64 s with | Ok sc -> Ok (Signed_command sc) @@ -106,27 +126,6 @@ let of_base64 s : t Or_error.t = zkApp (%s)" (Error.to_string_hum err1) (Error.to_string_hum err2) ) ) ) -(* -include Allocation_functor.Make.Versioned_v1.Full_compare_eq_hash (struct - let id = "user_command" - - [%%versioned - module Stable = struct - module V1 = struct - type t = - (Signed_command.Stable.V1.t, Snapp_command.Stable.V1.t) Poly.Stable.V1.t - [@@deriving sexp, compare, equal, hash, yojson] - - let to_latest = Fn.id - - type 'a creator : Signed_command.t -> Snapp_command.t -> 'a - - let create cmd1 cmd2 = (cmd1, cmd2) - end - end] -end) -*) - module Zero_one_or_two = struct [%%versioned module Stable = struct @@ -138,18 +137,11 @@ module Zero_one_or_two = struct end module Verifiable = struct - [%%versioned - module Stable = struct - module V2 = struct - type t = - ( Signed_command.Stable.V2.t - , Zkapp_command.Verifiable.Stable.V1.t ) - Poly.Stable.V2.t - [@@deriving sexp, compare, equal, hash, yojson] - - let to_latest = Fn.id - end - end] + type t = + ( Signed_command.Stable.Latest.t + , Zkapp_command.Verifiable.t ) + Poly.Stable.Latest.t + [@@deriving sexp, compare, equal, hash, yojson, bin_io_unversioned] let fee_payer (t : t) = match t with @@ -222,7 +214,7 @@ let of_verifiable (t : Verifiable.t) : t = | Zkapp_command p -> Zkapp_command (Zkapp_command.of_verifiable p) -let fee : t -> Currency.Fee.t = function +let fee : (_, _) with_forest -> Currency.Fee.t = function | Signed_command x -> Signed_command.fee x | Zkapp_command p -> @@ -237,7 +229,7 @@ let is_disabled ~(compile_config : Mina_compile_config.t) = function false (* always `Accessed` for fee payer *) -let accounts_accessed (t : t) (status : Transaction_status.t) : +let accounts_accessed (t : (_, _) with_forest) (status : Transaction_status.t) : (Account_id.t * [ `Accessed | `Not_accessed ]) list = match t with | Signed_command x -> @@ -245,10 +237,10 @@ let accounts_accessed (t : t) (status : Transaction_status.t) : | Zkapp_command ps -> Zkapp_command.account_access_statuses ps status -let accounts_referenced (t : t) = +let accounts_referenced (t : (_, _) with_forest) = List.map (accounts_accessed t Applied) ~f:(fun (acct_id, _status) -> acct_id) -let fee_payer (t : t) = +let fee_payer (t : (_, _) with_forest) = match t with | Signed_command x -> Signed_command.fee_payer x @@ -256,7 +248,7 @@ let fee_payer (t : t) = Zkapp_command.fee_payer p (** The application nonce is the nonce of the fee payer at which a user command can be applied. *) -let applicable_at_nonce (t : t) = +let applicable_at_nonce (t : (_, _) with_forest) = match t with | Signed_command x -> Signed_command.nonce x @@ -273,21 +265,21 @@ let extract_vks : t -> (Account_id.t * Verification_key_wire.t) List.t = Zkapp_command.extract_vks cmd (** The target nonce is what the nonce of the fee payer will be after a user command is successfully applied. *) -let target_nonce_on_success (t : t) = +let target_nonce_on_success (t : (_, _) with_forest) = match t with | Signed_command x -> Account.Nonce.succ (Signed_command.nonce x) | Zkapp_command p -> Zkapp_command.target_nonce_on_success p -let fee_token (t : t) = +let fee_token (t : (_, _) with_forest) = match t with | Signed_command x -> Signed_command.fee_token x | Zkapp_command x -> Zkapp_command.fee_token x -let valid_until (t : t) = +let valid_until (t : (_, _) with_forest) = match t with | Signed_command x -> Signed_command.valid_until x @@ -301,18 +293,8 @@ let valid_until (t : t) = module Valid = struct type t_ = t - [%%versioned - module Stable = struct - module V2 = struct - type t = - ( Signed_command.With_valid_signature.Stable.V2.t - , Zkapp_command.Valid.Stable.V1.t ) - Poly.Stable.V2.t - [@@deriving sexp, compare, equal, hash, yojson] - - let to_latest = Fn.id - end - end] + type t = (Signed_command.With_valid_signature.t, Zkapp_command.Valid.t) Poly.t + [@@deriving sexp, compare, equal, hash, yojson] module Gen = Gen_make (Signed_command.With_valid_signature) end @@ -364,14 +346,14 @@ let filter_by_participant (commands : t list) public_key = (* A metric on user commands that should correspond roughly to resource costs for validation/application *) -let weight : t -> int = function +let weight : (_, _) with_forest -> int = function | Signed_command signed_command -> Signed_command.payload signed_command |> Signed_command_payload.weight | Zkapp_command zkapp_command -> Zkapp_command.weight zkapp_command (* Fee per weight unit *) -let fee_per_wu (user_command : Stable.Latest.t) : Currency.Fee_rate.t = +let fee_per_wu (user_command : (_, _) with_forest) : Currency.Fee_rate.t = (*TODO: return Or_error*) Currency.Fee_rate.make_exn (fee user_command) (weight user_command) @@ -393,7 +375,7 @@ let is_incompatible_version = function | Zkapp_command p -> Zkapp_command.is_incompatible_version p -let has_invalid_call_forest : t -> bool = function +let has_invalid_call_forest : (_, _) with_forest -> bool = function | Signed_command _ -> false | Zkapp_command cmd -> @@ -431,7 +413,7 @@ module Well_formedness_error = struct end let check_well_formedness ~(genesis_constants : Genesis_constants.t) - ~(compile_config : Mina_compile_config.t) t : + ~(compile_config : Mina_compile_config.t) (t : (_, _) with_forest) : (unit, Well_formedness_error.t list) result = let preds = let open Well_formedness_error in @@ -460,7 +442,7 @@ let check_well_formedness ~(genesis_constants : Genesis_constants.t) type fee_payer_summary_t = Signature.t * Account.key * int [@@deriving yojson, hash] -let fee_payer_summary : t -> fee_payer_summary_t = function +let fee_payer_summary : (_, _) with_forest -> fee_payer_summary_t = function | Zkapp_command cmd -> let fp = Zkapp_command.fee_payer_account_update cmd in let open Account_update in @@ -472,14 +454,12 @@ let fee_payer_summary : t -> fee_payer_summary_t = function Signed_command. (signature cmd, fee_payer_pk cmd, nonce cmd |> Unsigned.UInt32.to_int) -let fee_payer_summary_json = - Fn.compose fee_payer_summary_t_to_yojson fee_payer_summary +let fee_payer_summary_json tx = + fee_payer_summary_t_to_yojson (fee_payer_summary tx) -let fee_payer_summary_string = - let to_string (signature, pk, nonce) = - sprintf "%s (%s %d)" - (Signature.to_base58_check signature) - (Signature_lib.Public_key.Compressed.to_base58_check pk) - nonce - in - Fn.compose to_string fee_payer_summary +let fee_payer_summary_string tx = + let signature, pk, nonce = fee_payer_summary tx in + sprintf "%s (%s %d)" + (Signature.to_base58_check signature) + (Signature_lib.Public_key.Compressed.to_base58_check pk) + nonce diff --git a/src/lib/mina_base/zkapp_command.ml b/src/lib/mina_base/zkapp_command.ml index 7ee195f1470..d42adeff771 100644 --- a/src/lib/mina_base/zkapp_command.ml +++ b/src/lib/mina_base/zkapp_command.ml @@ -1,15 +1,28 @@ open Core_kernel open Signature_lib -module Graphql_repr = struct +module Poly = struct [%%versioned module Stable = struct module V1 = struct - type t = + type 'account_updates t = + 'account_updates Mina_wire_types.Mina_base.Zkapp_command.V1.T.t = { fee_payer : Account_update.Fee_payer.Stable.V1.t - ; account_updates : Account_update.Graphql_repr.Stable.V1.t list + ; account_updates : 'account_updates ; memo : Signed_command_memo.Stable.V1.t } + [@@deriving annot, sexp, compare, equal, hash, yojson, fields] + + let to_latest = Fn.id + end + end] +end + +module Graphql_repr = struct + [%%versioned + module Stable = struct + module V1 = struct + type t = Account_update.Graphql_repr.Stable.V1.t list Poly.Stable.V1.t [@@deriving sexp, compare, equal, hash, yojson] let to_latest = Fn.id @@ -22,11 +35,7 @@ module Simple = struct [%%versioned module Stable = struct module V1 = struct - type t = - { fee_payer : Account_update.Fee_payer.Stable.V1.t - ; account_updates : Account_update.Simple.Stable.V1.t list - ; memo : Signed_command_memo.Stable.V1.t - } + type t = Account_update.Simple.Stable.V1.t list Poly.Stable.V1.t [@@deriving sexp, compare, equal, hash, yojson] let to_latest = Fn.id @@ -37,9 +46,19 @@ end module Call_forest = Zkapp_call_forest_base module Digest = Call_forest.Digest +type ('account_update_digest, 'forest_digest) with_forest = + (Account_update.t, 'account_update_digest, 'forest_digest) Call_forest.t + Poly.t +[@@deriving sexp, compare, equal, hash, yojson] + module T = struct - [%%versioned_binable + type t = (Digest.Account_update.t, Digest.Forest.t) with_forest + [@@deriving sexp, compare, equal, hash, yojson] + + [%%versioned module Stable = struct + [@@@no_toplevel_latest_type] + [@@@with_top_version_tag] (* DO NOT DELETE VERSIONS! @@ -52,146 +71,102 @@ module T = struct *) module V1 = struct - type t = Mina_wire_types.Mina_base.Zkapp_command.V1.t = - { fee_payer : Account_update.Fee_payer.Stable.V1.t - ; account_updates : - ( Account_update.Stable.V1.t - , Digest.Account_update.Stable.V1.t - , Digest.Forest.Stable.V1.t ) - Call_forest.Stable.V1.t - ; memo : Signed_command_memo.Stable.V1.t - } - [@@deriving annot, sexp, compare, equal, hash, yojson, fields] + type t = + (Account_update.Stable.V1.t, unit, unit) Call_forest.Stable.V1.t + Poly.Stable.V1.t + [@@deriving sexp, compare, equal, hash, yojson] let to_latest = Fn.id - module Wire = struct - [%%versioned - module Stable = struct - module V1 = struct - type t = - { fee_payer : Account_update.Fee_payer.Stable.V1.t - ; account_updates : - ( Account_update.Stable.V1.t - , unit - , unit ) - Call_forest.Stable.V1.t - ; memo : Signed_command_memo.Stable.V1.t - } - [@@deriving sexp, compare, equal, hash, yojson] - - let to_latest = Fn.id - end - end] - - let of_graphql_repr (t : Graphql_repr.t) : t = - { fee_payer = t.fee_payer - ; memo = t.memo - ; account_updates = - Call_forest.of_account_updates_map t.account_updates - ~f:Account_update.of_graphql_repr - ~account_update_depth:(fun (p : Account_update.Graphql_repr.t) - -> p.body.call_depth ) - } - - let to_graphql_repr (t : t) : Graphql_repr.t = - { fee_payer = t.fee_payer - ; memo = t.memo - ; account_updates = - t.account_updates - |> Call_forest.to_account_updates_map - ~f:(fun ~depth account_update -> - Account_update.to_graphql_repr account_update - ~call_depth:depth ) - } - - let gen = - let open Quickcheck.Generator in - let open Let_syntax in - let gen_call_forest = - fixed_point (fun self -> - let%bind calls_length = small_non_negative_int in - list_with_length calls_length - (let%map account_update = Account_update.gen - and calls = self in - { With_stack_hash.stack_hash = () - ; elt = - { Call_forest.Tree.account_update - ; account_update_digest = () - ; calls - } - } ) ) - in - let open Quickcheck.Let_syntax in - let%map fee_payer = Account_update.Fee_payer.gen - and account_updates = gen_call_forest - and memo = Signed_command_memo.gen in - { fee_payer; account_updates; memo } - - let shrinker : t Quickcheck.Shrinker.t = - Quickcheck.Shrinker.create (fun t -> - let shape = Call_forest.shape t.account_updates in - Sequence.map - (Quickcheck.Shrinker.shrink - Call_forest.Shape.quickcheck_shrinker shape ) - ~f:(fun shape' -> - { t with - account_updates = Call_forest.mask t.account_updates shape' - } ) ) - end - - let of_wire (w : Wire.t) : t = - { fee_payer = w.fee_payer - ; memo = w.memo + let of_graphql_repr (t : Graphql_repr.t) : t = + { fee_payer = t.fee_payer + ; memo = t.memo ; account_updates = - w.account_updates - |> Call_forest.accumulate_hashes - ~hash_account_update:(fun (p : Account_update.t) -> - Digest.Account_update.create p ) + Call_forest.of_account_updates_map t.account_updates + ~f:Account_update.of_graphql_repr + ~account_update_depth:(fun (p : Account_update.Graphql_repr.t) -> + p.body.call_depth ) } - let to_wire (t : t) : Wire.t = - let rec forget_hashes = List.map ~f:forget_hash - and forget_hash = function - | { With_stack_hash.stack_hash = _ - ; elt = - { Call_forest.Tree.account_update - ; account_update_digest = _ - ; calls - } - } -> - { With_stack_hash.stack_hash = () - ; elt = - { Call_forest.Tree.account_update - ; account_update_digest = () - ; calls = forget_hashes calls - } - } - in + let to_graphql_repr (t : t) : Graphql_repr.t = { fee_payer = t.fee_payer ; memo = t.memo - ; account_updates = forget_hashes t.account_updates + ; account_updates = + t.account_updates + |> Call_forest.to_account_updates_map + ~f:(fun ~depth account_update -> + Account_update.to_graphql_repr account_update + ~call_depth:depth ) } - include - Binable.Of_binable_without_uuid - (Wire.Stable.V1) - (struct - type nonrec t = t - - let of_binable t = of_wire t - - let to_binable = to_wire - end) + let gen = + let open Quickcheck.Generator in + let open Let_syntax in + let gen_call_forest = + fixed_point (fun self -> + let%bind calls_length = small_non_negative_int in + list_with_length calls_length + (let%map account_update = Account_update.gen and calls = self in + { With_stack_hash.stack_hash = () + ; elt = + { Call_forest.Tree.account_update + ; account_update_digest = () + ; calls + } + } ) ) + in + let open Quickcheck.Let_syntax in + let%map fee_payer = Account_update.Fee_payer.gen + and account_updates = gen_call_forest + and memo = Signed_command_memo.gen in + { Poly.fee_payer; account_updates; memo } + + let shrinker : t Quickcheck.Shrinker.t = + Quickcheck.Shrinker.create (fun t -> + let shape = Call_forest.shape t.Poly.account_updates in + Sequence.map + (Quickcheck.Shrinker.shrink Call_forest.Shape.quickcheck_shrinker + shape ) ~f:(fun shape' -> + { t with + account_updates = Call_forest.mask t.account_updates shape' + } ) ) end end] end include T -[%%define_locally Stable.Latest.(of_wire, to_wire)] +let generate (w : Stable.Latest.t) : t = + { fee_payer = w.fee_payer + ; memo = w.memo + ; account_updates = + w.account_updates + |> Call_forest.accumulate_hashes + ~hash_account_update:(fun (p : Account_update.t) -> + Digest.Account_update.create p ) + } + +let unwrap (t : t) : Stable.Latest.t = + let rec forget_hashes = List.map ~f:forget_hash + and forget_hash = function + | { With_stack_hash.stack_hash = _ + ; elt = + { Call_forest.Tree.account_update; account_update_digest = _; calls } + } -> + { With_stack_hash.stack_hash = () + ; elt = + { Call_forest.Tree.account_update + ; account_update_digest = () + ; calls = forget_hashes calls + } + } + in + { fee_payer = t.fee_payer + ; memo = t.memo + ; account_updates = forget_hashes t.account_updates + } -[%%define_locally Stable.Latest.Wire.(gen)] +[%%define_locally Stable.Latest.(gen)] let of_simple (w : Simple.t) : t = { fee_payer = w.fee_payer @@ -243,14 +218,14 @@ let all_account_updates (t : t) : _ Call_forest.t = in Call_forest.cons fee_payer t.account_updates -let fee (t : t) : Currency.Fee.t = t.fee_payer.body.fee +let fee (t : (_, _) with_forest) : Currency.Fee.t = t.fee_payer.body.fee -let fee_payer_account_update ({ fee_payer; _ } : t) = fee_payer +let fee_payer_account_update (t : (_, _) with_forest) = t.fee_payer -let applicable_at_nonce (t : t) : Account.Nonce.t = - (fee_payer_account_update t).body.nonce +let applicable_at_nonce (t : (_, _) with_forest) : Account.Nonce.t = + t.fee_payer.body.nonce -let target_nonce_on_success (t : t) : Account.Nonce.t = +let target_nonce_on_success (t : (_, _) with_forest) : Account.Nonce.t = let base_nonce = Account.Nonce.succ (applicable_at_nonce t) in let fee_payer_pubkey = t.fee_payer.body.public_key in let fee_payer_account_update_increments = @@ -261,7 +236,8 @@ let target_nonce_on_success (t : t) : Account.Nonce.t = Account.Nonce.add base_nonce (Account.Nonce.of_int fee_payer_account_update_increments) -let nonce_increments (t : t) : int Public_key.Compressed.Map.t = +let nonce_increments (t : (_, _) with_forest) : int Public_key.Compressed.Map.t + = let base_increments = Public_key.Compressed.Map.of_alist_exn [ (t.fee_payer.body.public_key, 1) ] in @@ -272,34 +248,36 @@ let nonce_increments (t : t) : int Public_key.Compressed.Map.t = ~f:(Option.value_map ~default:1 ~f:(( + ) 1)) else incr_map ) -let fee_token (_t : t) = Token_id.default +let fee_token (_t : (_, _) with_forest) = Token_id.default -let fee_payer (t : t) = +let fee_payer (t : (_, _) with_forest) = Account_id.create t.fee_payer.body.public_key (fee_token t) -let extract_vks (t : t) : (Account_id.t * Verification_key_wire.t) List.t = - account_updates t - |> Call_forest.fold ~init:[] ~f:(fun acc (p : Account_update.t) -> - match Account_update.verification_key_update_to_option p with - | Zkapp_basic.Set_or_keep.Set (Some vk) -> - (Account_update.account_id p, vk) :: acc - | _ -> - acc ) - -let account_updates_list (t : t) : Account_update.t list = +let extract_vks (t : (_, _) with_forest) : + (Account_id.t * Verification_key_wire.t) List.t = + Call_forest.fold ~init:[] t.account_updates + ~f:(fun acc (p : Account_update.t) -> + match Account_update.verification_key_update_to_option p with + | Zkapp_basic.Set_or_keep.Set (Some vk) -> + (Account_update.account_id p, vk) :: acc + | _ -> + acc ) + +let account_updates_list (t : (_, _) with_forest) : Account_update.t list = Call_forest.fold t.account_updates ~init:[] ~f:(Fn.flip List.cons) |> List.rev -let all_account_updates_list (t : t) : Account_update.t list = +let all_account_updates_list (t : (_, _) with_forest) : Account_update.t list = Call_forest.fold t.account_updates ~init:[ Account_update.of_fee_payer (fee_payer_account_update t) ] ~f:(Fn.flip List.cons) |> List.rev -let fee_excess (t : t) = +let fee_excess (t : (_, _) with_forest) = Fee_excess.of_single (fee_token t, Currency.Fee.Signed.of_unsigned (fee t)) (* always `Accessed` for fee payer *) -let account_access_statuses (t : t) (status : Transaction_status.t) = +let account_access_statuses (t : (_, _) with_forest) + (status : Transaction_status.t) = let init = [ (fee_payer t, `Accessed) ] in let status_sym = match status with Applied -> `Accessed | Failed _ -> `Not_accessed @@ -308,11 +286,11 @@ let account_access_statuses (t : t) (status : Transaction_status.t) = (Account_update.account_id p, status_sym) :: acc ) |> List.rev |> List.stable_dedup -let accounts_referenced (t : t) = +let accounts_referenced (t : (_, _) with_forest) = List.map (account_access_statuses t Applied) ~f:(fun (acct_id, _status) -> acct_id ) -let fee_payer_pk (t : t) = t.fee_payer.body.public_key +let fee_payer_pk (t : (_, _) with_forest) = t.fee_payer.body.public_key let value_if b ~then_ ~else_ = if b then then_ else else_ @@ -402,24 +380,14 @@ let check_authorization (p : Account_update.t) : unit Or_error.t = Error err module Verifiable : sig - [%%versioned: - module Stable : sig - module V1 : sig - type t = private - { fee_payer : Account_update.Fee_payer.Stable.V1.t - ; account_updates : - ( Side_loaded_verification_key.Stable.V2.t - , Zkapp_basic.F.Stable.V1.t ) - With_hash.Stable.V1.t - option - Call_forest.With_hashes_and_data.Stable.V1.t - ; memo : Signed_command_memo.Stable.V1.t - } - [@@deriving sexp, compare, equal, hash, yojson] - - val to_latest : t -> t - end - end] + type t = private + { fee_payer : Account_update.Fee_payer.t + ; account_updates : + (Side_loaded_verification_key.t, Zkapp_basic.F.t) With_hash.t option + Call_forest.With_hashes_and_data.t + ; memo : Signed_command_memo.t + } + [@@deriving sexp, compare, equal, hash, yojson, bin_io] val load_vk_from_ledger : location_of_account:(Account_id.t -> 'loc option) @@ -472,24 +440,17 @@ module Verifiable : sig with type 'a Command_wrapper.t = 'a With_status.t and type cache = Verification_key_wire.t Account_id.Map.t end = struct - [%%versioned - module Stable = struct - module V1 = struct - type t = - { fee_payer : Account_update.Fee_payer.Stable.V1.t - ; account_updates : - ( Side_loaded_verification_key.Stable.V2.t - , Zkapp_basic.F.Stable.V1.t ) - With_hash.Stable.V1.t - option - Call_forest.With_hashes_and_data.Stable.V1.t - ; memo : Signed_command_memo.Stable.V1.t - } - [@@deriving sexp, compare, equal, hash, yojson] - - let to_latest = Fn.id - end - end] + type t = + { fee_payer : Account_update.Fee_payer.Stable.Latest.t + ; account_updates : + ( Side_loaded_verification_key.Stable.Latest.t + , Zkapp_basic.F.Stable.Latest.t ) + With_hash.Stable.Latest.t + option + Call_forest.With_hashes_and_data.Stable.Latest.t + ; memo : Signed_command_memo.Stable.Latest.t + } + [@@deriving sexp, compare, equal, hash, yojson, bin_io_unversioned] let ok_if_vk_hash_expected ~got ~expected = if not @@ Zkapp_basic.F.equal (With_hash.hash got) expected then @@ -811,8 +772,8 @@ module Weight = struct let memo : Signed_command_memo.t -> int = fun _ -> 0 end -let weight (zkapp_command : t) : int = - let { fee_payer; account_updates; memo } = zkapp_command in +let weight (zkapp_command : (_, _) with_forest) : int = + let { Poly.fee_payer; account_updates; memo } = zkapp_command in List.sum (module Int) ~f:Fn.id @@ -822,13 +783,8 @@ let weight (zkapp_command : t) : int = ] module type Valid_intf = sig - [%%versioned: - module Stable : sig - module V1 : sig - type t = private { zkapp_command : T.Stable.V1.t } - [@@deriving sexp, compare, equal, hash, yojson] - end - end] + type nonrec t = private { zkapp_command : t } + [@@deriving sexp, compare, equal, hash, yojson] val to_valid_unsafe : T.t -> [> `If_this_is_used_it_should_have_a_comment_justifying_it of t ] @@ -847,34 +803,9 @@ module type Valid_intf = sig val forget : t -> T.t end -module Valid : - Valid_intf - with type Stable.V1.t = Mina_wire_types.Mina_base.Zkapp_command.Valid.V1.t = -struct - module S = Stable - - module Verification_key_hash = struct - [%%versioned - module Stable = struct - module V1 = struct - type t = Zkapp_basic.F.Stable.V1.t - [@@deriving sexp, compare, equal, hash, yojson] - - let to_latest = Fn.id - end - end] - end - - [%%versioned - module Stable = struct - module V1 = struct - type t = Mina_wire_types.Mina_base.Zkapp_command.Valid.V1.t = - { zkapp_command : S.V1.t } - [@@deriving sexp, compare, equal, hash, yojson] - - let to_latest = Fn.id - end - end] +module Valid : Valid_intf = struct + type t = { zkapp_command : T.t } + [@@deriving sexp, compare, equal, hash, yojson] let create zkapp_command : t = { zkapp_command } @@ -890,13 +821,10 @@ struct Verifiable.create t ~failed ~find_vk |> Or_error.map ~f:of_verifiable end -[%%define_locally Stable.Latest.(of_yojson, to_yojson)] - (* so transaction ids have a version tag *) include Codable.Make_base64 (Stable.Latest.With_top_version_tag) -type account_updates = - (Account_update.t, Digest.Account_update.t, Digest.Forest.t) Call_forest.t +type account_updates = (Account_update.t, unit, unit) Call_forest.t let account_updates_deriver obj = let of_zkapp_command_with_depth (ps : Account_update.Graphql_repr.t list) : @@ -905,7 +833,6 @@ let account_updates_deriver obj = ~account_update_depth:(fun (p : Account_update.Graphql_repr.t) -> p.body.call_depth ) |> Call_forest.map ~f:Account_update.of_graphql_repr - |> Call_forest.accumulate_hashes' and to_zkapp_command_with_depth (ps : account_updates) : Account_update.Graphql_repr.t list = ps @@ -919,6 +846,7 @@ let account_updates_deriver obj = let deriver obj = let open Fields_derivers_zkapps.Derivers in + let open Poly in let ( !. ) = ( !. ) ~t_fields_annots in Fields.make_creator obj ~fee_payer:!.Account_update.Fee_payer.deriver @@ -958,7 +886,7 @@ let dummy = ; authorization = Signature.dummy } in - { fee_payer + { Poly.fee_payer ; account_updates = Call_forest.cons account_update [] ; memo = Signed_command_memo.empty } ) @@ -987,7 +915,7 @@ end) : sig end val group_by_zkapp_command_rev : - t list + (_, _) with_forest list -> (Input.global_state * Input.local_state * Input.connecting_ledger_hash) list list @@ -1028,7 +956,7 @@ end = struct will need to be passed as part of the snark witness while applying that pair. *) - let group_by_zkapp_command_rev (zkapp_commands : t list) + let group_by_zkapp_command_rev (zkapp_commands : (_, _) with_forest list) (stmtss : (global_state * local_state * connecting_ledger_hash) list list) : Zkapp_command_intermediate_state.t list = let intermediate_state ~kind ~spec ~before ~after = @@ -1043,7 +971,7 @@ end = struct in let zkapp_account_updatess = [] - :: List.map zkapp_commands ~f:(fun (zkapp_command : t) -> + :: List.map zkapp_commands ~f:(fun zkapp_command -> all_account_updates_list zkapp_command ) in let rec group_by_zkapp_command_rev @@ -1329,8 +1257,8 @@ let zkapp_cost ~proof_segments ~signed_single_segments ~signed_pair_segments - when adding to the transaction pool - in incoming blocks *) -let valid_size ~(genesis_constants : Genesis_constants.t) (t : t) : - unit Or_error.t = +let valid_size ~(genesis_constants : Genesis_constants.t) + (t : (_, _) with_forest) : unit Or_error.t = let events_elements events = List.fold events ~init:0 ~f:(fun acc event -> acc + Array.length event) in @@ -1407,7 +1335,8 @@ let valid_size ~(genesis_constants : Genesis_constants.t) (t : t) : in Error (Error.of_string err_msg) -let has_zero_vesting_period t = +let has_zero_vesting_period (t : (Account_update.t, _, _) Call_forest.t Poly.t) + = Call_forest.exists t.account_updates ~f:(fun p -> match p.body.update.timing with | Keep -> @@ -1415,7 +1344,8 @@ let has_zero_vesting_period t = | Set { vesting_period; _ } -> Mina_numbers.Global_slot_span.(equal zero) vesting_period ) -let is_incompatible_version t = +let is_incompatible_version (t : (Account_update.t, _, _) Call_forest.t Poly.t) + = Call_forest.exists t.account_updates ~f:(fun p -> match p.body.update.permissions with | Keep -> diff --git a/src/lib/mina_block/block.ml b/src/lib/mina_block/block.ml index b6cd0648a57..71f6a316849 100644 --- a/src/lib/mina_block/block.ml +++ b/src/lib/mina_block/block.ml @@ -11,7 +11,7 @@ module Stable = struct { header : Header.Stable.V2.t ; body : Staged_ledger_diff.Body.Stable.V1.t } - [@@deriving fields] + [@@deriving fields, sexp] let to_latest = Fn.id diff --git a/src/lib/mina_block/block.mli b/src/lib/mina_block/block.mli index d389c6bdd69..fa73b9e9496 100644 --- a/src/lib/mina_block/block.mli +++ b/src/lib/mina_block/block.mli @@ -6,7 +6,7 @@ module Stable : sig [@@@no_toplevel_latest_type] module V2 : sig - type t [@@deriving equal] + type t [@@deriving equal, sexp] val header : t -> Header.Stable.V2.t diff --git a/src/lib/mina_block/precomputed_block.ml b/src/lib/mina_block/precomputed_block.ml index 4b5f7855388..6b2408bb5de 100644 --- a/src/lib/mina_block/precomputed_block.ml +++ b/src/lib/mina_block/precomputed_block.ml @@ -89,14 +89,14 @@ module Stable = struct ; tokens_used : (Token_id.Stable.V2.t * Account_id.Stable.V2.t option) list } - [@@deriving yojson] + [@@deriving sexp, yojson] let to_latest = Fn.id end end] (* functions for the versioned json, not the unversioned ones provided by `T` *) -[%%define_locally Stable.Latest.(to_yojson, of_yojson)] +[%%define_locally Stable.Latest.(to_yojson, of_yojson, sexp_of_t, t_of_sexp)] let of_block ~logger ~(constraint_constants : Genesis_constants.Constraint_constants.t) @@ -190,6 +190,22 @@ let of_block ~logger ; tokens_used } +(* NOTE: This serialization is used externally and MUST NOT change. + If the underlying types change, you should write a conversion, or add + optional fields and handle them appropriately. +*) +(* But if you really need to update it, you can generate new samples using: + `dune exec dump_blocks 1> block.txt` *) +let%test_unit "Sexp serialization is stable" = + let serialized_block = Sample_precomputed_block.sample_block_sexp in + ignore @@ t_of_sexp @@ Sexp.of_string serialized_block + +let%test_unit "Sexp serialization roundtrips" = + let serialized_block = Sample_precomputed_block.sample_block_sexp in + let sexp = Sexp.of_string serialized_block in + let sexp_roundtrip = sexp_of_t @@ t_of_sexp sexp in + [%test_eq: Sexp.t] sexp sexp_roundtrip + (* NOTE: This serialization is used externally and MUST NOT change. If the underlying types change, you should write a conversion, or add optional fields and handle them appropriately. diff --git a/src/lib/mina_block/precomputed_block.mli b/src/lib/mina_block/precomputed_block.mli index 67aebe1b701..abfb2af42da 100644 --- a/src/lib/mina_block/precomputed_block.mli +++ b/src/lib/mina_block/precomputed_block.mli @@ -49,7 +49,7 @@ type t = Stable.Latest.t = ; accounts_created : (Account_id.t * Currency.Fee.t) list ; tokens_used : (Token_id.t * Account_id.t option) list } -[@@deriving yojson] +[@@deriving sexp, yojson] val of_block : logger:Logger.t diff --git a/src/lib/mina_commands/mina_commands.ml b/src/lib/mina_commands/mina_commands.ml index bd2ff08141d..c762d0d7753 100644 --- a/src/lib/mina_commands/mina_commands.ml +++ b/src/lib/mina_commands/mina_commands.ml @@ -97,7 +97,9 @@ let setup_and_submit_user_command t (user_command_input : User_command_input.t) | `Not_broadcasted -> "not_broadcasted" ) ) ; ( "valid_commands" - , `List (List.map ~f:User_command.to_yojson valid_commands) ) + , `List + (List.map ~f:User_command.Stable.Latest.to_yojson valid_commands) + ) ; ( "invalid_commands" , `List (List.map invalid_commands ~f:(fun (_cmd, diff_err) -> @@ -118,7 +120,8 @@ let setup_and_submit_user_commands t user_command_list = [ ("mina_command", `String "scheduling a batch of user transactions") ] ; Mina_lib.add_transactions t user_command_list -let setup_and_submit_zkapp_commands t (zkapp_commands : Zkapp_command.t list) = +let setup_and_submit_zkapp_commands t + (zkapp_commands : Zkapp_command.Stable.Latest.t list) = let open Participating_state.Let_syntax in (* hack to get types to work out *) let%map () = return () in @@ -167,7 +170,8 @@ let setup_and_submit_zkapp_commands t (zkapp_commands : Zkapp_command.t list) = | Error e -> Error e -let setup_and_submit_zkapp_command t (zkapp_command : Zkapp_command.t) = +let setup_and_submit_zkapp_command t + (zkapp_command : Zkapp_command.Stable.Latest.t) = let res = setup_and_submit_zkapp_commands t [ zkapp_command ] in let%map.Participating_state res' = res in match%map.Deferred res' with @@ -226,8 +230,10 @@ let chain_id_inputs (t : Mina_lib.t) = , protocol_transaction_version , protocol_network_version ) -let verify_payment t (addr : Account_id.t) (verifying_txn : User_command.t) - (init_receipt, proof) = +let verify_payment t (addr : Account_id.t) + (verifying_txn : User_command.Stable.Latest.t) + (init_receipt, proof_unwrapped) = + let proof = List.map ~f:User_command.generate proof_unwrapped in let open Participating_state.Let_syntax in let%map account = get_account t addr in let account = Option.value_exn account in @@ -238,11 +244,14 @@ let verify_payment t (addr : Account_id.t) (verifying_txn : User_command.t) (Receipt_chain_verifier.verify ~init:init_receipt proof resulting_receipt) ~error:(Error.createf "Merkle list proof of payment is invalid") in - if List.exists proof ~f:(fun txn -> User_command.equal verifying_txn txn) then - Ok () + if + List.exists proof_unwrapped ~f:(fun txn -> + User_command.Stable.Latest.equal verifying_txn txn ) + then Ok () else Or_error.errorf - !"Merkle list proof does not contain payment %{sexp:User_command.t}" + !"Merkle list proof does not contain payment \ + %{sexp:User_command.Stable.Latest.t}" verifying_txn type active_state_fields = diff --git a/src/lib/mina_graphql/itn_zkapps.ml b/src/lib/mina_graphql/itn_zkapps.ml index e5758a34c01..c8a1632ec74 100644 --- a/src/lib/mina_graphql/itn_zkapps.ml +++ b/src/lib/mina_graphql/itn_zkapps.ml @@ -72,7 +72,10 @@ let deploy_zkapps ~scheduler_tbl ~mina ~ledger ~deployment_fee ~max_cost @@ fun () -> if finished () then Deferred.return (`Finished ()) else - match%bind Zkapps.send_zkapp_command mina zkapp_command with + (* TODO create without hash accumulation and remove unwrap call *) + match%bind + Zkapps.send_zkapp_command mina (Zkapp_command.unwrap zkapp_command) + with | Ok _ -> fee_payer_nonces.(ndx) := Account.Nonce.succ !(fee_payer_nonces.(ndx)) ; @@ -283,7 +286,10 @@ let send_zkapps ~(genesis_constants : Genesis_constants.t) let%bind () = O1trace.thread "itn_send_zkapp" @@ fun () -> - match%map Zkapps.send_zkapp_command mina zkapp_command with + (* TODO create without hash accumulation and remove unwrap call *) + match%map + Zkapps.send_zkapp_command mina (Zkapp_command.unwrap zkapp_command) + with | Ok _ -> [%log info] "Sent out zkApp with fee payer's summary $summary" ~metadata: diff --git a/src/lib/mina_graphql/mina_graphql.ml b/src/lib/mina_graphql/mina_graphql.ml index 012734f3ecf..9357110e443 100644 --- a/src/lib/mina_graphql/mina_graphql.ml +++ b/src/lib/mina_graphql/mina_graphql.ml @@ -380,7 +380,7 @@ module Mutations = struct in Types.Zkapp_command.With_status.map cmd ~f:(fun cmd -> { With_hash.data = cmd - ; hash = Transaction_hash.hash_command (Zkapp_command cmd) + ; hash = Transaction_hash.hash_zkapp_command cmd } ) ) in Ok cmds_with_hash @@ -391,8 +391,8 @@ module Mutations = struct | `Bootstrapping -> return (Error "Daemon is bootstrapping") - let mock_zkapp_command mina zkapp_command : - ( (Zkapp_command.t, Transaction_hash.t) With_hash.t + let mock_zkapp_command mina (zkapp_command : Zkapp_command.Stable.Latest.t) : + ( (Zkapp_command.Stable.Latest.t, Transaction_hash.t) With_hash.t Types.Zkapp_command.With_status.t , string ) result @@ -465,19 +465,16 @@ module Mutations = struct ( Transition_frontier.Breadcrumb.consensus_state breadcrumb |> Consensus.Data.Consensus_state .global_slot_since_genesis ) - ~state_view ledger zkapp_command + ~state_view ledger + (Zkapp_command.generate zkapp_command) in (* rearrange data to match result type of `send_zkapp_command` *) let applied_ok = Result.map applied ~f:(fun (zkapp_command_applied, _local_state_and_amount) -> - let ({ data = zkapp_command; status } - : Zkapp_command.t With_status.t ) = - zkapp_command_applied.command - in + let status = zkapp_command_applied.command.status in let hash = - Transaction_hash.hash_command - (Zkapp_command zkapp_command) + Transaction_hash.hash_zkapp_command zkapp_command in let (with_hash : _ With_hash.t) = { data = zkapp_command; hash } @@ -1708,7 +1705,8 @@ module Queries = struct match Zkapp_command.of_base64 serialized_txn with | Ok zkapp_command -> let user_cmd = - User_command.Zkapp_command zkapp_command + User_command.Zkapp_command + (Zkapp_command.generate zkapp_command) in (* The command gets piped through [forget_check] below; this is just to make the types work @@ -1801,6 +1799,7 @@ module Queries = struct let cmd_with_hash = Transaction_hash.User_command_with_valid_signature.forget_check txn + |> With_hash.map ~f:User_command.unwrap in match cmd_with_hash.data with | Signed_command _ -> @@ -2054,8 +2053,10 @@ module Queries = struct in let frontier_broadcast_pipe = Mina_lib.transition_frontier mina in let transaction_pool = Mina_lib.transaction_pool mina in + (* TODO: do not compute hashes to just get the status *) Transaction_inclusion_status.get_status ~frontier_broadcast_pipe - ~transaction_pool txn.data ) + ~transaction_pool + @@ User_command.generate txn.data ) let current_snark_worker = field "currentSnarkWorker" ~typ:Types.snark_worker diff --git a/src/lib/mina_graphql/types.ml b/src/lib/mina_graphql/types.ml index 247360aefe3..3902fdec567 100644 --- a/src/lib/mina_graphql/types.ml +++ b/src/lib/mina_graphql/types.ml @@ -631,8 +631,8 @@ module Snark_work_bundle = struct let spec = let work_to_yojson (w : Work_selector.work) = Snark_worker.Work.Single.Spec.to_yojson - @@ Snark_work_lib.Work.Single.Spec.map_proof ~f:Ledger_proof.Cached.unwrap - w + @@ Snark_work_lib.Work.Single.Spec.map ~f_proof:Ledger_proof.Cached.unwrap + ~f_witness:Transaction_witness.unwrap w in obj "WorkBundleSpec" ~doc: @@ -1985,25 +1985,27 @@ module Zkapp_command = struct let zkapp_command = let conv - (x : (Mina_lib.t, Zkapp_command.t) Fields_derivers_graphql.Schema.typ) : - (Mina_lib.t, Zkapp_command.t) typ = + (x : + ( Mina_lib.t + , Zkapp_command.Stable.Latest.t ) + Fields_derivers_graphql.Schema.typ ) : + (Mina_lib.t, Zkapp_command.Stable.Latest.t) typ = Obj.magic x in obj "ZkappCommandResult" ~fields:(fun _ -> [ field_no_status "id" ~doc:"A Base64 string representing the zkApp command" ~typ:(non_null transaction_id) ~args:[] - ~resolve:(fun _ zkapp_command -> - Zkapp_command zkapp_command.With_hash.data ) + ~resolve:(fun _ { With_hash.data; _ } -> Zkapp_command data) ; field_no_status "hash" ~doc:"A cryptographic hash of the zkApp command" ~typ:(non_null transaction_hash) ~args:[] - ~resolve:(fun _ zkapp_command -> zkapp_command.With_hash.hash) + ~resolve:(fun _ { With_hash.hash; _ } -> hash) ; field_no_status "zkappCommand" ~typ:(Zkapp_command.typ () |> conv) ~args:Arg.[] ~doc:"zkApp command representing the transaction" - ~resolve:(fun _ zkapp_command -> zkapp_command.With_hash.data) + ~resolve:(fun _ { With_hash.data; _ } -> data) ; field "failureReason" ~typ:(list @@ Command_status.failure_reasons) ~args:[] ~doc: @@ -2021,7 +2023,7 @@ module Zkapp_command = struct end let transactions = - let open Filtered_external_transition.Transactions in + let open Filtered_external_transition.Transactions.Stable.Latest in obj "Transactions" ~doc:"Different types of transactions in a block" ~fields:(fun _ -> [ field "userCommands" @@ -2623,7 +2625,7 @@ module Input = struct end module SendTestZkappInput = struct - type input = Mina_base.Zkapp_command.t + type input = Mina_base.Zkapp_command.Stable.Latest.t let arg_typ = scalar "SendTestZkappInput" ~doc:"zkApp command for a test zkApp" @@ -2985,8 +2987,10 @@ module Input = struct let arg_typ = let conv (x : - Mina_base.Zkapp_command.t Fields_derivers_graphql.Schema.Arg.arg_typ - ) : Mina_base.Zkapp_command.t Graphql_async.Schema.Arg.arg_typ = + Mina_base.Zkapp_command.Stable.Latest.t + Fields_derivers_graphql.Schema.Arg.arg_typ ) : + Mina_base.Zkapp_command.Stable.Latest.t + Graphql_async.Schema.Arg.arg_typ = Obj.magic x in let arg_typ = diff --git a/src/lib/mina_graphql/zkapps.ml b/src/lib/mina_graphql/zkapps.ml index bb1c4da9a61..214ab208d79 100644 --- a/src/lib/mina_graphql/zkapps.ml +++ b/src/lib/mina_graphql/zkapps.ml @@ -15,7 +15,7 @@ let send_zkapp_command mina zkapp_command = let cmd_with_hash = Types.Zkapp_command.With_status.map cmd ~f:(fun cmd -> { With_hash.data = cmd - ; hash = Transaction_hash.hash_command (Zkapp_command cmd) + ; hash = Transaction_hash.hash_zkapp_command cmd } ) in Ok cmd_with_hash diff --git a/src/lib/mina_lib/mina_lib.ml b/src/lib/mina_lib/mina_lib.ml index d9157b29003..c782c31d0a4 100644 --- a/src/lib/mina_lib/mina_lib.ml +++ b/src/lib/mina_lib/mina_lib.ml @@ -71,7 +71,7 @@ type components = (* tag commands so they can share a common pipe, to ensure sequentiality of nonces *) type command_inputs = | Signed_command_inputs of User_command_input.t list - | Zkapp_command_command_inputs of Zkapp_command.t list + | Zkapp_command_command_inputs of Zkapp_command.Stable.Latest.t list type pipes = { validated_transitions_reader : Mina_block.Validated.t Strict_pipe.Reader.t @@ -865,13 +865,12 @@ let request_work t = Work_selection_method.work ~logger:t.config.logger ~fee ~snark_pool:(snark_pool t) (snark_job_state t) in + let map_work = + Snark_work_lib.Work.Single.Spec.map ~f_proof:Ledger_proof.Cached.unwrap + ~f_witness:Transaction_witness.unwrap + in Option.map instances_opt ~f:(fun instances -> - let instances = - One_or_two.map instances - ~f: - (Snark_work_lib.Work.Single.Spec.map_proof - ~f:Ledger_proof.Cached.unwrap ) - in + let instances = One_or_two.map instances ~f:map_work in { Snark_work_lib.Work.Spec.instances; fee } ) let work_selection_method t = t.config.work_selection_method @@ -890,13 +889,12 @@ let add_work t (work : Snark_worker_lib.Work.Result.t) = Mina_metrics.( Gauge.set Snark_work.pending_snark_work (Int.to_float pending_work)) in - let cache = - Ledger_proof.Cached.generate ~proof_cache_db:t.config.proof_cache_db - in - let spec = - One_or_two.map work.spec.instances - ~f:(Snark_work_lib.Work.Single.Spec.map_proof ~f:cache) + let map_work = + Snark_work_lib.Work.Single.Spec.map ~f_witness:Transaction_witness.generate + ~f_proof: + (Ledger_proof.Cached.generate ~proof_cache_db:t.config.proof_cache_db) in + let spec = One_or_two.map work.spec.instances ~f:map_work in let cb _ = (* remove it from seen jobs after attempting to adding it to the pool to avoid this work being reassigned * If the diff is accepted then remove it from the seen jobs. @@ -976,7 +974,8 @@ let add_full_transactions t user_commands = in Deferred.Result.fail error -let add_zkapp_transactions t (zkapp_commands : Zkapp_command.t list) = +let add_zkapp_transactions t + (zkapp_commands : Zkapp_command.Stable.Latest.t list) = let add_all_txns () = let result_ivar = Ivar.create () in let cmd_inputs = Zkapp_command_command_inputs zkapp_commands in diff --git a/src/lib/mina_lib/mina_lib.mli b/src/lib/mina_lib/mina_lib.mli index 06bb14566df..9d44832c65a 100644 --- a/src/lib/mina_lib/mina_lib.mli +++ b/src/lib/mina_lib/mina_lib.mli @@ -136,7 +136,7 @@ val add_transactions : val add_full_transactions : t - -> User_command.t list + -> User_command.Stable.Latest.t list -> ( [ `Broadcasted | `Not_broadcasted ] * Network_pool.Transaction_pool.Resource_pool.Diff.t * Network_pool.Transaction_pool.Resource_pool.Diff.Rejected.t ) @@ -144,7 +144,7 @@ val add_full_transactions : val add_zkapp_transactions : t - -> Zkapp_command.t list + -> Zkapp_command.Stable.Latest.t list -> ( [ `Broadcasted | `Not_broadcasted ] * Network_pool.Transaction_pool.Resource_pool.Diff.t * Network_pool.Transaction_pool.Resource_pool.Diff.Rejected.t ) diff --git a/src/lib/mina_wire_types/mina_base/mina_base_zkapp_command.ml b/src/lib/mina_wire_types/mina_base/mina_base_zkapp_command.ml index 5b354e8b4c5..41afccd97ce 100644 --- a/src/lib/mina_wire_types/mina_base/mina_base_zkapp_command.ml +++ b/src/lib/mina_wire_types/mina_base/mina_base_zkapp_command.ml @@ -78,15 +78,15 @@ module Call_forest = struct end module V1 = struct - type t = - { fee_payer : Mina_base_account_update.Fee_payer.V1.t - ; account_updates : - ( Mina_base_account_update.V1.t - , Call_forest.Digest.Account_update.V1.t - , Call_forest.Digest.Forest.V1.t ) - Call_forest.V1.t - ; memo : Mina_base_signed_command_memo.V1.t - } + module T = struct + type 'a t = + { fee_payer : Mina_base_account_update.Fee_payer.V1.t + ; account_updates : 'a + ; memo : Mina_base_signed_command_memo.V1.t + } + end + + type t = (Mina_base_account_update.V1.t, unit, unit) Call_forest.V1.t T.t end module Valid = struct diff --git a/src/lib/mina_wire_types/mina_base/mina_base_zkapp_command.mli b/src/lib/mina_wire_types/mina_base/mina_base_zkapp_command.mli index d9a4dbf1c3e..5c68d480a6e 100644 --- a/src/lib/mina_wire_types/mina_base/mina_base_zkapp_command.mli +++ b/src/lib/mina_wire_types/mina_base/mina_base_zkapp_command.mli @@ -80,15 +80,15 @@ module Call_forest : sig end module V1 : sig - type t = - { fee_payer : Mina_base_account_update.Fee_payer.V1.t - ; account_updates : - ( Mina_base_account_update.V1.t - , Call_forest.Digest.Account_update.V1.t - , Call_forest.Digest.Forest.V1.t ) - Call_forest.V1.t - ; memo : Mina_base_signed_command_memo.V1.t - } + module T : sig + type 'a t = + { fee_payer : Mina_base_account_update.Fee_payer.V1.t + ; account_updates : 'a + ; memo : Mina_base_signed_command_memo.V1.t + } + end + + type t = (Mina_base_account_update.V1.t, unit, unit) Call_forest.V1.t T.t end module Valid : sig diff --git a/src/lib/mina_wire_types/mina_transaction.ml b/src/lib/mina_wire_types/mina_transaction.ml index 5e260e42a4e..c04f4aa5c57 100644 --- a/src/lib/mina_wire_types/mina_transaction.ml +++ b/src/lib/mina_wire_types/mina_transaction.ml @@ -10,9 +10,3 @@ end module V2 = struct type t = Mina_base.User_command.V2.t Poly.V2.t end - -module Valid = struct - module V2 = struct - type t = Mina_base.User_command.Valid.V2.t Poly.V2.t - end -end diff --git a/src/lib/mina_wire_types/test/type_equalities.ml b/src/lib/mina_wire_types/test/type_equalities.ml index 1fbb2428ae3..d92655ef35f 100644 --- a/src/lib/mina_wire_types/test/type_equalities.ml +++ b/src/lib/mina_wire_types/test/type_equalities.ml @@ -249,9 +249,7 @@ module Mina_base = struct include Assert_equal0V2 (O.Control.Stable) (W.Control) include Assert_equal0V1 (O.Account_update.Stable) (W.Account_update) include Assert_equal0V1 (O.Zkapp_command.Stable) (W.Zkapp_command) - include Assert_equal0V1 (O.Zkapp_command.Valid.Stable) (W.Zkapp_command.Valid) include Assert_equal0V2 (O.User_command.Stable) (W.User_command) - include Assert_equal0V2 (O.User_command.Valid.Stable) (W.User_command.Valid) include Assert_equal0V1 (O.Pending_coinbase.State_stack.Stable) @@ -318,7 +316,6 @@ module Mina_transaction = struct module W = WT.Mina_transaction include Assert_equal1V2 (O.Poly.Stable) (W.Poly) include Assert_equal0V2 (O.Stable) (W) - include Assert_equal0V2 (O.Valid.Stable) (W.Valid) end module Mina_state = struct diff --git a/src/lib/network_pool/indexed_pool.ml b/src/lib/network_pool/indexed_pool.ml index 7330e8e1600..c589e3970c1 100644 --- a/src/lib/network_pool/indexed_pool.ml +++ b/src/lib/network_pool/indexed_pool.ml @@ -66,7 +66,8 @@ let config t = t.config (* Compute the total currency required from the sender to execute a command. Returns None in case of overflow. *) -let currency_consumed_unchecked : User_command.t -> Currency.Amount.t option = +let currency_consumed_unchecked : + (_, _) User_command.with_forest -> Currency.Amount.t option = fun cmd -> let fee_amt = Currency.Amount.of_fee @@ User_command.fee cmd in let open Currency.Amount in @@ -90,7 +91,8 @@ let currency_consumed cmd = (Transaction_hash.User_command_with_valid_signature.command cmd) let currency_consumed' : - User_command.t -> (Currency.Amount.t, Command_error.t) Result.t = + (_, _) User_command.with_forest + -> (Currency.Amount.t, Command_error.t) Result.t = fun cmd -> cmd |> currency_consumed_unchecked |> Result.of_option ~error:Command_error.Overflow @@ -199,7 +201,8 @@ module For_tests = struct Set.iter data ~f:(check_fee key) ) ; Transaction_hash.Map.iteri pool.all_by_hash ~f:(fun ~key ~data -> [%test_eq: Transaction_hash.t] - (Transaction_hash.User_command_with_valid_signature.hash data) + (Transaction_hash.User_command_with_valid_signature.transaction_hash + data ) key ) end @@ -273,7 +276,7 @@ let global_slot_since_genesis conf = Mina_numbers.Global_slot_since_hard_fork.to_uint32 current_slot |> Mina_numbers.Global_slot_since_genesis.of_uint32 -let check_expiry t (cmd : User_command.t) = +let check_expiry t (cmd : (_, _) User_command.with_forest) = let global_slot_since_genesis = global_slot_since_genesis t in let valid_until = User_command.valid_until cmd in if Global_slot_since_genesis.(valid_until < global_slot_since_genesis) then @@ -327,7 +330,9 @@ let remove_all_by_fee_and_hash_and_expiration_exn : Transaction_hash.User_command_with_valid_signature.command cmd |> User_command.fee_per_wu in - let cmd_hash = Transaction_hash.User_command_with_valid_signature.hash cmd in + let cmd_hash = + Transaction_hash.User_command_with_valid_signature.transaction_hash cmd + in { t with all_by_fee = Map_set.remove_exn t.all_by_fee fee_per_wu cmd ; all_by_hash = Map.remove t.all_by_hash cmd_hash @@ -412,11 +417,12 @@ module Update = struct else acc in let cmd_hash = - Transaction_hash.User_command_with_valid_signature.hash cmd + Transaction_hash.User_command_with_valid_signature.transaction_hash + cmd in ( match Transaction_hash.User_command_with_valid_signature.data cmd with | Zkapp_command p -> - let p = Zkapp_command.Valid.forget p in + let p = Zkapp_command.(Valid.forget p |> unwrap) in let updates, proof_updates = let init = match @@ -515,8 +521,10 @@ let transactions ~logger t = in if Transaction_hash.equal - (Transaction_hash.User_command_with_valid_signature.hash txn) - (Transaction_hash.User_command_with_valid_signature.hash head_txn) + (Transaction_hash.User_command_with_valid_signature + .transaction_hash txn ) + (Transaction_hash.User_command_with_valid_signature + .transaction_hash head_txn ) then match F_sequence.uncons sender_queue' with | Some (next_txn, _) -> @@ -1177,7 +1185,9 @@ let add_from_backtrack : let%map () = check_expiry t.config unchecked in let fee_payer = User_command.fee_payer unchecked in let fee_per_wu = User_command.fee_per_wu unchecked in - let cmd_hash = Transaction_hash.User_command_with_valid_signature.hash cmd in + let cmd_hash = + Transaction_hash.User_command_with_valid_signature.transaction_hash cmd + in let consumed = Option.value_exn (currency_consumed cmd) in match Map.find t.all_by_sender fee_payer with | None -> @@ -1229,7 +1239,9 @@ let add_from_backtrack : t'.all_by_fee fee_per_wu cmd ; all_by_hash = Map.set t.all_by_hash - ~key:(Transaction_hash.User_command_with_valid_signature.hash cmd) + ~key: + (Transaction_hash.User_command_with_valid_signature + .transaction_hash cmd ) ~data:cmd ; all_by_sender = Map.set t'.all_by_sender ~key:fee_payer diff --git a/src/lib/network_pool/intf.ml b/src/lib/network_pool/intf.ml index 0666f01f9c9..91764e18a63 100644 --- a/src/lib/network_pool/intf.ml +++ b/src/lib/network_pool/intf.ml @@ -338,7 +338,7 @@ end module type Transaction_pool_diff_intf = sig type resource_pool - type t = User_command.t list [@@deriving of_yojson] + type t = User_command.Stable.Latest.t list [@@deriving of_yojson] module Diff_error : sig type t = @@ -360,7 +360,8 @@ module type Transaction_pool_diff_intf = sig end module Rejected : sig - type t = (User_command.t * Diff_error.t) list [@@deriving yojson] + type t = (User_command.Stable.Latest.t * Diff_error.t) list + [@@deriving yojson] end type Structured_log_events.t += diff --git a/src/lib/network_pool/test/indexed_pool_tests.ml b/src/lib/network_pool/test/indexed_pool_tests.ml index c3c33586d45..0249527f0ac 100644 --- a/src/lib/network_pool/test/indexed_pool_tests.ml +++ b/src/lib/network_pool/test/indexed_pool_tests.ml @@ -494,7 +494,8 @@ let commit_to_pool ledger pool cmd expected_drops = (Mina_ledger.Ledger.get ledger loc) ) in let lower = - List.map ~f:Transaction_hash.User_command_with_valid_signature.hash + List.map + ~f:Transaction_hash.User_command_with_valid_signature.transaction_hash in [%test_eq: Transaction_hash.t list] (lower (Sequence.to_list dropped)) @@ -507,7 +508,7 @@ let make_zkapp_command_payment ~(sender : Keypair.t) ~(receiver : Keypair.t) let nonce = Account.Nonce.of_int nonce_int in let sender_pk = Public_key.compress sender.public_key in let receiver_pk = Public_key.compress receiver.public_key in - let zkapp_command_wire : Zkapp_command.Stable.Latest.Wire.t = + let zkapp_command_wire : Zkapp_command.Stable.Latest.t = { fee_payer = { Account_update.Fee_payer.body = { public_key = sender_pk; fee; nonce; valid_until = None } @@ -567,7 +568,7 @@ let make_zkapp_command_payment ~(sender : Keypair.t) ~(receiver : Keypair.t) ; memo = Signed_command_memo.empty } in - let zkapp_command = Zkapp_command.of_wire zkapp_command_wire in + let zkapp_command = Zkapp_command.generate zkapp_command_wire in (* We skip signing the commitment and updating the authorization as it is not necessary to have a valid transaction for these tests. *) let (`If_this_is_used_it_should_have_a_comment_justifying_it cmd) = User_command.to_valid_unsafe (User_command.Zkapp_command zkapp_command) @@ -772,7 +773,8 @@ let apply_transactions txns accounts = in { a with nonce; balance } ) ) -let txn_hash = Transaction_hash.User_command_with_valid_signature.hash +let txn_hash = + Transaction_hash.User_command_with_valid_signature.transaction_hash let application_invalidates_applied_transactions () = Quickcheck.test ~trials:1000 diff --git a/src/lib/network_pool/transaction_pool.ml b/src/lib/network_pool/transaction_pool.ml index 1adc7cf9247..8d0855f6771 100644 --- a/src/lib/network_pool/transaction_pool.ml +++ b/src/lib/network_pool/transaction_pool.ml @@ -56,7 +56,7 @@ module Diff_versioned = struct the checks) and [set_from_gossip_exn] (which just does the mutating the pool), and do the same for snapp commands as well. *) - type t = User_command.t list [@@deriving sexp, yojson] + type t = User_command.Stable.Latest.t list [@@deriving sexp, yojson] module Diff_error = struct [%%versioned @@ -681,14 +681,16 @@ struct let cmd_hash = With_status.data cmd |> Transaction_hash.User_command_with_valid_signature.create - |> Transaction_hash.User_command_with_valid_signature.hash + |> Transaction_hash.User_command_with_valid_signature + .transaction_hash in Set.add set cmd_hash ) in Sequence.to_list dropped_commands |> List.partition_tf ~f:(fun cmd -> Set.mem command_hashes - (Transaction_hash.User_command_with_valid_signature.hash cmd) ) + (Transaction_hash.User_command_with_valid_signature + .transaction_hash cmd ) ) in List.iter committed_commands ~f:(fun cmd -> vk_table_lift_hashed vk_table_dec cmd ; @@ -826,12 +828,10 @@ struct ~time_controller ~slot_tx_end:config.Config.slot_tx_end ; locally_generated_uncommitted = Hashtbl.create - ( module Transaction_hash.User_command_with_valid_signature.Stable - .Latest ) + (module Transaction_hash.User_command_with_valid_signature) ; locally_generated_committed = Hashtbl.create - ( module Transaction_hash.User_command_with_valid_signature.Stable - .Latest ) + (module Transaction_hash.User_command_with_valid_signature) ; current_batch = 0 ; remaining_in_batch = max_per_15_seconds ; config @@ -947,7 +947,7 @@ struct type pool = t module Diff = struct - type t = User_command.t list [@@deriving sexp, yojson] + type t = User_command.Stable.Latest.t list [@@deriving sexp, yojson] let (_ : (t, Diff_versioned.t) Type_equal.t) = Type_equal.T @@ -998,7 +998,7 @@ struct end module Rejected = struct - type t = (User_command.t * Diff_error.t) list + type t = (User_command.Stable.Latest.t * Diff_error.t) list [@@deriving sexp, yojson, compare] let (_ : (t, Diff_versioned.Rejected.t) Type_equal.t) = Type_equal.T @@ -1011,6 +1011,7 @@ struct let reject_overloaded_diff (diff : verified) : rejected = List.map diff ~f:(fun cmd -> ( Transaction_hash.User_command_with_valid_signature.command cmd + |> User_command.unwrap , Diff_error.Overloaded ) ) let empty = [] @@ -1082,8 +1083,39 @@ struct | _ -> () + let load_vk_cache ~t ~ledger account_ids = + let account_ids = Set.to_list account_ids in + let ledger_vks = + Zkapp_command.Verifiable.load_vks_from_ledger + ~location_of_account_batch: + (Base_ledger.location_of_account_batch ledger) + ~get_batch:(Base_ledger.get_batch ledger) + account_ids + in + let ledger_vks = + Map.map ledger_vks ~f:(fun vk -> + Zkapp_basic.F_map.Map.singleton vk.hash vk ) + in + let mempool_vks = + List.map account_ids ~f:(fun account_id -> + let vks = + Vk_refcount_table.find_vks_by_account_id + t.verification_key_table account_id + in + let vks = + vks + |> List.map ~f:(fun vk -> (vk.hash, vk)) + |> Zkapp_basic.F_map.Map.of_alist_exn + in + (account_id, vks) ) + |> Account_id.Map.of_alist_exn + in + Map.merge_skewed ledger_vks mempool_vks ~combine:(fun ~key:_ -> + Map.merge_skewed ~combine:(fun ~key:_ _ x -> x) ) + (** DO NOT mutate any transaction pool state in this function, you may only mutate in the synchronous `apply` function. *) - let verify (t : pool) (diff : t Envelope.Incoming.t) : + let verify (t : pool) + Envelope.Incoming.{ data = diff; sender; received_at } : ( verified Envelope.Incoming.t , Intf.Verification_error.t ) Deferred.Result.t = @@ -1091,8 +1123,7 @@ struct let open Intf.Verification_error in let%bind () = let well_formedness_errors = - List.fold (Envelope.Incoming.data diff) ~init:[] - ~f:(fun acc user_cmd -> + List.fold diff ~init:[] ~f:(fun acc user_cmd -> match User_command.check_well_formedness ~genesis_constants:t.config.genesis_constants @@ -1105,10 +1136,8 @@ struct "User command $cmd from $sender has one or more \ well-formedness errors." ~metadata: - [ ("cmd", User_command.to_yojson user_cmd) - ; ( "sender" - , Envelope.(Sender.to_yojson (Incoming.sender diff)) - ) + [ ("cmd", User_command.Stable.Latest.to_yojson user_cmd) + ; ("sender", Envelope.Sender.to_yojson sender) ; ( "errors" , `List (List.map errs @@ -1146,48 +1175,18 @@ struct "We don't have a transition frontier at the moment, so \ we're unable to verify any transactions." ) in - - let%bind diff' = + let%bind verified_diff = O1trace.sync_thread "convert_transactions_to_verifiable" (fun () -> - Envelope.Incoming.map diff ~f:(fun diff -> - User_command.Unapplied_sequence.to_all_verifiable diff - ~load_vk_cache:(fun account_ids -> - let account_ids = Set.to_list account_ids in - let ledger_vks = - Zkapp_command.Verifiable.load_vks_from_ledger - ~location_of_account_batch: - (Base_ledger.location_of_account_batch ledger) - ~get_batch:(Base_ledger.get_batch ledger) - account_ids - in - let ledger_vks = - Map.map ledger_vks ~f:(fun vk -> - Zkapp_basic.F_map.Map.singleton vk.hash vk ) - in - let mempool_vks = - List.map account_ids ~f:(fun account_id -> - let vks = - Vk_refcount_table.find_vks_by_account_id - t.verification_key_table account_id - in - let vks = - vks - |> List.map ~f:(fun vk -> (vk.hash, vk)) - |> Zkapp_basic.F_map.Map.of_alist_exn - in - (account_id, vks) ) - |> Account_id.Map.of_alist_exn - in - Map.merge_skewed ledger_vks mempool_vks - ~combine:(fun ~key:_ -> - Map.merge_skewed ~combine:(fun ~key:_ _ x -> x) ) ) ) ) - |> Envelope.Incoming.lift_error + List.map ~f:User_command.generate diff + |> User_command.Unapplied_sequence.to_all_verifiable + ~load_vk_cache:(load_vk_cache ~t ~ledger) ) |> Result.map_error ~f:(fun e -> Invalid e) |> Deferred.return in match%bind.Deferred O1trace.thread "batching_transaction_verification" (fun () -> - Batcher.verify t.batcher diff' ) + Batcher.verify t.batcher + { Envelope.Incoming.data = verified_diff; received_at; sender } ) with | Error e -> [%log' error t.logger] "Transaction verification error: $error" @@ -1195,9 +1194,7 @@ struct [%log' debug t.logger] "Failed to batch verify $transaction_pool_diff" ~metadata: - [ ( "transaction_pool_diff" - , Diff_versioned.to_yojson (Envelope.Incoming.data diff) ) - ] ; + [ ("transaction_pool_diff", Diff_versioned.to_yojson diff) ] ; Deferred.Result.fail (Failure e) | Ok (Error invalid) -> let err = Verifier.invalid_to_error invalid in @@ -1206,7 +1203,7 @@ struct ~metadata:[ ("error", Error_json.error_to_yojson err) ] ; let%map.Deferred () = Trust_system.record_envelope_sender t.config.trust_system t.logger - (Envelope.Incoming.sender diff) + sender ( Trust_system.Actions.Sent_useless_gossip , Some ( "rejecting command because had invalid signature or proof" @@ -1218,8 +1215,9 @@ struct O1trace.sync_thread "hashing_transactions_after_verification" (fun () -> return - { diff with - data = + { Envelope.Incoming.received_at + ; sender + ; data = List.map commands ~f: Transaction_hash.User_command_with_valid_signature @@ -1371,12 +1369,16 @@ struct in let dropped_for_add_hashes = List.map dropped_for_add - ~f:Transaction_hash.User_command_with_valid_signature.hash + ~f: + Transaction_hash.User_command_with_valid_signature + .transaction_hash |> Transaction_hash.Set.of_list in let dropped_for_size_hashes = List.map dropped_for_size - ~f:Transaction_hash.User_command_with_valid_signature.hash + ~f: + Transaction_hash.User_command_with_valid_signature + .transaction_hash |> Transaction_hash.Set.of_list in let all_dropped_cmd_hashes = @@ -1414,8 +1416,8 @@ struct if not (Set.mem all_dropped_cmd_hashes - (Transaction_hash.User_command_with_valid_signature.hash - cmd ) ) + (Transaction_hash.User_command_with_valid_signature + .transaction_hash cmd ) ) then register_locally_generated t cmd | Error _ -> () ) ; @@ -1438,7 +1440,8 @@ struct *) if Set.mem all_dropped_cmd_hashes - (Transaction_hash.User_command_with_valid_signature.hash cmd) + (Transaction_hash.User_command_with_valid_signature + .transaction_hash cmd ) then `Trd cmd else `Fst cmd | Error (cmd, error) -> @@ -1465,13 +1468,14 @@ struct Time.(now () |> to_span_since_epoch |> Span.to_sec) in x -. Mina_metrics.time_offset_sec )) ) ; - let forget_cmd = - Transaction_hash.User_command_with_valid_signature.command + let f = + Fn.compose User_command.unwrap + Transaction_hash.User_command_with_valid_signature.command in Ok ( decision - , List.map ~f:forget_cmd accepted - , List.map ~f:(Tuple2.map_fst ~f:forget_cmd) rejected ) + , List.map ~f accepted + , List.map ~f:(Tuple2.map_fst ~f) rejected ) | Error e -> Error (`Other e) @@ -1529,10 +1533,13 @@ struct [%log internal] "%s" ("Transaction_diff_" ^ msg) ~metadata let t_of_verified = - List.map ~f:Transaction_hash.User_command_with_valid_signature.command + List.map + ~f: + (Fn.compose User_command.unwrap + Transaction_hash.User_command_with_valid_signature.command ) end - let get_rebroadcastable (t : t) ~has_timed_out = + let get_rebroadcastable (t : t) ~has_timed_out : Diff.t list = let metadata ~key ~time = [ ( "cmd" , Transaction_hash.User_command_with_valid_signature.to_yojson key ) @@ -1565,37 +1572,35 @@ struct | `Ok -> true ) ; (* Important to maintain ordering here *) - let rebroadcastable_txs = - Hashtbl.to_alist t.locally_generated_uncommitted - |> List.sort - ~compare:(fun (txn1, (_, `Batch batch1)) (txn2, (_, `Batch batch2)) - -> - let cmp = compare batch1 batch2 in - let get_hash = - Transaction_hash.User_command_with_valid_signature.hash - in - let get_nonce txn = - Transaction_hash.User_command_with_valid_signature.command txn - |> User_command.applicable_at_nonce + Hashtbl.to_alist t.locally_generated_uncommitted + |> List.sort + ~compare:(fun (txn1, (_, `Batch batch1)) (txn2, (_, `Batch batch2)) + -> + let cmp = compare batch1 batch2 in + let get_hash = + Transaction_hash.User_command_with_valid_signature + .transaction_hash + in + let get_nonce txn = + Transaction_hash.User_command_with_valid_signature.command txn + |> User_command.applicable_at_nonce + in + if cmp <> 0 then cmp + else + let cmp = + Mina_numbers.Account_nonce.compare (get_nonce txn1) + (get_nonce txn2) in if cmp <> 0 then cmp - else - let cmp = - Mina_numbers.Account_nonce.compare (get_nonce txn1) - (get_nonce txn2) - in - if cmp <> 0 then cmp - else Transaction_hash.compare (get_hash txn1) (get_hash txn2) ) - |> List.group - ~break:(fun (_, (_, `Batch batch1)) (_, (_, `Batch batch2)) -> - batch1 <> batch2 ) - |> List.map - ~f: - (List.map ~f:(fun (txn, _) -> - Transaction_hash.User_command_with_valid_signature.command - txn ) ) - in - rebroadcastable_txs + else Transaction_hash.compare (get_hash txn1) (get_hash txn2) ) + |> List.group + ~break:(fun (_, (_, `Batch batch1)) (_, (_, `Batch batch2)) -> + batch1 <> batch2 ) + |> List.map + ~f: + (List.map ~f:(fun (txn, _) -> + Transaction_hash.User_command_with_valid_signature.command txn + |> User_command.unwrap ) ) end include Network_pool_base.Make (Transition_frontier) (Resource_pool) @@ -1819,7 +1824,8 @@ let%test_module _ = let report_additional commands a b = Core.Printf.printf "%s user commands not in %s:\n" a b ; List.iter commands ~f:(fun c -> - Core.Printf.printf !" %{Sexp}\n" (User_command.sexp_of_t c) ) + Core.Printf.printf !" %{Sexp}\n" + (User_command.Stable.Latest.sexp_of_t c) ) in if List.length additional1 > 0 then report_additional additional1 "actual" "expected" ; @@ -1921,9 +1927,9 @@ let%test_module _ = @@ Sequence.map ~f:Transaction_hash.User_command.of_checked @@ Test.Resource_pool.transactions test.txn_pool ) (List.map - ~f: - (Fn.compose Transaction_hash.User_command.create - User_command.forget_check ) + ~f:(fun tx -> + Transaction_hash.User_command.create + User_command.(forget_check tx |> unwrap) ) txs ) let setup_test ?(verifier = verifier) ?permissions ?slot_tx_end () = @@ -2169,11 +2175,12 @@ let%test_module _ = replace_valid_zkapp_command_authorizations ~keymap ~ledger:best_tip_ledger valid_zkapp_commands - type pool_apply = (User_command.t list, [ `Other of Error.t ]) Result.t + type pool_apply = + (User_command.Stable.Latest.t list, [ `Other of Error.t ]) Result.t [@@deriving sexp, compare] let canonicalize t = - Result.map t ~f:(List.sort ~compare:User_command.compare) + Result.map t ~f:(List.sort ~compare:User_command.Stable.Latest.compare) let compare_pool_apply (t1 : pool_apply) (t2 : pool_apply) = compare_pool_apply (canonicalize t1) (canonicalize t2) @@ -2183,7 +2190,10 @@ let%test_module _ = Result.map result ~f:(fun (_, accepted, _) -> accepted) in [%test_eq: pool_apply] accepted_commands - (Ok (List.map ~f:User_command.forget_check expected_commands)) + (Ok + (List.map + ~f:User_command.(Fn.compose unwrap forget_check) + expected_commands ) ) let mk_with_status (cmd : User_command.Valid.t) = { With_status.data = cmd; status = Applied } @@ -2203,7 +2213,8 @@ let%test_module _ = let%map verified = Test.Resource_pool.Diff.verify test.txn_pool (Envelope.Incoming.wrap - ~data:(List.map ~f:User_command.forget_check cs) + ~data: + (List.map ~f:User_command.(Fn.compose unwrap forget_check) cs) ~sender ) >>| Fn.compose Or_error.ok_exn (Result.map_error ~f:Intf.Verification_error.to_error) @@ -2222,7 +2233,7 @@ let%test_module _ = Core.Printf.printf !"command was rejected because %s: %{Yojson.Safe}\n%!" (Diff_versioned.Diff_error.to_string_name err) - (User_command.to_yojson cmd) ) + (User_command.Stable.Latest.to_yojson cmd) ) | Ok (`Reject, _, _) -> failwith "diff was rejected during application" | Error (`Other err) -> @@ -2782,10 +2793,9 @@ let%test_module _ = let expected = if List.is_empty cmds then [] else - [ List.map cmds - ~f: - (Fn.compose Transaction_hash.User_command.create - User_command.forget_check ) + [ List.map cmds ~f:(fun tx -> + Transaction_hash.User_command.create + User_command.(forget_check tx |> unwrap) ) ] in let actual = @@ -2842,7 +2852,7 @@ let%test_module _ = ignore ( Test.Resource_pool.get_rebroadcastable t.txn_pool ~has_timed_out:(Fn.const `Timed_out) - : User_command.t list list ) ; + : User_command.Stable.Latest.t list list ) ; assert_rebroadcastable t [] ; Deferred.unit @@ -3107,14 +3117,14 @@ let%test_module _ = ~fee_payer_idx:0 ~fee:minimum_fee ~nonce:0 ~zkapp_account_idx:1 ~ledger:(Option.value_exn test.txn_pool.best_tip_ledger) in + let tx = + User_command.Zkapp_command + (Zkapp_command.Valid.of_verifiable zkapp_command) + in match%map Test.Resource_pool.Diff.verify test.txn_pool (Envelope.Incoming.wrap - ~data: - [ User_command.forget_check - @@ Zkapp_command - (Zkapp_command.Valid.of_verifiable zkapp_command) - ] + ~data:[ User_command.(forget_check tx |> unwrap) ] ~sender:Envelope.Sender.Local ) with | Error (Intf.Verification_error.Invalid e) -> diff --git a/src/lib/snark_work_lib/work.ml b/src/lib/snark_work_lib/work.ml index 9b288ea26cc..5225392828f 100644 --- a/src/lib/snark_work_lib/work.ml +++ b/src/lib/snark_work_lib/work.ml @@ -25,11 +25,11 @@ module Single = struct | Merge of Transaction_snark.Statement.t * 'ledger_proof * 'ledger_proof [@@deriving sexp, yojson] - let map_proof ~f = function + let map ~f_proof ~f_witness = function | Transition (stmt, w) -> - Transition (stmt, w) + Transition (stmt, f_witness w) | Merge (stmt, p1, p2) -> - Merge (stmt, f p1, f p2) + Merge (stmt, f_proof p1, f_proof p2) let witness (t : (_, _) t) = match t with Transition (_, witness) -> Some witness | Merge _ -> None diff --git a/src/lib/snark_worker/functor.ml b/src/lib/snark_worker/functor.ml index 5c1cdbba827..39effb18350 100644 --- a/src/lib/snark_worker/functor.ml +++ b/src/lib/snark_worker/functor.ml @@ -67,12 +67,16 @@ module Make (Inputs : Intf.Inputs_intf) : module Single = struct module Spec = struct - type t = (Transaction_witness.t, Ledger_proof.t) Work.Single.Spec.t + type t = + ( Transaction_witness.Stable.Latest.t + , Ledger_proof.t ) + Work.Single.Spec.t [@@deriving sexp, yojson] let transaction t = Option.map (Work.Single.Spec.witness t) ~f:(fun w -> - w.Transaction_witness.transaction ) + w.Transaction_witness.Stable.Latest.transaction + |> Mina_transaction.Transaction.generate ) let statement = Work.Single.Spec.statement end @@ -164,7 +168,7 @@ module Make (Inputs : Intf.Inputs_intf) : let init = match (Mina_base.Account_update.of_fee_payer - zkapp_command.Mina_base.Zkapp_command.fee_payer ) + zkapp_command.Mina_base.Zkapp_command.Poly.fee_payer ) .authorization with | Proof _ -> diff --git a/src/lib/snark_worker/intf.ml b/src/lib/snark_worker/intf.ml index 2a9d93bb03c..afe0c002f0d 100644 --- a/src/lib/snark_worker/intf.ml +++ b/src/lib/snark_worker/intf.ml @@ -23,7 +23,7 @@ module type Inputs_intf = sig val perform_single : Worker_state.t -> message:Mina_base.Sok_message.t - -> (Transaction_witness.t, Ledger_proof.t) Work.Single.Spec.t + -> (Transaction_witness.Stable.Latest.t, Ledger_proof.t) Work.Single.Spec.t -> (Ledger_proof.t * Time.Span.t) Deferred.Or_error.t end @@ -65,7 +65,8 @@ module type Work_S = sig module Single : sig module Spec : sig - type t = (Transaction_witness.t, ledger_proof) Work.Single.Spec.t + type t = + (Transaction_witness.Stable.Latest.t, ledger_proof) Work.Single.Spec.t [@@deriving sexp, yojson] end end diff --git a/src/lib/snark_worker/prod.ml b/src/lib/snark_worker/prod.ml index 08c9bfbe697..7ffc8cd0723 100644 --- a/src/lib/snark_worker/prod.ml +++ b/src/lib/snark_worker/prod.ml @@ -56,12 +56,26 @@ module Inputs = struct Snark_work_lib.Work.Single.Spec.Stable.Latest.t [@@deriving bin_io_unversioned, sexp] - type zkapp_command_inputs = - ( Transaction_witness.Zkapp_command_segment_witness.t - * Transaction_snark.Zkapp_command_segment.Basic.t - * Transaction_snark.Statement.With_sok.t ) - list - [@@deriving sexp, to_yojson] + let zkapp_command_inputs_to_yojson = + let convert = + List.map + ~f:(fun + ( (witness : Transaction_witness.Zkapp_command_segment_witness.t) + , segment + , statement ) + -> + ( Transaction_witness.Zkapp_command_segment_witness.unwrap witness + , segment + , statement ) ) + in + let impl = + [%to_yojson: + ( Transaction_witness.Zkapp_command_segment_witness.Stable.Latest.t + * Transaction_snark.Zkapp_command_segment.Basic.t + * Transaction_snark.Statement.With_sok.t ) + list] + in + Fn.compose impl convert let perform_single ({ m; cache; proof_level } : Worker_state.t) ~message = let open Deferred.Or_error.Let_syntax in @@ -99,8 +113,8 @@ module Inputs = struct Deferred.Or_error.return (proof, Time.Span.zero) | None -> ( match single with - | Work.Single.Spec.Transition (input, (w : Transaction_witness.t)) - -> + | Work.Single.Spec.Transition + (input, (w : Transaction_witness.Stable.Latest.t)) -> process (fun () -> match w.transaction with | Command (Zkapp_command zkapp_command) -> ( @@ -124,14 +138,15 @@ module Inputs = struct , `Sparse_ledger w.second_pass_ledger , `Connecting_ledger_hash input.connecting_ledger_left - , zkapp_command ) + , Zkapp_command.generate zkapp_command ) ] |> List.rev ) |> Result.map_error ~f:(fun e -> Error.createf !"Failed to generate inputs for \ zkapp_command : %s: %s" - ( Zkapp_command.to_yojson zkapp_command + ( Zkapp_command.Stable.Latest.to_yojson + zkapp_command |> Yojson.Safe.to_string ) (Error.to_string_hum e) ) |> Deferred.return diff --git a/src/lib/snark_worker/rpcs.ml b/src/lib/snark_worker/rpcs.ml index 15d736c2cfb..9a070e5dbd9 100644 --- a/src/lib/snark_worker/rpcs.ml +++ b/src/lib/snark_worker/rpcs.ml @@ -25,7 +25,9 @@ module Make (Inputs : Intf.Inputs_intf) = struct type query = unit type response = - ( (Transaction_witness.t, Ledger_proof.t) Work.Single.Spec.t + ( ( Transaction_witness.Stable.Latest.t + , Ledger_proof.t ) + Work.Single.Spec.t Work.Spec.t * Public_key.Compressed.t ) option @@ -45,7 +47,9 @@ module Make (Inputs : Intf.Inputs_intf) = struct module T = struct type query = - ( (Transaction_witness.t, Ledger_proof.t) Work.Single.Spec.t + ( ( Transaction_witness.Stable.Latest.t + , Ledger_proof.t ) + Work.Single.Spec.t Work.Spec.t , Ledger_proof.t ) Work.Result.t @@ -68,7 +72,9 @@ module Make (Inputs : Intf.Inputs_intf) = struct module T = struct type query = Error.t - * (Transaction_witness.t, Ledger_proof.t) Work.Single.Spec.t + * ( Transaction_witness.Stable.Latest.t + , Ledger_proof.t ) + Work.Single.Spec.t Work.Spec.t * Public_key.Compressed.t diff --git a/src/lib/snark_worker/standalone/run_snark_worker.ml b/src/lib/snark_worker/standalone/run_snark_worker.ml index 9dc29333f07..01fde073ba3 100644 --- a/src/lib/snark_worker/standalone/run_snark_worker.ml +++ b/src/lib/snark_worker/standalone/run_snark_worker.ml @@ -35,7 +35,9 @@ let submit_graphql input graphql_endpoint = let perform (s : Prod.Worker_state.t) ~fee ~public_key (spec : - (Transaction_witness.t, Ledger_proof.t) Snark_work_lib.Work.Single.Spec.t + ( Transaction_witness.Stable.Latest.t + , Ledger_proof.t ) + Snark_work_lib.Work.Single.Spec.t One_or_two.t ) = One_or_two.Deferred_result.map spec ~f:(fun w -> let open Deferred.Or_error.Let_syntax in @@ -122,7 +124,8 @@ let command = Yojson.Safe.from_string json |> One_or_two.of_yojson (Snark_work_lib.Work.Single.Spec.of_yojson - Transaction_witness.of_yojson Ledger_proof.of_yojson ) + Transaction_witness.Stable.Latest.of_yojson + Ledger_proof.of_yojson ) with | Ok spec -> spec @@ -144,7 +147,8 @@ let command = | Some spec -> One_or_two.t_of_sexp (Snark_work_lib.Work.Single.Spec.t_of_sexp - Transaction_witness.t_of_sexp Ledger_proof.t_of_sexp ) + Transaction_witness.Stable.Latest.t_of_sexp + Ledger_proof.t_of_sexp ) (Sexp.of_string spec) | None -> failwith "Provide a spec either in json or sexp format" ) ) diff --git a/src/lib/staged_ledger/staged_ledger.mli b/src/lib/staged_ledger/staged_ledger.mli index ad4b0acf582..96fcd4ef78a 100644 --- a/src/lib/staged_ledger/staged_ledger.mli +++ b/src/lib/staged_ledger/staged_ledger.mli @@ -47,7 +47,6 @@ module Scan_state : sig end type t = Transaction_snark_scan_state.Transaction_with_witness.t Poly.t - [@@deriving sexp, to_yojson] end val hash : t -> Staged_ledger_hash.Aux_hash.t diff --git a/src/lib/staged_ledger_diff/body.ml b/src/lib/staged_ledger_diff/body.ml index 84f3b67adc8..e6c9b718593 100644 --- a/src/lib/staged_ledger_diff/body.ml +++ b/src/lib/staged_ledger_diff/body.ml @@ -12,7 +12,7 @@ module Make_str (A : Wire_types.Concrete) = struct module V1 = struct type t = A.V1.t = { staged_ledger_diff : Diff.Stable.V2.t } - [@@deriving fields] + [@@deriving fields, sexp] let to_latest = Fn.id diff --git a/src/lib/staged_ledger_diff/body_intf.ml b/src/lib/staged_ledger_diff/body_intf.ml index 778cc4164bc..5aed7c929cb 100644 --- a/src/lib/staged_ledger_diff/body_intf.ml +++ b/src/lib/staged_ledger_diff/body_intf.ml @@ -4,7 +4,7 @@ module type Full = sig [@@@no_toplevel_latest_type] module V1 : sig - type t + type t [@@deriving sexp] val create : Diff.Stable.V2.t -> t diff --git a/src/lib/staged_ledger_diff/diff.ml b/src/lib/staged_ledger_diff/diff.ml index d9ad504f9a7..53c248c656e 100644 --- a/src/lib/staged_ledger_diff/diff.ml +++ b/src/lib/staged_ledger_diff/diff.ml @@ -169,7 +169,7 @@ 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 yojson] + [@@deriving sexp, yojson] let to_latest = Fn.id end @@ -181,10 +181,11 @@ module Make_str (A : Wire_types.Concrete) = struct let generate ~proof_cache_db : Stable.Latest.t -> t = Pre_diff_two.map ~f1:(Transaction_snark_work.generate ~proof_cache_db) - ~f2:Fn.id + ~f2:(With_status.map ~f:User_command.generate) let unwrap : t -> Stable.Latest.t = - Pre_diff_two.map ~f1:Transaction_snark_work.unwrap ~f2:Fn.id + Pre_diff_two.map ~f1:Transaction_snark_work.unwrap + ~f2:(With_status.map ~f:User_command.unwrap) end module Pre_diff_with_at_most_one_coinbase = struct @@ -197,7 +198,7 @@ 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 yojson] + [@@deriving sexp, yojson] let to_latest = Fn.id end @@ -209,10 +210,11 @@ module Make_str (A : Wire_types.Concrete) = struct let generate ~proof_cache_db : Stable.Latest.t -> t = Pre_diff_one.map ~f1:(Transaction_snark_work.generate ~proof_cache_db) - ~f2:Fn.id + ~f2:(With_status.map ~f:User_command.generate) let unwrap : t -> Stable.Latest.t = - Pre_diff_one.map ~f1:Transaction_snark_work.unwrap ~f2:Fn.id + Pre_diff_one.map ~f1:Transaction_snark_work.unwrap + ~f2:(With_status.map ~f:User_command.unwrap) end module Diff = struct @@ -224,7 +226,7 @@ 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 yojson] + [@@deriving sexp, yojson] let to_latest = Fn.id end @@ -258,7 +260,7 @@ module Make_str (A : Wire_types.Concrete) = struct [@@@no_toplevel_latest_type] module V2 = struct - type t = A.V2.t = { diff : Diff.Stable.V2.t } [@@deriving yojson] + type t = A.V2.t = { diff : Diff.Stable.V2.t } [@@deriving sexp, yojson] let to_latest = Fn.id diff --git a/src/lib/staged_ledger_diff/diff_intf.ml b/src/lib/staged_ledger_diff/diff_intf.ml index b864d82b6b5..602fd113e1d 100644 --- a/src/lib/staged_ledger_diff/diff_intf.ml +++ b/src/lib/staged_ledger_diff/diff_intf.ml @@ -114,7 +114,7 @@ module type Full = sig module Stable : sig module V2 : sig - type t [@@deriving bin_io, version, yojson] + type t [@@deriving bin_io, version, yojson, sexp] val to_latest : t -> t diff --git a/src/lib/transaction/transaction.ml b/src/lib/transaction/transaction.ml index b45b0361c3e..a30f951e9ba 100644 --- a/src/lib/transaction/transaction.ml +++ b/src/lib/transaction/transaction.ml @@ -26,22 +26,20 @@ module Poly = struct end module Valid = struct - [%%versioned - module Stable = struct - module V2 = struct - type t = User_command.Valid.Stable.V2.t Poly.Stable.V2.t - [@@deriving sexp, compare, equal, hash, yojson] - - let to_latest = Fn.id - end - end] + module T = struct + type t = User_command.Valid.t Poly.t + [@@deriving sexp, compare, equal, hash, yojson] + end - include Hashable.Make (Stable.Latest) - include Comparable.Make (Stable.Latest) + include T + include Hashable.Make (T) + include Comparable.Make (T) end [%%versioned module Stable = struct + [@@@no_toplevel_latest_type] + module V2 = struct type t = User_command.Stable.V2.t Poly.Stable.V2.t [@@deriving sexp, compare, equal, hash, yojson] @@ -50,8 +48,13 @@ module Stable = struct end end] -include Hashable.Make (Stable.Latest) -include Comparable.Make (Stable.Latest) +type t = User_command.t Poly.t [@@deriving sexp, yojson] + +let unwrap : t -> Stable.Latest.t = + Poly.Stable.Latest.map ~f:User_command.unwrap + +let generate : Stable.Latest.t -> t = + Poly.Stable.Latest.map ~f:User_command.generate type 'command t_ = 'command Poly.t = | Command of 'command @@ -169,7 +172,7 @@ let yojson_summary_of_command = in function | User_command.Zkapp_command cmd -> - mk_record (zkapp_type cmd) (Zkapp_command.memo cmd) + mk_record (zkapp_type cmd) cmd.Zkapp_command.Poly.memo ( Zkapp_command.fee_payer_account_update cmd |> Account_update.Fee_payer.authorization ) | Signed_command cmd -> diff --git a/src/lib/transaction/transaction_hash.ml b/src/lib/transaction/transaction_hash.ml index b7870d61d95..499e8c88365 100644 --- a/src/lib/transaction/transaction_hash.ml +++ b/src/lib/transaction/transaction_hash.ml @@ -74,7 +74,7 @@ let ( hash_signed_command_v1 let cmd_dummy_signature = { cmd with signature = Signature.dummy } in signed_cmd_hasher cmd_dummy_signature in - let hash_zkapp_command (cmd : Zkapp_command.t) = + let hash_zkapp_command (cmd : Zkapp_command.Stable.Latest.t) = let cmd_dummy_signatures_and_proofs = { cmd with fee_payer = { cmd.fee_payer with authorization = Signature.dummy } @@ -106,6 +106,9 @@ let ( hash_signed_command_v1 , hash_coinbase , hash_fee_transfer ) +let hash_wrapped_zkapp_command = + Fn.compose hash_zkapp_command Zkapp_command.unwrap + let hash_command cmd = match cmd with | User_command.Signed_command s -> @@ -113,6 +116,8 @@ let hash_command cmd = | User_command.Zkapp_command p -> hash_zkapp_command p +let hash_wrapped_command = Fn.compose hash_command User_command.unwrap + let hash_signed_command_v2 = hash_signed_command let hash_of_transaction_id (transaction_id : string) : t Or_error.t = @@ -168,37 +173,35 @@ module User_command_with_valid_signature = struct let hash_of_yojson = of_yojson - [%%versioned - module Stable = struct - module V2 = struct - type t = - ( (User_command.Valid.Stable.V2.t[@hash.ignore]) - , (T.Stable.V1.t[@to_yojson hash_to_yojson]) ) - With_hash.Stable.V1.t - [@@deriving sexp, hash, to_yojson] - - let to_latest = Fn.id - - (* Compare only on hashes, comparing on the data too would be slower and - add no value. - *) - let compare (x : t) (y : t) = T.compare x.hash y.hash - end - end] + type t = (User_command.Valid.t, hash) With_hash.t + [@@deriving hash, sexp, compare, to_yojson] let create (c : User_command.Valid.t) : t = - { data = c; hash = hash_command (User_command.forget_check c) } + { data = c + ; hash = hash_command (User_command.unwrap @@ User_command.forget_check c) + } let data ({ data; _ } : t) = data let command ({ data; _ } : t) = User_command.forget_check data - let hash ({ hash; _ } : t) = hash + let transaction_hash ({ hash; _ } : t) = hash let forget_check ({ data; hash } : t) = { With_hash.data = User_command.forget_check data; hash } - include Comparable.Make (Stable.Latest) + include Comparable.Make (struct + type nonrec t = t + + let sexp_of_t = sexp_of_t + + let t_of_sexp = t_of_sexp + + (* Compare only on hashes, comparing on the data too would be slower and + add no value. + *) + let compare (x : t) (y : t) = T.compare x.hash y.hash + end) let make data hash : t = { data; hash } end @@ -228,7 +231,8 @@ module User_command = struct end end] - let create (c : User_command.t) : t = { data = c; hash = hash_command c } + let create (c : User_command.Stable.Latest.t) : t = + { data = c; hash = hash_command c } let data ({ data; _ } : t) = data @@ -237,7 +241,7 @@ module User_command = struct let hash ({ hash; _ } : t) = hash let of_checked ({ data; hash } : User_command_with_valid_signature.t) : t = - { With_hash.data = User_command.forget_check data; hash } + { With_hash.data = User_command.(unwrap @@ forget_check data); hash } include Comparable.Make (Stable.Latest) end diff --git a/src/lib/transaction/transaction_hash.mli b/src/lib/transaction/transaction_hash.mli index c5a4e42b0b4..4fe35c242e1 100644 --- a/src/lib/transaction/transaction_hash.mli +++ b/src/lib/transaction/transaction_hash.mli @@ -31,9 +31,13 @@ val hash_signed_command : Signed_command.t -> t val hash_signed_command_v1 : Signed_command.Stable.V1.t -> t -val hash_zkapp_command : Zkapp_command.t -> t +val hash_zkapp_command : Zkapp_command.Stable.Latest.t -> t -val hash_command : User_command.t -> t +val hash_command : User_command.Stable.Latest.t -> t + +val hash_wrapped_zkapp_command : Zkapp_command.t -> t + +val hash_wrapped_command : User_command.t -> t val hash_fee_transfer : Fee_transfer.Single.t -> t @@ -51,19 +55,8 @@ include Comparable.S with type t := t module User_command_with_valid_signature : sig type hash = t [@@deriving sexp, compare, hash, yojson] - [%%versioned: - module Stable : sig - [@@@no_toplevel_latest_type] - - module V2 : sig - type t = - private - (User_command.Valid.Stable.V2.t, hash) With_hash.Stable.V1.t - [@@deriving sexp, compare, hash, to_yojson] - end - end] - - type t = Stable.Latest.t [@@deriving sexp, compare, to_yojson] + type t = private (User_command.Valid.t, hash) With_hash.t + [@@deriving hash, sexp, compare, to_yojson] val create : User_command.Valid.t -> t @@ -71,7 +64,7 @@ module User_command_with_valid_signature : sig val command : t -> User_command.t - val hash : t -> hash + val transaction_hash : t -> hash val forget_check : t -> (User_command.t, hash) With_hash.t @@ -95,11 +88,11 @@ module User_command : sig type t = Stable.Latest.t [@@deriving sexp, compare, to_yojson] - val create : User_command.t -> t + val create : User_command.Stable.Latest.t -> t - val data : t -> User_command.t + val data : t -> User_command.Stable.Latest.t - val command : t -> User_command.t + val command : t -> User_command.Stable.Latest.t val hash : t -> hash diff --git a/src/lib/transaction/transaction_id.ml b/src/lib/transaction/transaction_id.ml index 56e20faed09..9ff167a1071 100644 --- a/src/lib/transaction/transaction_id.ml +++ b/src/lib/transaction/transaction_id.ml @@ -1,7 +1,7 @@ (* transaction_id.ml : type and Base64 conversions for GraphQL *) -module User_command = Mina_base.User_command +open Mina_base -type t = User_command.t +type t = User_command.Stable.Latest.t [%%define_locally User_command.(to_base64, of_base64)] diff --git a/src/lib/transaction_logic/test/helpers.ml b/src/lib/transaction_logic/test/helpers.ml index 3ed25abdf71..be4ea40ebf2 100644 --- a/src/lib/transaction_logic/test/helpers.ml +++ b/src/lib/transaction_logic/test/helpers.ml @@ -7,6 +7,9 @@ module Zk_cmd_result = struct * Ledger.t let sexp_of_t (txn, _) = - Mina_transaction_logic.Transaction_applied.Zkapp_command_applied.sexp_of_t - txn + Mina_transaction_logic.Transaction_applied.Zkapp_command_applied.Stable + .Latest + .sexp_of_t + (Mina_transaction_logic.Transaction_applied.Zkapp_command_applied.unwrap + txn ) end diff --git a/src/lib/transaction_logic/test/transaction_logic/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic/transaction_logic.ml index 372a55e6886..89aa7945acb 100644 --- a/src/lib/transaction_logic/test/transaction_logic/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic/transaction_logic.ml @@ -9,9 +9,6 @@ open Transaction_logic_tests open Helpers open Protocol_config_examples -let expect_success = - [%test_pred: Transaction_applied.t list Or_error.t] Or_error.is_ok - let expect_failure ~error = function | Ok _ -> failwith "Success where failure was expected." @@ -95,9 +92,12 @@ let simple_payment () = | Error _ -> assert false in - [%test_pred: Transaction_applied.t list Or_error.t] Or_error.is_ok - (Transaction_logic.apply_transactions ~constraint_constants ~global_slot - ~txn_state_view ledger [ txn ] ) ) + [%test_pred: Transaction_applied.Stable.Latest.t list Or_error.t] + Or_error.is_ok + Or_error.( + Transaction_logic.apply_transactions ~constraint_constants + ~global_slot ~txn_state_view ledger [ txn ] + >>| List.map ~f:Transaction_applied.unwrap) ) let simple_payment_signer_different_from_fee_payer () = Quickcheck.test ~trials:1000 setup diff --git a/src/lib/transaction_logic/transaction_applied.ml b/src/lib/transaction_logic/transaction_applied.ml index aa62f240ce2..1eac01afb5c 100644 --- a/src/lib/transaction_logic/transaction_applied.ml +++ b/src/lib/transaction_logic/transaction_applied.ml @@ -55,6 +55,8 @@ end module Zkapp_command_applied = struct [%%versioned module Stable = struct + [@@@no_toplevel_latest_type] + module V1 = struct type t = { accounts : (Account_id.Stable.V2.t * Account.Stable.V2.t option) list @@ -66,11 +68,31 @@ module Zkapp_command_applied = struct let to_latest = Fn.id end end] + + type t = + { accounts : (Account_id.t * Account.t option) list + ; command : Zkapp_command.t With_status.t + ; new_accounts : Account_id.t list + } + + let generate { Stable.Latest.accounts; command; new_accounts } : t = + { accounts + ; command = With_status.map ~f:Zkapp_command.generate command + ; new_accounts + } + + let unwrap { accounts; command; new_accounts } : Stable.Latest.t = + { Stable.Latest.accounts + ; command = With_status.map ~f:Zkapp_command.unwrap command + ; new_accounts + } end module Command_applied = struct [%%versioned module Stable = struct + [@@@no_toplevel_latest_type] + module V2 = struct type t = | Signed_command of Signed_command_applied.Stable.V2.t @@ -80,6 +102,22 @@ module Command_applied = struct let to_latest = Fn.id end end] + + type t = + | Signed_command of Signed_command_applied.t + | Zkapp_command of Zkapp_command_applied.t + + let generate : Stable.Latest.t -> t = function + | Signed_command c -> + Signed_command c + | Zkapp_command c -> + Zkapp_command (Zkapp_command_applied.generate c) + + let unwrap : t -> Stable.Latest.t = function + | Signed_command c -> + Signed_command c + | Zkapp_command c -> + Zkapp_command (Zkapp_command_applied.unwrap c) end module Fee_transfer_applied = struct @@ -114,9 +152,29 @@ module Coinbase_applied = struct end] end -module Varying = struct +module Varying : sig + [%%versioned: + module Stable : sig + [@@@no_toplevel_latest_type] + + module V2 : sig + type t [@@deriving sexp, to_yojson] + end + end] + + type t = + | Command of Command_applied.t + | Fee_transfer of Fee_transfer_applied.t + | Coinbase of Coinbase_applied.t + + val generate : Stable.Latest.t -> t + + val unwrap : t -> Stable.Latest.t +end = struct [%%versioned module Stable = struct + [@@@no_toplevel_latest_type] + module V2 = struct type t = | Command of Command_applied.Stable.V2.t @@ -127,10 +185,33 @@ module Varying = struct let to_latest = Fn.id end end] + + type t = + | Command of Command_applied.t + | Fee_transfer of Fee_transfer_applied.t + | Coinbase of Coinbase_applied.t + + let generate : Stable.Latest.t -> t = function + | Command c -> + Command (Command_applied.generate c) + | Fee_transfer f -> + Fee_transfer f + | Coinbase c -> + Coinbase c + + let unwrap : t -> Stable.Latest.t = function + | Command c -> + Command (Command_applied.unwrap c) + | Fee_transfer f -> + Fee_transfer f + | Coinbase c -> + Coinbase c end [%%versioned module Stable = struct + [@@@no_toplevel_latest_type] + module V2 = struct type t = { previous_hash : Ledger_hash.Stable.V1.t; varying : Varying.Stable.V2.t } @@ -140,6 +221,8 @@ module Stable = struct end end] +type t = { previous_hash : Ledger_hash.t; varying : Varying.t } + let burned_tokens : t -> Currency.Amount.t = fun { varying; _ } -> match varying with @@ -239,3 +322,9 @@ let transaction_status : t -> Transaction_status.t = f.fee_transfer.status | Coinbase c -> c.coinbase.status + +let generate { Stable.Latest.previous_hash; varying } : t = + { previous_hash; varying = Varying.generate varying } + +let unwrap { previous_hash; varying } = + { Stable.Latest.previous_hash; varying = Varying.unwrap varying } diff --git a/src/lib/transaction_snark/transaction_snark.ml b/src/lib/transaction_snark/transaction_snark.ml index b2817e9825e..aa9902c1dda 100644 --- a/src/lib/transaction_snark/transaction_snark.ml +++ b/src/lib/transaction_snark/transaction_snark.ml @@ -4603,7 +4603,8 @@ module Make_str (A : Wire_types.Concrete) = struct } ) } in - let ( `Zkapp_command { Zkapp_command.fee_payer; account_updates; memo } + let ( `Zkapp_command + { Zkapp_command.Poly.fee_payer; account_updates; memo } , `Sender_account_update sender_account_update , `Proof_zkapp_command snapp_zkapp_command , `Txn_commitment commitment @@ -4711,7 +4712,7 @@ module Make_str (A : Wire_types.Concrete) = struct create_trivial_snapp () in let%bind.Async.Deferred vk = vk in - let ( `Zkapp_command { Zkapp_command.fee_payer; memo; _ } + let ( `Zkapp_command { Zkapp_command.Poly.fee_payer; memo; _ } , `Sender_account_update _ , `Proof_zkapp_command _ , `Txn_commitment _ @@ -4863,7 +4864,7 @@ module Make_str (A : Wire_types.Concrete) = struct (prover, vk) in let%bind.Async.Deferred vk = vk in - let ( `Zkapp_command ({ Zkapp_command.fee_payer; memo; _ } as p) + let ( `Zkapp_command ({ Zkapp_command.Poly.fee_payer; memo; _ } as p) , `Sender_account_update sender_account_update , `Proof_zkapp_command snapp_zkapp_command , `Txn_commitment commitment diff --git a/src/lib/transaction_snark_scan_state/transaction_snark_scan_state.ml b/src/lib/transaction_snark_scan_state/transaction_snark_scan_state.ml index 4569be8a61a..193a9719dcb 100644 --- a/src/lib/transaction_snark_scan_state/transaction_snark_scan_state.ml +++ b/src/lib/transaction_snark_scan_state/transaction_snark_scan_state.ml @@ -33,6 +33,8 @@ end module Transaction_with_witness = struct [%%versioned module Stable = struct + [@@@no_toplevel_latest_type] + module V2 = struct (* TODO: The statement is redundant here - it can be computed from the witness and the transaction @@ -56,6 +58,55 @@ module Transaction_with_witness = struct let to_latest = Fn.id end end] + + type t = + { transaction_with_info : Mina_transaction_logic.Transaction_applied.t + ; state_hash : State_hash.t * State_body_hash.t + ; statement : Transaction_snark.Statement.t + ; init_stack : Transaction_snark.Pending_coinbase_stack_state.Init_stack.t + ; first_pass_ledger_witness : Mina_ledger.Sparse_ledger.t + ; second_pass_ledger_witness : Mina_ledger.Sparse_ledger.t + ; block_global_slot : Mina_numbers.Global_slot_since_genesis.t + } + + let generate + { Stable.Latest.transaction_with_info + ; state_hash + ; statement + ; init_stack + ; first_pass_ledger_witness + ; second_pass_ledger_witness + ; block_global_slot + } = + { transaction_with_info = + Mina_transaction_logic.Transaction_applied.generate + transaction_with_info + ; state_hash + ; statement + ; init_stack + ; first_pass_ledger_witness + ; second_pass_ledger_witness + ; block_global_slot + } + + let unwrap + { transaction_with_info + ; state_hash + ; statement + ; init_stack + ; first_pass_ledger_witness + ; second_pass_ledger_witness + ; block_global_slot + } = + { Stable.Latest.transaction_with_info = + Mina_transaction_logic.Transaction_applied.unwrap transaction_with_info + ; state_hash + ; statement + ; init_stack + ; first_pass_ledger_witness + ; second_pass_ledger_witness + ; block_global_slot + } end module Ledger_proof_with_sok_message = struct @@ -680,7 +731,7 @@ module Transactions_ordered = struct [@@deriving sexp, to_yojson] end - type t = Transaction_with_witness.t Poly.t [@@deriving sexp, to_yojson] + type t = Transaction_with_witness.t Poly.t let map (t : 'a Poly.t) ~f : 'b Poly.t = let f = List.map ~f in @@ -1473,15 +1524,28 @@ let check_required_protocol_states t ~protocol_states = protocol_states_assoc let generate ~proof_cache_db - { Stable.Latest.scan_state = uncached; previous_incomplete_zkapp_updates } = + { Stable.Latest.scan_state = uncached + ; previous_incomplete_zkapp_updates = tx_list, border_status + } = let f1 (p, v) = (Ledger_proof.Cached.generate ~proof_cache_db p, v) in - { scan_state = Parallel_scan.State.map uncached ~f1 ~f2:ident - ; previous_incomplete_zkapp_updates + { scan_state = + Parallel_scan.State.map uncached ~f1 ~f2:Transaction_with_witness.generate + ; previous_incomplete_zkapp_updates = + (List.map ~f:Transaction_with_witness.generate tx_list, border_status) } -let unwrap { scan_state = cached; previous_incomplete_zkapp_updates } = +let unwrap + { scan_state = cached + ; previous_incomplete_zkapp_updates = tx_list, border_status + } = let f1 (p, v) = (Ledger_proof.Cached.unwrap p, v) in - let scan_state = Parallel_scan.State.map ~f1 ~f2:ident cached in - Stable.Latest.{ scan_state; previous_incomplete_zkapp_updates } + let scan_state = + Parallel_scan.State.map ~f1 ~f2:Transaction_with_witness.unwrap cached + in + Stable.Latest. + { scan_state + ; previous_incomplete_zkapp_updates = + (List.map ~f:Transaction_with_witness.unwrap tx_list, border_status) + } let hash = Fn.compose Stable.Latest.hash unwrap diff --git a/src/lib/transaction_snark_scan_state/transaction_snark_scan_state.mli b/src/lib/transaction_snark_scan_state/transaction_snark_scan_state.mli index 36b87d57d0c..84eae0cc3fc 100644 --- a/src/lib/transaction_snark_scan_state/transaction_snark_scan_state.mli +++ b/src/lib/transaction_snark_scan_state/transaction_snark_scan_state.mli @@ -28,7 +28,6 @@ module Transaction_with_witness : sig ; second_pass_ledger_witness : Mina_ledger.Sparse_ledger.t ; block_global_slot : Mina_numbers.Global_slot_since_genesis.t } - [@@deriving sexp] end module Ledger_proof_with_sok_message : sig @@ -92,7 +91,7 @@ module Transactions_ordered : sig [@@deriving sexp, to_yojson] end - type t = Transaction_with_witness.t Poly.t [@@deriving sexp, to_yojson] + type t = Transaction_with_witness.t Poly.t end val empty : diff --git a/src/lib/transaction_snark_work/transaction_snark_work.ml b/src/lib/transaction_snark_work/transaction_snark_work.ml index 2abbeb3e244..ee65d16cb5c 100644 --- a/src/lib/transaction_snark_work/transaction_snark_work.ml +++ b/src/lib/transaction_snark_work/transaction_snark_work.ml @@ -95,7 +95,7 @@ module T = struct ; proofs : Ledger_proof.Stable.V2.t One_or_two.Stable.V1.t ; prover : Public_key.Compressed.Stable.V1.t } - [@@deriving yojson] + [@@deriving sexp, yojson] let statement t = One_or_two.map t.proofs ~f:Ledger_proof.statement diff --git a/src/lib/transaction_snark_work/transaction_snark_work.mli b/src/lib/transaction_snark_work/transaction_snark_work.mli index 041c80522c9..d82282f491b 100644 --- a/src/lib/transaction_snark_work/transaction_snark_work.mli +++ b/src/lib/transaction_snark_work/transaction_snark_work.mli @@ -75,7 +75,7 @@ val statement : t -> Statement.t module Stable : sig module V2 : sig - type t [@@deriving bin_io, version, yojson] + type t [@@deriving bin_io, version, sexp, yojson] val statement : t -> Statement.Stable.V2.t diff --git a/src/lib/transaction_witness/transaction_witness.ml b/src/lib/transaction_witness/transaction_witness.ml index 3cce13a947f..a52679f5775 100644 --- a/src/lib/transaction_witness/transaction_witness.ml +++ b/src/lib/transaction_witness/transaction_witness.ml @@ -8,6 +8,8 @@ module Zkapp_command_segment_witness = struct (* TODO: Don't serialize all the hashes in here. *) [%%versioned module Stable = struct + [@@@no_toplevel_latest_type] + module V1 = struct type t = { global_first_pass_ledger : Sparse_ledger.Stable.V2.t @@ -46,10 +48,66 @@ module Zkapp_command_segment_witness = struct let to_latest = Fn.id end end] + + type t = + { global_first_pass_ledger : Sparse_ledger.t + ; global_second_pass_ledger : Sparse_ledger.t + ; local_state_init : + ( (Token_id.t, Zkapp_command.Call_forest.With_hashes.t) Stack_frame.t + , ( ( (Token_id.t, Zkapp_command.Call_forest.With_hashes.t) Stack_frame.t + , Stack_frame.Digest.t ) + With_hash.t + , Call_stack_digest.t ) + With_stack_hash.t + list + , (Amount.t, Sgn.t) Signed_poly.t + , Sparse_ledger.t + , bool + , Kimchi_backend.Pasta.Basic.Fp.t + , Mina_numbers.Index.t + , Transaction_status.Failure.Collection.t ) + Mina_transaction_logic.Zkapp_command_logic.Local_state.t + ; start_zkapp_command : + ( Zkapp_command.t + , Kimchi_backend.Pasta.Basic.Fp.t + , bool ) + Mina_transaction_logic.Zkapp_command_logic.Start_data.t + list + ; state_body : Mina_state.Protocol_state.Body.Value.t + ; init_stack : Pending_coinbase.Stack_versioned.t + ; block_global_slot : Mina_numbers.Global_slot_since_genesis.t + } + + let unwrap + { global_first_pass_ledger + ; global_second_pass_ledger + ; local_state_init + ; start_zkapp_command + ; state_body + ; init_stack + ; block_global_slot + } = + { Stable.Latest.global_first_pass_ledger + ; global_second_pass_ledger + ; local_state_init + ; start_zkapp_command = + List.map + ~f:(fun sd -> + Mina_transaction_logic.Zkapp_command_logic.Start_data. + { sd with + account_updates = Zkapp_command.unwrap sd.account_updates + } ) + start_zkapp_command + ; state_body + ; init_stack + ; block_global_slot + } end [%%versioned module Stable = struct + [@@@no_toplevel_latest_type] + module V2 = struct type t = { transaction : Mina_transaction.Transaction.Stable.V2.t @@ -65,3 +123,50 @@ module Stable = struct let to_latest = Fn.id end end] + +type t = + { transaction : Mina_transaction.Transaction.t + ; first_pass_ledger : Mina_ledger.Sparse_ledger.t + ; second_pass_ledger : Mina_ledger.Sparse_ledger.t + ; protocol_state_body : Mina_state.Protocol_state.Body.Value.t + ; init_stack : Mina_base.Pending_coinbase.Stack_versioned.t + ; status : Mina_base.Transaction_status.t + ; block_global_slot : Mina_numbers.Global_slot_since_genesis.t + } +[@@deriving sexp, yojson] + +let unwrap + { transaction + ; first_pass_ledger + ; second_pass_ledger + ; protocol_state_body + ; init_stack + ; status + ; block_global_slot + } = + { Stable.Latest.transaction = Mina_transaction.Transaction.unwrap transaction + ; first_pass_ledger + ; second_pass_ledger + ; protocol_state_body + ; init_stack + ; status + ; block_global_slot + } + +let generate + { Stable.Latest.transaction + ; first_pass_ledger + ; second_pass_ledger + ; protocol_state_body + ; init_stack + ; status + ; block_global_slot + } = + { transaction = Mina_transaction.Transaction.generate transaction + ; first_pass_ledger + ; second_pass_ledger + ; protocol_state_body + ; init_stack + ; status + ; block_global_slot + } diff --git a/src/lib/transaction_witness/transaction_witness.mli b/src/lib/transaction_witness/transaction_witness.mli deleted file mode 100644 index 64805b26046..00000000000 --- a/src/lib/transaction_witness/transaction_witness.mli +++ /dev/null @@ -1,62 +0,0 @@ -open Core_kernel - -module Zkapp_command_segment_witness : sig - open Mina_base - open Mina_ledger - open Currency - - [%%versioned: - module Stable : sig - module V1 : sig - type t = - { global_first_pass_ledger : Sparse_ledger.Stable.V2.t - ; global_second_pass_ledger : Sparse_ledger.Stable.V2.t - ; local_state_init : - ( ( Token_id.Stable.V2.t - , Zkapp_command.Call_forest.With_hashes.Stable.V1.t ) - Stack_frame.Stable.V1.t - , ( ( ( Token_id.Stable.V2.t - , Zkapp_command.Call_forest.With_hashes.Stable.V1.t ) - Stack_frame.Stable.V1.t - , Stack_frame.Digest.Stable.V1.t ) - With_hash.t - , Call_stack_digest.Stable.V1.t ) - With_stack_hash.Stable.V1.t - list - , (Amount.Stable.V1.t, Sgn.Stable.V1.t) Signed_poly.Stable.V1.t - , Sparse_ledger.Stable.V2.t - , bool - , Kimchi_backend.Pasta.Basic.Fp.Stable.V1.t - , Mina_numbers.Index.Stable.V1.t - , Transaction_status.Failure.Collection.Stable.V1.t ) - Mina_transaction_logic.Zkapp_command_logic.Local_state.Stable.V1.t - ; start_zkapp_command : - ( Zkapp_command.Stable.V1.t - , Kimchi_backend.Pasta.Basic.Fp.Stable.V1.t - , bool ) - Mina_transaction_logic.Zkapp_command_logic.Start_data.Stable.V1.t - list - ; state_body : Mina_state.Protocol_state.Body.Value.Stable.V2.t - ; init_stack : Pending_coinbase.Stack_versioned.Stable.V1.t - ; block_global_slot : Mina_numbers.Global_slot_since_genesis.Stable.V1.t - } - [@@deriving sexp, to_yojson] - end - end] -end - -[%%versioned: -module Stable : sig - module V2 : sig - type t = - { transaction : Mina_transaction.Transaction.Stable.V2.t - ; first_pass_ledger : Mina_ledger.Sparse_ledger.Stable.V2.t - ; second_pass_ledger : Mina_ledger.Sparse_ledger.Stable.V2.t - ; protocol_state_body : Mina_state.Protocol_state.Body.Value.Stable.V2.t - ; init_stack : Mina_base.Pending_coinbase.Stack_versioned.Stable.V1.t - ; status : Mina_base.Transaction_status.Stable.V2.t - ; block_global_slot : Mina_numbers.Global_slot_since_genesis.Stable.V1.t - } - [@@deriving sexp, yojson] - end -end] diff --git a/src/lib/transition_frontier/transition_frontier.ml b/src/lib/transition_frontier/transition_frontier.ml index c04f29354e9..7711bef69ab 100644 --- a/src/lib/transition_frontier/transition_frontier.ml +++ b/src/lib/transition_frontier/transition_frontier.ml @@ -470,10 +470,10 @@ let add_breadcrumb_exn t breadcrumb = Mina_block.Validated.valid_commands @@ Breadcrumb.validated_transition breadcrumb in - let tx_hash_json = - Fn.compose - Mina_transaction.Transaction_hash.(Fn.compose to_yojson hash_command) - User_command.forget_check + let tx_hash_json command = + User_command.forget_check command + |> Mina_transaction.Transaction_hash.hash_wrapped_command + |> Mina_transaction.Transaction_hash.to_yojson in [%str_log' trace t.logger] Added_breadcrumb_user_commands ~metadata: diff --git a/src/lib/uptime_service/uptime_service.ml b/src/lib/uptime_service/uptime_service.ml index c1621e4649a..c43cca81f70 100644 --- a/src/lib/uptime_service/uptime_service.ml +++ b/src/lib/uptime_service/uptime_service.ml @@ -195,7 +195,8 @@ let send_produced_block_at ~logger ~interruptor ~url ~peer_id ~produced:true block_data let unwrap_work_single_spec = - Snark_work_lib.Work.Single.Spec.map_proof ~f:Ledger_proof.Cached.unwrap + Snark_work_lib.Work.Single.Spec.map ~f_proof:Ledger_proof.Cached.unwrap + ~f_witness:Transaction_witness.unwrap let send_block_and_transaction_snark ~logger ~constraint_constants ~interruptor ~url ~snark_worker ~transition_frontier ~peer_id @@ -323,10 +324,11 @@ let send_block_and_transaction_snark ~logger ~constraint_constants ~interruptor send_uptime_data ~logger ~interruptor ~submitter_keypair ~url ~state_hash ~produced:false block_data | Some single_spec -> ( + let unwrapped = unwrap_work_single_spec single_spec in match%bind make_interruptible (Uptime_snark_worker.perform_single snark_worker - (message, unwrap_work_single_spec single_spec) ) + (message, unwrapped) ) with | Error e -> (* error in submitting to process *) diff --git a/src/lib/verifier/prod.ml b/src/lib/verifier/prod.ml index 41cff1ebbea..02f7b6ffcdf 100644 --- a/src/lib/verifier/prod.ml +++ b/src/lib/verifier/prod.ml @@ -319,8 +319,7 @@ module Worker = struct ; verify_commands = f ( [%bin_type_class: - User_command.Verifiable.Stable.Latest.t - With_status.Stable.Latest.t + User_command.Verifiable.t With_status.Stable.Latest.t With_id_tag.t list] , [%bin_type_class: