state

package
v0.0.0-...-92d349b Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: GPL-3.0 Imports: 52 Imported by: 0

Documentation

Overview

Package state provides a caching layer atop the Ethereum state trie.

Index

Constants

View Source
const (
	//FirstContractIncarnation - first incarnation for contract accounts. After 1 it increases by 1.
	FirstContractIncarnation = 1
	//NonContractIncarnation incarnation for non contracts
	NonContractIncarnation = 0
)
View Source
const CodeSizeTable = "CodeSize"
View Source
const StorageTable = "Storage"

Variables

View Source
var ExecTxsDone = metrics.NewCounter(`exec_txs_done`)
View Source
var SystemAddress = libcommon.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe")

SystemAddress - sender address for internal state updates.

Functions

func ReconnLess

func ReconnLess(i, thanItem reconPair) bool

func WalkAsOfAccounts

func WalkAsOfAccounts(tx kv.Tx, startAddress libcommon.Address, timestamp uint64, walker func(k []byte, v []byte) (bool, error)) error

func WalkAsOfStorage

func WalkAsOfStorage(tx kv.Tx, address libcommon.Address, incarnation uint64, startLocation libcommon.Hash, timestamp uint64, walker func(k1, k2, v []byte) (bool, error)) error

startKey is the concatenation of address and incarnation (BigEndian 8 byte)

Types

type BalanceIncrease

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

BalanceIncrease represents the increase of balance of an account that did not require reading the account first

type CachedReader

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

CachedReader is a wrapper for an instance of type StateReader This wrapper only makes calls to the underlying reader if the item is not in the cache

func NewCachedReader

func NewCachedReader(r StateReader, cache *shards.StateCache) *CachedReader

NewCachedReader wraps a given state reader into the cached reader

func (*CachedReader) ReadAccountCode

func (cr *CachedReader) ReadAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) ([]byte, error)

ReadAccountCode is called when code of an account needs to be fetched from the state Usually, one of (address;incarnation) or codeHash is enough to uniquely identify the code

func (*CachedReader) ReadAccountCodeSize

func (cr *CachedReader) ReadAccountCodeSize(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) (int, error)

func (*CachedReader) ReadAccountData

func (cr *CachedReader) ReadAccountData(address libcommon.Address) (*accounts.Account, error)

ReadAccountData is called when an account needs to be fetched from the state

func (*CachedReader) ReadAccountIncarnation

func (cr *CachedReader) ReadAccountIncarnation(address libcommon.Address) (uint64, error)

ReadAccountIncarnation is called when incarnation of the account is required (to create and recreate contract)

func (*CachedReader) ReadAccountStorage

func (cr *CachedReader) ReadAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash) ([]byte, error)

ReadAccountStorage is called when a storage item needs to be fetched from the state

type CachedReader2

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

CachedReader2 is a wrapper for an instance of type StateReader This wrapper only makes calls to the underlying reader if the item is not in the cache

func NewCachedReader2

func NewCachedReader2(cache kvcache.CacheView, tx kv.Tx) *CachedReader2

NewCachedReader2 wraps a given state reader into the cached reader

func (*CachedReader2) ReadAccountCode

func (r *CachedReader2) ReadAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) ([]byte, error)

func (*CachedReader2) ReadAccountCodeSize

func (r *CachedReader2) ReadAccountCodeSize(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) (int, error)

func (*CachedReader2) ReadAccountData

func (r *CachedReader2) ReadAccountData(address libcommon.Address) (*accounts.Account, error)

ReadAccountData is called when an account needs to be fetched from the state

func (*CachedReader2) ReadAccountIncarnation

func (r *CachedReader2) ReadAccountIncarnation(address libcommon.Address) (uint64, error)

func (*CachedReader2) ReadAccountStorage

func (r *CachedReader2) ReadAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash) ([]byte, error)

type CachedWriter

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

CachedWriter is a wrapper for an instance of type StateWriter

func NewCachedWriter

func NewCachedWriter(w WriterWithChangeSets, cache *shards.StateCache) *CachedWriter

NewCachedWriter wraps a given state writer into a cached writer

func (*CachedWriter) CreateContract

func (cw *CachedWriter) CreateContract(address libcommon.Address) error

func (*CachedWriter) DeleteAccount

func (cw *CachedWriter) DeleteAccount(address libcommon.Address, original *accounts.Account) error

func (*CachedWriter) UpdateAccountCode

func (cw *CachedWriter) UpdateAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash, code []byte) error

func (*CachedWriter) UpdateAccountData

func (cw *CachedWriter) UpdateAccountData(address libcommon.Address, original, account *accounts.Account) error

func (*CachedWriter) WriteAccountStorage

func (cw *CachedWriter) WriteAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash, original, value *uint256.Int) error

func (*CachedWriter) WriteChangeSets

func (cw *CachedWriter) WriteChangeSets() error

func (*CachedWriter) WriteHistory

func (cw *CachedWriter) WriteHistory() error

type ChangeSetWriter

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

ChangeSetWriter is a mock StateWriter that accumulates changes in-memory into ChangeSets.

func NewChangeSetWriter

func NewChangeSetWriter() *ChangeSetWriter

func NewChangeSetWriterPlain

func NewChangeSetWriterPlain(db kv.RwTx, blockNumber uint64) *ChangeSetWriter

