Mavryk_raw_protocol_alpha.Gas_limit_repr
Internal representation of the gas limit available to the node baking a new block. It should be proportional to the time and energy required to perform a computation.
This protects the bakers from performing exceedingly costly computations while baking and also allows them to select cheaper-to-compute operations to include in their blocks, as their reward for baking a block is not directly related to the resources consumed by the machine performing the operation.
It can be Unaccounted
(unlimited) or Limited
to some fixed-point value (see Fixed_point_repr
for the details). The value is represented with 3 decimal places of precision.
All computations on gas are performed in saturation arithmetic (see Saturation_repr
) bounded between 0
and 2 ^ 62 - 1
module Arith :
Fixed_point_repr.Full
with type 'a t = private Saturation_repr.may_saturate Saturation_repr.t
val encoding : t Mavryk_protocol_environment_alpha.Data_encoding.encoding
val pp : Mavryk_protocol_environment_alpha.Format.formatter -> t -> unit
type cost = Saturation_repr.may_saturate Saturation_repr.t
Represents a gas cost of an operation. The gas model is constructed such that the cost of each operation is roughly proportional to the time required to perform the operation. If the gas cost of an operation exceeds the available limit, such an operation is rejected. This is especially meant to protect bakers against DoS attacks.
val cost_encoding :
cost Mavryk_protocol_environment_alpha.Data_encoding.encoding
val pp_cost :
Mavryk_protocol_environment_alpha.Format.formatter ->
cost ->
unit
val pp_cost_as_gas :
Mavryk_protocol_environment_alpha.Format.formatter ->
cost ->
unit
Print the gas cost as gas unit
Subtracts the cost from the current limit. Returns None
if the limit would fall below 0
.
val free : cost
The cost of free operation is 0
.
val fp_of_milligas_int : int -> Arith.fp
Convert an amount of milligas expressed as a value of type int
to Arith.fp
.
val atomic_step_cost : _ Saturation_repr.t -> cost
atomic_step_cost x
corresponds to x
milliunit of gas.
val step_cost : _ Saturation_repr.t -> cost
step_cost x
corresponds to x
units of gas.
val alloc_cost : _ Saturation_repr.t -> cost
Cost of allocating qwords of storage.
alloc_cost n
estimates the cost of allocating n
qwords of storage.
val alloc_bytes_cost : int -> cost
Cost of allocating bytes in the storage.
alloc_bytes_cost b
estimates the cost of allocating b
bytes of storage.
val alloc_mbytes_cost : int -> cost
Cost of allocating bytes in the storage.
alloc_mbytes_cost b
estimates the cost of allocating b
bytes of storage and the cost of a header to describe these bytes.
val read_bytes_cost : int -> cost
Cost of reading the storage.
read_bytes_const n
estimates the cost of reading n
bytes of storage.
val write_bytes_cost : int -> cost
Cost of writing to storage.
write_bytes_const n
estimates the cost of writing n
bytes to the storage.
val (*@) : _ Saturation_repr.t -> cost -> cost
Multiply a cost by a factor. Both arguments are saturated arithmetic values, so no negative numbers are involved.
Ill-formed gas_limit
: see check_gas_limit
.
val check_gas_limit :
hard_gas_limit_per_operation:Arith.integral ->
gas_limit:'a Arith.t ->
unit Mavryk_protocol_environment_alpha.Error_monad.tzresult
Check that gas_limit
is well-formed, i.e. it is at most the given hard_gas_limit_per_operation
, and it is nonnegative.