state

package
v0.0.0-...-140c642 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2021 License: GPL-3.0 Imports: 35 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 MaxChangesetsSearch = 256

MaxChangesetsSearch -

Variables

View Source
var MaxTrieCacheSize = uint64(1024 * 1024)

MaxTrieCacheSize is the trie cache size limit after which to evict trie nodes from memory.

Functions

func FindByHistory

func FindByHistory(tx ethdb.Tx, storage bool, key []byte, timestamp uint64) ([]byte, error)

func GetAsOf

func GetAsOf(tx ethdb.Tx, storage bool, key []byte, timestamp uint64) ([]byte, error)

func WalkAsOfAccounts

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

func WalkAsOfStorage

func WalkAsOfStorage(tx ethdb.Tx, address common.Address, incarnation uint64, startLocation common.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 Buffer

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

Buffer is a structure holding updates, deletes, and reads registered within one change period A change period can be transaction within a block, or a block within group of blocks

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 common.Address, incarnation uint64, codeHash common.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 common.Address, incarnation uint64, codeHash common.Hash) (int, error)

func (*CachedReader) ReadAccountData

func (cr *CachedReader) ReadAccountData(address common.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 common.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 common.Address, incarnation uint64, key *common.Hash) ([]byte, error)

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

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 common.Address) error

func (*CachedWriter) DeleteAccount

func (cw *CachedWriter) DeleteAccount(ctx context.Context, address common.Address, original *accounts.Account) error

func (*CachedWriter) UpdateAccountCode

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

func (*CachedWriter) UpdateAccountData

func (cw *CachedWriter) UpdateAccountData(ctx context.Context, address common.Address, original, account *accounts.Account) error

func (*CachedWriter) WriteAccountStorage

func (cw *CachedWriter) WriteAccountStorage(ctx context.Context, address common.Address, incarnation uint64, key *common.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 ethdb.Database, blockNumber uint64) *ChangeSetWriter

func (*ChangeSetWriter) CreateContract

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

func (*ChangeSetWriter) DeleteAccount

func (w *ChangeSetWriter) DeleteAccount(ctx context.Context, address common.Address, original *accounts.Account) error

func (*ChangeSetWriter) GetAccountChanges

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

func (*ChangeSetWriter) GetStorageChanges

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

func (*ChangeSetWriter) PrintChangedAccounts

func (w *ChangeSetWriter) PrintChangedAccounts()

func (*ChangeSetWriter) UpdateAccountCode

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

func (*ChangeSetWriter) UpdateAccountData

func (w *ChangeSetWriter) UpdateAccountData(ctx context.Context, address common.Address, original, account *accounts.Account) error

func (*ChangeSetWriter) WriteAccountStorage

func (w *ChangeSetWriter) WriteAccountStorage(ctx context.Context, address common.Address, incarnation uint64, key *common.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 ethdb.Getter) *DbStateReader

func (*DbStateReader) ReadAccountCode

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

func (*DbStateReader) ReadAccountCodeSize

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

func (*DbStateReader) ReadAccountData

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

func (*DbStateReader) ReadAccountIncarnation

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

func (*DbStateReader) ReadAccountStorage

func (dbr *DbStateReader) ReadAccountStorage(address common.Address, incarnation uint64, key *common.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 ethdb.Database, blockNr uint64) *DbStateWriter

func (*DbStateWriter) ChangeSetWriter

func (dsw *DbStateWriter) ChangeSetWriter() *ChangeSetWriter

func (*DbStateWriter) CreateContract

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

func (*DbStateWriter) DeleteAccount

func (dsw *DbStateWriter) DeleteAccount(ctx context.Context, address common.Address, original *accounts.Account) error

func (*DbStateWriter) UpdateAccountCode

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

func (*DbStateWriter) UpdateAccountData

func (dsw *DbStateWriter) UpdateAccountData(ctx context.Context, address common.Address, original, account *accounts.Account) error

func (*DbStateWriter) WriteAccountStorage