func (*ChangeSetWriter) CreateContract

func (w *ChangeSetWriter) CreateContract(address libcommon.Address) error

func (*ChangeSetWriter) DeleteAccount

func (w *ChangeSetWriter) DeleteAccount(address libcommon.Address, original *accounts.Account) error

func (*ChangeSetWriter) GetAccountChanges

func (w *ChangeSetWriter) GetAccountChanges() (*historyv22.ChangeSet, error)

func (*ChangeSetWriter) GetStorageChanges

func (w *ChangeSetWriter) GetStorageChanges() (*historyv22.ChangeSet, error)

func (*ChangeSetWriter) PrintChangedAccounts

func (w *ChangeSetWriter) PrintChangedAccounts()

func (*ChangeSetWriter) UpdateAccountCode

func (w *ChangeSetWriter) UpdateAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash, code []byte) error

func (*ChangeSetWriter) UpdateAccountData

func (w *ChangeSetWriter) UpdateAccountData(address libcommon.Address, original, account *accounts.Account) error

func (*ChangeSetWriter) WriteAccountStorage

func (w *ChangeSetWriter) WriteAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash, original, value *uint256.Int) error

func (*ChangeSetWriter) WriteChangeSets

func (w *ChangeSetWriter) WriteChangeSets() error

func (*ChangeSetWriter) WriteHistory

func (w *ChangeSetWriter) WriteHistory() error

type Code

type Code []byte

func (Code) String

func (c Code) String() string

type DbStateReader

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

Implements StateReader by wrapping database only, without trie

func NewDbStateReader

func NewDbStateReader(db kv.Getter) *DbStateReader

func (*DbStateReader) ReadAccountCode

func (dbr *DbStateReader) ReadAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) ([]byte, error)

func (*DbStateReader) ReadAccountCodeSize

func (dbr *DbStateReader) ReadAccountCodeSize(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) (codeSize int, err error)

func (*DbStateReader) ReadAccountData

func (dbr *DbStateReader) ReadAccountData(address libcommon.Address) (*accounts.Account, error)

func (*DbStateReader) ReadAccountIncarnation

func (dbr *DbStateReader) ReadAccountIncarnation(address libcommon.Address) (uint64, error)

func (*DbStateReader) ReadAccountStorage

func (dbr *DbStateReader) ReadAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash) ([]byte, error)

func (*DbStateReader) SetAccountCache

func (dbr *DbStateReader) SetAccountCache(accountCache *fastcache.Cache)

func (*DbStateReader) SetCodeCache

func (dbr *DbStateReader) SetCodeCache(codeCache *fastcache.Cache)

func (*DbStateReader) SetCodeSizeCache

func (dbr *DbStateReader) SetCodeSizeCache(codeSizeCache *fastcache.Cache)

func (*DbStateReader) SetStorageCache

func (dbr *DbStateReader) SetStorageCache(storageCache *fastcache.Cache)

type DbStateWriter

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

func NewDbStateWriter

func NewDbStateWriter(db putDel, blockNr uint64) *DbStateWriter

func (*DbStateWriter) ChangeSetWriter

func (dsw *DbStateWriter) ChangeSetWriter() *ChangeSetWriter

func (*DbStateWriter) CreateContract

func (dsw *DbStateWriter) CreateContract(address libcommon.Address) error

func (*DbStateWriter) DeleteAccount

func (dsw *DbStateWriter) DeleteAccount(address libcommon.Address, original *accounts.Account) error

func (*DbStateWriter) UpdateAccountCode

func (dsw *DbStateWriter) UpdateAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash, code []byte) error

func (*DbStateWriter) UpdateAccountData

func (dsw *DbStateWriter) UpdateAccountData(address libcommon.Address, original, account *accounts.Account) error

func (*DbStateWriter) WriteAccountStorage

func (dsw *DbStateWriter) WriteAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash, original, value *uint256.Int) error

func (*DbStateWriter) WriteChangeSets

func (dsw *DbStateWriter) WriteChangeSets() error

WriteChangeSets causes accumulated change sets to be written into the database (or batch) associated with the `dsw`

func (*DbStateWriter) WriteHistory

func (dsw *DbStateWriter) WriteHistory() error

type Dump

type Dump struct {
	Root     string                            `json:"root"`
	Accounts map[libcommon.Address]DumpAccount `json:"accounts"`
}

Dump represents the full dump in a collected format, as one large map.

func (*Dump) OnAccount

func (d *Dump) OnAccount(addr libcommon.Address, account DumpAccount)

OnAccount implements DumpCollector interface

func (*Dump) OnRoot

func (d *Dump) OnRoot(root libcommon.Hash)

OnRoot implements DumpCollector interface

type DumpAccount

type DumpAccount struct {
	Balance   string             `json:"balance"`
	Nonce     uint64             `json:"nonce"`
	Root      hexutility.Bytes   `json:"root"`
	CodeHash  hexutility.Bytes   `json:"codeHash"`
	Code      hexutility.Bytes   `json:"code,omitempty"`
	Storage   map[string]string  `json:"storage,omitempty"`
	Address   *libcommon.Address `json:"address,omitempty"` // Address only present in iterative (line-by-line) mode
	SecureKey *hexutility.Bytes  `json:"key,omitempty"`     // If we don't have address, we can output the key
}

DumpAccount represents an account in the state.

type DumpCollector

