state

package
v0.33.38 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: AGPL-3.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// AccountsStorageIDKey is the path where we store the collection ID for accounts
	AccountsStorageIDKey = "AccountsStorageIDKey"
	// CodesStorageIDKey is the path where we store the collection ID for codes
	CodesStorageIDKey = "CodesStorageIDKey"
)

Variables

This section is empty.

Functions

func NewPersistentSlabStorage

func NewPersistentSlabStorage(baseStorage atree.BaseStorage) (*atree.PersistentSlabStorage, error)

Types

type Account

type Account struct {
	// address
	Address gethCommon.Address
	// balance of the address
	Balance *big.Int
	// nonce of the address
	Nonce uint64
	// hash of the code
	// if no code the gethTypes.EmptyCodeHash is stored
	CodeHash gethCommon.Hash
	// the id of the collection holds storage slots for this account
	// this value is nil for EOA accounts
	CollectionID []byte
}

Account holds the metadata of an address and provides (de)serialization functionality

Note that code and storage slots of an address is not part of this data structure

func DecodeAccount

func DecodeAccount(inp []byte) (*Account, error)

DecodeAccount constructs a new account from the encoded data

func NewAccount

func NewAccount(
	address gethCommon.Address,
	balance *big.Int,
	nonce uint64,
	codeHash gethCommon.Hash,
	collectionID []byte,
) *Account

NewAccount constructs a new account

func (*Account) Encode

func (a *Account) Encode() ([]byte, error)

Encode encodes the account

func (*Account) HasCode

func (a *Account) HasCode() bool

type BaseView

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

BaseView implements a types.BaseView it acts as the base layer of state queries for the stateDB it stores accounts, codes and storage slots.

under the hood it uses a set of collections, one for account's meta data, one for codes and one for each of account storage space.

func NewBaseView

func NewBaseView(ledger atree.Ledger, rootAddress flow.Address) (*BaseView, error)

NewBaseView constructs a new base view

func (*BaseView) AddressInAccessList

func (v *BaseView) AddressInAccessList(gethCommon.Address) bool

AddressInAccessList checks if an address is in the access list

access list control is not a functionality of the base view it always returns false

func (*BaseView) Commit

func (v *BaseView) Commit() error

Commit commits the changes to the underlying storage layers

func (*BaseView) CreateAccount

func (v *BaseView) CreateAccount(
	addr gethCommon.Address,
	balance *big.Int,
	nonce uint64,
	code []byte,
	codeHash gethCommon.Hash,
) error

CreateAccount creates a new account

func (*BaseView) DeleteAccount

func (v *BaseView) DeleteAccount(addr gethCommon.Address) error

DeleteAccount deletes an account's meta data, code, and storage slots associated with that address

func (*BaseView) Exist

func (v *BaseView) Exist(addr gethCommon.Address) (bool, error)

Exist returns true if the address exist in the state

func (*BaseView) GetBalance

func (v *BaseView) GetBalance(addr gethCommon.Address) (*big.Int, error)

GetBalance returns the balance of an address

for non-existent accounts it returns a balance of zero

func (*BaseView) GetCode

func (v *BaseView) GetCode(addr gethCommon.Address) ([]byte, error)

GetCode returns the code of an address

for non-existent accounts or accounts without a code (e.g. EOAs) it returns nil

func (*BaseView) GetCodeHash

func (v *BaseView) GetCodeHash(addr gethCommon.Address) (gethCommon.Hash, error)

GetCodeHash returns the code hash of an address

for non-existent accounts or accounts without a code (e.g. EOAs) it returns default empty hash value (gethTypes.EmptyCodeHash)

func (*BaseView) GetCodeSize

func (v *BaseView) GetCodeSize(addr gethCommon.Address) (int, error)

GetCodeSize returns the code size of an address

for non-existent accounts or accounts without a code (e.g. EOAs) it returns zero

func (*BaseView) GetNonce

func (v *BaseView) GetNonce(addr gethCommon.Address) (uint64, error)

GetNonce returns the nonce of an address

for non-existent accounts it returns zero

func (*BaseView) GetRefund

func (v *BaseView) GetRefund() uint64

GetRefund returns the total amount of (gas) refund

this method returns the value of zero

func (*BaseView) GetState

func (v *BaseView) GetState(sk types.SlotAddress) (gethCommon.Hash, error)

GetState returns values for a slot in the main storage