func (dsw *DbStateWriter) WriteAccountStorage(ctx context.Context, address common.Address, incarnation uint64, key *common.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[common.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 common.Address, account DumpAccount)

OnAccount implements DumpCollector interface

func (*Dump) OnRoot

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

OnRoot implements DumpCollector interface

type DumpAccount

type DumpAccount struct {
	Balance   string            `json:"balance"`
	Nonce     uint64            `json:"nonce"`
	Root      string            `json:"root"`
	CodeHash  string            `json:"codeHash"`
	Code      string            `json:"code,omitempty"`
	Storage   map[string]string `json:"storage,omitempty"`
	Address   *common.Address   `json:"address,omitempty"` // Address only present in iterative (line-by-line) mode
	SecureKey hexutil.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(common.Hash)
	// OnAccount is called once for each account in the trie
	OnAccount(common.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 ethdb.Tx, blockNumber uint64) *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, excludeMissingPreimages 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 common.Address, maxResults int) (nextKey []byte, err error)

func (*Dumper) IterativeDump

func (d *Dumper) IterativeDump(excludeCode, excludeStorage, excludeMissingPreimages 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, excludeMissingPreimages bool, start common.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, excludeMissingPreimages bool) Dump

RawDump returns the entire state an a single large object

type IntraBlockState

type IntraBlockState struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

func New

func New(stateReader StateReader) *IntraBlockState

Create a new state from a given trie

func (*IntraBlockState) AddAddressToAccessList

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

AddAddressToAccessList adds the given address to the access list

func (*IntraBlockState) AddBalance

func (sdb *IntraBlockState) AddBalance(addr common.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(log *types.Log)

func (*IntraBlockState) AddPreimage

func (sdb *IntraBlockState) AddPreimage(hash common.Hash, preimage []byte)

AddPreimage records a SHA3 preimage seen by the VM.

func (*IntraBlockState) AddRefund

func (sdb *IntraBlockState) AddRefund(gas uint64)

AddRefund adds gas to the refund counter

func (*IntraBlockState) AddSlotToAccessList

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

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

func (*IntraBlockState) AddressInAccessList

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

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

func (*IntraBlockState) CommitBlock

func (sdb *IntraBlockState) CommitBlock(ctx context.Context, stateWriter StateWriter) error

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

func (*IntraBlockState) Copy

func (sdb *IntraBlockState) Copy() *IntraBlockState

Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.

func (*IntraBlockState) CreateAccount

func (sdb *IntraBlockState) CreateAccount(addr common.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 common.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 common.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(ctx context.Context, stateWriter StateWriter) error

FinalizeTx should be called after every transaction.

func (*IntraBlockState) GetBalance

func (sdb *IntraBlockState) GetBalance(addr common.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 common.Address) []byte

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

func (*IntraBlockState) GetCodeHash

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

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

func (*IntraBlockState) GetCodeSize

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

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

func (*IntraBlockState) GetCommittedState

func (sdb *IntraBlockState) GetCommittedState(addr common.Address, key *common.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 common.Address) uint64

func (*IntraBlockState) GetLogs

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

func (*IntraBlockState) GetNonce

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

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

func (*IntraBlockState) GetOrNewStateObject

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

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

func (*IntraBlockState) GetProof

func (sdb *IntraBlockState) GetProof(a common.Address) ([][]byte, error)

GetProof returns the Merkle proof for a given account

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 common.Address, key *common.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) GetStorageProof

func (sdb *IntraBlockState) GetStorageProof(a common.Address, key common.Hash) ([][]byte, error)

GetStorageProof returns the storage proof for a given key

func (*IntraBlockState) HasSuicided

func (sdb *IntraBlockState) HasSuicided(addr common.Address) bool

func (*IntraBlockState) Logs

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

func (*IntraBlockState) Preimages

func (sdb *IntraBlockState) Preimages() map[common.Hash][]byte

Preimages returns a list of SHA3 preimages that have been submitted.

func (*IntraBlockState) Prepare

func (sdb *IntraBlockState) Prepare(thash, bhash common.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 common.Address, dst *common.Address, precompiles []common.Address, list types.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) Reset

func (sdb *IntraBlockState) Reset() error

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) SetBalance

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

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

func (*IntraBlockState) SetCode

func (sdb *IntraBlockState) SetCode(addr common.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 common.Address, incarnation uint64)

SetIncarnation sets incarnation for account if account exists

func (*IntraBlockState) SetNonce

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

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

func (*IntraBlockState) SetState

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

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

func (*IntraBlockState) SetStorage

func (sdb *IntraBlockState) SetStorage(addr common.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) SetTracer

func (sdb *IntraBlockState) SetTracer(tracer StateTracer)

func (*IntraBlockState) SlotInAccessList

func (sdb *IntraBlockState) SlotInAccessList(addr common.Address, slot common.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) SubBalance

func (sdb *IntraBlockState) SubBalance(addr common.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) Suicide

func (sdb *IntraBlockState) Suicide(addr common.Address) bool

Suicide 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) 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[common.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 common.Address, account DumpAccount)

