package tezos-protocol-alpha

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Basic roll manipulation.

The storage related to roll (i.e. `Storage.Roll`) is not used outside of this module. And, this interface enforces the invariant that a roll is always either in the limbo list or owned by a delegate.

type Tezos_protocol_environment_alpha__Environment.Error_monad.error +=
  1. | Consume_roll_change
  2. | No_roll_for_delegate
  3. | No_roll_snapshot_for_cycle of Cycle_repr.t
  4. | Unregistered_delegate of Tezos_crypto.Signature.public_key_hash
val init : Raw_context.t -> (Raw_context.t, Tezos_protocol_environment_alpha__Environment.Error_monad.error Tezos_protocol_environment_alpha__Environment.Error_monad.trace) Stdlib.result Lwt.t

init ctxt returns a new context initialized from ctxt where the next roll to be allocated is the first roll, i.e. (Storage.Roll.Next.get ctxt) = Roll_repr.first. This function returns a {!Storage_error Existing_key} error if the context has already been initialized.

val init_first_cycles : Raw_context.t -> (Raw_context.t, Tezos_protocol_environment_alpha__Environment.Error_monad.error Tezos_protocol_environment_alpha__Environment.Error_monad.trace) Stdlib.result Lwt.t

init_first_cycles ctxt computes a new context from ctxt where the store has been prepared to save roll snapshots for all cycles from 0 to Constants.preserved_cycles + 2:

1. rolls for all cycles in the interval (0, preserved_cycles) are frozen (after taking a snapshot), 2. a snapshot is taken for rolls of cycle preserved_cycles + 1, 3. rolls for cycle preserved_cycles + 2 are ready for a snapshot, i.e. the necessary storage has been prepared.

val cycle_end : Raw_context.t -> Cycle_repr.t -> (Raw_context.t, Tezos_protocol_environment_alpha__Environment.Error_monad.error Tezos_protocol_environment_alpha__Environment.Error_monad.trace) Stdlib.result Lwt.t

cycle_end ctxt last_cycle returns a new context after applying the end-of-cycle bookkeeping to ctxt:

1. clears cycle c = (last_cycle - preserved_cycles) if last_cycle >= preserved_cycles (this amounts to deleting the only snapshot left after the freezing of c), 2. freezes snapshot rolls for the cycle (last_cycle + preserved_cycles + 1) (this amounts to removing all snapshots for the cycle, except one randomly selected for computing baking rights), 3. makes cycle (last_cycle + preserved_cycles + 2) ready for snapshot.

val snapshot_rolls : Raw_context.t -> (Raw_context.t, Tezos_protocol_environment_alpha__Environment.Error_monad.error Tezos_protocol_environment_alpha__Environment.Error_monad.trace) Stdlib.result Lwt.t

snapshot_rolls ctxt creates roll snapshots for cycle c = level + preserved_cycles + 2. The returned context is such that:

1. the snapshot index associated to cycle c is incremented, 2. the rolls' owners are copied and associated to the snapshot id (c,index) (where index is the current snapshot index of cycle c), 3. the last roll for cycle c, and snapshot index is set to be the next roll of ctxt.

val fold : Raw_context.t -> f: (Roll_repr.roll -> Tezos_crypto.Signature.public_key -> 'a -> ('a, Tezos_protocol_environment_alpha__Environment.Error_monad.error Tezos_protocol_environment_alpha__Environment.Error_monad.trace) Stdlib.result Lwt.t) -> 'a -> ('a, Tezos_protocol_environment_alpha__Environment.Error_monad.error Tezos_protocol_environment_alpha__Environment.Error_monad.trace) Stdlib.result Lwt.t

fold ctxt f init folds f on the list of all rolls from Roll_repr.first to Storage.Next.Roll of the context ctxt. Only rolls which have owners are considered, rolls without owners are skipped. The first parameter of f is a roll r, the second parameter of f is the owner of r, and the last parameter is the initial value of the accumulator.

val baking_rights_owner : Raw_context.t -> Level_repr.t -> priority:int -> (Tezos_crypto.Signature.public_key, Tezos_protocol_environment_alpha__Environment.Error_monad.error Tezos_protocol_environment_alpha__Environment.Error_monad.trace) Stdlib.result Lwt.t

May return a No_roll_snapshot_for_cycle error.

val endorsement_rights_owner : Raw_context.t -> Level_repr.t -> slot:int -> (Tezos_crypto.Signature.public_key, Tezos_protocol_environment_alpha__Environment.Error_monad.error Tezos_protocol_environment_alpha__Environment.Error_monad.trace) Stdlib.result Lwt.t

May return a No_roll_snapshot_for_cycle error.

module Delegate : sig ... end
module Contract : sig ... end
val delegate_pubkey : Raw_context.t -> Tezos_crypto.Signature.public_key_hash -> (Tezos_crypto.Signature.public_key, Tezos_protocol_environment_alpha__Environment.Error_monad.error Tezos_protocol_environment_alpha__Environment.Error_monad.trace) Stdlib.result Lwt.t

delegate_pubkey ctxt delegate returns the public key of delegate found in context ctxt if there exists a registered contract.

val count_rolls : Raw_context.t -> Tezos_crypto.Signature.public_key_hash -> (int, Tezos_protocol_environment_alpha__Environment.Error_monad.error Tezos_protocol_environment_alpha__Environment.Error_monad.trace) Stdlib.result Lwt.t

count_rolls ctxt delegate returns the number of rolls held by delegate in context ctxt.

val get_change : Raw_context.t -> Tezos_crypto.Signature.public_key_hash -> (Tez_repr.t, Tezos_protocol_environment_alpha__Environment.Error_monad.error Tezos_protocol_environment_alpha__Environment.Error_monad.trace) Stdlib.result Lwt.t

get_change ctxt delegate returns the amount of change held by delegate in context ctxt. The change is the part of the staking balance of a delegate that is not part of a roll, i.e., the amount of staking balance (smaller than the value of a roll) not being taken into account for baking rights computation.

val update_tokens_per_roll : Raw_context.t -> Tez_repr.t -> (Raw_context.t, Tezos_protocol_environment_alpha__Environment.Error_monad.error Tezos_protocol_environment_alpha__Environment.Error_monad.trace) Stdlib.result Lwt.t

update_tokens_per_roll ctxt am performs the following actions:

1. set the constant tokens_per_roll to am, 2. if the constant was increased by tpram, then add the amount nr * tpram to each delegate, where nr is the delegate's number of rolls, 3. if the constant was instead decreased by tpram, then remove the amount nr * tpram from all delegates.

val get_contract_delegate : Raw_context.t -> Contract_repr.t -> (Tezos_crypto.Signature.public_key_hash option, Tezos_protocol_environment_alpha__Environment.Error_monad.error Tezos_protocol_environment_alpha__Environment.Error_monad.trace) Stdlib.result Lwt.t

get_contract_delegate ctxt contract returns the public key hash of the delegate whose contract is contract in context ctxt.

OCaml

Innovation. Community. Security.