Shell: delete duplicated functor

This commit is contained in:
bruno 2018-02-14 17:27:14 +01:00 committed by Grégoire Henry
parent f8ded9ca28
commit 227232e6c7
3 changed files with 63 additions and 120 deletions

View File

@ -816,32 +816,6 @@ module Raw = struct
let supported_versions = Message.cfg.versions let supported_versions = Message.cfg.versions
end end
module type DISTRIBUTED_DB = sig
type t
type key
type value
val known: t -> key -> bool Lwt.t
type error += Missing_data of key
val read: t -> key -> value tzresult Lwt.t
val read_opt: t -> key -> value option Lwt.t
val read_exn: t -> key -> value Lwt.t
type param
type error += Timeout of key
val fetch:
t ->
?peer:P2p_peer.Id.t ->
?timeout:float ->
key -> param -> value tzresult Lwt.t
val prefetch:
t ->
?peer:P2p_peer.Id.t ->
?timeout:float ->
key -> param -> unit
type error += Canceled of key
val clear_or_cancel: t -> key -> unit
val watch: t -> (key * value) Lwt_stream.t * Lwt_watcher.stopper
end
module Make module Make
(Table : Distributed_db_functors.DISTRIBUTED_DB) (Table : Distributed_db_functors.DISTRIBUTED_DB)
(Kind : sig (Kind : sig
@ -863,6 +837,7 @@ module Make
Table.fetch (Kind.proj t) ?peer ?timeout k p Table.fetch (Kind.proj t) ?peer ?timeout k p
let clear_or_cancel t k = Table.clear_or_cancel (Kind.proj t) k let clear_or_cancel t k = Table.clear_or_cancel (Kind.proj t) k
let inject t k v = Table.inject (Kind.proj t) k v let inject t k v = Table.inject (Kind.proj t) k v
let pending t k = Table.pending (Kind.proj t) k
let watch t = Table.watch (Kind.proj t) let watch t = Table.watch (Kind.proj t)
end end
@ -871,7 +846,7 @@ module Block_header = struct
include (Make (Raw_block_header.Table) (struct include (Make (Raw_block_header.Table) (struct
type t = net_db type t = net_db
let proj net = net.block_header_db.table let proj net = net.block_header_db.table
end) : DISTRIBUTED_DB with type t := net_db end) : Distributed_db_functors.DISTRIBUTED_DB with type t := net_db
and type key := Block_hash.t and type key := Block_hash.t
and type value := Block_header.t and type value := Block_header.t
and type param := unit) and type param := unit)
@ -894,7 +869,7 @@ module Operation = struct
include (Make (Raw_operation.Table) (struct include (Make (Raw_operation.Table) (struct
type t = net_db type t = net_db
let proj net = net.operation_db.table let proj net = net.operation_db.table
end) : DISTRIBUTED_DB with type t := net_db end) : Distributed_db_functors.DISTRIBUTED_DB with type t := net_db
and type key := Operation_hash.t and type key := Operation_hash.t
and type value := Operation.t and type value := Operation.t
and type param := unit) and type param := unit)
@ -905,7 +880,7 @@ module Protocol = struct
include (Make (Raw_protocol.Table) (struct include (Make (Raw_protocol.Table) (struct
type t = db type t = db
let proj db = db.protocol_db.table let proj db = db.protocol_db.table
end) : DISTRIBUTED_DB with type t := db end) : Distributed_db_functors.DISTRIBUTED_DB with type t := db
and type key := Protocol_hash.t and type key := Protocol_hash.t
and type value := Protocol.t and type value := Protocol.t
and type param := unit) and type param := unit)

View File

@ -9,6 +9,8 @@
(** Tezos Shell - High-level API for the Gossip network and local storage. *) (** Tezos Shell - High-level API for the Gossip network and local storage. *)
open Distributed_db_functors
type t type t
type db = t type db = t
@ -88,88 +90,6 @@ module Advertise : sig
end end
(** {1 Indexes} *)
(** Generic interface for a "distributed" index.
By "distributed", it means that this interface abstract the p2p
gossip layer and it is able to fetch missing data from known
peers in a "synchronous" interface.
*)
module type DISTRIBUTED_DB = sig
type t
type key
(** The index key *)
type value
(** The indexed data *)
(** Is the value known locally? *)
val known: t -> key -> bool Lwt.t
type error += Missing_data of key
(** Return the value if it is known locally, otherwise fail with
the error [Missing_data]. *)
val read: t -> key -> value tzresult Lwt.t
(** Return the value if it is known locally, otherwise fail with
the value [None]. *)
val read_opt: t -> key -> value option Lwt.t
(** Return the value if it is known locally, otherwise fail with
the exception [Not_found]. *)
val read_exn: t -> key -> value Lwt.t
type param (** An extra parameter for the network lookup, usually
used for prevalidating data. *)
type error += Timeout of key
(** Return the value if it is known locally, or block until the data
is received from the network. By default, the data will be
requested to all the active peers in the network; if the [peer]
argument is provided, the data will only be requested to the
provided peer. By default, the resulting promise will block
forever if the data is never received. If [timeout] is provided
the promise will be resolved with the error [Timeout] after the
provided amount of seconds.
A internal scheduler is able to re-send the request with an
exponential back-off until the data is received. If the function
is called multiple time with the same key but with disctinct
peers, the internal scheduler randomly chooses the requested
peer (at each retry). *)
val fetch:
t ->
?peer:P2p_peer.Id.t ->
?timeout:float ->
key -> param -> value tzresult Lwt.t
(** Same as `fetch` but the call is non-blocking: the data will be
stored in the local index when received. *)
val prefetch:
t ->
?peer:P2p_peer.Id.t ->
?timeout:float ->
key -> param -> unit
type error += Canceled of key
(** Remove the data from the local index or cancel all pending
request. Any pending [fetch] promises are resolved with the
error [Canceled]. *)
val clear_or_cancel: t -> key -> unit
(** Monitor all the fetched data. A given data will appear only
once. *)
val watch: t -> (key * value) Lwt_stream.t * Lwt_watcher.stopper
end
(** {2 Block index} *) (** {2 Block index} *)
(** Index of block headers. *) (** Index of block headers. *)

View File

@ -10,37 +10,85 @@
(** Tezos Shell - High-level API for the Gossip network and local (** Tezos Shell - High-level API for the Gossip network and local
storage (helpers). *) storage (helpers). *)
(** {1 Indexes} *)
(** Generic interface for a "distributed" index.
By "distributed", it means that this interface abstract the p2p
gossip layer and it is able to fetch missing data from known
peers in a "synchronous" interface.
*)
module type DISTRIBUTED_DB = sig module type DISTRIBUTED_DB = sig
type t type t
(** The index key *)
type key type key
(** The indexed data *)
type value type value
(** An extra parameter for the network lookup, usually
used for prevalidating data. *)
type param type param
(** Is the value known locally? *)
val known: t -> key -> bool Lwt.t val known: t -> key -> bool Lwt.t
type error += Missing_data of key type error += Missing_data of key
type error += Canceled of key type error += Canceled of key
type error += Timeout of key type error += Timeout of key
(** Return the value if it is known locally, otherwise fail with
the error [Missing_data]. *)
val read: t -> key -> value tzresult Lwt.t val read: t -> key -> value tzresult Lwt.t
(** Return the value if it is known locally, otherwise fail with
the value [None]. *)
val read_opt: t -> key -> value option Lwt.t val read_opt: t -> key -> value option Lwt.t
(** Return the value if it is known locally, otherwise fail with
the exception [Not_found]. *)
val read_exn: t -> key -> value Lwt.t val read_exn: t -> key -> value Lwt.t
(** Same as `fetch` but the call is non-blocking: the data will be
stored in the local index when received. *)
val prefetch: val prefetch:
t -> t ->
?peer:P2p_peer.Id.t -> ?peer:P2p_peer.Id.t ->
?timeout:float -> ?timeout:float ->
key -> param -> unit key -> param -> unit
(** Return the value if it is known locally, or block until the data
is received from the network. By default, the data will be
requested to all the active peers in the network; if the [peer]
argument is provided, the data will only be requested to the
provided peer. By default, the resulting promise will block
forever if the data is never received. If [timeout] is provided
the promise will be resolved with the error [Timeout] after the
provided amount of seconds.
A internal scheduler is able to re-send the request with an
exponential back-off until the data is received. If the function
is called multiple time with the same key but with disctinct
peers, the internal scheduler randomly chooses the requested
peer (at each retry). *)
val fetch: val fetch:
t -> t ->
?peer:P2p_peer.Id.t -> ?peer:P2p_peer.Id.t ->
?timeout:float -> ?timeout:float ->
key -> param -> value tzresult Lwt.t key -> param -> value tzresult Lwt.t
(** Remove the data from the local index or cancel all pending
request. Any pending [fetch] promises are resolved with the
error [Canceled]. *)
val clear_or_cancel: t -> key -> unit val clear_or_cancel: t -> key -> unit
val inject: t -> key -> value -> bool Lwt.t val inject: t -> key -> value -> bool Lwt.t
(** Monitor all the fetched data. A given data will appear only
once. *)
val watch: t -> (key * value) Lwt_stream.t * Lwt_watcher.stopper val watch: t -> (key * value) Lwt_stream.t * Lwt_watcher.stopper
val pending: t -> key -> bool val pending: t -> key -> bool