type DumpCollector interface {
	// OnRoot is called with the state root
	OnRoot(libcommon.Hash)
	// OnAccount is called once for each account in the trie
	OnAccount(libcommon.Address, DumpAccount)
}

DumpCollector interface which the state trie calls during iteration

type Dumper

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

func NewDumper

func NewDumper(db kv.Tx, blockNumber uint64, historyV3 bool) *Dumper

func (*Dumper) DefaultDump

func (d *Dumper) DefaultDump() []byte

DefaultDump returns a JSON string representing the state with the default params

func (*Dumper) DefaultRawDump

func (d *Dumper) DefaultRawDump() Dump

func (*Dumper) Dump

func (d *Dumper) Dump(excludeCode, excludeStorage bool) []byte

Dump returns a JSON string representing the entire state as a single json-object

func (*Dumper) DumpToCollector

func (d *Dumper) DumpToCollector(c DumpCollector, excludeCode, excludeStorage bool, startAddress libcommon.Address, maxResults int) ([]byte, error)

func (*Dumper) IterativeDump

func (d *Dumper) IterativeDump(excludeCode, excludeStorage bool, output *json.Encoder)

IterativeDump dumps out accounts as json-objects, delimited by linebreaks on stdout

func (*Dumper) IteratorDump

func (d *Dumper) IteratorDump(excludeCode, excludeStorage bool, start libcommon.Address, maxResults int) (IteratorDump, error)

IteratorDump dumps out a batch of accounts starts with the given start key

func (*Dumper) RawDump

func (d *Dumper) RawDump(excludeCode, excludeStorage bool) Dump

RawDump returns the entire state an a single large object

type HistoryReaderInc

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

func NewHistoryReaderInc

func NewHistoryReaderInc(as *libstate.AggregatorStep, rs *ReconState) *HistoryReaderInc

func (*HistoryReaderInc) ReadAccountCode

func (hr *HistoryReaderInc) ReadAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) ([]byte, error)

func (*HistoryReaderInc) ReadAccountCodeSize

func (hr *HistoryReaderInc) ReadAccountCodeSize(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) (int, error)

func (*HistoryReaderInc) ReadAccountData

func (hr *HistoryReaderInc) ReadAccountData(address libcommon.Address) (*accounts.Account, error)

func (*HistoryReaderInc) ReadAccountIncarnation

func (hr *HistoryReaderInc) ReadAccountIncarnation(address libcommon.Address) (uint64, error)

func (*HistoryReaderInc) ReadAccountStorage

func (hr *HistoryReaderInc) ReadAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash) ([]byte, error)

func (*HistoryReaderInc) ReadError

func (hr *HistoryReaderInc) ReadError() (uint64, bool)

func (*HistoryReaderInc) ResetError

func (hr *HistoryReaderInc) ResetError()

func (*HistoryReaderInc) SetChainTx

func (hr *HistoryReaderInc) SetChainTx(chainTx kv.Tx)

func (*HistoryReaderInc) SetTrace

func (hr *HistoryReaderInc) SetTrace(trace bool)

func (*HistoryReaderInc) SetTx

func (hr *HistoryReaderInc) SetTx(tx kv.Tx)

func (*HistoryReaderInc) SetTxNum

func (hr *HistoryReaderInc) SetTxNum(txNum uint64)

type HistoryReaderV3

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

HistoryReaderV3 Implements StateReader and StateWriter

func NewHistoryReaderV3

func NewHistoryReaderV3() *HistoryReaderV3

func (*HistoryReaderV3) GetTxCount

func (hr *HistoryReaderV3) GetTxCount() (uint64, error)

func (*HistoryReaderV3) ReadAccountCode

func (hr *HistoryReaderV3) ReadAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) ([]byte, error)

func (*HistoryReaderV3) ReadAccountCodeSize

func (hr *HistoryReaderV3) ReadAccountCodeSize(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) (int, error)

func (*HistoryReaderV3) ReadAccountData

func (hr *HistoryReaderV3) ReadAccountData(address libcommon.Address) (*accounts.Account, error)

func (*HistoryReaderV3) ReadAccountIncarnation

func (hr *HistoryReaderV3) ReadAccountIncarnation(address libcommon.Address) (uint64, error)

func (*HistoryReaderV3) ReadAccountStorage

func (hr *HistoryReaderV3) ReadAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash) ([]byte, error)

func (*HistoryReaderV3) SetTrace

func (hr *HistoryReaderV3) SetTrace(trace bool)

func (*HistoryReaderV3) SetTx

func (hr *HistoryReaderV3) SetTx(tx kv.Tx)

func (*HistoryReaderV3) SetTxNum

func (hr *HistoryReaderV3) SetTxNum(txNum uint64)

type HistoryReaderV4

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

HistoryReaderV4 Implements StateReader and StateWriter

func (*HistoryReaderV4) FinishTx

func (hr *HistoryReaderV4) FinishTx() error

func (*HistoryReaderV4) ReadAccountCode

func (hr *HistoryReaderV4) ReadAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) ([]byte, error)

func (*HistoryReaderV4) ReadAccountCodeSize

func (hr *HistoryReaderV4) ReadAccountCodeSize(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) (int, error)

func (*HistoryReaderV4) ReadAccountData

func (hr *HistoryReaderV4) ReadAccountData(address libcommon.Address) (*accounts.Account, error)