for non-existent slots it returns the default empty hash value (gethTypes.EmptyCodeHash)

func (*BaseView) GetTransientState

func (v *BaseView) GetTransientState(types.SlotAddress) gethCommon.Hash

GetTransientState returns values for an slot transient storage

transient storage is not a functionality for the base view so it always returns the default value for non-existent slots

func (*BaseView) HasSelfDestructed

func (v *BaseView) HasSelfDestructed(gethCommon.Address) (bool, *big.Int)

HasSelfDestructed returns true if an address is flagged for destruction at the end of transaction

func (*BaseView) IsCreated

func (v *BaseView) IsCreated(gethCommon.Address) bool

IsCreated returns true if the address has been created in the context of this transaction

func (*BaseView) SlotInAccessList

func (v *BaseView) SlotInAccessList(types.SlotAddress) (addressOk bool, slotOk bool)

SlotInAccessList checks if a slot is in the access list

access list control is not a functionality of the base view it always returns false

func (*BaseView) UpdateAccount

func (v *BaseView) UpdateAccount(
	addr gethCommon.Address,
	balance *big.Int,
	nonce uint64,
	code []byte,
	codeHash gethCommon.Hash,
) error

UpdateAccount updates an account's meta data

func (*BaseView) UpdateSlot

func (v *BaseView) UpdateSlot(sk types.SlotAddress, value gethCommon.Hash) error

UpdateSlot updates the value for a slot

type ByteStringValue

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

func NewByteStringValue

func NewByteStringValue(data []byte) ByteStringValue

func (ByteStringValue) ByteSize

func (v ByteStringValue) ByteSize() uint32

func (ByteStringValue) Bytes

func (v ByteStringValue) Bytes() []byte

func (ByteStringValue) ChildStorables

func (v ByteStringValue) ChildStorables() []atree.Storable

func (ByteStringValue) Encode

func (v ByteStringValue) Encode(enc *atree.Encoder) error

func (ByteStringValue) Storable

func (v ByteStringValue) Storable(storage atree.SlabStorage, address atree.Address, maxInlineSize uint64) (atree.Storable, error)

func (ByteStringValue) StoredValue

func (v ByteStringValue) StoredValue(_ atree.SlabStorage) (atree.Value, error)

func (ByteStringValue) String

func (v ByteStringValue) String() string

type Collection

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

Collection provides a persistent and compact way of storing key/value pairs each collection has a unique collectionID that can be used to fetch the collection

TODO(ramtin): we might not need any extra hashing on the atree side and optimize this to just use the key given the keys are hashed ?

func (*Collection) CollectionID

func (c *Collection) CollectionID() []byte

CollectionID returns the unique id for the collection

func (*Collection) Destroy

func (c *Collection) Destroy() ([][]byte, error)

Destroy destroys the whole collection

func (*Collection) Get

func (c *Collection) Get(key []byte) ([]byte, error)

Get gets the value for the given key

if key doesn't exist it returns nil (no error)

func (*Collection) Remove

func (c *Collection) Remove(key []byte) error

Remove removes a key from the collection

if the key doesn't exist it return no error

func (*Collection) Set

func (c *Collection) Set(key, value []byte) error

Set sets the value for the given key

if a value already stored at the given key it replaces the value

type CollectionProvider

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

CollectionProvider provides access to collections

func NewCollectionProvider

func NewCollectionProvider(
	rootAddr atree.Address,
	ledger atree.Ledger,
) (*CollectionProvider, error)

NewCollectionProvider constructs a new CollectionProvider

func (*CollectionProvider) CollectionByID

func (cp *CollectionProvider) CollectionByID(collectionID []byte) (*Collection, error)

CollectionByID returns the collection by collection ID

if no collection is found with that collection id, it return error Warning: this method should only used only once for each collection and the returned pointer should be kept for the future. calling twice for the same collection might result in odd-behaviours currently collection provider doesn't do any internal caching to protect aginast these cases

func (*CollectionProvider) Commit

func (cp *CollectionProvider) Commit() error

Commit commits all changes to the collections with changes

func (*CollectionProvider) NewCollection

func (cp *CollectionProvider) NewCollection() (*Collection, error)

NewCollection constructs a new collection

type DeltaView

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

DeltaView captures the changes to the state during the execution

for most of the read calls it checks its change logs and if no record is found it would redirect the call to the parent view.

func NewDeltaView

