Context: switch to blake2B
Get rid of the old SHA1 that was used by git...
This commit is contained in:
parent
61984d6edd
commit
7807f7aa4d
@ -301,6 +301,7 @@ module Prefix = struct
|
|||||||
let operation_list_hash = "\133\233" (* Lo(52) *)
|
let operation_list_hash = "\133\233" (* Lo(52) *)
|
||||||
let operation_list_list_hash = "\029\159\109" (* LLo(53) *)
|
let operation_list_list_hash = "\029\159\109" (* LLo(53) *)
|
||||||
let protocol_hash = "\002\170" (* P(51) *)
|
let protocol_hash = "\002\170" (* P(51) *)
|
||||||
|
let context_hash = "\079\199" (* Co(52) *)
|
||||||
|
|
||||||
(* 20 *)
|
(* 20 *)
|
||||||
let ed25519_public_key_hash = "\006\161\159" (* tz1(36) *)
|
let ed25519_public_key_hash = "\006\161\159" (* tz1(36) *)
|
||||||
|
@ -16,6 +16,7 @@ module Prefix : sig
|
|||||||
val operation_list_hash: string
|
val operation_list_hash: string
|
||||||
val operation_list_list_hash: string
|
val operation_list_list_hash: string
|
||||||
val protocol_hash: string
|
val protocol_hash: string
|
||||||
|
val context_hash: string
|
||||||
val ed25519_public_key_hash: string
|
val ed25519_public_key_hash: string
|
||||||
val cryptobox_public_key_hash: string
|
val cryptobox_public_key_hash: string
|
||||||
val ed25519_public_key: string
|
val ed25519_public_key: string
|
||||||
|
@ -209,6 +209,11 @@ module Make (R : sig
|
|||||||
Data_encoding.(list (tup2 encoding arg_encoding))
|
Data_encoding.(list (tup2 encoding arg_encoding))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let zero =
|
||||||
|
match of_hex (String.make (size * 2) '0') with
|
||||||
|
| Some c -> c
|
||||||
|
| None -> assert false
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Generic_Merkle_tree (H : sig
|
module Generic_Merkle_tree (H : sig
|
||||||
|
18
lib_crypto/context_hash.ml
Normal file
18
lib_crypto/context_hash.ml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
(**************************************************************************)
|
||||||
|
(* *)
|
||||||
|
(* Copyright (c) 2014 - 2017. *)
|
||||||
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
||||||
|
(* *)
|
||||||
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
||||||
|
(* *)
|
||||||
|
(**************************************************************************)
|
||||||
|
|
||||||
|
include Blake2B.Make (Base58) (struct
|
||||||
|
let name = "Context_hash"
|
||||||
|
let title = "A hash of context"
|
||||||
|
let b58check_prefix = Base58.Prefix.context_hash
|
||||||
|
let size = None
|
||||||
|
end)
|
||||||
|
|
||||||
|
let () =
|
||||||
|
Base58.check_encoded_prefix b58check_encoding "Co" 52
|
10
lib_crypto/context_hash.mli
Normal file
10
lib_crypto/context_hash.mli
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
(**************************************************************************)
|
||||||
|
(* *)
|
||||||
|
(* Copyright (c) 2014 - 2017. *)
|
||||||
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
||||||
|
(* *)
|
||||||
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
||||||
|
(* *)
|
||||||
|
(**************************************************************************)
|
||||||
|
|
||||||
|
include S.INTERNAL_HASH
|
@ -148,3 +148,8 @@ end
|
|||||||
|
|
||||||
let () =
|
let () =
|
||||||
Base58.check_encoded_prefix b58check_encoding "Net" 15
|
Base58.check_encoded_prefix b58check_encoding "Net" 15
|
||||||
|
|
||||||
|
let zero =
|
||||||
|
match of_hex (String.make (size * 2) '0') with
|
||||||
|
| Some c -> c
|
||||||
|
| None -> assert false
|
||||||
|
@ -94,6 +94,7 @@ module type INTERNAL_HASH = sig
|
|||||||
(t -> 'a, 'arg, 'ret) Cli_entries.params
|
(t -> 'a, 'arg, 'ret) Cli_entries.params
|
||||||
val random_set_elt: Set.t -> t
|
val random_set_elt: Set.t -> t
|
||||||
module Table : Hashtbl.S with type key = t
|
module Table : Hashtbl.S with type key = t
|
||||||
|
val zero: t
|
||||||
end
|
end
|
||||||
|
|
||||||
module type INTERNAL_MERKLE_TREE = sig
|
module type INTERNAL_MERKLE_TREE = sig
|
||||||
|
@ -29,13 +29,49 @@ module Metadata = struct
|
|||||||
let merge = Irmin.Merge.default t
|
let merge = Irmin.Merge.default t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module IrminBlake2B : Irmin.Hash.S with type t = Context_hash.t = struct
|
||||||
|
|
||||||
|
type t = Context_hash.t
|
||||||
|
|
||||||
|
let digest_size = Context_hash.size
|
||||||
|
|
||||||
|
let to_raw t = Cstruct.of_bigarray (Context_hash.to_bytes t)
|
||||||
|
let of_raw t =
|
||||||
|
match Context_hash.of_bytes (Cstruct.to_bigarray t) with
|
||||||
|
| Some t -> t
|
||||||
|
| None ->
|
||||||
|
let str = Cstruct.to_string t in
|
||||||
|
Format.kasprintf invalid_arg "%s (%d)" str (String.length str)
|
||||||
|
|
||||||
|
let t = Irmin.Type.like Irmin.Type.cstruct of_raw to_raw
|
||||||
|
|
||||||
|
let digest t x =
|
||||||
|
Context_hash.hash_bytes
|
||||||
|
[Cstruct.to_bigarray (Irmin.Type.encode_cstruct t x)]
|
||||||
|
|
||||||
|
let pp = Context_hash.pp
|
||||||
|
|
||||||
|
let of_string x =
|
||||||
|
match Context_hash.of_b58check_exn x with
|
||||||
|
| exception (Invalid_argument s) -> Error (`Msg s)
|
||||||
|
| h -> Ok h
|
||||||
|
|
||||||
|
let has_kind = function
|
||||||
|
| `SHA1 -> true
|
||||||
|
| _ -> false
|
||||||
|
|
||||||
|
let to_raw_int c =
|
||||||
|
Int64.to_int @@ MBytes.get_int64 (Context_hash.to_bytes c) 0
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
module GitStore =
|
module GitStore =
|
||||||
Irmin_leveldb.Make
|
Irmin_leveldb.Make
|
||||||
(Metadata)
|
(Metadata)
|
||||||
(MBytesContent)
|
(MBytesContent)
|
||||||
(Irmin.Path.String_list)
|
(Irmin.Path.String_list)
|
||||||
(Irmin.Branch.String)
|
(Irmin.Branch.String)
|
||||||
(Irmin.Hash.SHA1)
|
(IrminBlake2B)
|
||||||
|
|
||||||
type index = {
|
type index = {
|
||||||
path: string ;
|
path: string ;
|
||||||
@ -50,30 +86,6 @@ and context = {
|
|||||||
}
|
}
|
||||||
type t = context
|
type t = context
|
||||||
|
|
||||||
type commit = GitStore.Commit.Hash.t
|
|
||||||
|
|
||||||
let dummy_commit =
|
|
||||||
match
|
|
||||||
GitStore.Commit.Hash.of_string "0000000000000000000000000000000000000000"
|
|
||||||
with
|
|
||||||
| Ok c -> c
|
|
||||||
| Error _ -> assert false
|
|
||||||
|
|
||||||
let commit_encoding : commit Data_encoding.t =
|
|
||||||
let open Data_encoding in
|
|
||||||
conv
|
|
||||||
(fun c -> Cstruct.to_bigarray (Irmin.Type.encode_cstruct GitStore.Commit.Hash.t c))
|
|
||||||
(fun c ->
|
|
||||||
match
|
|
||||||
Irmin.Type.decode_cstruct
|
|
||||||
GitStore.Commit.Hash.t
|
|
||||||
(Cstruct.of_bigarray c)
|
|
||||||
with
|
|
||||||
| Ok x -> x
|
|
||||||
| _ -> assert false
|
|
||||||
)
|
|
||||||
bytes
|
|
||||||
|
|
||||||
(*-- Version Access and Update -----------------------------------------------*)
|
(*-- Version Access and Update -----------------------------------------------*)
|
||||||
|
|
||||||
let current_protocol_key = ["protocol"]
|
let current_protocol_key = ["protocol"]
|
||||||
|
@ -16,11 +16,6 @@ type index
|
|||||||
type t
|
type t
|
||||||
type context = t
|
type context = t
|
||||||
|
|
||||||
type commit
|
|
||||||
|
|
||||||
val dummy_commit: commit
|
|
||||||
val commit_encoding: commit Data_encoding.t
|
|
||||||
|
|
||||||
(** Open or initialize a versioned store at a given path. *)
|
(** Open or initialize a versioned store at a given path. *)
|
||||||
val init:
|
val init:
|
||||||
?patch_context:(context -> context Lwt.t) ->
|
?patch_context:(context -> context Lwt.t) ->
|
||||||
@ -32,11 +27,11 @@ val commit_genesis:
|
|||||||
net_id:Net_id.t ->
|
net_id:Net_id.t ->
|
||||||
time:Time.t ->
|
time:Time.t ->
|
||||||
protocol:Protocol_hash.t ->
|
protocol:Protocol_hash.t ->
|
||||||
commit Lwt.t
|
Context_hash.t Lwt.t
|
||||||
|
|
||||||
val commit_test_network_genesis:
|
val commit_test_network_genesis:
|
||||||
index -> Block_hash.t -> Time.t -> context ->
|
index -> Block_hash.t -> Time.t -> context ->
|
||||||
(Net_id.t * Block_hash.t * commit) tzresult Lwt.t
|
(Net_id.t * Block_hash.t * Context_hash.t) tzresult Lwt.t
|
||||||
|
|
||||||
(** {2 Generic interface} ****************************************************)
|
(** {2 Generic interface} ****************************************************)
|
||||||
|
|
||||||
@ -61,16 +56,16 @@ val fold_keys:
|
|||||||
|
|
||||||
(** {2 Accessing and Updating Versions} **************************************)
|
(** {2 Accessing and Updating Versions} **************************************)
|
||||||
|
|
||||||
val exists: index -> commit -> bool Lwt.t
|
val exists: index -> Context_hash.t -> bool Lwt.t
|
||||||
val checkout: index -> commit -> context option Lwt.t
|
val checkout: index -> Context_hash.t -> context option Lwt.t
|
||||||
val checkout_exn: index -> commit -> context Lwt.t
|
val checkout_exn: index -> Context_hash.t -> context Lwt.t
|
||||||
val commit:
|
val commit:
|
||||||
time:Time.t ->
|
time:Time.t ->
|
||||||
message:string ->
|
message:string ->
|
||||||
context ->
|
context ->
|
||||||
commit Lwt.t
|
Context_hash.t Lwt.t
|
||||||
val set_head: index -> Net_id.t -> commit -> unit Lwt.t
|
val set_head: index -> Net_id.t -> Context_hash.t -> unit Lwt.t
|
||||||
val set_master: index -> commit -> unit Lwt.t
|
val set_master: index -> Context_hash.t -> unit Lwt.t
|
||||||
|
|
||||||
(** {2 Predefined Fields} ****************************************************)
|
(** {2 Predefined Fields} ****************************************************)
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ module Block = struct
|
|||||||
max_operations_ttl: int ;
|
max_operations_ttl: int ;
|
||||||
max_number_of_operations: int list;
|
max_number_of_operations: int list;
|
||||||
max_operation_data_length: int;
|
max_operation_data_length: int;
|
||||||
context: Context.commit ;
|
context: Context_hash.t ;
|
||||||
}
|
}
|
||||||
|
|
||||||
module Contents =
|
module Contents =
|
||||||
@ -115,7 +115,7 @@ module Block = struct
|
|||||||
(req "max_operations_ttl" uint16)
|
(req "max_operations_ttl" uint16)
|
||||||
(req "max_number_of_operations" (list uint16))
|
(req "max_number_of_operations" (list uint16))
|
||||||
(req "max_operation_data_length" uint16)
|
(req "max_operation_data_length" uint16)
|
||||||
(req "context" Context.commit_encoding)
|
(req "context" Context_hash.encoding)
|
||||||
(req "header" Block_header.encoding))
|
(req "header" Block_header.encoding))
|
||||||
end))
|
end))
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ module Block : sig
|
|||||||
max_operations_ttl: int ;
|
max_operations_ttl: int ;
|
||||||
max_number_of_operations: int list;
|
max_number_of_operations: int list;
|
||||||
max_operation_data_length: int;
|
max_operation_data_length: int;
|
||||||
context: Context.commit ;
|
context: Context_hash.t ;
|
||||||
}
|
}
|
||||||
|
|
||||||
module Contents : SINGLE_STORE
|
module Contents : SINGLE_STORE
|
||||||
|
@ -84,10 +84,10 @@ let create_block3b idx block2_commit =
|
|||||||
|
|
||||||
type t = {
|
type t = {
|
||||||
idx: Context.index ;
|
idx: Context.index ;
|
||||||
genesis: Context.commit ;
|
genesis: Context_hash.t ;
|
||||||
block2: Context.commit ;
|
block2: Context_hash.t ;
|
||||||
block3a: Context.commit ;
|
block3a: Context_hash.t ;
|
||||||
block3b: Context.commit ;
|
block3b: Context_hash.t ;
|
||||||
}
|
}
|
||||||
|
|
||||||
let wrap_context_init f base_dir =
|
let wrap_context_init f base_dir =
|
||||||
|
@ -88,7 +88,7 @@ let lolblock ?(operations = []) header =
|
|||||||
} ;
|
} ;
|
||||||
max_operations_ttl = 0 ;
|
max_operations_ttl = 0 ;
|
||||||
message = "" ;
|
message = "" ;
|
||||||
context = Context.dummy_commit ;
|
context = Context_hash.zero ;
|
||||||
max_number_of_operations = [] ;
|
max_number_of_operations = [] ;
|
||||||
max_operation_data_length = 0 ;
|
max_operation_data_length = 0 ;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user