func (*HistoryReaderV4) ReadAccountIncarnation

func (hr *HistoryReaderV4) ReadAccountIncarnation(address libcommon.Address) (uint64, error)

func (*HistoryReaderV4) ReadAccountStorage

func (hr *HistoryReaderV4) ReadAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash) ([]byte, error)

func (*HistoryReaderV4) SetRwTx

func (hr *HistoryReaderV4) SetRwTx(tx kv.RwTx)

func (*HistoryReaderV4) SetTrace

func (hr *HistoryReaderV4) SetTrace(trace bool)

func (*HistoryReaderV4) SetTx

func (hr *HistoryReaderV4) SetTx(tx kv.Tx)

func (*HistoryReaderV4) SetTxNum

func (hr *HistoryReaderV4) SetTxNum(txNum uint64)

type IntraBlockState

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

IntraBlockState is responsible for caching and managing state changes that occur during block's execution. NOT THREAD SAFE!

func New

func New(stateReader StateReader) *IntraBlockState

Create a new state from a given trie

func (*IntraBlockState) AddAddressToAccessList

func (sdb *IntraBlockState) AddAddressToAccessList(addr libcommon.Address)

AddAddressToAccessList adds the given address to the access list

func (*IntraBlockState) AddBalance

func (sdb *IntraBlockState) AddBalance(addr libcommon.Address, amount *uint256.Int)

AddBalance adds amount to the account associated with addr. DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account

func (*IntraBlockState) AddLog

func (sdb *IntraBlockState) AddLog(log2 *types.Log)

func (*IntraBlockState) AddRefund

func (sdb *IntraBlockState) AddRefund(gas uint64)

AddRefund adds gas to the refund counter

func (*IntraBlockState) AddSlotToAccessList

func (sdb *IntraBlockState) AddSlotToAccessList(addr libcommon.Address, slot libcommon.Hash)

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

func (*IntraBlockState) AddressInAccessList

func (sdb *IntraBlockState) AddressInAccessList(addr libcommon.Address) bool

AddressInAccessList returns true if the given address is in the access list.

func (*IntraBlockState) BalanceIncreaseSet

func (sdb *IntraBlockState) BalanceIncreaseSet() map[libcommon.Address]uint256.Int

func (*IntraBlockState) CommitBlock

func (sdb *IntraBlockState) CommitBlock(chainRules *chain.Rules, stateWriter StateWriter) error

CommitBlock finalizes the state by removing the self destructed objects and clears the journal as well as the refunds.

func (*IntraBlockState) CreateAccount

func (sdb *IntraBlockState) CreateAccount(addr libcommon.Address, contractCreation bool)

CreateAccount explicitly creates a state object. If a state object with the address already exists the balance is carried over to the new account.

CreateAccount is called during the EVM CREATE operation. The situation might arise that a contract does the following:

  1. sends funds to sha(account ++ (nonce + 1))
  2. tx_create(sha(account ++ nonce)) (note that this gets the address of 1)

Carrying over the balance ensures that Ether doesn't disappear.

func (*IntraBlockState) Empty

func (sdb *IntraBlockState) Empty(addr libcommon.Address) bool

Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0)

func (*IntraBlockState) Error

func (sdb *IntraBlockState) Error() error

func (*IntraBlockState) Exist

func (sdb *IntraBlockState) Exist(addr libcommon.Address) bool

Exist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.

func (*IntraBlockState) FinalizeTx

func (sdb *IntraBlockState) FinalizeTx(chainRules *chain.Rules, stateWriter StateWriter) error

FinalizeTx should be called after every transaction.

func (*IntraBlockState) GetBalance

func (sdb *IntraBlockState) GetBalance(addr libcommon.Address) *uint256.Int

GetBalance retrieves the balance from the given address or 0 if object not found DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account

func (*IntraBlockState) GetCode

func (sdb *IntraBlockState) GetCode(addr libcommon.Address) []byte

DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account

func (*IntraBlockState) GetCodeHash

func (sdb *IntraBlockState) GetCodeHash(addr libcommon.Address) libcommon.Hash

DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account

func (*IntraBlockState) GetCodeSize

func (sdb *IntraBlockState) GetCodeSize(addr libcommon.Address) int

DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account

func (*IntraBlockState) GetCommittedState

func (sdb *IntraBlockState) GetCommittedState(addr libcommon.Address, key *libcommon.Hash, value *uint256.Int)

GetCommittedState retrieves a value from the given account's committed storage trie. DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account

func (*IntraBlockState) GetIncarnation

func (sdb *IntraBlockState) GetIncarnation(addr libcommon.Address) uint64

func (*IntraBlockState) GetLogs

func (sdb *IntraBlockState) GetLogs(hash libcommon.Hash) []*types.Log

func (*IntraBlockState) GetNonce

func (sdb *IntraBlockState) GetNonce(addr libcommon.Address) uint64

DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account

func (*IntraBlockState) GetOrNewStateObject

func (sdb *IntraBlockState) GetOrNewStateObject(addr libcommon.Address) *stateObject

Retrieve a state object or create a new state object if nil.

func (*IntraBlockState) GetRefund

func (sdb *IntraBlockState) GetRefund() uint64

GetRefund returns the current value of the refund counter.

func (*IntraBlockState) GetState

