Help us shape the future of Go! Take the 2026 Go Developer Survey

state

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: AGPL-3.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultMaxKeySize   = 16_000      // ~16KB
	DefaultMaxValueSize = 256_000_000 // ~256MB
)

Variables

View Source
var DefaultSpockSecretHasher = func() hash.Hasher {
	return hash.NewSHA3_256()
}

DefaultSpockSecretHasher returns a new SHA3_256 hasher

Functions

This section is empty.

Types

type ExecutionParameters added in v0.37.20

type ExecutionParameters struct {
	meter.MeterParameters
}

type ExecutionState

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

State represents the execution state it holds draft of updates and captures all register touches

func NewExecutionState

func NewExecutionState(
	snapshot snapshot.StorageSnapshot,
	params StateParameters,
) *ExecutionState

NewExecutionState constructs a new state

func NewExecutionStateWithSpockStateHasher added in v0.33.30

func NewExecutionStateWithSpockStateHasher(
	snapshot snapshot.StorageSnapshot,
	params StateParameters,
	getHasher func() hash.Hasher,
) *ExecutionState

NewExecutionStateWithSpockStateHasher constructs a new state with a custom hasher

func (*ExecutionState) BytesWritten

func (state *ExecutionState) BytesWritten() uint64

BytesWritten returns the amount of total ledger bytes written

func (*ExecutionState) ComputationAvailable added in v0.33.1

func (state *ExecutionState) ComputationAvailable(usage common.ComputationUsage) bool

ComputationAvailable checks if enough computation capacity is available without metering

func (*ExecutionState) ComputationIntensities

func (state *ExecutionState) ComputationIntensities() meter.MeteredComputationIntensities

ComputationIntensities returns computation intensities

func (*ExecutionState) ComputationRemaining added in v0.38.0

func (state *ExecutionState) ComputationRemaining(kind common.ComputationKind) uint64

ComputationRemaining returns the remaining computation for the given kind.

func (*ExecutionState) DropChanges

func (state *ExecutionState) DropChanges() error

func (*ExecutionState) ExecutionParameters added in v0.37.20

func (state *ExecutionState) ExecutionParameters() ExecutionParameters

func (*ExecutionState) Finalize

func (state *ExecutionState) Finalize() *snapshot.ExecutionSnapshot

func (*ExecutionState) Get

Get returns a register value given owner and key

func (*ExecutionState) InteractionUsed

func (state *ExecutionState) InteractionUsed() uint64

InteractionUsed returns the amount of ledger interaction (total ledger byte read + total ledger byte written)

func (*ExecutionState) MemoryAmounts added in v0.42.0

func (state *ExecutionState) MemoryAmounts() meter.MeteredMemoryAmounts

MemoryAmounts returns memory amounts

func (*ExecutionState) Merge

func (state *ExecutionState) Merge(other *snapshot.ExecutionSnapshot) error

MergeState the changes from a the given execution snapshot to this state.

func (*ExecutionState) MeterComputation

func (state *ExecutionState) MeterComputation(usage common.ComputationUsage) error

MeterComputation meters computation usage

func (*ExecutionState) MeterEmittedEvent

func (state *ExecutionState) MeterEmittedEvent(byteSize uint64) error

func (*ExecutionState) MeterMemory

func (state *ExecutionState) MeterMemory(usage common.MemoryUsage) error

MeterMemory meters memory usage

func (*ExecutionState) NewChild

func (state *ExecutionState) NewChild() *ExecutionState

NewChild generates a new child state using the parent's meter parameters.

func (*ExecutionState) NewChildWithMeterParams

func (state *ExecutionState) NewChildWithMeterParams(
	params ExecutionParameters,
) *ExecutionState

NewChildWithMeterParams generates a new child state using the provide meter parameters.

func (ExecutionState) RunWithMeteringDisabled added in v0.43.0

func (controller ExecutionState) RunWithMeteringDisabled(f func())

func (*ExecutionState) Set

func (state *ExecutionState) Set(id flow.RegisterID, value flow.RegisterValue) error

Set updates state delta with a register update

func (*ExecutionState) TotalComputationLimit

func (state *ExecutionState) TotalComputationLimit() uint64

TotalComputationLimit returns total computation limit

func (*ExecutionState) TotalComputationUsed

func (state *ExecutionState) TotalComputationUsed() uint64

TotalComputationUsed returns total computation used

func (*ExecutionState) TotalEmittedEventBytes

func (state *ExecutionState) TotalEmittedEventBytes() uint64

func (*ExecutionState) TotalMemoryEstimate

func (state *ExecutionState) TotalMemoryEstimate() uint64

TotalMemoryEstimate returns total memory used

func (*ExecutionState) TotalMemoryLimit

func (state *ExecutionState) TotalMemoryLimit() uint

TotalMemoryLimit returns total memory limit

type Meter

type Meter interface {
	MeterComputation(usage common.ComputationUsage) error
	ComputationAvailable(usage common.ComputationUsage) bool
	ComputationRemaining(kind common.ComputationKind) uint64
	ComputationIntensities() meter.MeteredComputationIntensities
	TotalComputationLimit() uint64
	TotalComputationUsed() uint64

	MeterMemory(usage common.MemoryUsage) error
	MemoryAmounts() meter.MeteredMemoryAmounts
	TotalMemoryEstimate() uint64

	InteractionUsed() uint64

	MeterEmittedEvent(byteSize uint64) error
	TotalEmittedEventBytes() uint64

	// RunWithMeteringDisabled runs f with limits disabled
	// This function can be used to run a function that fits one of these cases:
	// - the function should not fail due to metering limits
	// - the function is not invokable by the user and has a constant execution time (e.g. fee deduction)
	// - the function is metered once before calling `RunWithMeteringDisabled` with a special weight (e.g. create account)
	// 		and doesn't need additional metering inside the function
	RunWithMeteringDisabled(f func())
}

