state

package
v0.27.6-collection-ret... Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccountKeyPrefix  = "a."
	KeyAccountStatus  = AccountKeyPrefix + "s"
	KeyCode           = "code"
	KeyContractNames  = "contract_names"
	MaxPublicKeyCount = math.MaxUint64
)
View Source
const (
	DefaultMaxKeySize         = 16_000      // ~16KB
	DefaultMaxValueSize       = 256_000_000 // ~256MB
	DefaultMaxInteractionSize = 20_000_000  // ~20MB
)

Variables

This section is empty.

Functions

func ContractKey added in v0.15.0

func ContractKey(contractName string) string

func IsFVMStateKey added in v0.16.2

func IsFVMStateKey(owner, 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 IsValidAccountKeyHashAlgo added in v0.15.0

func IsValidAccountKeyHashAlgo(algo hash.HashingAlgorithm) bool

func IsValidAccountKeySignAlgo added in v0.15.0

func IsValidAccountKeySignAlgo(algo crypto.SigningAlgorithm) bool

func KeyPublicKey added in v0.27.0

func KeyPublicKey(index uint64) string

func PrintableKey added in v0.23.4

func PrintableKey(key string) string

PrintableKey formats slabs properly and avoids invalid utf8s

func RegisterSize added in v0.13.0

func RegisterSize(address flow.Address, key string, value flow.RegisterValue) int

func WithMaxInteractionSizeAllowed added in v0.14.0

func WithMaxInteractionSizeAllowed(limit uint64) func(st *State) *State

WithMaxInteractionSizeAllowed sets limit on total byte interaction with ledger

func WithMaxKeySizeAllowed added in v0.14.0

func WithMaxKeySizeAllowed(limit uint64) func(st *State) *State

WithMaxKeySizeAllowed sets limit on max key size

func WithMaxValueSizeAllowed added in v0.14.0

func WithMaxValueSizeAllowed(limit uint64) func(st *State) *State

WithMaxValueSizeAllowed sets limit on max value size

Types

type AccountStatus added in v0.27.0

type AccountStatus [accountStatusSize]byte

AccountStatus holds meta information about an account

currently modelled as a byte array with on-demand encoding/decoding of sub arrays the first byte captures flags (e.g. frozen) the next 8 bytes (big-endian) captures storage used by an account the next 8 bytes (big-endian) captures the storage index of an account and the last 8 bytes (big-endian) captures the number of public keys stored on this account

func AccountStatusFromBytes added in v0.27.0

func AccountStatusFromBytes(inp []byte) (*AccountStatus, error)

AccountStatusFromBytes constructs an AccountStatus from the given byte slice

func NewAccountStatus added in v0.27.0

func NewAccountStatus() *AccountStatus

NewAccountStatus returns a new AccountStatus sets the storage index to the init value

func (*AccountStatus) IsAccountFrozen added in v0.27.0

func (a *AccountStatus) IsAccountFrozen() bool

IsAccountFrozen returns true if account's frozen flag is set

func (*AccountStatus) PublicKeyCount added in v0.27.0

func (a *AccountStatus) PublicKeyCount() uint64

PublicKeyCount returns the public key count of the account

func (*AccountStatus) SetFrozenFlag added in v0.27.0

func (a *AccountStatus) SetFrozenFlag(frozen bool)

SetFrozenFlag sets the frozen flag

func (*AccountStatus) SetPublicKeyCount added in v0.27.0

func (a *AccountStatus) SetPublicKeyCount(count uint64)

SetPublicKeyCount updates the public key count of the account

func (*AccountStatus) SetStorageIndex added in v0.27.0

func (a *AccountStatus) SetStorageIndex(index atree.StorageIndex)

SetStorageIndex updates the storage index of the account

func (*AccountStatus) SetStorageUsed added in v0.27.0

func (a *AccountStatus) SetStorageUsed(used uint64)

SetStorageUsed updates the storage used by the account

func (*AccountStatus) StorageIndex added in v0.27.0

func (a *AccountStatus) StorageIndex() atree.StorageIndex

StorageIndex returns the storage index of the account

func (*AccountStatus) StorageUsed added in v0.27.0

func (a *AccountStatus) StorageUsed() uint64

StorageUsed returns the storage used by the account

func (*AccountStatus) ToBytes added in v0.27.0

func (a *AccountStatus) ToBytes() []byte

ToBytes converts AccountStatus to a byte slice

this has been kept this way in case one day we decided to move on to use an struct to represent account status.

type Accounts

type Accounts interface {
	Exists(address flow.Address) (bool, error)
	Get(address flow.Address) (*flow.Account, error)
	GetPublicKeyCount(address flow.Address) (uint64, error)
	AppendPublicKey(address flow.Address, key flow.AccountPublicKey) error
	GetPublicKey(address flow.Address, keyIndex uint64) (flow.AccountPublicKey, error)
	SetPublicKey(address flow.Address, keyIndex uint64, publicKey flow.AccountPublicKey) ([]byte, error)
	GetContractNames(address flow.Address) ([]string, error)
	GetContract(contractName string, address flow.Address) ([]byte, error)
	ContractExists(contractName string, address flow.Address) (bool, error)
	SetContract(contractName string, address flow.Address, contract []byte) error
	DeleteContract(contractName string, address flow.Address) error
	Create(publicKeys []flow.AccountPublicKey, newAddress flow.Address) error
	GetValue(address flow.Address, key string) (flow.RegisterValue, error)
	CheckAccountNotFrozen(address flow.Address) error
	GetStorageUsed(address flow.Address) (uint64, error)
	SetValue(address flow.Address, key string, value flow.RegisterValue) error
	AllocateStorageIndex(address flow.Address) (atree.StorageIndex, error)
	SetAccountFrozen(address flow.Address, frozen bool) error
}

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 State added in v0.14.0

type State struct {
	ReadCounter       uint64
	WriteCounter      uint64
	TotalBytesRead    uint64
	TotalBytesWritten uint64
	// contains filtered or unexported fields
}

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

func NewState added in v0.14.0

func NewState(view View, meter meter.Meter, opts ...StateOption) *State

NewState constructs a new state

func (*State) ComputationIntensities added in v0.25.2

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

ComputationIntensities returns computation intensities

func (*State) Delete added in v0.14.0

func (s *State) Delete(owner, key string, enforceLimit bool) error

Delete deletes a register

func (*State) Get added in v0.14.0

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

Get returns a register value given owner and key

func (*State) InteractionUsed added in v0.14.0

func (s *State) InteractionUsed() uint64

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

func (*State) MemoryIntensities added in v0.25.2

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

MemoryIntensities returns computation intensities

func (*State) MergeState added in v0.15.0

func (s *State) MergeState(other *State, enforceLimit bool) error

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

func (*State) Meter added in v0.25.2

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

func (*State) MeterComputation added in v0.25.2

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

MeterComputation meters computation usage

func (*State) MeterMemory added in v0.25.2

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

MeterMemory meters memory usage

func (*State) NewChild added in v0.15.0

func (s *State) NewChild() *State

NewChild generates a new child state

func (*State) Set added in v0.14.0

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

Set updates state delta with a register update

func (*State) TotalComputationLimit added in v0.25.2

func (s *State) TotalComputationLimit() uint

TotalComputationLimit returns total computation limit

func (*State) TotalComputationUsed added in v0.25.2

func (s *State) TotalComputationUsed() uint

TotalComputationUsed returns total computation used

func (*State) TotalMemoryEstimate added in v0.27.0

func (s *State) TotalMemoryEstimate() uint

TotalMemoryEstimate returns total memory used

func (*State) TotalMemoryLimit added in v0.25.2

func (s *State) TotalMemoryLimit() uint

TotalMemoryLimit returns total memory limit

func (*State) Touch added in v0.14.0

func (s *State) Touch(owner, key string) error

Touch touches a register

func (*State) UpdatedAddresses added in v0.14.0

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

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

func (*State) View added in v0.15.0

func (s *State) View() View

type StateBoundAddressGenerator added in v0.14.0

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

StateBoundAddressGenerator is a decorator for an address generator. It uses the underlying generator it gets from the chain. The only change is that when next address is called the state is updated as well.

func NewStateBoundAddressGenerator added in v0.14.0

func NewStateBoundAddressGenerator(stateHolder *StateHolder, chain flow.Chain) *StateBoundAddressGenerator

func (*StateBoundAddressGenerator) AddressCount added in v0.18.3

func (g *StateBoundAddressGenerator) AddressCount() uint64

func (*StateBoundAddressGenerator) Bytes added in v0.14.0

func (g *StateBoundAddressGenerator) Bytes() []byte

TODO return error instead of a panic this requires changes outside of fvm since the type is defined on flow model and emulator and others might be dependent on that

func (*StateBoundAddressGenerator) CurrentAddress added in v0.14.0

func (g *StateBoundAddressGenerator) CurrentAddress() flow.Address

func (*StateBoundAddressGenerator) NextAddress added in v0.14.0

func (g *StateBoundAddressGenerator) NextAddress() (flow.Address, error)

type StateHolder added in v0.15.0

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

StateHolder provides active states and facilitates common state management operations in order to make services such as accounts not worry about the state it is recommended that such services wraps a state manager instead of a state itself.

func NewStateHolder added in v0.15.0

func NewStateHolder(startState *State) *StateHolder

NewStateHolder constructs a new state manager

func (*StateHolder) DisableAllLimitEnforcements added in v0.25.2

func (s *StateHolder) DisableAllLimitEnforcements()

DisableAllLimitEnforcements disables all the limits

func (*StateHolder) EnableAllLimitEnforcements added in v0.25.2

func (s *StateHolder) EnableAllLimitEnforcements()

EnableAllLimitEnforcements enables all the limits

func (*StateHolder) EnforceComputationLimits added in v0.25.2

func (s *StateHolder) EnforceComputationLimits() bool

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

func (*StateHolder) EnforceInteractionLimits added in v0.23.1

func (s *StateHolder) EnforceInteractionLimits() bool

EnforceInteractionLimits returns if the interaction limits should be enforced or not

func (*StateHolder) EnforceMemoryLimits added in v0.25.2

func (s *StateHolder) EnforceMemoryLimits() bool

EnforceMemoryLimits returns if the memory limits should be enforced or not

func (*StateHolder) NewChild added in v0.15.0

func (s *StateHolder) NewChild() *State

NewChild constructs a new child of active state and set it as active state and return it this is basically a utility function for common operations

func (*StateHolder) SetActiveState added in v0.15.0

func (s *StateHolder) SetActiveState(st *State)

SetActiveState sets active state

func (*StateHolder) SetPayerIsServiceAccount added in v0.23.4

func (s *StateHolder) SetPayerIsServiceAccount()

SetPayerIsServiceAccount sets if the payer is the service account

func (*StateHolder) State added in v0.15.0

func (s *StateHolder) State() *State

State returns the active state

type StateOption added in v0.14.0

type StateOption func(st *State) *State

type StatefulAccounts added in v0.21.8

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

func NewAccounts

func NewAccounts(stateHolder *StateHolder) *StatefulAccounts

func (*StatefulAccounts) AllocateStorageIndex added in v0.21.8

func (a *StatefulAccounts) AllocateStorageIndex(address flow.Address) (atree.StorageIndex, error)

func (*StatefulAccounts) AppendPublicKey added in v0.21.8

func (a *StatefulAccounts) AppendPublicKey(address flow.Address, publicKey flow.AccountPublicKey) error

func (*StatefulAccounts) CheckAccountNotFrozen added in v0.21.8

func (a *StatefulAccounts) CheckAccountNotFrozen(address flow.Address) error

handy function to error out if account is frozen

func (*StatefulAccounts) ContractExists added in v0.26.0

func (a *StatefulAccounts) ContractExists(contractName string, address flow.Address) (bool, error)

func (*StatefulAccounts) Create added in v0.21.8

func (a *StatefulAccounts) Create(publicKeys []flow.AccountPublicKey, newAddress flow.Address) error

Create account sets all required registers on an address.

func (*StatefulAccounts) DeleteContract added in v0.21.8

func (a *StatefulAccounts) DeleteContract(contractName string, address flow.Address) error

func (*StatefulAccounts) Exists added in v0.21.8

func (a *StatefulAccounts) Exists(address flow.Address) (bool, error)

func (*StatefulAccounts) Get added in v0.21.8

func (a *StatefulAccounts) Get(address flow.Address) (*flow.Account, error)

func (*StatefulAccounts) GetAccountFrozen added in v0.21.8

func (a *StatefulAccounts) GetAccountFrozen(address flow.Address) (bool, error)

func (*StatefulAccounts) GetContract added in v0.21.8

func (a *StatefulAccounts) GetContract(contractName string, address flow.Address) ([]byte, error)

func (*StatefulAccounts) GetContractNames added in v0.21.8

func (a *StatefulAccounts) GetContractNames(address flow.Address) ([]string, error)

GetContractNames gets a sorted list of names of contracts deployed on an address

func (*StatefulAccounts) GetPublicKey added in v0.21.8

func (a *StatefulAccounts) GetPublicKey(address flow.Address, keyIndex uint64) (flow.AccountPublicKey, error)

func (*StatefulAccounts) GetPublicKeyCount added in v0.21.8

func (a *StatefulAccounts) GetPublicKeyCount(address flow.Address) (uint64, error)

func (*StatefulAccounts) GetPublicKeys added in v0.21.8

func (a *StatefulAccounts) GetPublicKeys(address flow.Address) (publicKeys []flow.AccountPublicKey, err error)

func (*StatefulAccounts) GetStorageUsed added in v0.21.8

func (a *StatefulAccounts) GetStorageUsed(address flow.Address) (uint64, error)

GetStorageUsed returns the amount of storage used in bytes by this account

func (*StatefulAccounts) GetValue added in v0.21.8

func (a *StatefulAccounts) GetValue(address flow.Address, key string) (flow.RegisterValue, error)

func (*StatefulAccounts) SetAccountFrozen added in v0.21.8

func (a *StatefulAccounts) SetAccountFrozen(address flow.Address, frozen bool) error

func (*StatefulAccounts) SetAllPublicKeys added in v0.21.8

func (a *StatefulAccounts) SetAllPublicKeys(address flow.Address, publicKeys []flow.AccountPublicKey) error

func (*StatefulAccounts) SetContract added in v0.21.8

func (a *StatefulAccounts) SetContract(contractName string, address flow.Address, contract []byte) error

func (*StatefulAccounts) SetPublicKey added in v0.21.8

func (a *StatefulAccounts) SetPublicKey(
	address flow.Address,
	keyIndex uint64,
	publicKey flow.AccountPublicKey,
) (encodedPublicKey []byte, err error)

func (*StatefulAccounts) SetValue added in v0.21.8

func (a *StatefulAccounts) SetValue(address flow.Address, key string, value flow.RegisterValue) error

SetValue sets a value in address' storage

func (*StatefulAccounts) TouchContract added in v0.21.8

func (a *StatefulAccounts) TouchContract(contractName string, address flow.Address)

type UUIDGenerator added in v0.15.0

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

func NewUUIDGenerator added in v0.15.0

func NewUUIDGenerator(stateHolder *StateHolder) *UUIDGenerator

func (*UUIDGenerator) GenerateUUID added in v0.15.0

func (u *UUIDGenerator) GenerateUUID() (uint64, error)

GenerateUUID generates a new uuid and persist the data changes into state

func (*UUIDGenerator) GetUUID added in v0.15.0

func (u *UUIDGenerator) GetUUID() (uint64, error)

GetUUID reads uint64 byte value for uuid from the state

func (*UUIDGenerator) SetUUID added in v0.15.0

func (u *UUIDGenerator) SetUUID(uuid uint64) error

SetUUID sets a new uint64 byte value

type View added in v0.15.0

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