2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2018-02-06 00:17:03 +04:00
|
|
|
(* Copyright (c) 2014 - 2018. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2017-11-13 22:06:30 +04:00
|
|
|
(** Tezos Shell - Abstraction over all the disk storage.
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
It encapsulates access to:
|
|
|
|
|
|
|
|
- the index of validation contexts; and
|
|
|
|
- the persistent state of the node:
|
2018-02-16 04:26:24 +04:00
|
|
|
- the blockchain and its alternate heads ;
|
|
|
|
- the pool of pending operations of a chain. *)
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-11-13 22:06:30 +04:00
|
|
|
type t
|
|
|
|
type global_state = t
|
|
|
|
|
|
|
|
(** Read the internal state of the node and initialize
|
|
|
|
the databases. *)
|
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
|
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 +=
|
2018-02-16 04:26:24 +04:00
|
|
|
| Unknown_chain of Chain_id.t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
(** {2 Network} ************************************************************)
|
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
(** Data specific to a given chain (e.g the main chain or the current
|
|
|
|
test chain). *)
|
|
|
|
module Chain : sig
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
type t
|
2018-02-16 04:26:24 +04:00
|
|
|
type chain_state = t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-11-13 22:06:30 +04:00
|
|
|
(** The chain starts from a genesis block associated to a seed protocol *)
|
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
|
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
(** Initialize a chain for a given [genesis]. By default,
|
|
|
|
the chain does accept forking test chain. When
|
|
|
|
[~allow_forked_chain:true] is provided, test chain are allowed. *)
|
2017-02-24 20:17:53 +04:00
|
|
|
val create:
|
|
|
|
global_state ->
|
2018-02-16 04:26:24 +04:00
|
|
|
?allow_forked_chain:bool ->
|
|
|
|
genesis -> chain_state Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
(** Look up for a chain by the hash of its genesis block. *)
|
|
|
|
val get: global_state -> Chain_id.t -> chain_state tzresult Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
(** Returns all the known chains. *)
|
|
|
|
val all: global_state -> chain_state list Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
(** Destroy a chain: this completly removes from the local storage all
|
|
|
|
the data associated to the chain (this includes blocks and
|
2017-02-24 20:17:53 +04:00
|
|
|
operations). *)
|
2018-02-16 04:26:24 +04:00
|
|
|
val destroy: global_state -> chain_state -> unit Lwt.t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-11-13 22:06:30 +04:00
|
|
|
(** Various accessors. *)
|
2018-02-16 04:26:24 +04:00
|
|
|
val id: chain_state -> Chain_id.t
|
|
|
|
val genesis: chain_state -> genesis
|
|
|
|
val global_state: chain_state -> global_state
|
2017-11-13 22:06:30 +04:00
|
|
|
|
|
|
|
(** Hash of the faked block header of the genesis block. *)
|
2018-02-16 04:26:24 +04:00
|
|
|
val faked_genesis_hash: chain_state -> Block_hash.t
|
2017-11-13 22:06:30 +04:00
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
(** Return the expiration timestamp of a test chain. *)
|
|
|
|
val expiration: chain_state -> Time.t option
|
|
|
|
val allow_forked_chain: chain_state -> bool
|
2016-09-22 17:34:38 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
|
2017-11-13 22:06:30 +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
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
val known: Chain.t -> Block_hash.t -> bool Lwt.t
|
|
|
|
val known_valid: Chain.t -> Block_hash.t -> bool Lwt.t
|
|
|
|
val known_invalid: Chain.t -> Block_hash.t -> bool Lwt.t
|
|
|
|
val read_invalid: Chain.t -> Block_hash.t -> Store.Block.invalid_block option Lwt.t
|
|
|
|
val list_invalid: Chain.t -> (Block_hash.t * int32 * error list) list Lwt.t
|
|
|
|
val unmark_invalid: Chain.t -> Block_hash.t -> unit tzresult Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
val read: Chain.t -> Block_hash.t -> block tzresult Lwt.t
|
|
|
|
val read_opt: Chain.t -> Block_hash.t -> block option Lwt.t
|
|
|
|
val read_exn: Chain.t -> Block_hash.t -> block Lwt.t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-12-05 18:19:25 +04:00
|
|
|
type error += Inconsistent_hash of Context_hash.t * Context_hash.t
|
|
|
|
|
2016-10-21 16:01:20 +04:00
|
|
|
val store:
|
2018-02-12 19:36:24 +04:00
|
|
|
?dont_enforce_context_hash:bool ->
|
2018-02-16 04:26:24 +04:00
|
|
|
Chain.t ->
|
2017-04-19 23:46:10 +04:00
|
|
|
Block_header.t ->
|
|
|
|
Operation.t list list ->
|
|
|
|
Updater.validation_result ->
|
|
|
|
block option tzresult Lwt.t
|
|
|
|
|
|
|
|
val store_invalid:
|
2018-02-16 04:26:24 +04:00
|
|
|
Chain.t ->
|
2017-04-19 23:46:10 +04:00
|
|
|
Block_header.t ->
|
2017-10-31 20:59:02 +04:00
|
|
|
error list ->
|
2017-04-19 23:46:10 +04:00
|
|
|
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
|
2017-09-29 20:43:13 +04:00
|
|
|
val validation_passes: t -> int
|
2018-02-16 04:26:24 +04:00
|
|
|
val chain_id: t -> Chain_id.t
|
|
|
|
val chain_state: t -> Chain.t
|
2017-04-19 23:46:10 +04:00
|
|
|
val level: t -> Int32.t
|
2017-12-05 18:18:05 +04:00
|
|
|
val message: t -> string option
|
2017-04-20 10:49:14 +04:00
|
|
|
val max_operations_ttl: t -> int
|
2017-11-19 17:38:36 +04:00
|
|
|
val max_operation_data_length: t -> int
|
2017-04-19 23:46:10 +04:00
|
|
|
|
2017-11-11 06:34:12 +04:00
|
|
|
val is_genesis: t -> bool
|
2017-04-19 23:46:10 +04:00
|
|
|
val predecessor: t -> block option Lwt.t
|
2018-02-16 04:26:24 +04:00
|
|
|
val predecessor_n: Chain.t -> Block_hash.t -> int -> Block_hash.t option Lwt.t
|
2017-04-19 23:46:10 +04:00
|
|
|
|
|
|
|
val context: t -> Context.t Lwt.t
|
|
|
|
val protocol_hash: t -> Protocol_hash.t Lwt.t
|
2018-02-16 04:26:24 +04:00
|
|
|
val test_chain: t -> Test_chain_status.t Lwt.t
|
2017-04-19 23:46:10 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
val watcher: Chain.t -> block Lwt_stream.t * Lwt_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
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
val compute_locator: Chain.t -> ?size:int -> Block.t -> Block_locator.t Lwt.t
|
2017-12-17 22:51:06 +04:00
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
val fork_testchain:
|
|
|
|
Block.t -> Protocol_hash.t -> Time.t -> Chain.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-11-30 21:34:22 +04:00
|
|
|
current_mempool: Mempool.t ;
|
2017-11-14 04:29:19 +04:00
|
|
|
live_blocks: Block_hash.Set.t ;
|
|
|
|
live_operations: Operation_hash.Set.t ;
|
2017-12-17 22:51:06 +04:00
|
|
|
locator: Block_locator.t Lwt.t lazy_t ;
|
2017-04-19 23:46:10 +04:00
|
|
|
}
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
val read_chain_data:
|
|
|
|
Chain.t ->
|
|
|
|
(Store.Chain_data.store -> chain_data -> 'a Lwt.t) ->
|
2017-04-19 23:46:10 +04:00
|
|
|
'a Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
val update_chain_data:
|
|
|
|
Chain.t ->
|
|
|
|
(Store.Chain_data.store -> chain_data -> (chain_data option * 'a) Lwt.t) ->
|
2017-04-19 23:46:10 +04:00
|
|
|
'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-11-27 09:13:12 +04:00
|
|
|
include (module type of (struct include Protocol end))
|
|
|
|
|
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
|
|
|
|
2017-11-30 21:34:22 +04:00
|
|
|
module Current_mempool : sig
|
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
val get: Chain.t -> (Block_header.t * Mempool.t) Lwt.t
|
2017-11-30 21:34:22 +04:00
|
|
|
(** The current mempool. *)
|
|
|
|
|
2018-02-16 04:26:24 +04:00
|
|
|
val set: Chain.t -> head:Block_hash.t -> Mempool.t -> unit Lwt.t
|
2017-11-30 21:34:22 +04:00
|
|
|
(** Set the current mempool. It is ignored if the current head is
|
|
|
|
not the provided one. *)
|
|
|
|
|
|
|
|
end
|
|
|
|
|