type NestedTransactionId

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

Opaque identifier used for Restarting nested transactions

func (NestedTransactionId) StateForTestingOnly

func (id NestedTransactionId) StateForTestingOnly() *ExecutionState

type NestedTransactionPreparer

type NestedTransactionPreparer interface {
	Meter

	// ExecutionParameters returns the execution parameters
	ExecutionParameters() ExecutionParameters

	// NumNestedTransactions returns the number of uncommitted nested
	// transactions.  Note that the main transaction is not considered a
	// nested transaction.
	NumNestedTransactions() int

	// IsParseRestricted returns true if the current nested transaction is in
	// parse resticted access mode.
	IsParseRestricted() bool

	MainTransactionId() NestedTransactionId

	// IsCurrent returns true if the provide id refers to the current (nested)
	// transaction.
	IsCurrent(id NestedTransactionId) bool

	// InterimReadSet returns the current read set aggregated from all
	// outstanding nested transactions.
	InterimReadSet() map[flow.RegisterID]struct{}

	// FinalizeMainTransaction finalizes the main transaction and returns
	// its execution snapshot.  The finalized main transaction will not accept
	// any new commits after this point.  This returns an error if there are
	// outstanding nested transactions.
	FinalizeMainTransaction() (*snapshot.ExecutionSnapshot, error)

	// BeginNestedTransaction creates a unrestricted nested transaction within
	// the current unrestricted (nested) transaction.  The meter parameters are
	// inherited from the current transaction.  This returns error if the
	// current nested transaction is program restricted.
	BeginNestedTransaction() (
		NestedTransactionId,
		error,
	)

	// BeginNestedTransactionWithMeterParams creates a unrestricted nested
	// transaction within the current unrestricted (nested) transaction, using
	// the provided meter parameters. This returns error if the current nested
	// transaction is program restricted.
	BeginNestedTransactionWithMeterParams(
		params ExecutionParameters,
	) (
		NestedTransactionId,
		error,
	)

	// BeginParseRestrictedNestedTransaction creates a restricted nested
	// transaction within the current (nested) transaction.  The meter
	// parameters are inherited from the current transaction.
	BeginParseRestrictedNestedTransaction(
		location common.AddressLocation,
	) (
		NestedTransactionId,
		error,
	)

	// CommitNestedTransaction commits the changes in the current unrestricted
	// nested transaction to the parent (nested) transaction.  This returns
	// error if the expectedId does not match the current nested transaction.
	// This returns the committed execution snapshot otherwise.
	//
	// Note: The returned committed execution snapshot may be reused by another
	// transaction via AttachAndCommitNestedTransaction to update the
	// transaction bookkeeping, but the caller must manually invalidate the
	// state.
	// USE WITH EXTREME CAUTION.
	CommitNestedTransaction(
		expectedId NestedTransactionId,
	) (
		*snapshot.ExecutionSnapshot,
		error,
	)

	// CommitParseRestrictedNestedTransaction commits the changes in the
	// current restricted nested transaction to the parent (nested)
	// transaction.  This returns error if the specified location does not
	// match the tracked location. This returns the committed execution
	// snapshot otherwise.
	//
	// Note: The returned committed execution snapshot may be reused by another
	// transaction via AttachAndCommitNestedTransaction to update the
	// transaction bookkeeping, but the caller must manually invalidate the
	// state.
	// USE WITH EXTREME CAUTION.
	CommitParseRestrictedNestedTransaction(
		location common.AddressLocation,
	) (
		*snapshot.ExecutionSnapshot,
		error,
	)

	// AttachAndCommitNestedTransaction commits the changes from the cached
	// nested transaction execution snapshot to the current (nested)
	// transaction.
	AttachAndCommitNestedTransaction(
		cachedSnapshot *snapshot.ExecutionSnapshot,
	) error

	// RestartNestedTransaction merges all changes that belongs to the nested
	// transaction about to be restart (for spock/meter bookkeeping), then
	// wipes its view changes.
	RestartNestedTransaction(
		id NestedTransactionId,
	) error

	Get(id flow.RegisterID) (flow.RegisterValue, error)

	Set(id flow.RegisterID, value flow.RegisterValue) error
}

NestedTransactionPreparer provides active transaction states and facilitates common state management operations.

func NewTransactionState

func NewTransactionState(
	snapshot snapshot.StorageSnapshot,
	params StateParameters,
) NestedTransactionPreparer

NewTransactionState constructs a new state transaction which manages nested transactions.

func NewTransactionStateFromExecutionState added in v0.33.30

func NewTransactionStateFromExecutionState(
	startState *ExecutionState,
) NestedTransactionPreparer

NewTransactionStateFromExecutionState constructs a new state transaction directly from an execution state.

type StateParameters

type StateParameters struct {
	meter.MeterParameters
	// contains filtered or unexported fields
}

func DefaultParameters

func DefaultParameters() StateParameters

func (StateParameters) WithMaxKeySizeAllowed

func (params StateParameters) WithMaxKeySizeAllowed(
	limit uint64,
) StateParameters

WithMaxKeySizeAllowed sets limit on max key size

func (StateParameters) WithMaxValueSizeAllowed

func (params StateParameters) WithMaxValueSizeAllowed(
	limit uint64,
) StateParameters

WithMaxValueSizeAllowed sets limit on max value size

func (StateParameters) WithMeterParameters

func (params StateParameters) WithMeterParameters(
	meterParams meter.MeterParameters,
) StateParameters

WithMeterParameters sets the state's meter parameters

Jump to

Keyboard shortcuts

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