func (sdb *IntraBlockState) GetState(addr libcommon.Address, key *libcommon.Hash, value *uint256.Int)

GetState retrieves a value from the given account's storage trie. DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account

func (*IntraBlockState) GetTxCount

func (sdb *IntraBlockState) GetTxCount() (uint64, error)

func (*IntraBlockState) HasSelfdestructed

func (sdb *IntraBlockState) HasSelfdestructed(addr libcommon.Address) bool

func (*IntraBlockState) Logs

func (sdb *IntraBlockState) Logs() []*types.Log

func (*IntraBlockState) MakeWriteSet

func (sdb *IntraBlockState) MakeWriteSet(chainRules *chain.Rules, stateWriter StateWriter) error

func (*IntraBlockState) Prepare

func (sdb *IntraBlockState) Prepare(thash, bhash libcommon.Hash, ti int)

Prepare sets the current transaction hash and index and block hash which is used when the EVM emits new state logs.

func (*IntraBlockState) PrepareAccessList

func (sdb *IntraBlockState) PrepareAccessList(sender libcommon.Address, dst *libcommon.Address, precompiles []libcommon.Address, list types2.AccessList)

PrepareAccessList handles the preparatory steps for executing a state transition with regards to both EIP-2929 and EIP-2930:

- Add sender to access list (2929) - Add destination to access list (2929) - Add precompiles to access list (2929) - Add the contents of the optional tx access list (2930)

This method should only be called if Yolov3/Berlin/2929+2930 is applicable at the current number.

func (*IntraBlockState) Print

func (sdb *IntraBlockState) Print(chainRules chain.Rules)

func (*IntraBlockState) Reset

func (sdb *IntraBlockState) Reset()

Reset clears out all ephemeral state objects from the state db, but keeps the underlying state trie to avoid reloading data for the next operations.

func (*IntraBlockState) RevertToSnapshot

func (sdb *IntraBlockState) RevertToSnapshot(revid int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*IntraBlockState) ScalableSetSmtRootHash

func (sdb *IntraBlockState) ScalableSetSmtRootHash(roHermezDb ReadOnlyHermezDb) error

func (*IntraBlockState) ScalableSetTxNum

func (sdb *IntraBlockState) ScalableSetTxNum()

func (*IntraBlockState) Selfdestruct

func (sdb *IntraBlockState) Selfdestruct(addr libcommon.Address) bool

Selfdestruct marks the given account as suicided. This clears the account balance.

The account's state object is still available until the state is committed, getStateObject will return a non-nil account after Suicide.

func (*IntraBlockState) SetBalance

func (sdb *IntraBlockState) SetBalance(addr libcommon.Address, amount *uint256.Int)

DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account

func (*IntraBlockState) SetCode

func (sdb *IntraBlockState) SetCode(addr libcommon.Address, code []byte)

DESCRIBED: docs/programmers_guide/guide.md#code-hash DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account

func (*IntraBlockState) SetIncarnation

func (sdb *IntraBlockState) SetIncarnation(addr libcommon.Address, incarnation uint64)

SetIncarnation sets incarnation for account if account exists

func (*IntraBlockState) SetNonce

func (sdb *IntraBlockState) SetNonce(addr libcommon.Address, nonce uint64)

DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account

func (*IntraBlockState) SetState

func (sdb *IntraBlockState) SetState(addr libcommon.Address, key *libcommon.Hash, value uint256.Int)

DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account

func (*IntraBlockState) SetStorage

func (sdb *IntraBlockState) SetStorage(addr libcommon.Address, storage Storage)

SetStorage replaces the entire storage for the specified account with given storage. This function should only be used for debugging.

func (*IntraBlockState) SetTrace

func (sdb *IntraBlockState) SetTrace(trace bool)

func (*IntraBlockState) SlotInAccessList

func (sdb *IntraBlockState) SlotInAccessList(addr libcommon.Address, slot libcommon.Hash) (addressPresent bool, slotPresent bool)

SlotInAccessList returns true if the given (address, slot)-tuple is in the access list.

func (*IntraBlockState) Snapshot

func (sdb *IntraBlockState) Snapshot() int

Snapshot returns an identifier for the current revision of the state.

func (*IntraBlockState) SoftFinalise

func (sdb *IntraBlockState) SoftFinalise()

func (*IntraBlockState) SubBalance

func (sdb *IntraBlockState) SubBalance(addr libcommon.Address, amount *uint256.Int)

SubBalance subtracts amount from the account associated with addr. DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account

func (*IntraBlockState) SubRefund

func (sdb *IntraBlockState) SubRefund(gas uint64)

SubRefund removes gas from the refund counter. This method will panic if the refund counter goes below zero

func (*IntraBlockState) TxIndex

func (sdb *IntraBlockState) TxIndex() int

TxIndex returns the current transaction index set by Prepare.

type IteratorDump

type IteratorDump struct {
	Root     string                            `json:"root"`
	Accounts map[libcommon.Address]DumpAccount `json:"accounts"`
	Next     []byte                            `json:"next,omitempty"` // nil if no more accounts
}

IteratorDump is an implementation for iterating over data.

func (*IteratorDump) OnAccount

func (d *IteratorDump) OnAccount(addr libcommon.Address, account DumpAccount)

OnAccount implements DumpCollector interface

func (*IteratorDump) OnRoot

func (d *IteratorDump) OnRoot(root libcommon.Hash)

