meter

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: AGPL-3.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ComputationKindHash common.ComputationKind
	ComputationKindVerifySignature
	ComputationKindAddAccountKey
	ComputationKindAddEncodedAccountKey
	ComputationKindAllocateStorageIndex
	ComputationKindCreateAccount
	ComputationKindEmitEvent
	ComputationKindGenerateUUID
	ComputationKindGetAccountAvailableBalance
	ComputationKindGetAccountBalance
	ComputationKindGetAccountContractCode
	ComputationKindGetAccountContractNames
	ComputationKindGetAccountKey
	ComputationKindGetBlockAtHeight
	ComputationKindGetCode
	ComputationKindGetCurrentBlockHeight
	ComputationKindGetProgram
	ComputationKindGetStorageCapacity
	ComputationKindGetStorageUsed
	ComputationKindGetValue
	ComputationKindRemoveAccountContractCode
	ComputationKindResolveLocation
	ComputationKindRevokeAccountKey
	ComputationKindRevokeEncodedAccountKey
	ComputationKindSetProgram
	ComputationKindSetValue
	ComputationKindUpdateAccountContractCode
	ComputationKindValidatePublicKey
	ComputationKindValueExists
)
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{}/* 176 elements not displayed */

)

Functions

This section is empty.

Types

type ExecutionEffortWeights added in v0.27.0

type ExecutionEffortWeights map[common.ComputationKind]uint64

type ExecutionMemoryWeights added in v0.27.0

type ExecutionMemoryWeights map[common.MemoryKind]uint64

type Meter

type Meter interface {
	// merge child funcionality
	NewChild() Meter
	MergeMeter(child Meter, enforceLimits bool) error

	// computation metering
	MeterComputation(kind common.ComputationKind, intensity uint) error
	ComputationIntensities() MeteredComputationIntensities
	TotalComputationUsed() uint
	TotalComputationLimit() uint

	// memory metering
	MeterMemory(kind common.MemoryKind, intensity uint) error
	MemoryIntensities() MeteredMemoryIntensities
	TotalMemoryEstimate() uint
	TotalMemoryLimit() uint

	// TODO(patrick): make these non-optional arguments to NewMeter
	SetComputationWeights(weights ExecutionEffortWeights)
	SetMemoryWeights(weights ExecutionMemoryWeights)
	SetTotalMemoryLimit(limit uint64)
}

func NewMeter added in v0.27.0

func NewMeter(computationLimit, memoryLimit uint, options ...WeightedMeterOptions) Meter

NewMeter constructs a new Meter

type MeteredComputationIntensities added in v0.26.0

type MeteredComputationIntensities map[common.ComputationKind]uint

type MeteredMemoryIntensities added in v0.26.0

type MeteredMemoryIntensities map[common.MemoryKind]uint

type MetringOperationType

type MetringOperationType uint

type WeightedMeter added in v0.27.0

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

WeightedMeter 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 (*WeightedMeter) ComputationIntensities added in v0.27.0

func (m *WeightedMeter) ComputationIntensities() MeteredComputationIntensities

ComputationIntensities returns all the measured computational intensities

func (*WeightedMeter) MemoryIntensities added in v0.27.0

func (m *WeightedMeter) MemoryIntensities() MeteredMemoryIntensities

MemoryIntensities returns all the measured memory intensities

func (*WeightedMeter) MergeMeter added in v0.27.0

func (m *WeightedMeter) MergeMeter(child Meter, enforceLimits bool) error

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

func (*WeightedMeter) MeterComputation added in v0.27.0

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

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

func (*WeightedMeter) MeterMemory added in v0.27.0

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

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

func (*WeightedMeter) NewChild added in v0.27.0

func (m *WeightedMeter) NewChild() Meter

NewChild construct a new Meter instance with the same limits as parent

func (*WeightedMeter) SetComputationWeights added in v0.27.0

func (m *WeightedMeter) SetComputationWeights(weights ExecutionEffortWeights)

SetComputationWeights sets the computation weights

func (*WeightedMeter) SetMemoryWeights added in v0.27.0

func (m *WeightedMeter) SetMemoryWeights(weights ExecutionMemoryWeights)

SetMemoryWeights sets the memory weights

func (*WeightedMeter) SetTotalMemoryLimit added in v0.27.0

func (m *WeightedMeter) SetTotalMemoryLimit(limit uint64)

SetTotalMemoryLimit sets the total memory limit

func (*WeightedMeter) TotalComputationLimit added in v0.27.0

func (m *WeightedMeter) TotalComputationLimit() uint

TotalComputationLimit returns the total computation limit

func (*WeightedMeter) TotalComputationUsed added in v0.27.0

func (m *WeightedMeter) TotalComputationUsed() uint

TotalComputationUsed returns the total computation used

func (*WeightedMeter) TotalMemoryEstimate added in v0.27.0

func (m *WeightedMeter) TotalMemoryEstimate() uint

TotalMemoryEstimate returns the total memory used

func (*WeightedMeter) TotalMemoryLimit added in v0.27.0

func (m *WeightedMeter) TotalMemoryLimit() uint

TotalMemoryLimit returns the total memory limit

type WeightedMeterOptions added in v0.27.0

type WeightedMeterOptions func(*WeightedMeter)

func WithComputationWeights added in v0.27.0

func WithComputationWeights(weights ExecutionEffortWeights) WeightedMeterOptions

WithComputationWeights sets the weights for computation intensities

func WithMemoryWeights added in v0.27.0

func WithMemoryWeights(weights ExecutionMemoryWeights) WeightedMeterOptions

WithMemoryWeights sets the weights for the memory intensities

Jump to

Keyboard shortcuts

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