state

package
v0.31.10 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: AGPL-3.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

This section is empty.

Types

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 (*ExecutionState) BytesWritten

func (state *ExecutionState) BytesWritten() uint64

BytesWritten returns the amount of total ledger bytes written

func (*ExecutionState) ComputationIntensities

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

ComputationIntensities returns computation intensities

func (*ExecutionState) DropChanges

func (state *ExecutionState) DropChanges() error

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) MemoryIntensities

func (state *ExecutionState) MemoryIntensities() meter.MeteredMemoryIntensities

MemoryIntensities returns computation intensities

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(kind common.ComputationKind, intensity uint) error

MeterComputation meters computation usage

func (*ExecutionState) MeterEmittedEvent

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

func (*ExecutionState) MeterMemory

func (state *ExecutionState) MeterMemory(kind common.MemoryKind, intensity uint) 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 meter.MeterParameters,
) *ExecutionState

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

func (ExecutionState) RunWithAllLimitsDisabled

func (controller ExecutionState) RunWithAllLimitsDisabled(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() uint

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(kind common.ComputationKind, intensity uint) error
	ComputationIntensities() meter.MeteredComputationIntensities
	TotalComputationLimit() uint
	TotalComputationUsed() uint64

	MeterMemory(kind common.MemoryKind, intensity uint) error
	MemoryIntensities() meter.MeteredMemoryIntensities
	TotalMemoryEstimate() uint64

	InteractionUsed() uint64

	MeterEmittedEvent(byteSize uint64) error
	TotalEmittedEventBytes() uint64

	// RunWithAllLimitsDisabled runs f with limits disabled
	RunWithAllLimitsDisabled(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

	// 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 meter.MeterParameters,
	) (
		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.

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