OnRoot implements DumpCollector interface

type NoopWriter

type NoopWriter struct {
}

func NewNoopWriter

func NewNoopWriter() *NoopWriter

func (*NoopWriter) CreateContract

func (nw *NoopWriter) CreateContract(address libcommon.Address) error

func (*NoopWriter) DeleteAccount

func (nw *NoopWriter) DeleteAccount(address libcommon.Address, original *accounts.Account) error

func (*NoopWriter) UpdateAccountCode

func (nw *NoopWriter) UpdateAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash, code []byte) error

func (*NoopWriter) UpdateAccountData

func (nw *NoopWriter) UpdateAccountData(address libcommon.Address, original, account *accounts.Account) error

func (*NoopWriter) WriteAccountStorage

func (nw *NoopWriter) WriteAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash, original, value *uint256.Int) error

func (*NoopWriter) WriteChangeSets

func (nw *NoopWriter) WriteChangeSets() error

func (*NoopWriter) WriteHistory

func (nw *NoopWriter) WriteHistory() error

type PlainState

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

State at the beginning of blockNr

func NewPlainState

func NewPlainState(tx kv.Tx, blockNr uint64, systemContractLookup map[libcommon.Address][]libcommon.CodeRecord) *PlainState

func (*PlainState) CreateContract

func (s *PlainState) CreateContract(address libcommon.Address) error

func (*PlainState) DeleteAccount

func (s *PlainState) DeleteAccount(address libcommon.Address, original *accounts.Account) error

func (*PlainState) ForEachStorage

func (s *PlainState) ForEachStorage(addr libcommon.Address, startLocation libcommon.Hash, cb func(key, seckey libcommon.Hash, value uint256.Int) bool, maxResults int) error

func (*PlainState) GetBlockNr

func (s *PlainState) GetBlockNr() uint64

func (*PlainState) ReadAccountCode

func (s *PlainState) ReadAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) ([]byte, error)

func (*PlainState) ReadAccountCodeSize

func (s *PlainState) ReadAccountCodeSize(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) (int, error)

func (*PlainState) ReadAccountData

func (s *PlainState) ReadAccountData(address libcommon.Address) (*accounts.Account, error)

func (*PlainState) ReadAccountDataMaybeNil

func (s *PlainState) ReadAccountDataMaybeNil(address libcommon.Address) (*accounts.Account, error)

func (*PlainState) ReadAccountIncarnation

func (s *PlainState) ReadAccountIncarnation(address libcommon.Address) (uint64, error)

func (*PlainState) ReadAccountStorage

func (s *PlainState) ReadAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash) ([]byte, error)

func (*PlainState) SetBlockNr

func (s *PlainState) SetBlockNr(blockNr uint64)

func (*PlainState) SetTrace

func (s *PlainState) SetTrace(trace bool)

func (*PlainState) UpdateAccountCode

func (s *PlainState) UpdateAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash, code []byte) error

func (*PlainState) UpdateAccountData

func (s *PlainState) UpdateAccountData(address libcommon.Address, original, account *accounts.Account) error

func (*PlainState) WriteAccountStorage

func (s *PlainState) WriteAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash, original, value *uint256.Int) error

type PlainStateReader

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

PlainStateReader reads data from so called "plain state". Data in the plain state is stored using un-hashed account/storage items as opposed to the "normal" state that uses hashes of merkle paths to store items.

func NewPlainStateReader

func NewPlainStateReader(db kv.Getter) *PlainStateReader

func (*PlainStateReader) ForEach

func (r *PlainStateReader) ForEach(table string, fromPrefix []byte, walker func(k, v []byte) error) error

func (*PlainStateReader) GetTxCount

func (r *PlainStateReader) GetTxCount() (uint64, error)

func (*PlainStateReader) ReadAccountCode

func (r *PlainStateReader) ReadAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) ([]byte, error)

func (*PlainStateReader) ReadAccountCodeSize

func (r *PlainStateReader) ReadAccountCodeSize(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) (int, error)

func (*PlainStateReader) ReadAccountData

func (r *PlainStateReader) ReadAccountData(address libcommon.Address) (*accounts.Account, error)

func (*PlainStateReader) ReadAccountIncarnation

func (r *PlainStateReader) ReadAccountIncarnation(address libcommon.Address) (uint64, error)

func (*PlainStateReader) ReadAccountStorage

func (r *PlainStateReader) ReadAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash) ([]byte, error)

type PlainStateWriter

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

func NewPlainStateWriter

func NewPlainStateWriter(db putDel, changeSetsDB kv.RwTx, blockNumber uint64) *PlainStateWriter

func NewPlainStateWriterNoHistory

func NewPlainStateWriterNoHistory(db putDel) *PlainStateWriter

func (*PlainStateWriter) ChangeSetWriter

func (w *PlainStateWriter) ChangeSetWriter() *ChangeSetWriter

func (*PlainStateWriter) CreateContract

func (w *PlainStateWriter) CreateContract(address libcommon.Address) error

func (*PlainStateWriter) DeleteAccount

func (w *PlainStateWriter) DeleteAccount(address libcommon.Address, original *accounts.Account) error

func (*PlainStateWriter) SetAccumulator

func (w *PlainStateWriter) SetAccumulator(accumulator *shards.Accumulator) *PlainStateWriter

