gas

package
v1.0.0-alpha.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 3 Imported by: 9

Documentation

Overview

Package gas provides a basic API for app modules to track gas usage.

Index

Constants

This section is empty.

Variables

View Source
var ErrOutOfGas = errors.New("out of gas")

ErrOutOfGas must be used by GasMeter implementers to signal that the state transition consumed all the allowed computational gas.

Functions

This section is empty.

Types

type Gas

type Gas = uint64

Gas defines type alias of uint64 for gas consumption. Gas is used to measure computational overhead when executing state transitions, it might be related to storage access and not only.

const NoGasLimit Gas = math.MaxUint64

NoGasLimit signals that no gas limit must be applied.

type GasConfig added in v1.0.0

type GasConfig struct {
	HasCost          Gas
	DeleteCost       Gas
	ReadCostFlat     Gas
	ReadCostPerByte  Gas
	WriteCostFlat    Gas
	WriteCostPerByte Gas
	IterNextCostFlat Gas
}

GasConfig defines the gas costs for the application.

type Meter

type Meter interface {
	Consume(amount Gas, descriptor string) error
	Refund(amount Gas, descriptor string) error
	Remaining() Gas
	Consumed() Gas
	Limit() Gas
}

Meter represents a gas meter for modules consumption

type Service

type Service interface {
	// GasMeter returns the current transaction-level gas meter. A non-nil meter
	// is always returned. When one is unavailable in the context an infinite gas meter
	// will be returned.
	GasMeter(context.Context) Meter

	// GasConfig returns the gas costs.
	GasConfig(ctx context.Context) GasConfig
}

Service represents a gas service which can retrieve and set a gas meter in a context. gas.Service is a core API type that should be provided by the runtime module being used to build an app via depinject.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL