package tezos-protocol-014-PtKathma
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=7062cd57addd452852598a2214ade393130efa087b99068d53713bdf912b3680
sha512=08e4091144a03ce3c107fb91a66501bd8b65ca3278917c455a2eaac6df3e108ade63f6ab8340a4bb152d60f404326e464d0ec95d26cafe8e82f870465d24a5fc
doc/tezos-protocol-014-PtKathma.raw/Tezos_raw_protocol_014_PtKathma/Alpha_context/Gas/index.html
Module Alpha_context.Gas
Source
This module implements the gas subsystem of the context.
Gas reflects the computational cost of each operation to limit the cost of operations and, by extension, the cost of blocks.
There are two gas quotas: one for operation and one for block. For this reason, we maintain two gas levels -- one for operations and another one for blocks -- that correspond to the remaining amounts of gas, initialized with the quota limits and decreased each time gas is consumed.
module Arith :
Fixed_point_repr.Safe
with type 'a t = private Saturation_repr.may_saturate Saturation_repr.t
For maintenance operations or for testing, gas can be Unaccounted
. Otherwise, the computation is Limited
by the remaining
gas in the context.
set_limit ctxt limit
returns a context with a given limit
level of gas allocated for an operation.
remaining_operation_gas ctxt
returns the current gas level in the context ctxt
for the current operation. If gas is Unaccounted
, an arbitrary value will be returned.
reset_block_gas ctxt
returns a context where the remaining gas in the block is reset to the constant hard_gas_limit_per_block
, i.e., as if no operations have been included in the block.
/!\ Do not call this function unless you want to validate operations on their own (like in the mempool).
level ctxt
is the current gas level in ctxt
for the current operation.
update_remaining_operation_gas ctxt remaining
sets the current gas level for operations to remaining
.
consumed since until
is the operation gas level difference between context since
and context until
. This function returns Arith.zero
if any of the two contexts allows for an unlimited gas consumption. This function also returns Arith.zero
if since
has less gas than until
.
block_level ctxt
returns the block gas level in context ctxt
.
Costs are computed using a saturating arithmetic. See Saturation_repr
.
val consume :
context ->
cost ->
context Tezos_protocol_environment_014_PtKathma.Error_monad.tzresult
consume ctxt cost
subtracts cost
to the current operation gas level in ctxt
. This operation may fail with Operation_quota_exceeded
if the operation gas level would go below zero.
val consume_from :
Arith.fp ->
cost ->
Arith.fp Tezos_protocol_environment_014_PtKathma.Error_monad.tzresult
consume_from available_gas cost
subtracts cost
from available_gas
and returns the remaining gas.
val consume_limit_in_block :
context ->
'a Arith.t ->
context Tezos_protocol_environment_014_PtKathma.Error_monad.tzresult
val check_limit_and_consume_from_block_gas :
hard_gas_limit_per_operation:Arith.integral ->
remaining_block_gas:Arith.fp ->
gas_limit:Arith.integral ->
Arith.fp Tezos_protocol_environment_014_PtKathma.Error_monad.tzresult
Check that gas_limit
is a valid operation gas limit (at most hard_gas_limit_per_operation
and nonnegative), then subtract it from remaining_block_gas
and return the difference.
This function mimics consume_limit_in_block
but bypasses the context.
Convert an amount of milligas expressed as an int to Arith.fp.
atomic_step_cost x
corresponds to x
milliunit of gas.
step_cost x
corresponds to x
units of gas.
Cost of allocating qwords of storage. alloc_cost n
estimates the cost of allocating n
qwords of storage.
Cost of allocating bytes in the storage. alloc_bytes_cost b
estimates the cost of allocating b
bytes of storage.
Cost of allocating bytes in the storage.
alloc_mbytes_cost b
estimates the cost of allocating b
bytes of storage and the cost of an header to describe these bytes.
Cost of reading the storage. read_bytes_cost n
estimates the cost of reading n
bytes of storage.
Cost of writing to storage. write_bytes_const n
estimates the cost of writing n
bytes to the storage.
Multiply a cost by a factor. Both arguments are saturated arithmetic values, so no negative numbers are involved.
cost_of_repr
is an internal operation needed to inject costs for Storage_costs into Gas.cost.