OnAccount implements DumpCollector interface

func (*IteratorDump) OnRoot

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

OnRoot implements DumpCollector interface

type NoopWriter

type NoopWriter struct {
}

func NewNoopWriter

func NewNoopWriter() *NoopWriter

func (*NoopWriter) CreateContract

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

func (*NoopWriter) DeleteAccount

func (nw *NoopWriter) DeleteAccount(_ context.Context, address common.Address, original *accounts.Account) error

func (*NoopWriter) UpdateAccountCode

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

func (*NoopWriter) UpdateAccountData

func (nw *NoopWriter) UpdateAccountData(_ context.Context, address common.Address, original, account *accounts.Account) error

func (*NoopWriter) WriteAccountStorage

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

func (*NoopWriter) WriteChangeSets

func (nw *NoopWriter) WriteChangeSets() error

func (*NoopWriter) WriteHistory

func (nw *NoopWriter) WriteHistory() error

type PlainDBState

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

Implements StateReader by wrapping database only, without trie

func NewPlainDBState

func NewPlainDBState(db ethdb.Database, blockNr uint64) *PlainDBState

func (*PlainDBState) CreateContract

func (dbs *PlainDBState) CreateContract(address common.Address) error

func (*PlainDBState) DeleteAccount

func (dbs *PlainDBState) DeleteAccount(_ context.Context, address common.Address, original *accounts.Account) error

func (*PlainDBState) ForEachStorage

func (dbs *PlainDBState) ForEachStorage(addr common.Address, startLocation common.Hash, cb func(key, seckey common.Hash, value uint256.Int) bool, maxResults int) error

func (*PlainDBState) GetBlockNr

func (dbs *PlainDBState) GetBlockNr() uint64

func (*PlainDBState) ReadAccountCode

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

func (*PlainDBState) ReadAccountCodeSize

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

func (*PlainDBState) ReadAccountData

func (dbs *PlainDBState) ReadAccountData(address common.Address) (*accounts.Account, error)

func (*PlainDBState) ReadAccountIncarnation

func (dbs *PlainDBState) ReadAccountIncarnation(address common.Address) (uint64, error)

func (*PlainDBState) ReadAccountStorage

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

func (*PlainDBState) SetBlockNr

func (dbs *PlainDBState) SetBlockNr(blockNr uint64)

func (*PlainDBState) UpdateAccountCode

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

func (*PlainDBState) UpdateAccountData

func (dbs *PlainDBState) UpdateAccountData(_ context.Context, address common.Address, original, account *accounts.Account) error

func (*PlainDBState) WriteAccountStorage

func (dbs *PlainDBState) WriteAccountStorage(_ context.Context, address common.Address, incarnation uint64, key *common.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 ethdb.Database) *PlainStateReader

func (*PlainStateReader) ReadAccountCode

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

func (*PlainStateReader) ReadAccountCodeSize

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

func (*PlainStateReader) ReadAccountData

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

