meter

package
v0.29.6 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ComputationKindCreateAccount = 2006
	ComputationKindGetValue      = 2020
	ComputationKindSetValue      = 2026
)

TODO(patrick): rm after https://github.com/onflow/flow-emulator/pull/229 is merged and integrated.

View Source
const MeterExecutionInternalPrecisionBytes = 16

MeterExecutionInternalPrecisionBytes are the amount of bytes that are used internally by the WeigthedMeter to allow for metering computation smaller than one unit of computation. This allows for more fine weights. A weight of 1 unit of computation is equal to 1<<16. The minimum possible weight is 1/65536.

Variables

View Source
var (
	// DefaultComputationWeights is the default weights for computation intensities
	// these weighs make the computation metering the same as it was before dynamic execution fees
	DefaultComputationWeights = ExecutionEffortWeights{
		common.ComputationKindStatement:          1 << MeterExecutionInternalPrecisionBytes,
		common.ComputationKindLoop:               1 << MeterExecutionInternalPrecisionBytes,
		common.ComputationKindFunctionInvocation: 1 << MeterExecutionInternalPrecisionBytes,
	}

	// DefaultMemoryWeights are currently hard-coded here. In the future we might like to
	// define this in a contract similar to the computation weights
	DefaultMemoryWeights = ExecutionMemoryWeights{}/* 178 elements not displayed */

)

Functions

func GetStorageKeyValueSizeForTesting

func GetStorageKeyValueSizeForTesting(
	storageKey StorageInteractionKey,
	value flow.RegisterValue) uint64

Types

type ExecutionEffortWeights

type ExecutionEffortWeights map[common.ComputationKind]uint64

type ExecutionMemoryWeights

type ExecutionMemoryWeights map[common.MemoryKind]uint64

type Meter

type Meter struct {
	MeterParameters
	// contains filtered or unexported fields
}

Meter collects memory and computation usage and enforces limits for any each memory/computation usage call it sums intensity multiplied by the weight of the intensity to the total memory/computation usage metrics and returns error if limits are not met.

func NewMeter

func NewMeter(params MeterParameters) *Meter

NewMeter constructs a new Meter

func (*Meter) ComputationIntensities

func (m *Meter) ComputationIntensities() MeteredComputationIntensities

ComputationIntensities returns all the measured computational intensities

func (*Meter) GetStorageUpdateSizeMapForTesting

func (m *Meter) GetStorageUpdateSizeMapForTesting() MeteredStorageInteractionMap

func (*Meter) MemoryIntensities

func (m *Meter) MemoryIntensities() MeteredMemoryIntensities

MemoryIntensities returns all the measured memory intensities

func (*Meter) MergeMeter

func (m *Meter) MergeMeter(child *Meter)

MergeMeter merges the input meter into the current meter and checks for the limits

func (*Meter) MeterComputation

func (m *Meter) MeterComputation(kind common.ComputationKind, intensity uint) error

MeterComputation captures computation usage and returns an error if it goes beyond the limit

func (*Meter) MeterEmittedEvent

func (m *Meter) MeterEmittedEvent(byteSize uint64) error

func (*Meter) MeterMemory

func (m *Meter) MeterMemory(kind common.MemoryKind, intensity uint) error

MeterMemory captures memory usage and returns an error if it goes beyond the limit

func (*Meter) MeterStorageRead

func (m *Meter) MeterStorageRead(
	storageKey StorageInteractionKey,
	value flow.RegisterValue,
	enforceLimit bool) error

MeterStorageRead captures storage read bytes count and returns an error if it goes beyond the total interaction limit and limit is enforced

func (*Meter) MeterStorageWrite

func (m *Meter) MeterStorageWrite(
	storageKey StorageInteractionKey,
	value flow.RegisterValue,
	enforceLimit bool) error

MeterStorageRead captures storage written bytes count and returns an error if it goes beyond the total interaction limit and limit is enforced

func (*Meter) TotalBytesOfStorageInteractions

func (m *Meter) TotalBytesOfStorageInteractions() uint64

TotalBytesOfStorageInteractions returns total number of byte read and written from/to storage

func (*Meter) TotalBytesReadFromStorage

func (m *Meter) TotalBytesReadFromStorage() uint64

TotalBytesReadFromStorage returns total number of byte read from storage

func (*Meter) TotalBytesWrittenToStorage

func (m *Meter) TotalBytesWrittenToStorage() uint64

TotalBytesReadFromStorage returns total number of byte written to storage

func (*Meter) TotalComputationUsed

func (m *Meter) TotalComputationUsed() uint64

TotalComputationUsed returns the total computation used

func (*Meter) TotalEmittedEventBytes

func (m *Meter) TotalEmittedEventBytes() uint64

func (*Meter) TotalMemoryEstimate

func (m *Meter) TotalMemoryEstimate() uint64

TotalMemoryEstimate returns the total memory used

type MeterOptions

type MeterOptions func(*Meter)

type MeterParameters

type MeterParameters struct {
	// contains filtered or unexported fields
}

func DefaultParameters

func DefaultParameters() MeterParameters

func (MeterParameters) ComputationWeights

func (params MeterParameters) ComputationWeights() ExecutionEffortWeights

func (MeterParameters) MemoryWeights

func (params MeterParameters) MemoryWeights() ExecutionMemoryWeights

func (MeterParameters) TotalComputationLimit

func (params MeterParameters) TotalComputationLimit() uint

TotalComputationLimit returns the total computation limit

func (MeterParameters) TotalMemoryLimit

func (params MeterParameters) TotalMemoryLimit() uint64

TotalMemoryLimit returns the total memory limit

func (MeterParameters) WithComputationLimit

func (params MeterParameters) WithComputationLimit(limit uint) MeterParameters

func (MeterParameters) WithComputationWeights

func (params MeterParameters) WithComputationWeights(
	weights ExecutionEffortWeights,
) MeterParameters

func (MeterParameters) WithEventEmitByteLimit

func (params MeterParameters) WithEventEmitByteLimit(
	byteLimit uint64,
) MeterParameters

func (MeterParameters) WithMemoryLimit

func (params MeterParameters) WithMemoryLimit(limit uint64) MeterParameters

func (MeterParameters) WithMemoryWeights

func (params MeterParameters) WithMemoryWeights(
	weights ExecutionMemoryWeights,
) MeterParameters

func (MeterParameters) WithStorageInteractionLimit

func (params MeterParameters) WithStorageInteractionLimit(
	maxStorageInteractionLimit uint64,
) MeterParameters

type MeteredComputationIntensities

type MeteredComputationIntensities map[common.ComputationKind]uint

type MeteredMemoryIntensities

type MeteredMemoryIntensities map[common.MemoryKind]uint

type MeteredStorageInteractionMap

type MeteredStorageInteractionMap map[StorageInteractionKey]uint64

type StorageInteractionKey

type StorageInteractionKey struct {
	Owner, Key string
}

Jump to

Keyboard shortcuts

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