state

package
v0.14.1-libevm.rc.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2025 License: GPL-3.0, LGPL-3.0 Imports: 16 Imported by: 35

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeCoinID

func NormalizeCoinID(coinID *common.Hash)

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

func NormalizeStateKey(key *common.Hash)

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

func NewDatabase(db ethdb.Database) Database

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

func NewDatabaseWithConfig(db ethdb.Database, config *triedb.Config) Database

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.

func NewDatabaseWithNodeDB added in v0.12.3

func NewDatabaseWithNodeDB(db ethdb.Database, triedb *triedb.Database) Database

NewDatabaseWithNodeDB creates a state database with an already initialized node database.

type Dump

type Dump = ethstate.Dump

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

type StateDB struct {
	*ethstate.StateDB
	// contains filtered or unexported fields
}

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 New

func New(root common.Hash, db Database, snaps ethstate.SnapshotTree) (*StateDB, error)

New creates a new state from a given trie.

func (*StateDB) AddBalanceMultiCoin

func (s *StateDB) AddBalanceMultiCoin(addr common.Address, coinID common.Hash, amount *big.Int)

AddBalance adds amount to the account associated with addr.

func (*StateDB) Copy

func (s *StateDB) Copy() *StateDB

func (*StateDB) GetBalanceMultiCoin

func (s *StateDB) GetBalanceMultiCoin(addr common.Address, coinID common.Hash) *big.Int

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

func (*StateDB) GetState

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

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

func (*StateDB) GetTxHash added in v0.12.10

func (s *StateDB) GetTxHash() common.Hash

GetTxHash returns the current tx hash on the StateDB set by SetTxContext.

func (*StateDB) SetState

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

func (*StateDB) SetTxContext added in v0.12.3

func (s *StateDB) SetTxContext(thash common.Hash, ti int)

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.

func (*StateDB) SubBalanceMultiCoin

func (s *StateDB) SubBalanceMultiCoin(addr common.Address, coinID common.Hash, amount *big.Int)

SubBalance subtracts amount from the account associated with addr.

type Trie

type Trie = ethstate.Trie

Trie is a Ethereum Merkle Patricia trie.

Directories

Path Synopsis
Package snapshot implements a journalled, dynamic state dump.
Package snapshot implements a journalled, dynamic state dump.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