func NewDeltaView(parent types.ReadOnlyView) *DeltaView

NewDeltaView constructs a new delta view

func (*DeltaView) AddAddressToAccessList

func (d *DeltaView) AddAddressToAccessList(addr gethCommon.Address) bool

AddAddressToAccessList adds an address to the access list

func (*DeltaView) AddBalance

func (d *DeltaView) AddBalance(addr gethCommon.Address, amount *big.Int) error

AddBalance adds the amount to the current balance of the given address

func (*DeltaView) AddLog

func (d *DeltaView) AddLog(log *gethTypes.Log)

AddLog appends a log to the log collection

func (*DeltaView) AddPreimage

func (d *DeltaView) AddPreimage(hash gethCommon.Hash, preimage []byte)

AddPreimage adds a preimage

func (*DeltaView) AddRefund

func (d *DeltaView) AddRefund(amount uint64) error

AddRefund adds the amount to the total (gas) refund

func (*DeltaView) AddSlotToAccessList

func (d *DeltaView) AddSlotToAccessList(sk types.SlotAddress) (addrAdded bool, slotAdded bool)

AddSlotToAccessList adds a slot to the access list it also adds the address to the address list

func (*DeltaView) AddressInAccessList

func (d *DeltaView) AddressInAccessList(addr gethCommon.Address) bool

AddressInAccessList checks if the address is in the access list

func (*DeltaView) CreateAccount

func (d *DeltaView) CreateAccount(addr gethCommon.Address) error

CreateAccount creates a new account for the given address

if address already extists (even if destructed), carry over the balance and reset the data from the orginal account.

func (*DeltaView) DirtyAddresses

func (d *DeltaView) DirtyAddresses() map[gethCommon.Address]struct{}

DirtyAddresses returns a set of addresses that has been updated in this view

func (*DeltaView) DirtySlots

func (d *DeltaView) DirtySlots() map[types.SlotAddress]struct{}

DirtySlots returns a set of slots that has been updated in this view

func (*DeltaView) Exist

func (d *DeltaView) Exist(addr gethCommon.Address) (bool, error)

Exist returns true if address exists

it also returns true for both newly created accounts or accounts that has been flagged for deletion

func (*DeltaView) GetBalance

func (d *DeltaView) GetBalance(addr gethCommon.Address) (*big.Int, error)

GetBalance returns the balance of the given address

func (*DeltaView) GetCode

func (d *DeltaView) GetCode(addr gethCommon.Address) ([]byte, error)

GetCode returns the code of the given address

func (*DeltaView) GetCodeHash

func (d *DeltaView) GetCodeHash(addr gethCommon.Address) (gethCommon.Hash, error)

GetCodeHash returns the code hash of the given address

func (*DeltaView) GetCodeSize

func (d *DeltaView) GetCodeSize(addr gethCommon.Address) (int, error)

GetCodeSize returns the code size of the given address

func (*DeltaView) GetNonce

func (d *DeltaView) GetNonce(addr gethCommon.Address) (uint64, error)

GetNonce returns the nonce of the given address

func (*DeltaView) GetRefund

func (d *DeltaView) GetRefund() uint64

GetRefund returns the total (gas) refund

func (*DeltaView) GetState

func (d *DeltaView) GetState(sk types.SlotAddress) (gethCommon.Hash, error)

GetState returns the value of the slot of the main state

func (*DeltaView) GetTransientState

func (d *DeltaView) GetTransientState(sk types.SlotAddress) gethCommon.Hash

GetTransientState returns the value of the slot of the transient state

func (*DeltaView) HasSelfDestructed

func (d *DeltaView) HasSelfDestructed(addr gethCommon.Address) (bool, *big.Int)

HasSelfDestructed returns true if address has been flagged for destruction it also returns the balance of the address before the destruction call

func (*DeltaView) IsCreated

func (d *DeltaView) IsCreated(addr gethCommon.Address) bool

IsCreated returns true if address has been created in this tx

func (*DeltaView) Logs

func (d *DeltaView) Logs() []*gethTypes.Log

Logs returns the logs that has been captured in this view

func (*DeltaView) NewChildView

func (d *DeltaView) NewChildView() *DeltaView

NewChildView constructs a new delta view having the current view as parent

func (*DeltaView) Preimages

func (d *DeltaView) Preimages() map[gethCommon.Hash][]byte

Preimages returns a map of preimages

func (*DeltaView) SelfDestruct

