diff --git a/src/node/shell/distributed_db.ml b/src/node/shell/distributed_db.ml index fb45a0010..1cd1fda88 100644 --- a/src/node/shell/distributed_db.ml +++ b/src/node/shell/distributed_db.ml @@ -20,7 +20,12 @@ type 'a request_param = { } module Make_raw - (Hash : sig type t end) + (Hash : sig + type t + val name : string + val encoding : t Data_encoding.t + val pp : Format.formatter -> t -> unit + end) (Disk_table : Distributed_db_functors.DISK_TABLE with type key := Hash.t) (Memory_table : @@ -155,7 +160,14 @@ module Raw_operation_hashes = struct include Make_raw - (struct type t = Block_hash.t * int end) + (struct + type t = Block_hash.t * int + let name = "raw_operation_hash" + let pp ppf (h, n) = Format.fprintf ppf "%a:%d" Block_hash.pp h n + let encoding = + let open Data_encoding in + obj2 (req "block" Block_hash.encoding) (req "index" uint16) + end) (Operation_hashes_storage) (Operations_table) (struct @@ -217,7 +229,14 @@ end module Raw_operations = struct include Make_raw - (struct type t = Block_hash.t * int end) + (struct + type t = Block_hash.t * int + let name = "raw_operation" + let pp ppf (h, n) = Format.fprintf ppf "%a:%d" Block_hash.pp h n + let encoding = + let open Data_encoding in + obj2 (req "block" Block_hash.encoding) (req "index" uint16) + end) (Operations_storage) (Operations_table) (struct diff --git a/src/node/shell/distributed_db_functors.ml b/src/node/shell/distributed_db_functors.ml index 7a3e08c93..26c9bcaa9 100644 --- a/src/node/shell/distributed_db_functors.ml +++ b/src/node/shell/distributed_db_functors.ml @@ -70,7 +70,12 @@ module type PRECHECK = sig end module Make_table - (Hash : sig type t end) + (Hash : sig + type t + val name : string + val encoding : t Data_encoding.t + val pp : Format.formatter -> t -> unit + end) (Disk_table : DISK_TABLE with type key := Hash.t) (Memory_table : MEMORY_TABLE with type key := Hash.t) (Scheduler : SCHEDULER_EVENTS with type key := Hash.t) @@ -123,6 +128,17 @@ end = struct type error += Missing_data of key + let () = + Error_monad.register_error_kind `Permanent + ~id: ("distributed_db." ^ Hash.name ^ ".missing") + ~title: ("Missing " ^ Hash.name) + ~description: ("Some " ^ Hash.name ^ " is missing from the distributed db") + ~pp: (fun ppf key -> + Format.fprintf ppf "Missing %s %a" Hash.name Hash.pp key) + (Data_encoding.obj1 (Data_encoding.req "key" Hash.encoding)) + (function Missing_data key -> Some key | _ -> None) + (fun key -> Missing_data key) + let read s k = match Memory_table.find s.memory k with | exception Not_found -> diff --git a/src/node/shell/distributed_db_functors.mli b/src/node/shell/distributed_db_functors.mli index dba1d6bf2..083f4ce20 100644 --- a/src/node/shell/distributed_db_functors.mli +++ b/src/node/shell/distributed_db_functors.mli @@ -71,7 +71,12 @@ module type PRECHECK = sig end module Make_table - (Hash : sig type t end) + (Hash : sig + type t + val name : string + val encoding : t Data_encoding.t + val pp : Format.formatter -> t -> unit + end) (Disk_table : DISK_TABLE with type key := Hash.t) (Memory_table : MEMORY_TABLE with type key := Hash.t) (Scheduler : SCHEDULER_EVENTS with type key := Hash.t)