func (*PlainStateWriter) UpdateAccountCode

func (w *PlainStateWriter) UpdateAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash, code []byte) error

func (*PlainStateWriter) UpdateAccountData

func (w *PlainStateWriter) UpdateAccountData(address libcommon.Address, original, account *accounts.Account) error

func (*PlainStateWriter) WriteAccountStorage

func (w *PlainStateWriter) WriteAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash, original, value *uint256.Int) error

func (*PlainStateWriter) WriteChangeSets

func (w *PlainStateWriter) WriteChangeSets() error

func (*PlainStateWriter) WriteHistory

func (w *PlainStateWriter) WriteHistory() error

type ReadOnlyHermezDb

type ReadOnlyHermezDb interface {
	GetEffectiveGasPricePercentage(txHash libcommon.Hash) (uint8, error)
	GetStateRoot(l2BlockNo uint64) (libcommon.Hash, error)
}

type ReconState

type ReconState struct {
	*ReconnWork //has it's own mutex. allow avoid lock-contention between state.Get() and work.Done() methods
	// contains filtered or unexported fields
}

ReconState is the accumulator of changes to the state

func NewReconState

func NewReconState(workCh chan *exec22.TxTask) *ReconState

func (*ReconState) Delete

func (rs *ReconState) Delete(table string, key1, key2 []byte, txNum uint64)

func (*ReconState) Flush

func (rs *ReconState) Flush(rwTx kv.RwTx) error

func (*ReconState) Get

func (rs *ReconState) Get(table string, key1, key2 []byte, txNum uint64) []byte

func (*ReconState) Put

func (rs *ReconState) Put(table string, key1, key2, val []byte, txNum uint64)

func (*ReconState) RemoveAll

func (rs *ReconState) RemoveAll(table string, key1 []byte)

func (*ReconState) Reset

func (rs *ReconState) Reset(workCh chan *exec22.TxTask)

func (*ReconState) SizeEstimate

func (rs *ReconState) SizeEstimate() uint64

type ReconnWork

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

func (*ReconnWork) CommitTxNum

func (rs *ReconnWork) CommitTxNum(txNum uint64)

func (*ReconnWork) Done

func (rs *ReconnWork) Done(txNum uint64) bool

func (*ReconnWork) DoneCount

func (rs *ReconnWork) DoneCount() uint64

func (*ReconnWork) MaxTxNum

func (rs *ReconnWork) MaxTxNum() uint64

func (*ReconnWork) QueueLen

func (rs *ReconnWork) QueueLen() int

func (*ReconnWork) RollbackCount

func (rs *ReconnWork) RollbackCount() uint64

func (*ReconnWork) RollbackTx

func (rs *ReconnWork) RollbackTx(txTask *exec22.TxTask, dependency uint64)

func (*ReconnWork) Schedule

func (rs *ReconnWork) Schedule(ctx context.Context) (*exec22.TxTask, bool, error)

type RequiredStateError

type RequiredStateError struct {
	StateTxNum uint64
}

func (*RequiredStateError) Error

func (r *RequiredStateError) Error() string

type StateReader

type StateReader interface {
	ReadAccountData(address libcommon.Address) (*accounts.Account, error)
	ReadAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash) ([]byte, error)
	ReadAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) ([]byte, error)
	ReadAccountCodeSize(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash) (int, error)
	ReadAccountIncarnation(address libcommon.Address) (uint64, error)
}

type StateReaderIterator

type StateReaderIterator interface {
	StateReader
	ForEach(table string, fromPrefix []byte, walker func(k, v []byte) error) error
}

type StateReaderV3

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

func NewStateReaderV3

func NewStateReaderV3(rs *StateV3) *StateReaderV3

func (*StateReaderV3) DiscardReadList

func (r *StateReaderV3) DiscardReadList()

func (*StateReaderV3) ReadAccountCode

func (r *StateReaderV3) ReadAccountCode(address common.Address, incarnation uint64, codeHash common.Hash) ([]byte, error)

func (*StateReaderV3) ReadAccountCodeSize

func (r *StateReaderV3) ReadAccountCodeSize(address common.Address, incarnation uint64, codeHash common.Hash) (int, error)

func (*StateReaderV3) ReadAccountData

func (r *StateReaderV3) ReadAccountData(address common.Address) (*accounts.Account, error)

func (*StateReaderV3) ReadAccountIncarnation

func (r *StateReaderV3) ReadAccountIncarnation(address common.Address) (uint64, error)

func (*StateReaderV3) ReadAccountStorage

func (r *StateReaderV3) ReadAccountStorage(address common.Address, incarnation uint64, key *common.Hash) ([]byte, error)

func (*StateReaderV3) ReadSet

func (r *StateReaderV3) ReadSet() map[string]*exec22.KvList

func (*StateReaderV3) ResetReadSet

func (r *StateReaderV3) ResetReadSet()

func (*StateReaderV3) SetTrace

func (r *StateReaderV3) SetTrace(trace bool)

func (*StateReaderV3) SetTx

func (r *StateReaderV3) SetTx(tx kv.Tx)

func (*StateReaderV3) SetTxNum

func (r *StateReaderV3) SetTxNum(txNum uint64)

type StateReconWriterInc

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

func NewStateReconWriterInc

func NewStateReconWriterInc(as *libstate.AggregatorStep, rs *ReconState) *StateReconWriterInc