func (*PlainStateReader) ReadAccountIncarnation

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

func (*PlainStateReader) ReadAccountStorage

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

type PlainStateWriter

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

func NewPlainStateWriter

func NewPlainStateWriter(db ethdb.Database, changeSetsDB ethdb.Database, blockNumber uint64) *PlainStateWriter

func (*PlainStateWriter) ChangeSetWriter

func (w *PlainStateWriter) ChangeSetWriter() *ChangeSetWriter

func (*PlainStateWriter) CreateContract

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

func (*PlainStateWriter) DeleteAccount

func (w *PlainStateWriter) DeleteAccount(ctx context.Context, address common.Address, original *accounts.Account) error

func (*PlainStateWriter) UpdateAccountCode

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

func (*PlainStateWriter) UpdateAccountData

func (w *PlainStateWriter) UpdateAccountData(ctx context.Context, address common.Address, original, account *accounts.Account) error

func (*PlainStateWriter) WriteAccountStorage

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

func (*PlainStateWriter) WriteChangeSets

func (w *PlainStateWriter) WriteChangeSets() error

func (*PlainStateWriter) WriteHistory

func (w *PlainStateWriter) WriteHistory() error

type PreimageWriter

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

func (*PreimageWriter) HashAddress

func (pw *PreimageWriter) HashAddress(address common.Address, save bool) (common.Hash, error)

func (*PreimageWriter) HashKey

func (pw *PreimageWriter) HashKey(key *common.Hash, save bool) (common.Hash, error)

func (*PreimageWriter) SetSavePreimages

func (pw *PreimageWriter) SetSavePreimages(save bool)

type StateReader

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

type StateTracer

type StateTracer interface {
	CaptureAccountRead(account common.Address) error
	CaptureAccountWrite(account common.Address) error
}

type StateWriter

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

type Stateless

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

Stateless is the inter-block cache for stateless client prototype, iteration 2 It creates the initial state trie during the construction, and then updates it during the execution of block(s)

func NewStateless

func NewStateless(stateRoot common.Hash, blockWitness *trie.Witness, blockNr uint64, trace bool, isBinary bool) (*Stateless, error)

NewStateless creates a new instance of Stateless It deserialises the block witness and creates the state trie out of it, checking that the root of the constructed state trie matches the value of `stateRoot` parameter

func (*Stateless) CheckRoot

func (s *Stateless) CheckRoot(expected common.Hash) error

CheckRoot finalises the execution of a block and computes the resulting state root

func (*Stateless) CreateContract

func (s *Stateless) CreateContract(address common.Address) error

CreateContract is a part of StateWriter interface This implementation registers given address in the internal map `created`

func (*Stateless) DeleteAccount

func (s *Stateless) DeleteAccount(_ context.Context, address common.Address, original *accounts.Account) error

DeleteAccount is a part of the StateWriter interface This implementation registers the deletion of the account in two internal maps

func (*Stateless) GetTrie

func (s *Stateless) GetTrie() *trie.Trie

func (*Stateless) ReadAccountCode

func (s *Stateless) ReadAccountCode(address common.Address, incarnation uint64, codeHash common.Hash) (code []byte, err error)

ReadAccountCode is a part of the StateReader interface

func (*Stateless) ReadAccountCodeSize

func (s *Stateless) ReadAccountCodeSize(address common.Address, incarnation uint64, codeHash common.Hash) (codeSize int, err error)

ReadAccountCodeSize is a part of the StateReader interface This implementation looks the code up in the codeMap, and returns its size It fails if the code is not found in the map

func (*Stateless) ReadAccountData

func (s *Stateless) ReadAccountData(address common.Address) (*accounts.Account, error)

ReadAccountData is a part of the StateReader interface This implementation attempts to look up account data in the state trie, and fails if it is not found

func (*Stateless) ReadAccountIncarnation

func (s *Stateless) ReadAccountIncarnation(address common.Address) (uint64, error)

func (*Stateless) ReadAccountStorage

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

