ethStatedb

package
v0.0.0-...-5fb9e85 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package ethStatedb

@author: xwc1125

Package ethStatedb

@author: xwc1125

Package ethStatedb

@author: xwc1125

Package ethStatedb

@author: xwc1125

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDatabase

func NewDatabase(db kvstore.Database) basedb.Database

func NewDatabaseWithCache

func NewDatabaseWithCache(db kvstore.Database, cache int) basedb.Database

NewDatabaseWithCache creates a backing store for state. The returned database is safe for concurrent use and retains a lot of collapsed RLP trie nodes in a large memory cache.

func NewStateSync

func NewStateSync(root types.Hash, database kvstore.KeyValueReader, bloom *tree.SyncBloom) *tree.Sync

NewStateSync create a new state trie download scheduler.

Types

type StateDB

type StateDB struct {

	// Measurements gathered during execution for debugging purposes
	AccountReads   time.Duration
	AccountHashes  time.Duration
	AccountUpdates time.Duration
	AccountCommits time.Duration
	StorageReads   time.Duration
	StorageHashes  time.Duration
	StorageUpdates time.Duration
	StorageCommits time.Duration
	// contains filtered or unexported fields
}

StateDBs within the ethereum protocol are used to store anything within the merkle trie. StateDBs take care of caching and storing nested states. It's the general query interface to retrieve: * Contracts * Accounts

func New

func New(root types.Hash, db basedb.Database) (*StateDB, error)

Create a new state from a given trie.

func (*StateDB) AddBalance

func (s *StateDB) AddBalance(addr types.Address, amount *big.Int)

AddBalance adds amount to the account associated with addr.

func (*StateDB) AddKV

func (s *StateDB) AddKV(addr types.Address, namespace string, key string, val interface{}) error

func (*StateDB) AddLog

func (s *StateDB) AddLog(logger *statetype.Log)

func (*StateDB) AddPreimage

func (s *StateDB) AddPreimage(hash types.Hash, preimage []byte)

AddPreimage records a SHA3 preimage seen by the VM.

func (*StateDB) AddRefund

func (s *StateDB) AddRefund(gas uint64)

AddRefund adds gas to the refund counter

func (*StateDB) BlockHash

func (s *StateDB) BlockHash() types.Hash

BlockHash returns the current block hash set by Prepare.

func (*StateDB) Commit

func (s *StateDB) Commit(deleteEmptyObjects bool) (types.Hash, error)

Commit writes the state to the underlying in-memory trie database.

func (*StateDB) Copy

func (s *StateDB) Copy() *StateDB

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

func (*StateDB) CreateAccount

func (s *StateDB) CreateAccount(addr types.Address)

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 (*StateDB) Database

func (s *StateDB) Database() basedb.Database

Database retrieves the low level database supporting the lower level trie ops.

func (*StateDB) Empty

func (s *StateDB) Empty(addr types.Address) bool

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

func (*StateDB) Error

func (s *StateDB) Error() error

func (*StateDB) Exist

func (s *StateDB) Exist(addr types.Address) bool

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

func (*StateDB) Finalise

func (s *StateDB) Finalise(deleteEmptyObjects bool)

Finalise finalises the state by removing the s destructed objects and clears the journal as well as the refunds. Finalise, however, will not push any updates into the tries just yet. Only IntermediateRoot or Commit will do that.

func (*StateDB) ForEachStorage

func (db *StateDB) ForEachStorage(addr types.Address, cb func(key, value types.Hash) bool) error

func (*StateDB) GetBalance

func (s *StateDB) GetBalance(addr types.Address) *big.Int

Retrieve the balance from the given address or 0 if object not found

func (*StateDB) GetCode

func (s *StateDB) GetCode(addr types.Address) []byte

func (*StateDB) GetCodeHash

func (s *StateDB) GetCodeHash(addr types.Address) types.Hash

func (*StateDB) GetCodeSize

func (s *StateDB) GetCodeSize(addr types.Address) int

