state

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: 10 Imported by: 0

Documentation

Index

Constants

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

	// Service level keys (owner is empty):
	UUIDKey         = "uuid"
	AddressStateKey = "account_address_state"

	// Account level keys
	AccountKeyPrefix   = "a."
	AccountStatusKey   = AccountKeyPrefix + "s"
	CodeKeyPrefix      = "code."
	ContractNamesKey   = "contract_names"
	PublicKeyKeyPrefix = "public_key_"
)

Variables

This section is empty.

Functions

func IsFVMStateKey

func IsFVMStateKey(owner string, key string) bool

IsFVMStateKey returns true if the key is controlled by the fvm env and return false otherwise (key controlled by the cadence env)

func IsSlabIndex

func IsSlabIndex(key string) bool

This returns true if the key is a slab index for an account's ordered fields map.

In general, each account's regular fields are stored in ordered map known only to cadence. Cadence encodes this map into bytes and split the bytes into slab chunks before storing the slabs into the ledger.

func PrintableKey

func PrintableKey(key string) string

PrintableKey formats slabs properly and avoids invalid utf8s

Types

type Ledger

type Ledger interface {
	Set(owner, key string, value flow.RegisterValue) error
	Get(owner, key string) (flow.RegisterValue, error)
	Touch(owner, key string) error
	Delete(owner, key string) error
}

Ledger is the storage interface used by the virtual machine to read and write register values.

TODO Rename this to Storage and remove reference to flow.RegisterValue and use byte[]

type NestedTransactionId

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

Opaque identifier used for Restarting nested transactions

func (NestedTransactionId) StateForTestingOnly

func (id NestedTransactionId) StateForTestingOnly() *State

type State

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

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

func NewState

func NewState(view View, params StateParameters) *State

NewState constructs a new state

func (*State) ComputationIntensities

func (s *State) ComputationIntensities() meter.MeteredComputationIntensities

ComputationIntensities returns computation intensities

func (*State) Get

func (s *State) Get(owner, key string, enforceLimit bool) (flow.RegisterValue, error)

Get returns a register value given owner and key

func (*State) InteractionUsed

func (s *State) InteractionUsed() uint64

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

func (*State) MemoryIntensities

func (s *State) MemoryIntensities() meter.MeteredMemoryIntensities

MemoryIntensities returns computation intensities

func (*State) MergeState

func (s *State) MergeState(other *State) error

MergeState applies the changes from a the given view to this view.

func (*State) Meter

func (s *State) Meter() *meter.Meter

func (*State) MeterComputation

func (s *State) MeterComputation(kind common.ComputationKind, intensity uint) error

MeterComputation meters computation usage

func (*State) MeterEmittedEvent

func (s *State) MeterEmittedEvent(byteSize uint64) error

func (*State) MeterMemory

func (s *State) MeterMemory(kind common.MemoryKind, intensity uint) error

MeterMemory meters memory usage

func (*State) NewChild

func (s *State) NewChild() *State

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

func (*State) NewChildWithMeterParams

func (s *State) NewChildWithMeterParams(
	params meter.MeterParameters,
) *State

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

func (*State) RegisterUpdates

func (s *State) RegisterUpdates() ([]flow.RegisterID, []flow.RegisterValue)

RegisterUpdates returns the lists of register id / value that were updated.

func (*State) Set

func (s *State) Set(owner, key string, value flow.RegisterValue, enforceLimit bool) error

Set updates state delta with a register update

func (*State) TotalComputationLimit

func (s *State) TotalComputationLimit() uint

TotalComputationLimit returns total computation limit

func (*State) TotalComputationUsed

func (s *State) TotalComputationUsed() uint64

TotalComputationUsed returns total computation used

func (*State) TotalEmittedEventBytes

func (s *State) TotalEmittedEventBytes() uint64

func (*State) TotalMemoryEstimate

func (s *State) TotalMemoryEstimate() uint64

TotalMemoryEstimate returns total memory used

func (*State) TotalMemoryLimit

func (s *State) TotalMemoryLimit() uint

TotalMemoryLimit returns total memory limit

func (*State) UpdatedAddresses

func (s *State) UpdatedAddresses() []flow.Address

UpdatedAddresses returns a sorted list of addresses that were updated (at least 1 register update)

func (*State) View

func (s *State) View() View

type StateOption

type StateOption func(st *State) *State

type StateParameters

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

func DefaultParameters

func DefaultParameters() StateParameters

func (StateParameters) WithMaxInteractionSizeAllowed

func (params StateParameters) WithMaxInteractionSizeAllowed(limit uint64) StateParameters

TODO(patrick): rm once https://github.com/onflow/flow-emulator/pull/245 is integrated.

WithMaxInteractionSizeAllowed sets limit on total byte interaction with ledger

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

type TransactionState

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

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

func NewTransactionState

func NewTransactionState(
	startView View,
	params StateParameters,
) *TransactionState

NewTransactionState constructs a new state transaction which manages nested transactions.

func (*TransactionState) AttachAndCommit

func (s *TransactionState) AttachAndCommit(cachedState *State) error

AttachAndCommit commits the changes in the cached nested transaction state to the current (nested) transaction.

func (*TransactionState) BeginNestedTransaction