ReadAccountStorage is a part of the StateReader interface This implementation attempts to look up the storage in the state trie, and fails if it is not found

func (*Stateless) SetBlockNr

func (s *Stateless) SetBlockNr(blockNr uint64)

SetBlockNr changes the block number associated with this

func (*Stateless) UpdateAccountCode

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

UpdateAccountCode is a part of the StateWriter interface This implementation adds the code to the codeMap to make it available for further accesses

func (*Stateless) UpdateAccountData

func (s *Stateless) UpdateAccountData(_ context.Context, address common.Address, original, account *accounts.Account) error

UpdateAccountData is a part of the StateWriter interface This implementation registers the account update in the `accountUpdates` map

func (*Stateless) WriteAccountStorage

func (s *Stateless) WriteAccountStorage(_ context.Context, address common.Address, incarnation uint64, key *common.Hash, original, value *uint256.Int) error

WriteAccountStorage is a part of the StateWriter interface This implementation registeres the change of the account's storage in the internal double map `storageUpdates`

type Storage

type Storage map[common.Hash]uint256.Int

func (Storage) Copy

func (s Storage) Copy() Storage

func (Storage) String

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

type TrieDbState

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

TrieDbState implements StateReader by wrapping a trie and a database, where trie acts as a cache for the database

func NewTrieDbState

func NewTrieDbState(root common.Hash, db ethdb.Database, blockNr uint64) *TrieDbState

func (*TrieDbState) CalcTrieRoots

func (tds *TrieDbState) CalcTrieRoots(trace bool) (common.Hash, error)

CalcTrieRoots calculates trie roots without modifying the state trie

func (*TrieDbState) ComputeTrieRoots

func (tds *TrieDbState) ComputeTrieRoots() ([]common.Hash, error)

ComputeTrieRoots is a combination of `ResolveStateTrie` and `UpdateStateTrie` DESCRIBED: docs/programmers_guide/guide.md#organising-ethereum-state-into-a-merkle-tree

func (*TrieDbState) Copy

func (tds *TrieDbState) Copy() *TrieDbState

func (*TrieDbState) Database

func (tds *TrieDbState) Database() ethdb.Database

func (*TrieDbState) DbStateWriter

func (tds *TrieDbState) DbStateWriter() *DbStateWriter

DbStateWriter creates a writer that is designed to write changes into the database batch

func (*TrieDbState) EnablePreimages

func (tds *TrieDbState) EnablePreimages(ep bool)

func (*TrieDbState) EvictTries

func (tds *TrieDbState) EvictTries(print bool)

func (*TrieDbState) ExtractTouches

func (tds *TrieDbState) ExtractTouches() (accountTouches [][]byte, storageTouches [][]byte)

ExtractTouches returns two lists of keys - for accounts and storage items correspondingly Each list is the collection of keys that have been "touched" (inserted, updated, or simply accessed) since the last invocation of `ExtractTouches`.

func (*TrieDbState) ExtractWitness

func (tds *TrieDbState) ExtractWitness(trace bool, isBinary bool) (*trie.Witness, error)

ExtractWitness produces block witness for the block just been processed, in a serialised form

func (*TrieDbState) ExtractWitnessForPrefix

func (tds *TrieDbState) ExtractWitnessForPrefix(prefix []byte, trace bool, isBinary bool) (*trie.Witness, error)

ExtractWitness produces block witness for the block just been processed, in a serialised form

func (*TrieDbState) GetAccount

func (tds *TrieDbState) GetAccount(addrHash common.Hash) (*accounts.Account, bool)

func (*TrieDbState) GetBlockNr

func (tds *TrieDbState) GetBlockNr() uint64

func (*TrieDbState) GetKey

func (tds *TrieDbState) GetKey(shaKey []byte) []byte

func (*TrieDbState) GetNodeByHash

func (tds *TrieDbState) GetNodeByHash(hash common.Hash) []byte

GetNodeByHash gets node's RLP by hash.

func (*TrieDbState) GetTrieHash

func (tds *TrieDbState) GetTrieHash() common.Hash

