Shell: delete duplicated functor
This commit is contained in:
parent
f8ded9ca28
commit
227232e6c7
@ -816,32 +816,6 @@ module Raw = struct
|
||||
let supported_versions = Message.cfg.versions
|
||||
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
|
||||
(Table : Distributed_db_functors.DISTRIBUTED_DB)
|
||||
(Kind : sig
|
||||
@ -863,6 +837,7 @@ module Make
|
||||
Table.fetch (Kind.proj t) ?peer ?timeout k p
|
||||
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 pending t k = Table.pending (Kind.proj t) k
|
||||
let watch t = Table.watch (Kind.proj t)
|
||||
end
|
||||
|
||||
@ -871,10 +846,10 @@ module Block_header = struct
|
||||
include (Make (Raw_block_header.Table) (struct
|
||||
type t = net_db
|
||||
let proj net = net.block_header_db.table
|
||||
end) : DISTRIBUTED_DB with type t := net_db
|
||||
and type key := Block_hash.t
|
||||
and type value := Block_header.t
|
||||
and type param := unit)
|
||||
end) : Distributed_db_functors.DISTRIBUTED_DB with type t := net_db
|
||||
and type key := Block_hash.t
|
||||
and type value := Block_header.t
|
||||
and type param := unit)
|
||||
end
|
||||
|
||||
module Operation_hashes =
|
||||
@ -894,10 +869,10 @@ module Operation = struct
|
||||
include (Make (Raw_operation.Table) (struct
|
||||
type t = net_db
|
||||
let proj net = net.operation_db.table
|
||||
end) : DISTRIBUTED_DB with type t := net_db
|
||||
and type key := Operation_hash.t
|
||||
and type value := Operation.t
|
||||
and type param := unit)
|
||||
end) : Distributed_db_functors.DISTRIBUTED_DB with type t := net_db
|
||||
and type key := Operation_hash.t
|
||||
and type value := Operation.t
|
||||
and type param := unit)
|
||||
end
|
||||
|
||||
module Protocol = struct
|
||||
@ -905,10 +880,10 @@ module Protocol = struct
|
||||
include (Make (Raw_protocol.Table) (struct
|
||||
type t = db
|
||||
let proj db = db.protocol_db.table
|
||||
end) : DISTRIBUTED_DB with type t := db
|
||||
and type key := Protocol_hash.t
|
||||
and type value := Protocol.t
|
||||
and type param := unit)
|
||||
end) : Distributed_db_functors.DISTRIBUTED_DB with type t := db
|
||||
and type key := Protocol_hash.t
|
||||
and type value := Protocol.t
|
||||
and type param := unit)
|
||||
end
|
||||
|
||||
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
(** Tezos Shell - High-level API for the Gossip network and local storage. *)
|
||||
|
||||
open Distributed_db_functors
|
||||
|
||||
type t
|
||||
type db = t
|
||||
|
||||
@ -88,88 +90,6 @@ module Advertise : sig
|
||||
|
||||
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} *)
|
||||
|
||||
(** Index of block headers. *)
|
||||
|
@ -10,37 +10,85 @@
|
||||
(** Tezos Shell - High-level API for the Gossip network and local
|
||||
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
|
||||
|
||||
type t
|
||||
|
||||
(** The index key *)
|
||||
type key
|
||||
|
||||
(** The indexed data *)
|
||||
type value
|
||||
|
||||
(** An extra parameter for the network lookup, usually
|
||||
used for prevalidating data. *)
|
||||
type param
|
||||
|
||||
(** Is the value known locally? *)
|
||||
val known: t -> key -> bool Lwt.t
|
||||
|
||||
type error += Missing_data of key
|
||||
type error += Canceled 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
|
||||
|
||||
(** 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
|
||||
|
||||
(** 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
|
||||
|
||||
(** 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
|
||||
|
||||
(** 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 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 pending: t -> key -> bool
|
||||
|
Loading…
Reference in New Issue
Block a user