func (d *DeltaView) SelfDestruct(addr gethCommon.Address) error

SelfDestruct sets a flag to destruct the account at the end of transaction

if an account has been created in this transaction, it would return an error

func (*DeltaView) SetCode

func (d *DeltaView) SetCode(addr gethCommon.Address, code []byte) error

SetCode sets the code for the given address

func (*DeltaView) SetNonce

func (d *DeltaView) SetNonce(addr gethCommon.Address, nonce uint64) error

SetNonce sets the nonce for the given address

func (*DeltaView) SetState

func (d *DeltaView) SetState(sk types.SlotAddress, value gethCommon.Hash) error

SetState adds sets a value for the given slot of the main storage

func (*DeltaView) SetTransientState

func (d *DeltaView) SetTransientState(sk types.SlotAddress, value gethCommon.Hash)

SetTransientState adds sets a value for the given slot of the transient storage

func (*DeltaView) SlotInAccessList

func (d *DeltaView) SlotInAccessList(sk types.SlotAddress) (addressOk bool, slotOk bool)

SlotInAccessList checks if the slot is in the access list

func (*DeltaView) SubBalance

func (d *DeltaView) SubBalance(addr gethCommon.Address, amount *big.Int) error

SubBalance subtracts the amount from the current balance of the given address

func (*DeltaView) SubRefund

func (d *DeltaView) SubRefund(amount uint64) error

SubRefund subtracts the amount from the total (gas) refund

type StateDB

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

StateDB implements a types.StateDB interface

stateDB interface defined by the Geth doesn't support returning errors when state calls are happening, and requires stateDB to cache the error and return it at a later time (when commit is called). Only the first error is expected to be returned. Warning: current implementation of the StateDB is considered to be used for a single EVM transaction execution and is not thread safe. yet the current design supports addition of concurrency in the future if needed

func NewStateDB

func NewStateDB(ledger atree.Ledger, root flow.Address) (*StateDB, error)

NewStateDB constructs a new StateDB

func (*StateDB) AddAddressToAccessList

func (db *StateDB) AddAddressToAccessList(addr gethCommon.Address)

AddAddressToAccessList adds the given address to the access list.

func (*StateDB) AddBalance

func (db *StateDB) AddBalance(addr gethCommon.Address, amount *big.Int)

AddBalance adds the amount from the balance of the given address

func (*StateDB) AddLog

func (db *StateDB) AddLog(log *gethTypes.Log)

AddLog appends a lot to the collection of logs

func (*StateDB) AddPreimage

func (db *StateDB) AddPreimage(hash gethCommon.Hash, data []byte)

AddPreimage adds a preimage to the collection of preimages

func (*StateDB) AddRefund

func (db *StateDB) AddRefund(amount uint64)

AddRefund adds the amount to the total (gas) refund

func (*StateDB) AddSlotToAccessList

func (db *StateDB) AddSlotToAccessList(addr gethCommon.Address, key gethCommon.Hash)

AddSlotToAccessList adds the given (address,slot) to the access list.

func (*StateDB) AddressInAccessList

func (db *StateDB) AddressInAccessList(addr gethCommon.Address) bool

AddressInAccessList checks if an address is in the access list

func (*StateDB) Commit

func (db *StateDB) Commit() error

Commit commits state changes back to the underlying

func (*StateDB) CreateAccount

func (db *StateDB) CreateAccount(addr gethCommon.Address)

CreateAccount creates a new account for the given address it sets the nonce to zero

func (*StateDB) Empty

func (db *StateDB) Empty(addr gethCommon.Address) bool

Empty returns whether the given account is empty.

Empty is defined according to EIP161 (balance = nonce = code = 0).

func (*StateDB) Error

func (s *StateDB) Error() error

Error returns the memorized database failure occurred earlier.

func (*StateDB) Exist

func (db *StateDB) Exist(addr gethCommon.Address) bool

Exist returns true if the given address exists in state.

this should also return true for self destructed accounts during the transaction execution.

func (*StateDB) GetBalance

func (db *StateDB) GetBalance(addr gethCommon.Address) *big.Int

GetBalance returns the balance of the given address

func (*StateDB) GetCode

func (db *StateDB) GetCode(addr gethCommon.Address) []byte

GetCode returns the code for the given address

func (*StateDB) GetCodeHash

func (db *StateDB) GetCodeHash(addr gethCommon.Address) gethCommon.Hash