func (*TrieDbState) LastRoot

func (tds *TrieDbState) LastRoot() common.Hash

func (*TrieDbState) PlainStateWriter

func (tds *TrieDbState) PlainStateWriter() *PlainStateWriter

DbStateWriter creates a writer that is designed to write changes into the database batch

func (*TrieDbState) PrintTrie

func (tds *TrieDbState) PrintTrie(w io.Writer)

func (*TrieDbState) ReadAccountCode

func (tds *TrieDbState) ReadAccountCode(address common.Address, incarnation uint64, codeHash common.Hash) (code []byte, err error)

func (*TrieDbState) ReadAccountCodeSize

func (tds *TrieDbState) ReadAccountCodeSize(address common.Address, incarnation uint64, codeHash common.Hash) (codeSize int, err error)

func (*TrieDbState) ReadAccountData

func (tds *TrieDbState) ReadAccountData(address common.Address) (*accounts.Account, error)

func (*TrieDbState) ReadAccountIncarnation

func (tds *TrieDbState) ReadAccountIncarnation(address common.Address) (uint64, error)

func (*TrieDbState) ReadAccountStorage

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

func (*TrieDbState) ReadCodeByHash

func (tds *TrieDbState) ReadCodeByHash(codeHash common.Hash) (code []byte, err error)

func (*TrieDbState) ResolveStateTrie

func (tds *TrieDbState) ResolveStateTrie(extractWitnesses bool, trace bool) ([]*trie.Witness, error)

ResolveStateTrie resolves parts of the state trie that would be necessary for any updates (and reads, if `resolveReads` is set).

func (*TrieDbState) ResolveStateTrieStateless

func (tds *TrieDbState) ResolveStateTrieStateless(database trie.WitnessStorage) error

ResolveStateTrieStateless uses a witness DB to resolve subtries

func (*TrieDbState) SetBlockNr

func (tds *TrieDbState) SetBlockNr(blockNr uint64)

func (*TrieDbState) SetHistorical

func (tds *TrieDbState) SetHistorical(h bool)

func (*TrieDbState) SetNoHistory

func (tds *TrieDbState) SetNoHistory(nh bool)

func (*TrieDbState) SetResolveReads

func (tds *TrieDbState) SetResolveReads(rr bool)

func (*TrieDbState) StartNewBuffer

func (tds *TrieDbState) StartNewBuffer()

func (*TrieDbState) Trie

func (tds *TrieDbState) Trie() *trie.Trie

func (*TrieDbState) TriePruningDebugDump

func (tds *TrieDbState) TriePruningDebugDump() string

func (*TrieDbState) TrieStateWriter

func (tds *TrieDbState) TrieStateWriter() *TrieStateWriter

func (*TrieDbState) UnwindTo

func (tds *TrieDbState) UnwindTo(blockNr uint64) error

func (*TrieDbState) UpdateStateTrie

func (tds *TrieDbState) UpdateStateTrie() ([]common.Hash, error)

UpdateStateTrie assumes that the state trie is already fully resolved, i.e. any operations will find necessary data inside the trie.

func (*TrieDbState) WithNewBuffer

func (tds *TrieDbState) WithNewBuffer() *TrieDbState

type TrieStateWriter

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

func (*TrieStateWriter) CreateContract

func (tsw *TrieStateWriter) CreateContract(address common.Address) error

func (*TrieStateWriter) DeleteAccount

func (tsw *TrieStateWriter) DeleteAccount(_ context.Context, address common.Address, original *accounts.Account) error

func (*TrieStateWriter) UpdateAccountCode

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

func (*TrieStateWriter) UpdateAccountData

func (tsw *TrieStateWriter) UpdateAccountData(_ context.Context, address common.Address, original, account *accounts.Account) error

func (*TrieStateWriter) WriteAccountStorage

func (tsw *TrieStateWriter) WriteAccountStorage(_ context.Context, address common.Address, incarnation uint64, key *common.Hash, original, value *uint256.Int) 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