Documentation
¶
Overview ¶
Package multigas defines multi-dimensional gas for the EVM.
This package introduces mechanisms to track each resource used by the EVM separately. The possible resources are computation, history growth, storage access, and storage growth. By tracking each one individually and setting specific constraints, we can increase the overall gas target for the chain.
Index ¶
- type MultiGas
- func ComputationGas(amount uint64) *MultiGas
- func HistoryGrowthGas(amount uint64) *MultiGas
- func NewMultiGas(kind ResourceKind, amount uint64) *MultiGas
- func StorageAccessGas(amount uint64) *MultiGas
- func StorageGrowthGas(amount uint64) *MultiGas
- func UnknownGas(amount uint64) *MultiGas
- func ZeroGas() *MultiGas
- func (z *MultiGas) Get(kind ResourceKind) uint64
- func (z *MultiGas) GetRefund() uint64
- func (z *MultiGas) SafeAdd(x *MultiGas, y *MultiGas) (*MultiGas, bool)
- func (z *MultiGas) SafeIncrement(kind ResourceKind, gas uint64) bool
- func (z *MultiGas) Set(kind ResourceKind, gas uint64) (*MultiGas, bool)
- func (z *MultiGas) SetRefund(amount uint64) *MultiGas
- func (z *MultiGas) SingleGas() uint64
- type ResourceKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MultiGas ¶
type MultiGas struct {
// contains filtered or unexported fields
}
MultiGas tracks gas usage across multiple resource kinds, while also maintaining a single-dimensional total gas sum and refund amount.
func ComputationGas ¶
ComputationGas returns a MultiGas initialized with computation gas.
func HistoryGrowthGas ¶
HistoryGrowthGas returns a MultiGas initialized with history growth gas.
func NewMultiGas ¶
func NewMultiGas(kind ResourceKind, amount uint64) *MultiGas
NewMultiGas creates a new MultiGas with the given resource kind initialized to `amount`. All other kinds are zero. The total is also set to `amount`.
func StorageAccessGas ¶
StorageAccessGas returns a MultiGas initialized with storage access gas.
func StorageGrowthGas ¶
StorageGrowthGas returns a MultiGas initialized with storage growth gas.
func UnknownGas ¶
UnknownGas returns a MultiGas initialized with unknown gas.
func ZeroGas ¶
func ZeroGas() *MultiGas
ZeroGas creates a MultiGas value with all fields set to zero.
func (*MultiGas) Get ¶
func (z *MultiGas) Get(kind ResourceKind) uint64
Get returns the gas amount for the specified resource kind.
func (*MultiGas) GetRefund ¶
GetRefund gets the SSTORE refund computed at the end of the transaction.
func (*MultiGas) SafeAdd ¶
SafeAdd sets z to the sum of x and y, per resource kind and total. Returns the modified MultiGas and a boolean indicating if an overflow occurred in either the kind-specific or total value.
func (*MultiGas) SafeIncrement ¶
func (z *MultiGas) SafeIncrement(kind ResourceKind, gas uint64) bool
SafeIncrement increments the given resource kind by the amount of gas and to the total. Returns true if an overflow occurred in either the kind-specific or total value.
func (*MultiGas) Set ¶
func (z *MultiGas) Set(kind ResourceKind, gas uint64) (*MultiGas, bool)
Set sets the gas for a given resource kind to `gas`, adjusting the total accordingly. Returns the same MultiGas and a boolean indicating if an overflow occurred when updating the total.
type ResourceKind ¶
type ResourceKind uint8
ResourceKind represents a dimension for the multi-dimensional gas.
const ( ResourceKindUnknown ResourceKind = iota ResourceKindComputation ResourceKindHistoryGrowth ResourceKindStorageAccess ResourceKindStorageGrowth NumResourceKind )