Skip to content

Commit

Permalink
merkle_ledger: auto open Core_Kernel in dune
Browse files Browse the repository at this point in the history
  • Loading branch information
rbonichon committed Feb 16, 2024
1 parent 1a6423d commit 063fcba
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 31 deletions.
2 changes: 0 additions & 2 deletions src/lib/merkle_ledger/any_ledger.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
* Props to @nholland for showing me this trick.
* *)

open Core_kernel

module Make_base (Inputs : Intf.Inputs.Intf) :
Intf.Ledger.ANY
with module Location = Inputs.Location
Expand Down
4 changes: 2 additions & 2 deletions src/lib/merkle_ledger/database.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Core

module Make (Inputs : Intf.Inputs.DATABASE) = struct
(* The max depth of a merkle tree can never be greater than 253. *)
open Inputs
Expand Down Expand Up @@ -46,6 +44,8 @@ module Make (Inputs : Intf.Inputs.DATABASE) = struct
let depth t = t.depth

let create ?directory_name ~depth () =
let open Core in
(* for ^/ and Unix below *)
assert (depth < 0xfe) ;
let uuid = Uuid_unix.create () in
let directory =
Expand Down
2 changes: 1 addition & 1 deletion src/lib/merkle_ledger/dune
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
; module openings may both solve the warning *and* help the reader)
;
; 44: open-shadow-identifier (operation overloading is common in the codebase)
(:standard -w +a-40..42-44 -warn-error +a-70 -open Core))
(:standard -w +a-40..42-44 -warn-error +a-70 -open Core_kernel))
(library_flags -linkall)
(modules_without_implementation
location_intf)
Expand Down
1 change: 0 additions & 1 deletion src/lib/merkle_ledger/graphviz.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
open Core
open Async

module Make (Inputs : Intf.Graphviz.I) :
Expand Down
60 changes: 54 additions & 6 deletions src/lib/merkle_ledger/intf.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
open Core
module type LOCATION = sig
module Addr : module type of Merkle_address

module Prefix : sig
val generic : Unsigned.UInt8.t

val account : Unsigned.UInt8.t

val hash : ledger_depth:int -> int -> Unsigned.UInt8.t
end

type t = Generic of Bigstring.t | Account of Addr.t | Hash of Addr.t
[@@deriving sexp, hash, compare]

val is_generic : t -> bool

val is_account : t -> bool

val is_hash : t -> bool

val height : ledger_depth:int -> t -> int

val root_hash : t

val last_direction : Addr.t -> Direction.t

val build_generic : Bigstring.t -> t

val parse : ledger_depth:int -> Bigstring.t -> (t, unit) Result.t

val prefix_bigstring : Unsigned.UInt8.t -> Bigstring.t -> Bigstring.t

val to_path_exn : t -> Addr.t

val serialize : ledger_depth:int -> t -> Bigstring.t

val parent : t -> t

val next : t -> t Option.t

val prev : t -> t Option.t

val sibling : t -> t

val order_siblings : t -> 'a -> 'a -> 'a * 'a

val merkle_path_dependencies_exn : t -> (t * Direction.t) list

include Comparable.S with type t := t
end

module type Key = sig
type t [@@deriving sexp]
Expand Down Expand Up @@ -211,14 +260,13 @@ module Inputs = struct

module Hash : Hash with type account := Account.t

module Location : Location_intf.S
module Location : LOCATION
end

module type DATABASE = sig
include Intf

module Location_binable :
Core_kernel.Hashable.S_binable with type t := Location.t
module Location_binable : Hashable.S_binable with type t := Location.t

module Kvdb : Key_value_database with type config := string

Expand Down Expand Up @@ -397,7 +445,7 @@ module Ledger = struct

type hash

module Location : Location_intf.S
module Location : LOCATION

(** The type of the witness for a base ledger exposed here so that it can
* be easily accessed from outside this module *)
Expand Down Expand Up @@ -436,7 +484,7 @@ module Ledger = struct

module For_tests : sig
val gen_account_location :
ledger_depth:int -> Location.t Core.Quickcheck.Generator.t
ledger_depth:int -> Location.t Quickcheck.Generator.t
end
end
end
Expand Down
7 changes: 3 additions & 4 deletions src/lib/merkle_ledger/location.ml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
open Core
open Unsigned

(* add functions to library module Bigstring so we can derive hash for the type t below *)
module Bigstring = struct
[%%versioned_binable
module Stable = struct
module V1 = struct
type t = Core_kernel.Bigstring.Stable.V1.t [@@deriving sexp, compare]
type t = Bigstring.Stable.V1.t [@@deriving sexp, compare]

let to_latest = Fn.id

Expand All @@ -18,9 +17,9 @@ module Bigstring = struct
include Bounded_types.String.Of_stringable (struct
type nonrec t = t

let of_string s = Core_kernel.Bigstring.of_string s
let of_string s = Bigstring.of_string s

let to_string s = Core_kernel.Bigstring.to_string s
let to_string s = Bigstring.to_string s
end)
end
end]
Expand Down
10 changes: 5 additions & 5 deletions src/lib/merkle_ledger/location.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ module Bigstring : sig
[%%versioned:
module Stable : sig
module V1 : sig
type t = Core_kernel.Bigstring.Stable.V1.t [@@deriving sexp, compare]
type t = Bigstring.Stable.V1.t [@@deriving sexp, compare]

include Core_kernel.Binable.S with type t := t
include Binable.S with type t := t

val hash_fold_t : Core_kernel.Hash.state -> t -> Core_kernel.Hash.state
val hash_fold_t : Hash.state -> t -> Hash.state

val hash : t -> Core_kernel.Hash.hash_value
val hash : t -> Hash.hash_value
end
end]

include Core_kernel.Hashable.S with type t := t
include Hashable.S with type t := t
end

module T : Location_intf.S
2 changes: 0 additions & 2 deletions src/lib/merkle_ledger/location_intf.mli
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
(* location_intf.ml -- interface file for Location *)

open Core

module type S = sig
module Addr : module type of Merkle_address

Expand Down
2 changes: 0 additions & 2 deletions src/lib/merkle_ledger/merkle_path.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Core_kernel

module type S = sig
type hash

Expand Down
2 changes: 0 additions & 2 deletions src/lib/merkle_ledger/null_ledger.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Core_kernel

module Make (Inputs : Intf.Inputs.Intf) : sig
include
Intf.Ledger.NULL
Expand Down
2 changes: 0 additions & 2 deletions src/lib/merkle_ledger/util.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Core_kernel

module type Inputs_intf = sig
module Location : Location_intf.S

Expand Down
3 changes: 1 addition & 2 deletions src/lib/merkle_ledger/util.mli
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module type Inputs_intf = sig
module Location : Location_intf.S

module Location_binable :
Core_kernel.Hashable.S_binable with type t := Location.t
module Location_binable : Hashable.S_binable with type t := Location.t

module Key : Intf.Key

Expand Down

0 comments on commit 063fcba

Please sign in to comment.