GetCodeHash returns the code hash of the given address

func (*StateDB) GetCodeSize

func (db *StateDB) GetCodeSize(addr gethCommon.Address) int

GetCodeSize returns the size of the code for the given address

func (*StateDB) GetCommittedState

func (db *StateDB) GetCommittedState(addr gethCommon.Address, key gethCommon.Hash) gethCommon.Hash

GetCommittedState returns the value for the given storage slot considering only the commited state and not changes in the scope of current transaction.

func (*StateDB) GetNonce

func (db *StateDB) GetNonce(addr gethCommon.Address) uint64

GetNonce returns the nonce of the given address

func (*StateDB) GetRefund

func (db *StateDB) GetRefund() uint64

GetRefund returns the total (gas) refund

func (*StateDB) GetState

func (db *StateDB) GetState(addr gethCommon.Address, key gethCommon.Hash) gethCommon.Hash

GetState returns the value for the given storage slot

func (*StateDB) GetTransientState

func (db *StateDB) GetTransientState(addr gethCommon.Address, key gethCommon.Hash) gethCommon.Hash

GetTransientState returns the value for the given key of the transient storage

func (*StateDB) HasSelfDestructed

func (db *StateDB) HasSelfDestructed(addr gethCommon.Address) bool

HasSelfDestructed returns true if address is flaged with self destruct.

func (*StateDB) IsCreated

func (db *StateDB) IsCreated(addr gethCommon.Address) bool

IsCreated returns true if address is recently created (context of a transaction)

func (*StateDB) Logs

func (db *StateDB) Logs(
	blockHash gethCommon.Hash,
	blockNumber uint64,
	txHash gethCommon.Hash,
	txIndex uint,
) []*gethTypes.Log

Logs returns the list of logs it also update each log with the block and tx info

func (*StateDB) Preimages

func (db *StateDB) Preimages() map[gethCommon.Hash][]byte

Preimages returns a set of preimages

func (*StateDB) Prepare

func (db *StateDB) Prepare(rules gethParams.Rules, sender, coinbase gethCommon.Address, dest *gethCommon.Address, precompiles []gethCommon.Address, txAccesses gethTypes.AccessList)

Prepare is a highlevel logic that sadly is considered to be part of the stateDB interface and not on the layers above. based on parameters that are passed it updates accesslists

func (*StateDB) RevertToSnapshot

func (db *StateDB) RevertToSnapshot(index int)

RevertToSnapshot reverts the changes until we reach the given snaptshot

func (*StateDB) SelfDestruct

func (db *StateDB) SelfDestruct(addr gethCommon.Address)

SelfDestruct flags the address for deletion.

while this address exists for the rest of transaction, the balance of this account is return zero after the SelfDestruct call.

func (*StateDB) Selfdestruct6780

func (db *StateDB) Selfdestruct6780(addr gethCommon.Address)

Selfdestruct6780 would only follow the self destruct steps if account is created

func (*StateDB) SetCode

func (db *StateDB) SetCode(addr gethCommon.Address, code []byte)

SetCode sets the code for the given address

func (*StateDB) SetNonce

func (db *StateDB) SetNonce(addr gethCommon.Address, nonce uint64)

SetNonce sets the nonce value for the given address

func (*StateDB) SetState

func (db *StateDB) SetState(addr gethCommon.Address, key gethCommon.Hash, value gethCommon.Hash)

SetState sets a value for the given storage slot

func (*StateDB) SetTransientState

func (db *StateDB) SetTransientState(addr gethCommon.Address, key, value gethCommon.Hash)

SetTransientState sets a value for the given key of the transient storage

func (*StateDB) SlotInAccessList

func (db *StateDB) SlotInAccessList(addr gethCommon.Address, key gethCommon.Hash) (addressOk bool, slotOk bool)

SlotInAccessList checks if the given (address,slot) is in the access list

func (*StateDB) Snapshot

func (db *StateDB) Snapshot() int

Snapshot takes an snapshot of the state and returns an int that can be used later for revert calls.

func (*StateDB) SubBalance

func (db *StateDB) SubBalance(addr gethCommon.Address, amount *big.Int)

SubBalance substitutes the amount from the balance of the given address

func (*StateDB) SubRefund

func (db *StateDB) SubRefund(amount uint64)

SubRefund subtracts the amount from the total (gas) refund

Jump to

Keyboard shortcuts

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