2019-09-05 17:21:01 +04:00
|
|
|
(*****************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Open Source License *)
|
|
|
|
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* Permission is hereby granted, free of charge, to any person obtaining a *)
|
|
|
|
(* copy of this software and associated documentation files (the "Software"),*)
|
|
|
|
(* to deal in the Software without restriction, including without limitation *)
|
|
|
|
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
|
|
|
|
(* and/or sell copies of the Software, and to permit persons to whom the *)
|
|
|
|
(* Software is furnished to do so, subject to the following conditions: *)
|
|
|
|
(* *)
|
|
|
|
(* The above copyright notice and this permission notice shall be included *)
|
|
|
|
(* in all copies or substantial portions of the Software. *)
|
|
|
|
(* *)
|
|
|
|
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
|
|
|
|
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
|
|
|
|
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
|
|
|
|
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
|
|
|
|
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
|
|
|
|
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
|
|
|
|
(* DEALINGS IN THE SOFTWARE. *)
|
|
|
|
(* *)
|
|
|
|
(*****************************************************************************)
|
|
|
|
|
|
|
|
(** Tezos Protocol Implementation - Typed storage
|
|
|
|
|
|
|
|
This module hides the hierarchical (key x value) database under
|
|
|
|
pre-allocated typed accessors for all persistent entities of the
|
|
|
|
tezos context.
|
|
|
|
|
|
|
|
This interface enforces no invariant on the contents of the
|
|
|
|
database. Its goal is to centralize all accessors in order to have
|
|
|
|
a complete view over the database contents and avoid key
|
|
|
|
collisions. *)
|
|
|
|
|
|
|
|
open Storage_sigs
|
|
|
|
|
2019-10-17 13:45:27 +04:00
|
|
|
module Block_priority : sig
|
2019-09-05 17:21:01 +04:00
|
|
|
val get : Raw_context.t -> int tzresult Lwt.t
|
2020-02-12 20:40:17 +04:00
|
|
|
|
2019-09-05 17:21:01 +04:00
|
|
|
val set : Raw_context.t -> int -> Raw_context.t tzresult Lwt.t
|
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
val init : Raw_context.t -> int -> Raw_context.t tzresult Lwt.t
|
2019-10-17 13:45:27 +04:00
|
|
|
end
|
|
|
|
|
2019-09-05 17:21:01 +04:00
|
|
|
module Roll : sig
|
|
|
|
(** Storage from this submodule must only be accessed through the
|
|
|
|
module `Roll`. *)
|
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Owner :
|
|
|
|
Indexed_data_snapshotable_storage
|
|
|
|
with type key = Roll_repr.t
|
|
|
|
and type snapshot = Cycle_repr.t * int
|
|
|
|
and type value = Signature.Public_key.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
val clear : Raw_context.t -> Raw_context.t Lwt.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** The next roll to be allocated. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Next :
|
|
|
|
Single_data_storage
|
|
|
|
with type value = Roll_repr.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Rolls linked lists represent both account owned and free rolls.
|
|
|
|
All rolls belongs either to the limbo list or to an owned list. *)
|
|
|
|
|
|
|
|
(** Head of the linked list of rolls in limbo *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Limbo :
|
|
|
|
Single_data_storage
|
|
|
|
with type value = Roll_repr.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Rolls associated to contracts, a linked list per contract *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Delegate_roll_list :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Signature.Public_key_hash.t
|
|
|
|
and type value = Roll_repr.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Use this to iter on a linked list of rolls *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Successor :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Roll_repr.t
|
|
|
|
and type value = Roll_repr.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** The tez of a contract that are not assigned to rolls *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Delegate_change :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Signature.Public_key_hash.t
|
|
|
|
and type value = Tez_repr.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Index of the randomly selected roll snapshot of a given cycle. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Snapshot_for_cycle :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Cycle_repr.t
|
|
|
|
and type value = int
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Last roll in the snapshoted roll allocation of a given cycle. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Last_for_snapshot :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = int
|
|
|
|
and type value = Roll_repr.t
|
|
|
|
and type t = Raw_context.t * Cycle_repr.t
|
2019-09-05 17:21:01 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
module Contract : sig
|
|
|
|
(** Storage from this submodule must only be accessed through the
|
|
|
|
module `Contract`. *)
|
|
|
|
|
|
|
|
module Global_counter : sig
|
|
|
|
val get : Raw_context.t -> Z.t tzresult Lwt.t
|
2020-02-12 20:40:17 +04:00
|
|
|
|
2019-09-05 17:21:01 +04:00
|
|
|
val set : Raw_context.t -> Z.t -> Raw_context.t tzresult Lwt.t
|
2020-02-12 20:40:17 +04:00
|
|
|
|
2019-09-05 17:21:01 +04:00
|
|
|
val init : Raw_context.t -> Z.t -> Raw_context.t tzresult Lwt.t
|
|
|
|
end
|
|
|
|
|
|
|
|
(** The domain of alive contracts *)
|
|
|
|
val fold :
|
|
|
|
Raw_context.t ->
|
2020-02-12 20:40:17 +04:00
|
|
|
init:'a ->
|
|
|
|
f:(Contract_repr.t -> 'a -> 'a Lwt.t) ->
|
|
|
|
'a Lwt.t
|
|
|
|
|
2019-09-05 17:21:01 +04:00
|
|
|
val list : Raw_context.t -> Contract_repr.t list Lwt.t
|
|
|
|
|
|
|
|
(** All the tez possesed by a contract, including rolls and change *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Balance :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Contract_repr.t
|
|
|
|
and type value = Tez_repr.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Frozen balance, see 'delegate_storage.mli' for more explanation.
|
|
|
|
Always update `Delegates_with_frozen_balance` accordingly. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Frozen_deposits :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Cycle_repr.t
|
|
|
|
and type value = Tez_repr.t
|
|
|
|
and type t = Raw_context.t * Contract_repr.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Frozen_fees :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Cycle_repr.t
|
|
|
|
and type value = Tez_repr.t
|
|
|
|
and type t = Raw_context.t * Contract_repr.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Frozen_rewards :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Cycle_repr.t
|
|
|
|
and type value = Tez_repr.t
|
|
|
|
and type t = Raw_context.t * Contract_repr.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** The manager of a contract *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Manager :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Contract_repr.t
|
|
|
|
and type value = Manager_repr.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** The delegate of a contract, if any. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Delegate :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Contract_repr.t
|
|
|
|
and type value = Signature.Public_key_hash.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
2019-10-17 13:45:27 +04:00
|
|
|
(** All contracts (implicit and originated) that are delegated, if any *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Delegated :
|
|
|
|
Data_set_storage
|
|
|
|
with type elt = Contract_repr.t
|
|
|
|
and type t = Raw_context.t * Contract_repr.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Inactive_delegate :
|
|
|
|
Data_set_storage with type elt = Contract_repr.t and type t = Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** The cycle where the delegate should be desactivated. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Delegate_desactivation :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Contract_repr.t
|
|
|
|
and type value = Cycle_repr.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Counter :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Contract_repr.t
|
|
|
|
and type value = Z.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Code :
|
|
|
|
Non_iterable_indexed_carbonated_data_storage
|
2019-10-17 13:45:27 +04:00
|
|
|
with type key = Contract_repr.t
|
|
|
|
and type value = Script_repr.lazy_expr
|
|
|
|
and type t := Raw_context.t
|
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Storage :
|
|
|
|
Non_iterable_indexed_carbonated_data_storage
|
2019-10-17 13:45:27 +04:00
|
|
|
with type key = Contract_repr.t
|
|
|
|
and type value = Script_repr.lazy_expr
|
|
|
|
and type t := Raw_context.t
|
|
|
|
|
2019-09-05 17:21:01 +04:00
|
|
|
(** Current storage space in bytes.
|
|
|
|
Includes code, global storage and big map elements. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Used_storage_space :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Contract_repr.t
|
|
|
|
and type value = Z.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Maximal space available without needing to burn new fees. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Paid_storage_space :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Contract_repr.t
|
|
|
|
and type value = Z.t
|
|
|
|
and type t := Raw_context.t
|
2019-10-17 13:45:27 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
module Big_map : sig
|
|
|
|
module Next : sig
|
|
|
|
val incr : Raw_context.t -> (Raw_context.t * Z.t) tzresult Lwt.t
|
2020-02-12 20:40:17 +04:00
|
|
|
|
2019-10-17 13:45:27 +04:00
|
|
|
val init : Raw_context.t -> Raw_context.t tzresult Lwt.t
|
|
|
|
end
|
|
|
|
|
|
|
|
(** The domain of alive big maps *)
|
2020-02-12 20:40:17 +04:00
|
|
|
val fold : Raw_context.t -> init:'a -> f:(Z.t -> 'a -> 'a Lwt.t) -> 'a Lwt.t
|
|
|
|
|
2019-10-17 13:45:27 +04:00
|
|
|
val list : Raw_context.t -> Z.t list Lwt.t
|
|
|
|
|
|
|
|
val remove_rec : Raw_context.t -> Z.t -> Raw_context.t Lwt.t
|
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
val copy :
|
|
|
|
Raw_context.t -> from:Z.t -> to_:Z.t -> Raw_context.t tzresult Lwt.t
|
2019-10-17 13:45:27 +04:00
|
|
|
|
|
|
|
type key = Raw_context.t * Z.t
|
|
|
|
|
|
|
|
val rpc_arg : Z.t RPC_arg.t
|
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Contents :
|
|
|
|
Non_iterable_indexed_carbonated_data_storage
|
|
|
|
with type key = Script_expr_hash.t
|
|
|
|
and type value = Script_repr.expr
|
|
|
|
and type t := key
|
2019-10-17 13:45:27 +04:00
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Total_bytes :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Z.t
|
|
|
|
and type value = Z.t
|
|
|
|
and type t := Raw_context.t
|
2019-10-17 13:45:27 +04:00
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Key_type :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Z.t
|
|
|
|
and type value = Script_repr.expr
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Value_type :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Z.t
|
|
|
|
and type value = Script_repr.expr
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
(** Set of all registered delegates. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Delegates :
|
|
|
|
Data_set_storage
|
|
|
|
with type t := Raw_context.t
|
|
|
|
and type elt = Signature.Public_key_hash.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Set of all active delegates with rolls. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Active_delegates_with_rolls :
|
|
|
|
Data_set_storage
|
|
|
|
with type t := Raw_context.t
|
|
|
|
and type elt = Signature.Public_key_hash.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Set of all the delegates with frozen rewards/bonds/fees for a given cycle. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Delegates_with_frozen_balance :
|
|
|
|
Data_set_storage
|
|
|
|
with type t = Raw_context.t * Cycle_repr.t
|
|
|
|
and type elt = Signature.Public_key_hash.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Votes *)
|
|
|
|
|
|
|
|
module Vote : sig
|
2020-02-12 20:40:17 +04:00
|
|
|
module Current_period_kind :
|
|
|
|
Single_data_storage
|
|
|
|
with type value = Voting_period_repr.kind
|
|
|
|
and type t := Raw_context.t
|
2019-10-17 13:45:27 +04:00
|
|
|
|
|
|
|
(** Participation exponential moving average, in centile of percentage *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Participation_ema :
|
|
|
|
Single_data_storage with type value = int32 and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Current_proposal :
|
|
|
|
Single_data_storage
|
|
|
|
with type value = Protocol_hash.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Sum of all rolls of all delegates. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Listings_size :
|
|
|
|
Single_data_storage with type value = int32 and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Contains all delegates with their assigned number of rolls. *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Listings :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Signature.Public_key_hash.t
|
|
|
|
and type value = int32
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Set of protocol proposal with corresponding proposer delegate *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Proposals :
|
|
|
|
Data_set_storage
|
|
|
|
with type elt = Protocol_hash.t * Signature.Public_key_hash.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Keeps for each delegate the number of proposed protocols *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Proposals_count :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Signature.Public_key_hash.t
|
|
|
|
and type value = int
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Contains for each delegate its ballot *)
|
2020-02-12 20:40:17 +04:00
|
|
|
module Ballots :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Signature.Public_key_hash.t
|
|
|
|
and type value = Vote_repr.ballot
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
(** Seed *)
|
|
|
|
|
|
|
|
module Seed : sig
|
|
|
|
(** Storage from this submodule must only be accessed through the
|
|
|
|
module `Seed`. *)
|
|
|
|
|
|
|
|
type unrevealed_nonce = {
|
2020-02-12 20:40:17 +04:00
|
|
|
nonce_hash : Nonce_hash.t;
|
|
|
|
delegate : Signature.Public_key_hash.t;
|
|
|
|
rewards : Tez_repr.t;
|
|
|
|
fees : Tez_repr.t;
|
2019-09-05 17:21:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
type nonce_status =
|
|
|
|
| Unrevealed of unrevealed_nonce
|
|
|
|
| Revealed of Seed_repr.nonce
|
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Nonce :
|
|
|
|
Non_iterable_indexed_data_storage
|
|
|
|
with type key := Level_repr.t
|
|
|
|
and type value := nonce_status
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
module For_cycle : sig
|
2020-02-12 20:40:17 +04:00
|
|
|
val init :
|
|
|
|
Raw_context.t ->
|
|
|
|
Cycle_repr.t ->
|
|
|
|
Seed_repr.seed ->
|
|
|
|
Raw_context.t tzresult Lwt.t
|
|
|
|
|
2019-09-05 17:21:01 +04:00
|
|
|
val get : Raw_context.t -> Cycle_repr.t -> Seed_repr.seed tzresult Lwt.t
|
2020-02-12 20:40:17 +04:00
|
|
|
|
2019-09-05 17:21:01 +04:00
|
|
|
val delete : Raw_context.t -> Cycle_repr.t -> Raw_context.t tzresult Lwt.t
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
(** Commitments *)
|
|
|
|
|
2020-02-12 20:40:17 +04:00
|
|
|
module Commitments :
|
|
|
|
Indexed_data_storage
|
|
|
|
with type key = Blinded_public_key_hash.t
|
|
|
|
and type value = Tez_repr.t
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
(** Ramp up security deposits... *)
|
|
|
|
|
|
|
|
module Ramp_up : sig
|
|
|
|
module Rewards :
|
|
|
|
Indexed_data_storage
|
2020-02-12 20:40:17 +04:00
|
|
|
with type key = Cycle_repr.t
|
|
|
|
and type value := Tez_repr.t list * Tez_repr.t list
|
|
|
|
(* baking rewards per endorsement * endorsement rewards *)
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
|
|
|
|
module Security_deposits :
|
|
|
|
Indexed_data_storage
|
2020-02-12 20:40:17 +04:00
|
|
|
with type key = Cycle_repr.t
|
|
|
|
and type value = Tez_repr.t * Tez_repr.t
|
|
|
|
(* baking * endorsement *)
|
|
|
|
and type t := Raw_context.t
|
2019-09-05 17:21:01 +04:00
|
|
|
end
|