Documentation
¶
Overview ¶
Package state provides a caching layer atop the Ethereum state trie.
Index ¶
- func NormalizeCoinID(coinID *common.Hash)
- func NormalizeStateKey(key *common.Hash)
- func WithConcurrentWorkers(prefetchers int) ethstate.PrefetcherOption
- type Database
- type Dump
- type DumpAccount
- type DumpCollector
- type DumpConfig
- type StateDB
- func (s *StateDB) AddBalanceMultiCoin(addr common.Address, coinID common.Hash, amount *big.Int)
- func (s *StateDB) Copy() *StateDB
- func (s *StateDB) GetBalanceMultiCoin(addr common.Address, coinID common.Hash) *big.Int
- func (s *StateDB) GetState(addr common.Address, hash common.Hash) common.Hash
- func (s *StateDB) GetTxHash() common.Hash
- func (s *StateDB) SetState(addr common.Address, key, value common.Hash)
- func (s *StateDB) SetTxContext(thash common.Hash, ti int)
- func (s *StateDB) SubBalanceMultiCoin(addr common.Address, coinID common.Hash, amount *big.Int)
- type Trie
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizeCoinID ¶
NormalizeCoinID ORs the 0th bit of the first byte in [coinID], which ensures this bit will be 1 and all other bits are left the same. This partitions multicoin storage from normal state storage.
func NormalizeStateKey ¶
NormalizeStateKey ANDs the 0th bit of the first byte in [key], which ensures this bit will be 0 and all other bits are left the same. This partitions normal state storage from multicoin storage.
func WithConcurrentWorkers ¶
func WithConcurrentWorkers(prefetchers int) ethstate.PrefetcherOption
Types ¶
type Database ¶
type Database interface { // OpenTrie opens the main account trie. OpenTrie(root common.Hash) (Trie, error) // OpenStorageTrie opens the storage trie of an account. OpenStorageTrie(stateRoot common.Hash, address common.Address, root common.Hash, trie Trie) (Trie, error) // CopyTrie returns an independent copy of the given trie. CopyTrie(Trie) Trie // ContractCode retrieves a particular contract's code. ContractCode(addr common.Address, codeHash common.Hash) ([]byte, error) // ContractCodeSize retrieves a particular contracts code's size. ContractCodeSize(addr common.Address, codeHash common.Hash) (int, error) // DiskDB returns the underlying key-value disk database. DiskDB() ethdb.KeyValueStore // TrieDB returns the underlying trie database for managing trie nodes. TrieDB() *triedb.Database }
Database wraps access to tries and contract code.
func NewDatabase ¶
NewDatabase creates a backing store for state. The returned database is safe for concurrent use, but does not retain any recent trie nodes in memory. To keep some historical state in memory, use the NewDatabaseWithConfig constructor.
func NewDatabaseWithConfig ¶ added in v0.5.0
NewDatabaseWithConfig 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.
type DumpAccount ¶
type DumpAccount = ethstate.DumpAccount
type DumpCollector ¶ added in v0.3.1
type DumpCollector = ethstate.DumpCollector
type DumpConfig ¶ added in v0.6.0
type DumpConfig = ethstate.DumpConfig
type StateDB ¶
StateDB structs 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
Once the state is committed, tries cached in stateDB (including account trie, storage tries) will no longer be functional. A new state instance must be created with new root and updated database for accessing post- commit states.
func (*StateDB) AddBalanceMultiCoin ¶
AddBalance adds amount to the account associated with addr.
func (*StateDB) GetBalanceMultiCoin ¶
Retrieve the balance from the given address or 0 if object not found
func (*StateDB) GetTxHash ¶ added in v0.12.10
GetTxHash returns the current tx hash on the StateDB set by SetTxContext.
func (*StateDB) SetTxContext ¶ added in v0.12.3
SetTxContext sets the current transaction hash and index which are used when the EVM emits new state logs. It should be invoked before transaction execution.