Documentation ¶
Index ¶
- Constants
- func IsFVMStateKey(owner string, key string) bool
- func IsSlabIndex(key string) bool
- func PrintableKey(key string) string
- type Ledger
- type NestedTransactionId
- type State
- func (s *State) ComputationIntensities() meter.MeteredComputationIntensities
- func (s *State) Get(owner, key string, enforceLimit bool) (flow.RegisterValue, error)
- func (s *State) InteractionUsed() uint64
- func (s *State) MemoryIntensities() meter.MeteredMemoryIntensities
- func (s *State) MergeState(other *State) error
- func (s *State) Meter() *meter.Meter
- func (s *State) MeterComputation(kind common.ComputationKind, intensity uint) error
- func (s *State) MeterEmittedEvent(byteSize uint64) error
- func (s *State) MeterMemory(kind common.MemoryKind, intensity uint) error
- func (s *State) NewChild() *State
- func (s *State) NewChildWithMeterParams(params meter.MeterParameters) *State
- func (s *State) RegisterUpdates() ([]flow.RegisterID, []flow.RegisterValue)
- func (s *State) Set(owner, key string, value flow.RegisterValue, enforceLimit bool) error
- func (s *State) TotalComputationLimit() uint
- func (s *State) TotalComputationUsed() uint64
- func (s *State) TotalEmittedEventBytes() uint64
- func (s *State) TotalMemoryEstimate() uint64
- func (s *State) TotalMemoryLimit() uint
- func (s *State) UpdatedAddresses() []flow.Address
- func (s *State) View() View
- type StateOption
- type StateParameters
- func (params StateParameters) WithMaxInteractionSizeAllowed(limit uint64) StateParameters
- func (params StateParameters) WithMaxKeySizeAllowed(limit uint64) StateParameters
- func (params StateParameters) WithMaxValueSizeAllowed(limit uint64) StateParameters
- func (params StateParameters) WithMeterParameters(meterParams meter.MeterParameters) StateParameters
- type TransactionState
- func (s *TransactionState) AttachAndCommit(cachedState *State) error
- func (s *TransactionState) BeginNestedTransaction() (NestedTransactionId, error)
- func (s *TransactionState) BeginNestedTransactionWithMeterParams(params meter.MeterParameters) (NestedTransactionId, error)
- func (s *TransactionState) BeginParseRestrictedNestedTransaction(location common.AddressLocation) (NestedTransactionId, error)
- func (s *TransactionState) Commit(expectedId NestedTransactionId) (*State, error)
- func (s *TransactionState) CommitParseRestricted(location common.AddressLocation) (*State, error)
- func (s *TransactionState) ComputationIntensities() meter.MeteredComputationIntensities
- func (s *TransactionState) DisableAllLimitEnforcements()
- func (s *TransactionState) EnableAllLimitEnforcements()
- func (s *TransactionState) EnforceComputationLimits() bool
- func (s *TransactionState) EnforceLimits() bool
- func (s *TransactionState) Get(owner string, key string, enforceLimit bool) (flow.RegisterValue, error)
- func (s *TransactionState) InteractionUsed() uint64
- func (s *TransactionState) IsCurrent(id NestedTransactionId) bool
- func (s *TransactionState) IsParseRestricted() bool
- func (s *TransactionState) MainTransactionId() NestedTransactionId
- func (s *TransactionState) MemoryIntensities() meter.MeteredMemoryIntensities
- func (s *TransactionState) MeterComputation(kind common.ComputationKind, intensity uint) error
- func (s *TransactionState) MeterEmittedEvent(byteSize uint64) error
- func (s *TransactionState) MeterMemory(kind common.MemoryKind, intensity uint) error
- func (s *TransactionState) NumNestedTransactions() int
- func (s *TransactionState) Pause(expectedId NestedTransactionId) (*State, error)
- func (s *TransactionState) RegisterUpdates() ([]flow.RegisterID, []flow.RegisterValue)
- func (s *TransactionState) RestartNestedTransaction(id NestedTransactionId) error
- func (s *TransactionState) Resume(pausedState *State)
- func (s *TransactionState) RunWithAllLimitsDisabled(f func())
- func (s *TransactionState) Set(owner string, key string, value flow.RegisterValue, enforceLimit bool) error
- func (s *TransactionState) TotalComputationLimit() uint
- func (s *TransactionState) TotalComputationUsed() uint64
- func (s *TransactionState) TotalEmittedEventBytes() uint64
- func (s *TransactionState) TotalMemoryEstimate() uint64
- func (s *TransactionState) UpdatedAddresses() []flow.Address
- func (s *TransactionState) ViewForTestingOnly() View
- type View
Constants ¶
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 ¶
IsFVMStateKey returns true if the key is controlled by the fvm env and return false otherwise (key controlled by the cadence env)
func IsSlabIndex ¶
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 ¶
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) InteractionUsed ¶
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 ¶
MergeState applies the changes from a the given view to this view.
func (*State) MeterComputation ¶
func (s *State) MeterComputation(kind common.ComputationKind, intensity uint) error
MeterComputation meters computation usage
func (*State) MeterEmittedEvent ¶
func (*State) MeterMemory ¶
func (s *State) MeterMemory(kind common.MemoryKind, intensity uint) error
MeterMemory meters memory usage
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) TotalComputationLimit ¶
TotalComputationLimit returns total computation limit
func (*State) TotalComputationUsed ¶
TotalComputationUsed returns total computation used
func (*State) TotalEmittedEventBytes ¶
func (*State) TotalMemoryEstimate ¶
TotalMemoryEstimate returns total memory used
func (*State) TotalMemoryLimit ¶
TotalMemoryLimit returns total memory limit
func (*State) UpdatedAddresses ¶
UpdatedAddresses returns a sorted list of addresses that were updated (at least 1 register update)
type StateOption ¶
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 }