2017-11-14 03:32:46 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2016. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
(** Tezos Protocol Environment - Protocol Implementation Updater *)
|
|
|
|
|
2017-04-10 14:14:11 +04:00
|
|
|
type validation_result = {
|
|
|
|
context: Context.t ;
|
2017-04-19 21:21:23 +04:00
|
|
|
fitness: Fitness.t ;
|
2017-04-10 14:14:11 +04:00
|
|
|
message: string option ;
|
2017-04-18 13:29:14 +04:00
|
|
|
max_operations_ttl: int ;
|
2017-04-10 14:14:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
type rpc_context = {
|
2017-04-14 00:48:07 +04:00
|
|
|
block_hash: Block_hash.t ;
|
2017-04-19 21:21:23 +04:00
|
|
|
block_header: Block_header.t ;
|
2017-04-14 02:07:01 +04:00
|
|
|
operation_hashes: unit -> Operation_hash.t list list Lwt.t ;
|
2017-04-19 21:21:23 +04:00
|
|
|
operations: unit -> Operation.t list list Lwt.t ;
|
2017-04-10 14:14:11 +04:00
|
|
|
context: Context.t ;
|
|
|
|
}
|
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
(** This is the signature of a Tezos protocol implementation. It has
|
2016-10-20 20:54:16 +04:00
|
|
|
access to the standard library and the Environment module. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
module type PROTOCOL = sig
|
|
|
|
|
|
|
|
(** The version specific type of operations. *)
|
|
|
|
type operation
|
|
|
|
|
|
|
|
(** The maximum size of operations in bytes *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val max_operation_data_length: int
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
(** The maximum size of block headers in bytes *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val max_block_length: int
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
(** The maximum *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val max_number_of_operations: int
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
(** The parsing / preliminary validation function for
|
2016-10-19 22:47:04 +04:00
|
|
|
operations. Similar to {!parse_block}. *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val parse_operation:
|
2017-04-19 21:21:23 +04:00
|
|
|
Operation_hash.t -> Operation.t -> operation tzresult
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-10-20 20:54:16 +04:00
|
|
|
(** Basic ordering of operations. [compare_operations op1 op2] means
|
|
|
|
that [op1] should appear before [op2] in a block. *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val compare_operations: operation -> operation -> int
|
2016-10-20 20:54:16 +04:00
|
|
|
|
|
|
|
(** A functional state that is transmitted through the steps of a
|
|
|
|
block validation sequence. It must retain the current state of
|
|
|
|
the store (that can be extracted from the outside using
|
|
|
|
{!current_context}, and whose final value is produced by
|
|
|
|
{!finalize_block}). It can also contain the information that
|
|
|
|
must be remembered during the validation, which must be
|
|
|
|
immutable (as validator or baker implementations are allowed to
|
|
|
|
pause, replay or backtrack during the validation process). *)
|
|
|
|
type validation_state
|
|
|
|
|
|
|
|
(** Access the context at a given validation step. *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val current_context: validation_state -> Context.t tzresult Lwt.t
|
2016-10-20 20:54:16 +04:00
|
|
|
|
|
|
|
(** Checks that a block is well formed in a given context. This
|
|
|
|
function should run quickly, as its main use is to reject bad
|
|
|
|
blocks from the network as early as possible. The input context
|
|
|
|
is the one resulting of an ancestor block of same protocol
|
|
|
|
version, not necessarily the one of its predecessor. *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val precheck_block:
|
2016-10-20 20:54:16 +04:00
|
|
|
ancestor_context: Context.t ->
|
|
|
|
ancestor_timestamp: Time.t ->
|
2017-04-19 21:21:23 +04:00
|
|
|
Block_header.t ->
|
2016-10-20 20:54:16 +04:00
|
|
|
unit tzresult Lwt.t
|
|
|
|
|
|
|
|
(** The first step in a block validation sequence. Initializes a
|
|
|
|
validation context for validating a block. Takes as argument the
|
2017-04-19 21:21:23 +04:00
|
|
|
{!Block_header.t} to initialize the context for this block, patching
|
2016-10-20 20:54:16 +04:00
|
|
|
the context resulting of the application of the predecessor
|
|
|
|
block passed as parameter. The function {!precheck_block} may
|
|
|
|
not have been called before [begin_application], so all the
|
|
|
|
check performed by the former must be repeated in the latter. *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val begin_application:
|
2016-10-20 20:54:16 +04:00
|
|
|
predecessor_context: Context.t ->
|
|
|
|
predecessor_timestamp: Time.t ->
|
2017-04-19 21:21:23 +04:00
|
|
|
predecessor_fitness: Fitness.t ->
|
|
|
|
Block_header.t ->
|
2016-10-20 20:54:16 +04:00
|
|
|
validation_state tzresult Lwt.t
|
|
|
|
|
|
|
|
(** Initializes a validation context for constructing a new block
|
|
|
|
(as opposed to validating an existing block). Since there is no
|
2017-04-19 21:21:23 +04:00
|
|
|
{!Block_header.t} header available, the parts that it provides are
|
2016-10-20 20:54:16 +04:00
|
|
|
passed as arguments (predecessor block hash, context resulting
|
|
|
|
of the application of the predecessor block, and timestamp). *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val begin_construction:
|
2016-10-20 20:54:16 +04:00
|
|
|
predecessor_context: Context.t ->
|
|
|
|
predecessor_timestamp: Time.t ->
|
2017-04-10 15:01:22 +04:00
|
|
|
predecessor_level: Int32.t ->
|
2017-04-19 21:21:23 +04:00
|
|
|
predecessor_fitness: Fitness.t ->
|
2016-10-20 20:54:16 +04:00
|
|
|
predecessor: Block_hash.t ->
|
|
|
|
timestamp: Time.t ->
|
2017-04-26 17:01:39 +04:00
|
|
|
?proto_header: MBytes.t ->
|
|
|
|
unit -> validation_state tzresult Lwt.t
|
2016-10-20 20:54:16 +04:00
|
|
|
|
|
|
|
(** Called after {!begin_application} (or {!begin_construction}) and
|
|
|
|
before {!finalize_block}, with each operation in the block. *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val apply_operation:
|
2016-10-20 20:54:16 +04:00
|
|
|
validation_state -> operation -> validation_state tzresult Lwt.t
|
|
|
|
|
|
|
|
(** The last step in a block validation sequence. It produces the
|
|
|
|
context that will be used as input for the validation of its
|
|
|
|
successor block candidates. *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val finalize_block:
|
2017-04-10 14:14:11 +04:00
|
|
|
validation_state -> validation_result tzresult Lwt.t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
(** The list of remote procedures exported by this implementation *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val rpc_services: rpc_context RPC.directory
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-10-09 12:55:12 +04:00
|
|
|
val configure_sandbox:
|
2016-09-08 21:13:10 +04:00
|
|
|
Context.t -> Data_encoding.json option -> Context.t tzresult Lwt.t
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
(** Takes a version hash, a list of OCaml components in compilation
|
|
|
|
order. The last element must be named [protocol] and respect the
|
2017-02-24 20:17:53 +04:00
|
|
|
[protocol.ml] interface. Tries to compile it and returns true
|
2016-09-08 21:13:10 +04:00
|
|
|
if the operation was successful. *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val compile: Protocol_hash.t -> Protocol.t -> bool Lwt.t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
(** Activates a given protocol version from a given context. This
|
|
|
|
means that the context used for the next block will use this
|
|
|
|
version (this is not an immediate change). The version must have
|
|
|
|
been previously compiled successfully. *)
|
2017-10-09 12:55:12 +04:00
|
|
|
val activate: Context.t -> Protocol_hash.t -> Context.t Lwt.t
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-10 23:14:17 +04:00
|
|
|
(** Fork a test network. The forkerd network will use the current block
|
|
|
|
as genesis, and [protocol] as economic protocol. The network will
|
|
|
|
be destroyed when a (successor) block will have a timestamp greater
|
|
|
|
than [expiration]. The protocol must have been previously compiled
|
|
|
|
successfully. *)
|
|
|
|
val fork_test_network:
|
|
|
|
Context.t -> protocol:Protocol_hash.t -> expiration:Time.t -> Context.t Lwt.t
|