func (s *TransactionState) BeginNestedTransaction() (
	NestedTransactionId,
	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.

func (*TransactionState) BeginNestedTransactionWithMeterParams

func (s *TransactionState) BeginNestedTransactionWithMeterParams(
	params meter.MeterParameters,
) (
	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.

func (*TransactionState) BeginParseRestrictedNestedTransaction

func (s *TransactionState) BeginParseRestrictedNestedTransaction(
	location common.AddressLocation,
) (
	NestedTransactionId,
	error,
)

BeginParseRestrictedNestedTransaction creates a restricted nested transaction within the current (nested) transaction. The meter parameters are inherited from the current transaction.

func (*TransactionState) Commit

func (s *TransactionState) Commit(
	expectedId NestedTransactionId,
) (
	*State,
	error,
)

Commit 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 state otherwise.

Note: The returned committed state may be reused by another transaction via AttachAndCommit to update the transaction bookkeeping, but the caller must manually invalidate the state. USE WITH EXTREME CAUTION.

func (*TransactionState) CommitParseRestricted

func (s *TransactionState) CommitParseRestricted(
	location common.AddressLocation,
) (
	*State,
	error,
)

CommitParseRestricted 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 state otherwise.

Note: The returned committed state may be reused by another transaction via AttachAndCommit to update the transaction bookkeeping, but the caller must manually invalidate the state. USE WITH EXTREME CAUTION.

func (*TransactionState) ComputationIntensities

func (s *TransactionState) ComputationIntensities() meter.MeteredComputationIntensities

func (*TransactionState) DisableAllLimitEnforcements

func (s *TransactionState) DisableAllLimitEnforcements()

DisableAllLimitEnforcements disables all the limits

func (*TransactionState) EnableAllLimitEnforcements

func (s *TransactionState) EnableAllLimitEnforcements()

EnableAllLimitEnforcements enables all the limits

func (*TransactionState) EnforceComputationLimits

func (s *TransactionState) EnforceComputationLimits() bool

EnforceComputationLimits returns if the computation limits should be enforced or not.

func (*TransactionState) EnforceLimits

func (s *TransactionState) EnforceLimits() bool

EnforceInteractionLimits returns if the interaction limits should be enforced or not

func (*TransactionState) Get

func (s *TransactionState) Get(
	owner string,
	key string,
	enforceLimit bool,
) (
	flow.RegisterValue,
	error,
)

func (*TransactionState) InteractionUsed

func (s *TransactionState) InteractionUsed() uint64

func (*TransactionState) IsCurrent

func (s *TransactionState) IsCurrent(id NestedTransactionId) bool

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

func (*TransactionState) IsParseRestricted

func (s *TransactionState) IsParseRestricted() bool

IsParseRestricted returns true if the current nested transaction is in parse resticted access mode.

func (*TransactionState) MainTransactionId

func (s *TransactionState) MainTransactionId() NestedTransactionId

func (*TransactionState) MemoryIntensities

func (s *TransactionState) MemoryIntensities() meter.MeteredMemoryIntensities

func (*TransactionState) MeterComputation

func (s *TransactionState) MeterComputation(
	kind common.ComputationKind,
	intensity uint,
) error

func (*TransactionState) MeterEmittedEvent

func (s *TransactionState) MeterEmittedEvent(byteSize uint64) error

func (*TransactionState) MeterMemory

func (s *TransactionState) MeterMemory(
	kind common.MemoryKind,
	intensity uint,
) error

func (*TransactionState) NumNestedTransactions

func (s *TransactionState) NumNestedTransactions() int

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

func (*TransactionState) Pause

func (s *TransactionState) Pause(
	expectedId NestedTransactionId,
) (
	*State,
	error,
)

Pause detaches the current nested transaction from the parent transaction, and returns the paused nested transaction state. The paused nested transaction may be resume via Resume.

WARNING: Pause and Resume are intended for implementing continuation passing style behavior for the transaction executor, with the assumption that the states accessed prior to pausing remain valid after resumption. The paused nested transaction should not be reused across transactions. IT IS NOT SAFE TO PAUSE A NESTED TRANSACTION IN GENERAL SINCE THAT COULD LEAD TO PHANTOM READS.

func (*TransactionState) RegisterUpdates

func (s *TransactionState) RegisterUpdates() (
	[]flow.RegisterID,
	[]flow.RegisterValue,
)

func (*TransactionState) RestartNestedTransaction

func (s *TransactionState) RestartNestedTransaction(
	id NestedTransactionId,
) error

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

func (*TransactionState) Resume

func (s *TransactionState) Resume(pausedState *State)

Resume attaches the paused nested transaction (state) to the current transaction.

func (*TransactionState) RunWithAllLimitsDisabled

func (s *TransactionState) RunWithAllLimitsDisabled(f func())

RunWithAllLimitsDisabled runs f with limits disabled

func (*TransactionState) Set

func (s *TransactionState) Set(
	owner string,
	key string,
	value flow.RegisterValue,
	enforceLimit bool,
) error

func (*TransactionState) TotalComputationLimit

func (s *TransactionState) TotalComputationLimit() uint

func (*TransactionState) TotalComputationUsed

func (s *TransactionState) TotalComputationUsed() uint64

func (*TransactionState) TotalEmittedEventBytes

func (s *TransactionState) TotalEmittedEventBytes() uint64

func (*TransactionState) TotalMemoryEstimate

func (s *TransactionState) TotalMemoryEstimate() uint64

func (*TransactionState) UpdatedAddresses

func (s *TransactionState) UpdatedAddresses() []flow.Address

func (*TransactionState) ViewForTestingOnly

func (s *TransactionState) ViewForTestingOnly() View

type View

type View interface {
	NewChild() View
	MergeView(child View) error
	DropDelta() // drops all the delta changes
	RegisterUpdates() ([]flow.RegisterID, []flow.RegisterValue)
	AllRegisters() []flow.RegisterID
	Ledger
}

Jump to

Keyboard shortcuts

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