-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16543 from MinaProtocol/georgeee/merge-compatible…
…-to-develop-28jan2025 Merge compatible to develop (28 Jan 2025)
- Loading branch information
Showing
35 changed files
with
663 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
open Core_kernel | ||
open Async | ||
|
||
module Make : functor (T : Binable.S) -> sig | ||
type t | ||
|
||
(** Initialize the on-disk cache explicitly before interactions with it take place. *) | ||
val initialize : | ||
string | ||
-> logger:Logger.t | ||
-> (t, [> `Initialization_error of Error.t ]) Deferred.Result.t | ||
|
||
type id | ||
|
||
(** Put the value to disk, return an identifier that is associated with a special handler in GC. *) | ||
val put : t -> T.t -> id | ||
|
||
(** Read from the cache, crashing if the value cannot be found. *) | ||
val get : t -> id -> T.t | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(library | ||
(public_name disk_cache) | ||
(virtual_modules disk_cache) | ||
(default_implementation disk_cache.filesystem) | ||
(libraries | ||
;; opam libraries | ||
core_kernel | ||
async | ||
;; local libraries | ||
logger | ||
) | ||
(preprocess | ||
(pps ppx_mina ppx_version)) | ||
(instrumentation (backend bisect_ppx))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
(* Cache proofs using the filesystem, one file per proof. *) | ||
|
||
open Core | ||
open Async | ||
|
||
module Make (B : sig | ||
include Binable.S | ||
end) = | ||
struct | ||
type t = string * int ref | ||
|
||
type id = { idx : int } | ||
|
||
let failed_to_get_cache_folder_status ~logger ~(error_msg : string) ~path = | ||
[%log error] "%s" error_msg ~metadata:[ ("path", `String path) ] ; | ||
failwithf "%s (%s)" error_msg path () | ||
|
||
let initialize path ~logger = | ||
let open Deferred.Let_syntax in | ||
match%bind Sys.is_directory path with | ||
| `Yes -> | ||
let%bind () = File_system.clear_dir path in | ||
Deferred.Result.return (path, ref 0) | ||
| `No -> ( | ||
match%bind Sys.is_file path with | ||
| `Yes -> | ||
failed_to_get_cache_folder_status ~logger | ||
~error_msg: | ||
"Invalid path to proof cache folder. Path points to a file" | ||
~path | ||
| `No -> | ||
let%bind () = File_system.create_dir path in | ||
Deferred.Result.return (path, ref 0) | ||
| `Unknown -> | ||
failed_to_get_cache_folder_status ~logger | ||
~error_msg:"Cannot evaluate existence of cache folder" ~path ) | ||
| `Unknown -> | ||
failed_to_get_cache_folder_status ~logger | ||
~error_msg:"Cannot evaluate existence of cache folder" ~path | ||
|
||
let path root i = root ^ Filename.dir_sep ^ Int.to_string i | ||
|
||
let get ((root, _counter) : t) (id : id) : B.t = | ||
(* Read from the file. *) | ||
In_channel.with_file ~binary:true (path root id.idx) ~f:(fun chan -> | ||
let str = In_channel.input_all chan in | ||
Binable.of_string (module B) str ) | ||
|
||
let put ((root, counter) : t) x : id = | ||
let new_counter = !counter in | ||
incr counter ; | ||
let res = { idx = new_counter } in | ||
(* When this reference is GC'd, delete the file. *) | ||
Core.Gc.Expert.add_finalizer_last_exn res (fun () -> | ||
Core.Unix.unlink (path root new_counter) ) ; | ||
(* Write the proof to the file. *) | ||
Out_channel.with_file ~binary:true (path root new_counter) ~f:(fun chan -> | ||
Out_channel.output_string chan @@ Binable.to_string (module B) x ) ; | ||
res | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(library | ||
(public_name disk_cache.filesystem) | ||
(name disk_cache_filesystem) | ||
(implements disk_cache) | ||
(libraries | ||
;; opam libraries | ||
core | ||
async | ||
;; local libraries | ||
logger | ||
file_system | ||
) | ||
(preprocess | ||
(pps ppx_mina ppx_version ppx_jane)) | ||
(instrumentation (backend bisect_ppx)) | ||
) |
Oops, something went wrong.