Skip to content

Commit

Permalink
support old hashes in berkeley migration app
Browse files Browse the repository at this point in the history
  • Loading branch information
dkijania committed Dec 15, 2023
1 parent 76e741d commit 7e1d946
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 22 additions & 7 deletions src/app/archive/lib/processor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@ module User_command = struct
}

let add_extensional_if_doesn't_exist (module Conn : CONNECTION)
(user_cmd : Extensional.User_command.t) =
?(v1_transaction_hash = false) (user_cmd : Extensional.User_command.t) =
let open Deferred.Result.Let_syntax in
match%bind find (module Conn) ~transaction_hash:user_cmd.hash with
| Some id ->
Expand All @@ -1860,6 +1860,13 @@ module User_command = struct
let%bind receiver_id =
Public_key.add_if_doesn't_exist (module Conn) user_cmd.receiver
in
let to_base58_check hash =
match v1_transaction_hash with
| true ->
Transaction_hash.to_base58_check_v1 hash
| false ->
Transaction_hash.to_base58_check hash
in
Conn.find
(Caqti_request.find typ Caqti_type.int
(Mina_caqti.insert_into_cols ~returning:"id" ~table_name
Expand All @@ -1879,7 +1886,7 @@ module User_command = struct
(Fn.compose Unsigned.UInt32.to_int64
Mina_numbers.Global_slot_since_genesis.to_uint32 )
; memo = user_cmd.memo |> Signed_command_memo.to_base58_check
; hash = user_cmd.hash |> Transaction_hash.to_base58_check
; hash = user_cmd.hash |> to_base58_check
}
end

Expand Down Expand Up @@ -1995,6 +2002,7 @@ module Internal_command = struct
id

let add_extensional_if_doesn't_exist (module Conn : CONNECTION)
?(v1_transaction_hash = false)
(internal_cmd : Extensional.Internal_command.t) =
let open Deferred.Result.Let_syntax in
match%bind
Expand All @@ -2009,6 +2017,13 @@ module Internal_command = struct
let%bind receiver_id =
Public_key.add_if_doesn't_exist (module Conn) internal_cmd.receiver
in
let to_base58_check hash =
match v1_transaction_hash with
| true ->
Transaction_hash.to_base58_check_v1 hash
| false ->
Transaction_hash.to_base58_check hash
in
Conn.find
(Caqti_request.find typ Caqti_type.int
(Mina_caqti.insert_into_cols ~returning:"id" ~table_name
Expand All @@ -2019,7 +2034,7 @@ module Internal_command = struct
{ command_type = internal_cmd.command_type
; receiver_id
; fee = Currency.Fee.to_string internal_cmd.fee
; hash = internal_cmd.hash |> Transaction_hash.to_base58_check
; hash = internal_cmd.hash |> to_base58_check
}
end

Expand Down Expand Up @@ -3176,7 +3191,7 @@ module Block = struct
~hash:(Protocol_state.hashes t.protocol_state).state_hash

let add_from_extensional (module Conn : CONNECTION)
(block : Extensional.Block.t) =
?(v1_transaction_hash = false) (block : Extensional.Block.t) =
let open Deferred.Result.Let_syntax in
let%bind block_id =
match%bind find_opt (module Conn) ~state_hash:block.state_hash with
Expand Down Expand Up @@ -3287,7 +3302,7 @@ module Block = struct
let%map cmd_id =
User_command.Signed_command.add_extensional_if_doesn't_exist
(module Conn)
user_cmd
user_cmd ~v1_transaction_hash
in
cmd_id :: acc )
in
Expand All @@ -3311,7 +3326,7 @@ module Block = struct
let%map cmd_id =
Internal_command.add_extensional_if_doesn't_exist
(module Conn)
internal_cmd
internal_cmd ~v1_transaction_hash
in
(internal_cmd, cmd_id) :: acc )
in
Expand Down Expand Up @@ -3786,7 +3801,7 @@ let add_block_aux_precomputed ~constraint_constants ~logger ?retries ~pool
(* used by `archive_blocks` app *)
let add_block_aux_extensional ~logger ?retries ~pool ~delete_older_than block =
add_block_aux ~logger ?retries ~pool ~delete_older_than
~add_block:Block.add_from_extensional
~add_block:(Block.add_from_extensional ~v1_transaction_hash:false)
~hash:(fun (block : Extensional.Block.t) -> block.state_hash)
~accounts_accessed:block.Extensional.Block.accounts_accessed
~accounts_created:block.Extensional.Block.accounts_created
Expand Down
2 changes: 1 addition & 1 deletion src/app/berkeley_migration/berkeley_migration.ml
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ let main ~mainnet_archive_uri ~migrated_archive_uri ~runtime_config_file
query_migrated_db ~f:(fun db ->
match%map
Archive_lib.Processor.Block.add_from_extensional db
extensional_block
extensional_block ~v1_transaction_hash:true
with
| Ok _id ->
Ok ()
Expand Down

0 comments on commit 7e1d946

Please sign in to comment.