diff --git a/src/app/archive/lib/dune b/src/app/archive/lib/dune index 0117fce5bb8..385408aca97 100644 --- a/src/app/archive/lib/dune +++ b/src/app/archive/lib/dune @@ -27,8 +27,8 @@ child_processes precomputed_values coda_genesis_ledger + consensus.vrf mina_runtime_config - hex sgn mina_base.util kimchi_backend.pasta @@ -72,9 +72,10 @@ mina_version staged_ledger_diff error_json + ppx_deriving_yojson.runtime ppx_version.runtime ) (inline_tests (flags -verbose -show-counts)) (modes native) (instrumentation (backend bisect_ppx)) - (preprocess (pps ppx_mina ppx_version ppx_jane ppx_custom_printf h_list.ppx))) + (preprocess (pps ppx_mina ppx_version ppx_jane ppx_custom_printf ppx_deriving_yojson h_list.ppx))) diff --git a/src/app/archive/lib/extensional.ml b/src/app/archive/lib/extensional.ml index bd4c962e21a..30d02cce6f4 100644 --- a/src/app/archive/lib/extensional.ml +++ b/src/app/archive/lib/extensional.ml @@ -111,7 +111,7 @@ module Block = struct ; parent_hash : State_hash.Stable.V1.t ; creator : Public_key.Compressed.Stable.V1.t ; block_winner : Public_key.Compressed.Stable.V1.t - ; last_vrf_output : string + ; last_vrf_output : Consensus_vrf.Output.Truncated.Stable.V1.t ; snarked_ledger_hash : Frozen_ledger_hash.Stable.V1.t ; staking_epoch_data : Mina_base.Epoch_data.Value.Stable.V1.t ; next_epoch_data : Mina_base.Epoch_data.Value.Stable.V1.t diff --git a/src/app/archive/lib/processor.ml b/src/app/archive/lib/processor.ml index 58c873c0fee..cbbef5942ae 100644 --- a/src/app/archive/lib/processor.ml +++ b/src/app/archive/lib/processor.ml @@ -1845,7 +1845,7 @@ module User_command = struct (Caqti_request.find typ Caqti_type.int (Mina_caqti.insert_into_cols ~returning:"id" ~table_name ~tannot:(function - | "typ" -> Some "user_command_type" | _ -> None ) + | "command_type" -> Some "user_command_type" | _ -> None ) ~cols:Fields.names () ) ) { command_type = user_cmd.command_type ; fee_payer_id @@ -1994,7 +1994,8 @@ module Internal_command = struct (Caqti_request.find typ Caqti_type.int (Mina_caqti.insert_into_cols ~returning:"id" ~table_name ~tannot:(function - | "typ" -> Some "internal_command_type" | _ -> None ) + | "command_type" -> Some "internal_command_type" | _ -> None + ) ~cols:Fields.names () ) ) { command_type = internal_cmd.command_type ; receiver_id @@ -2767,9 +2768,9 @@ module Block = struct (Consensus.Data.Consensus_state.block_stake_winner consensus_state) in let last_vrf_output = - (* encode as hex, Postgresql won't accept arbitrary bitstrings *) + (* encode as base64, same as in precomputed blocks JSON *) Consensus.Data.Consensus_state.last_vrf_output consensus_state - |> Hex.Safe.to_hex + |> Base64.encode_exn ~alphabet:Base64.uri_safe_alphabet in let%bind snarked_ledger_hash_id = Snarked_ledger_hash.add_if_doesn't_exist @@ -3173,8 +3174,9 @@ module Block = struct Public_key.add_if_doesn't_exist (module Conn) block.block_winner in let last_vrf_output = - (* already encoded as hex *) + (* encode as base64, same as in precomputed blocks JSON *) block.last_vrf_output + |> Base64.encode_exn ~alphabet:Base64.uri_safe_alphabet in let%bind snarked_ledger_hash_id = Snarked_ledger_hash.add_if_doesn't_exist @@ -3214,19 +3216,15 @@ module Block = struct in Conn.find (Caqti_request.find typ Caqti_type.int - {sql| INSERT INTO blocks - (state_hash, parent_id, parent_hash, - creator_id, block_winner_id,last_vrf_output, - snarked_ledger_hash_id, staking_epoch_data_id, - next_epoch_data_id, - min_window_density, sub_window_densities, total_currency, - ledger_hash, height, - global_slot_since_hard_fork, global_slot_since_genesis, - protocol_version, proposed_protocol_version, - timestamp, chain_status) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?::bigint[], ?, ?, ?, ?, ?, ?, ?, ?, ?::chain_status_type) - RETURNING id - |sql} ) + (Mina_caqti.insert_into_cols ~returning:"id" ~table_name + ~tannot:(function + | "sub_window_densities" -> + Some "bigint[]" + | "chain_status" -> + Some "chain_status_type" + | _ -> + None ) + ~cols:Fields.names () ) ) { state_hash = block.state_hash |> State_hash.to_base58_check ; parent_id ; parent_hash = block.parent_hash |> State_hash.to_base58_check diff --git a/src/app/extract_blocks/dune b/src/app/extract_blocks/dune index a0df1831b25..e3bf8046c9e 100644 --- a/src/app/extract_blocks/dune +++ b/src/app/extract_blocks/dune @@ -18,6 +18,7 @@ uri async.async_command ;; local libraries + consensus_vrf mina_wire_types mina_base mina_base.import diff --git a/src/app/extract_blocks/extract_blocks.ml b/src/app/extract_blocks/extract_blocks.ml index f4fa0ac2e77..3605538ae44 100644 --- a/src/app/extract_blocks/extract_blocks.ml +++ b/src/app/extract_blocks/extract_blocks.ml @@ -49,8 +49,7 @@ let fill_in_block pool (block : Archive_lib.Processor.Block.t) : let%bind creator = pk_of_id block.creator_id in let%bind block_winner = pk_of_id block.block_winner_id in let last_vrf_output = - (* keep hex encoding *) - block.last_vrf_output + Base64.decode_exn ~alphabet:Base64.uri_safe_alphabet block.last_vrf_output in let%bind snarked_ledger_hash_str = query_db ~f:(fun db -> diff --git a/src/app/replayer/replayer.ml b/src/app/replayer/replayer.ml index a47e9eaeca4..e35e3622d2f 100644 --- a/src/app/replayer/replayer.ml +++ b/src/app/replayer/replayer.ml @@ -1574,7 +1574,7 @@ let () = Command.async ~summary:"Replay transactions from Mina archive database" (let%map input_file = Param.flag "--input-file" - ~doc:"file File containing the genesis ledger" + ~doc:"file File containing the starting ledger" Param.(required string) and output_file_opt = Param.flag "--output-file" diff --git a/src/app/replayer/sql.ml b/src/app/replayer/sql.ml index 711c4bd447f..40caaf5af13 100644 --- a/src/app/replayer/sql.ml +++ b/src/app/replayer/sql.ml @@ -464,16 +464,3 @@ module Parent_block = struct epoch_ledgers_state_hash = Conn.find query_parent_state_hash epoch_ledgers_state_hash end - -module Balances = struct - let query_insert_nonce = - Caqti_request.exec - Caqti_type.(tup2 int int64) - {sql| UPDATE balances - SET nonce = $2 - WHERE id = $1 - |sql} - - let insert_nonce (module Conn : Caqti_async.CONNECTION) ~id ~nonce = - Conn.exec query_insert_nonce (id, nonce) -end diff --git a/src/lib/consensus/vrf/consensus_vrf.ml b/src/lib/consensus/vrf/consensus_vrf.ml index 550f59dd770..60646a4ccc5 100644 --- a/src/lib/consensus/vrf/consensus_vrf.ml +++ b/src/lib/consensus/vrf/consensus_vrf.ml @@ -165,20 +165,24 @@ module Output = struct [%%versioned module Stable = struct module V1 = struct - type t = string [@@deriving sexp, equal, compare, hash] + type t = string [@@deriving sexp, equal, compare, hash, yojson] let to_yojson t = `String (Base64.encode_exn ~alphabet:Base64.uri_safe_alphabet t) let of_yojson = function | `String s -> - Result.map_error - (Base64.decode ~alphabet:Base64.uri_safe_alphabet s) - ~f:(function `Msg err -> - sprintf - "Error decoding vrf output in \ - Vrf.Output.Truncated.Stable.V1.of_yojson: %s" - err ) + (* missing type equation somewhere, add explicit type *) + ( match Base64.decode ~alphabet:Base64.uri_safe_alphabet s with + | Ok b64 -> + Ppx_deriving_yojson_runtime.Result.Ok b64 + | Error (`Msg err) -> + Error + (sprintf + "Error decoding vrf output in \ + Vrf.Output.Truncated.Stable.V1.of_yojson: %s" + err ) + : (t, string) Ppx_deriving_yojson_runtime.Result.result ) | _ -> Error "Vrf.Output.Truncated.Stable.V1.of_yojson: Expected a string" @@ -195,6 +199,9 @@ module Output = struct let description = "Vrf Truncated Output" end) + (* don't want the yojson functions from Make_base58_check *) + [%%define_locally Stable.Latest.(of_yojson, to_yojson)] + open Tick let length_in_bits = Int.min 256 (Field.size_in_bits - 2) diff --git a/src/lib/consensus/vrf/dune b/src/lib/consensus/vrf/dune index d9057e3abc1..9b76dd6b1a2 100644 --- a/src/lib/consensus/vrf/dune +++ b/src/lib/consensus/vrf/dune @@ -47,6 +47,7 @@ kimchi_bindings kimchi_types pasta_bindings + ppx_deriving_yojson.runtime ppx_version.runtime ) (inline_tests (flags -verbose -show-counts))