func (*StateDB) GetCommittedState

func (s *StateDB) GetCommittedState(addr types.Address, hash types.Hash) types.Hash

GetCommittedState retrieves a value from the given account's committed storage trie.

func (*StateDB) GetKV

func (s *StateDB) GetKV(addr types.Address, namespace string, key string) (interface{}, error)

func (*StateDB) GetKVNP

func (s *StateDB) GetKVNP(addr types.Address, namespace string) (*linkedHashMap.LinkedHashMap, error)

func (*StateDB) GetKVS

func (s *StateDB) GetKVS(addr types.Address) *linkedHashMap.LinkedHashMap

kvs

func (*StateDB) GetLogs

func (s *StateDB) GetLogs(hash types.Hash) []*statetype.Log

func (*StateDB) GetNonce

func (s *StateDB) GetNonce(addr types.Address) uint64

func (*StateDB) GetOrNewStateObject

func (s *StateDB) GetOrNewStateObject(addr types.Address) *stateObject

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

func (*StateDB) GetProof

func (s *StateDB) GetProof(a types.Address) ([][]byte, error)

GetProof returns the MerkleProof for a given AccountName

func (*StateDB) GetRefund

func (s *StateDB) GetRefund() uint64

GetRefund returns the current value of the refund counter.

func (*StateDB) GetState

func (s *StateDB) GetState(addr types.Address, hash types.Hash) types.Hash

GetState retrieves a value from the given account's storage trie.

func (*StateDB) GetStorageProof

func (s *StateDB) GetStorageProof(a types.Address, key types.Hash) ([][]byte, error)

GetProof returns the StorageProof for given key

func (*StateDB) HasSuicided

func (s *StateDB) HasSuicided(addr types.Address) bool

func (*StateDB) IntermediateRoot

func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) types.Hash

IntermediateRoot computes the current root hash of the state trie. It is called in between transactions to get the root hash that goes into transaction receipts.

func (*StateDB) KVExist

func (s *StateDB) KVExist(addr types.Address, namespace string, key string) bool

func (*StateDB) Logs

func (s *StateDB) Logs() []*statetype.Log

func (*StateDB) Preimages

func (s *StateDB) Preimages() map[types.Hash][]byte

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

func (*StateDB) Prepare

func (s *StateDB) Prepare(thash, bhash types.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 (*StateDB) Reset

func (s *StateDB) Reset(root types.Hash) 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 (*StateDB) RevertToSnapshot

func (s *StateDB) RevertToSnapshot(revid int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*StateDB) SetBalance

func (s *StateDB) SetBalance(addr types.Address, amount *big.Int)

func (*StateDB) SetCode

func (s *StateDB) SetCode(addr types.Address, code []byte)

func (*StateDB) SetNonce

func (s *StateDB) SetNonce(addr types.Address, nonce uint64)

func (*StateDB) SetState

func (s *StateDB) SetState(addr types.Address, key, value types.Hash)

func (*StateDB) Snapshot

func (s *StateDB) Snapshot() int

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

func (*StateDB) StorageTree

func (s *StateDB) StorageTree(addr types.Address) basedb.Tree

StorageTrie returns the storage trie of an account. The return value is a copy and is nil for non-existent accounts.

func (*StateDB) SubBalance

func (s *StateDB) SubBalance(addr types.Address, amount *big.Int)

SubBalance subtracts amount from the account associated with addr.

func (*StateDB) SubRefund

func (s *StateDB) SubRefund(gas uint64)

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

func (*StateDB) Suicide

func (s *StateDB) Suicide(addr types.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 (*StateDB) TxIndex

func (s *StateDB) TxIndex() int

TxIndex returns the current transaction index set by Prepare.

Directories

Path Synopsis
Package model @author: xwc1125 Package model @author: xwc1125 Package model @author: xwc1125
Package model @author: xwc1125 Package model @author: xwc1125 Package model @author: xwc1125

Jump to

Keyboard shortcuts

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