func (*StateReconWriterInc) CreateContract

func (w *StateReconWriterInc) CreateContract(address libcommon.Address) error

func (*StateReconWriterInc) DeleteAccount

func (w *StateReconWriterInc) DeleteAccount(address libcommon.Address, original *accounts.Account) error

func (*StateReconWriterInc) SetChainTx

func (w *StateReconWriterInc) SetChainTx(chainTx kv.Tx)

func (*StateReconWriterInc) SetTx

func (w *StateReconWriterInc) SetTx(tx kv.Tx)

func (*StateReconWriterInc) SetTxNum

func (w *StateReconWriterInc) SetTxNum(txNum uint64)

func (*StateReconWriterInc) UpdateAccountCode

func (w *StateReconWriterInc) UpdateAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash, code []byte) error

func (*StateReconWriterInc) UpdateAccountData

func (w *StateReconWriterInc) UpdateAccountData(address libcommon.Address, original, account *accounts.Account) error

func (*StateReconWriterInc) WriteAccountStorage

func (w *StateReconWriterInc) WriteAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash, original, value *uint256.Int) error

type StateV3

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

func NewStateV3

func NewStateV3(tmpdir string) *StateV3

func (*StateV3) AddWork

func (rs *StateV3) AddWork(ctx context.Context, txTask *exec22.TxTask, in *exec22.QueueWithRetry)

func (*StateV3) ApplyHistory

func (rs *StateV3) ApplyHistory(txTask *exec22.TxTask, agg *libstate.AggregatorV3) error

func (*StateV3) ApplyState

func (rs *StateV3) ApplyState(roTx kv.Tx, txTask *exec22.TxTask, agg *libstate.AggregatorV3) error

func (*StateV3) CommitTxNum

func (rs *StateV3) CommitTxNum(sender *common.Address, txNum uint64, in *exec22.QueueWithRetry) (count int)

func (*StateV3) DoneCount

func (rs *StateV3) DoneCount() uint64

func (*StateV3) Flush

func (rs *StateV3) Flush(ctx context.Context, rwTx kv.RwTx, logPrefix string, logEvery *time.Ticker) error

func (*StateV3) Get

func (rs *StateV3) Get(table string, key []byte) (v []byte, ok bool)

func (*StateV3) ReTry

func (rs *StateV3) ReTry(txTask *exec22.TxTask, in *exec22.QueueWithRetry)

func (*StateV3) ReadsValid

func (rs *StateV3) ReadsValid(readLists map[string]*exec22.KvList) bool

func (*StateV3) RegisterSender

func (rs *StateV3) RegisterSender(txTask *exec22.TxTask) bool

func (*StateV3) SizeEstimate

func (rs *StateV3) SizeEstimate() (r uint64)

func (*StateV3) Unwind

func (rs *StateV3) Unwind(ctx context.Context, tx kv.RwTx, txUnwindTo uint64, agg *libstate.AggregatorV3, accumulator *shards.Accumulator) error

type StateWriter

type StateWriter interface {
	UpdateAccountData(address libcommon.Address, original, account *accounts.Account) error
	UpdateAccountCode(address libcommon.Address, incarnation uint64, codeHash libcommon.Hash, code []byte) error
	DeleteAccount(address libcommon.Address, original *accounts.Account) error
	WriteAccountStorage(address libcommon.Address, incarnation uint64, key *libcommon.Hash, original, value *uint256.Int) error
	CreateContract(address libcommon.Address) error
}

type StateWriterV3

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

func NewStateWriterV3

func NewStateWriterV3(rs *StateV3) *StateWriterV3

func (*StateWriterV3) CreateContract

func (w *StateWriterV3) CreateContract(address common.Address) error

func (*StateWriterV3) DeleteAccount

func (w *StateWriterV3) DeleteAccount(address common.Address, original *accounts.Account) error

func (*StateWriterV3) PrevAndDels

func (w *StateWriterV3) PrevAndDels() (map[string][]byte, map[string]*accounts.Account, map[string][]byte, map[string]uint64)

func (*StateWriterV3) ResetWriteSet

func (w *StateWriterV3) ResetWriteSet()

func (*StateWriterV3) SetTxNum

func (w *StateWriterV3) SetTxNum(txNum uint64)

func (*StateWriterV3) UpdateAccountCode

func (w *StateWriterV3) UpdateAccountCode(address common.Address, incarnation uint64, codeHash common.Hash, code []byte) error

func (*StateWriterV3) UpdateAccountData

func (w *StateWriterV3) UpdateAccountData(address common.Address, original, account *accounts.Account) error

func (*StateWriterV3) WriteAccountStorage

func (w *StateWriterV3) WriteAccountStorage(address common.Address, incarnation uint64, key *common.Hash, original, value *uint256.Int) error

func (*StateWriterV3) WriteSet

func (w *StateWriterV3) WriteSet() map[string]*exec22.KvList

type Storage

type Storage map[libcommon.Hash]uint256.Int

func (Storage) Copy

func (s Storage) Copy() Storage

func (Storage) String

func (s Storage) String() (str string)

type TxCountReader

type TxCountReader interface {
	GetTxCount() (uint64, error)
}

type WriterWithChangeSets

type WriterWithChangeSets interface {
	StateWriter
	WriteChangeSets() error
	WriteHistory() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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