2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2016. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
type t
|
|
|
|
type global_state = t
|
2016-09-08 21:13:10 +04:00
|
|
|
(** An abstraction over all the disk storage used by the node.
|
|
|
|
|
|
|
|
It encapsulates access to:
|
|
|
|
|
|
|
|
- the index of validation contexts; and
|
|
|
|
- the persistent state of the node:
|
|
|
|
- the blockchain and its alternate heads of a "network";
|
2017-04-19 23:46:10 +04:00
|
|
|
- the pool of pending operations of a "network". *)
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
val read:
|
2017-02-24 20:17:53 +04:00
|
|
|
?patch_context:(Context.t -> Context.t Lwt.t) ->
|
2016-09-08 21:13:10 +04:00
|
|
|
store_root:string ->
|
|
|
|
context_root:string ->
|
|
|
|
unit ->
|
2017-02-24 20:17:53 +04:00
|
|
|
global_state tzresult Lwt.t
|
2017-04-19 23:46:10 +04:00
|
|
|
(** Read the internal state of the node and initialize
|
|
|
|
the databases. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-05-31 20:27:11 +04:00
|
|
|
val close:
|
|
|
|
global_state -> unit Lwt.t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
(** {2 Errors} **************************************************************)
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
type error +=
|
2017-03-31 15:04:05 +04:00
|
|
|
| Unknown_network of Net_id.t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
(** {2 Network} ************************************************************)
|
|
|
|
|
|
|
|
(** Data specific to a given network. *)
|
|
|
|
module Net : sig
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
type t
|
2017-04-19 23:46:10 +04:00
|
|
|
type net_state = t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
type genesis = {
|
|
|
|
time: Time.t ;
|
|
|
|
block: Block_hash.t ;
|
|
|
|
protocol: Protocol_hash.t ;
|
2016-09-08 21:13:10 +04:00
|
|
|
}
|
2017-02-24 20:17:53 +04:00
|
|
|
val genesis_encoding: genesis Data_encoding.t
|
|
|
|
|
|
|
|
val create:
|
|
|
|
global_state ->
|
2017-04-10 23:14:17 +04:00
|
|
|
?allow_forked_network:bool ->
|
2017-04-19 23:46:10 +04:00
|
|
|
genesis -> net_state Lwt.t
|
|
|
|
(** Initialize a network for a given [genesis]. By default,
|
|
|
|
the network does accept forking test network. When
|
|
|
|
[~allow_forked_network:true] is provided, test network are allowed. *)
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
val get: global_state -> Net_id.t -> net_state tzresult Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
(** Look up for a network by the hash of its genesis block. *)
|
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
val all: global_state -> net_state list Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
(** Returns all the known networks. *)
|
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
val destroy: global_state -> net_state -> unit Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
(** Destroy a network: this completly removes from the local storage all
|
|
|
|
the data associated to the network (this includes blocks and
|
|
|
|
operations). *)
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
val id: net_state -> Net_id.t
|
|
|
|
val genesis: net_state -> genesis
|
|
|
|
val expiration: net_state -> Time.t option
|
|
|
|
val allow_forked_network: net_state -> bool
|
2017-02-24 20:17:53 +04:00
|
|
|
(** Accessors. Respectively access to;
|
|
|
|
- the network id (the hash of its genesis block)
|
|
|
|
- its optional expiration time
|
|
|
|
- the associated global state. *)
|
|
|
|
|
2016-09-22 17:34:38 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
(** {2 Block database} ********************************************************)
|
2017-03-30 15:16:21 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
module Block : sig
|
2017-03-30 15:16:21 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
type t
|
|
|
|
type block = t
|
2017-03-30 15:16:21 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
val known_valid: Net.t -> Block_hash.t -> bool Lwt.t
|
|
|
|
val known_invalid: Net.t -> Block_hash.t -> bool Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
val read: Net.t -> Block_hash.t -> block tzresult Lwt.t
|
|
|
|
val read_opt: Net.t -> Block_hash.t -> block option Lwt.t
|
|
|
|
val read_exn: Net.t -> Block_hash.t -> block Lwt.t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-10-21 16:01:20 +04:00
|
|
|
val store:
|
2017-04-19 23:46:10 +04:00
|
|
|
Net.t ->
|
|
|
|
Block_header.t ->
|
|
|
|
Operation.t list list ->
|
|
|
|
Updater.validation_result ->
|
|
|
|
block option tzresult Lwt.t
|
|
|
|
|
|
|
|
val store_invalid:
|
|
|
|
Net.t ->
|
|
|
|
Block_header.t ->
|
|
|
|
bool tzresult Lwt.t
|
|
|
|
|
|
|
|
val compare: t -> t -> int
|
|
|
|
val equal: t -> t -> bool
|
|
|
|
|
|
|
|
val hash: t -> Block_hash.t
|
|
|
|
val header: t -> Block_header.t
|
|
|
|
val shell_header: t -> Block_header.shell_header
|
|
|
|
val timestamp: t -> Time.t
|
|
|
|
val fitness: t -> Fitness.t
|
|
|
|
val operation_list_count: t -> int
|
|
|
|
val net_id: t -> Net_id.t
|
|
|
|
val level: t -> Int32.t
|
|
|
|
val message: t -> string
|
2017-04-20 10:49:14 +04:00
|
|
|
val max_operations_ttl: t -> int
|
2017-04-19 23:46:10 +04:00
|
|
|
|
|
|
|
val predecessor: t -> block option Lwt.t
|
|
|
|
|
|
|
|
val context: t -> Context.t Lwt.t
|
|
|
|
val protocol_hash: t -> Protocol_hash.t Lwt.t
|
|
|
|
val test_network: t -> Context.test_network Lwt.t
|
|
|
|
|
|
|
|
val operation_hashes:
|
|
|
|
t -> int ->
|
|
|
|
(Operation_hash.t list * Operation_list_list_hash.path) Lwt.t
|
|
|
|
val all_operation_hashes: t -> Operation_hash.t list list Lwt.t
|
|
|
|
|
|
|
|
val operations:
|
|
|
|
t -> int -> (Operation.t list * Operation_list_list_hash.path) Lwt.t
|
|
|
|
val all_operations: t -> Operation.t list list Lwt.t
|
|
|
|
|
|
|
|
val watcher: Net.t -> block Lwt_stream.t * Watcher.stopper
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
end
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
val read_block:
|
|
|
|
global_state -> Block_hash.t -> Block.t option Lwt.t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
val read_block_exn:
|
|
|
|
global_state -> Block_hash.t -> Block.t Lwt.t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
val fork_testnet:
|
|
|
|
global_state -> Block.t -> Protocol_hash.t -> Time.t ->
|
|
|
|
Net.t tzresult Lwt.t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
type chain_data = {
|
|
|
|
current_head: Block.t ;
|
|
|
|
}
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
val read_chain_store:
|
|
|
|
Net.t ->
|
|
|
|
(Store.Chain.store -> chain_data -> 'a Lwt.t) ->
|
|
|
|
'a Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
val update_chain_store:
|
|
|
|
Net.t ->
|
|
|
|
(Store.Chain.store -> chain_data -> (chain_data option * 'a) Lwt.t) ->
|
|
|
|
'a Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
(** {2 Protocol database} ***************************************************)
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
module Protocol : sig
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
(** Is a value stored in the local database ? *)
|
|
|
|
val known: global_state -> Protocol_hash.t -> bool Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
(** Read a value in the local database. *)
|
|
|
|
val read: global_state -> Protocol_hash.t -> Protocol.t tzresult Lwt.t
|
|
|
|
val read_opt: global_state -> Protocol_hash.t -> Protocol.t option Lwt.t
|
|
|
|
val read_exn: global_state -> Protocol_hash.t -> Protocol.t Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
(** Read a value in the local database (without parsing). *)
|
|
|
|
val read_raw: global_state -> Protocol_hash.t -> MBytes.t tzresult Lwt.t
|
|
|
|
val read_raw_opt: global_state -> Protocol_hash.t -> MBytes.t option Lwt.t
|
|
|
|
val read_raw_exn: global_state -> Protocol_hash.t -> MBytes.t Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
val store: global_state -> Protocol.t -> Protocol_hash.t option Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
(** Remove a value from the local database. *)
|
|
|
|
val remove: global_state -> Protocol_hash.t -> bool Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
val list: global_state -> Protocol_hash.Set.t Lwt.t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
end
|
2017-10-09 12:55:12 +04:00
|
|
|
|
|
|
|
module Registred_protocol : sig
|
|
|
|
|
|
|
|
module type T = sig
|
|
|
|
val hash: Protocol_hash.t
|
|
|
|
include Updater.RAW_PROTOCOL with type error := error
|
|
|
|
and type 'a tzresult := 'a tzresult
|
|
|
|
val complete_b58prefix : Context.t -> string -> string list Lwt.t
|
|
|
|
end
|
|
|
|
|
|
|
|
val mem: Protocol_hash.t -> bool
|
|
|
|
|
|
|
|
val get: Protocol_hash.t -> (module T) option
|
|
|
|
val get_exn: Protocol_hash.t -> (module T)
|
|
|
|
|
|
|
|
end
|