state

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommitStateDB

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

CommitStateDB implements the Geth state.StateDB interface. Instead of using a trie and database for querying and persistence, the Keeper uses KVStores and an account mapper is used to facilitate state transitions.

TODO: This implementation is subject to change in regards to its statefull manner. In otherwords, how this relates to the keeper in this module.

func NewCommitStateDB

func NewCommitStateDB(ctx sdk.Context, ak *auth.AccountKeeper, storageKey, codeKey sdk.StoreKey) (*CommitStateDB, error)

NewCommitStateDB returns a reference to a newly initialized CommitStateDB which implements Geth's state.StateDB interface.

CONTRACT: Stores used for state must be cache-wrapped as the ordering of the key/value space matters in determining the merkle root.

func (*CommitStateDB) AddBalance

func (csdb *CommitStateDB) AddBalance(addr ethcmn.Address, amount *big.Int)

AddBalance adds amount to the account associated with addr.

func (*CommitStateDB) AddLog

func (csdb *CommitStateDB) AddLog(log *ethtypes.Log)

AddLog adds a new log to the state and sets the log metadata from the state.

func (*CommitStateDB) AddPreimage

func (csdb *CommitStateDB) AddPreimage(hash ethcmn.Hash, preimage []byte)

AddPreimage records a SHA3 preimage seen by the VM.

func (*CommitStateDB) AddRefund

func (csdb *CommitStateDB) AddRefund(gas uint64)

AddRefund adds gas to the refund counter.

func (*CommitStateDB) Commit

func (csdb *CommitStateDB) Commit(deleteEmptyObjects bool) (root ethcmn.Hash, err error)

Commit writes the state to the appropriate KVStores. For each state object in the cache, it will either be removed, or have it's code set and/or it's state (storage) updated. In addition, the state object (account) itself will be written. Finally, the root hash (version) will be returned.

func (*CommitStateDB) Copy

func (csdb *CommitStateDB) Copy() *CommitStateDB

Copy creates a deep, independent copy of the state.

NOTE: Snapshots of the copied state cannot be applied to the copy.

func (*CommitStateDB) CreateAccount

func (csdb *CommitStateDB) CreateAccount(addr ethcmn.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 (*CommitStateDB) Database

func (csdb *CommitStateDB) Database() ethstate.Database

Database retrieves the low level database supporting the lower level trie ops. It is not used in Ethermint, so it returns nil.

func (*CommitStateDB) Empty

func (csdb *CommitStateDB) Empty(addr ethcmn.Address) bool

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

func (*CommitStateDB) Error

func (csdb *CommitStateDB) Error() error

Error returns the first non-nil error the StateDB encountered.

func (*CommitStateDB) Exist

func (csdb *CommitStateDB) Exist(addr ethcmn.Address) bool

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

func (*CommitStateDB) Finalize

func (csdb *CommitStateDB) Finalize(deleteEmptyObjects bool)

Finalize finalizes the state objects (accounts) state by setting their state, removing the csdb destructed objects and clearing the journal as well as the refunds.

func (*CommitStateDB) ForEachStorage

func (csdb *CommitStateDB) ForEachStorage(addr ethcmn.Address, cb func(key, value ethcmn.Hash) bool)

ForEachStorage iterates over each storage items, all invokes the provided callback on each key, value pair .

func (*CommitStateDB) GetBalance

func (csdb *CommitStateDB) GetBalance(addr ethcmn.Address) *big.Int

GetBalance retrieves the balance from the given address or 0 if object not found.

func (*CommitStateDB) GetCode

func (csdb *CommitStateDB) GetCode(addr ethcmn.Address) []byte

GetCode returns the code for a given account.

func (*CommitStateDB) GetCodeHash

func (csdb *CommitStateDB) GetCodeHash(addr ethcmn.Address) ethcmn.Hash

GetCodeHash returns the code hash for a given account.

func (*CommitStateDB) GetCodeSize

func (csdb *CommitStateDB) GetCodeSize(addr ethcmn.Address) int

GetCodeSize returns the code size for a given account.

func (*CommitStateDB) GetCommittedState

func (csdb *CommitStateDB) GetCommittedState(addr ethcmn.Address, hash ethcmn.Hash) ethcmn.Hash

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

func (*CommitStateDB) GetLogs

func (csdb *CommitStateDB) GetLogs(hash ethcmn.Hash) []*ethtypes.Log

GetLogs returns the current logs for a given hash in the state.

func (*CommitStateDB) GetNonce

func (csdb *CommitStateDB) GetNonce(addr ethcmn.Address) uint64

GetNonce returns the nonce (sequence number) for a given account.

func (*CommitStateDB) GetOrNewStateObject

func (csdb *CommitStateDB) GetOrNewStateObject(addr ethcmn.Address) (stateObject *stateObject)

GetOrNewStateObject retrieves a state object or create a new state object if nil.

func (*CommitStateDB) GetRefund

func (csdb *CommitStateDB) GetRefund() uint64

GetRefund returns the current value of the refund counter.

func (*CommitStateDB) GetState

func (csdb *CommitStateDB) GetState(addr ethcmn.Address, hash ethcmn.Hash) ethcmn.Hash

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

func (*CommitStateDB) HasSuicided

func (csdb *CommitStateDB) HasSuicided(addr ethcmn.Address) bool

HasSuicided returns if the given account for the specified address has been killed.

func (*CommitStateDB) IntermediateRoot

func (csdb *CommitStateDB) IntermediateRoot(deleteEmptyObjects bool) ethcmn.Hash

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

NOTE: The SDK has not concept or method of getting any intermediate merkle root as commitment of the merkle-ized tree doesn't happen until the BaseApps' EndBlocker.

func (*CommitStateDB) Logs

func (csdb *CommitStateDB) Logs() []*ethtypes.Log

Logs returns all the current logs in the state.

func (*CommitStateDB) Preimages

func (csdb *CommitStateDB) Preimages() map[ethcmn.Hash][]byte

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

func (*CommitStateDB) Prepare

func (csdb *CommitStateDB) Prepare(thash, bhash ethcmn.Hash, txi int)

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

func (*CommitStateDB) Reset

func (csdb *CommitStateDB) Reset(root ethcmn.Hash) error

Reset clears out all ephemeral state objects from the state db, but keeps the underlying account mapper and store keys to avoid reloading data for the next operations.

func (*CommitStateDB) RevertToSnapshot

func (csdb *CommitStateDB) RevertToSnapshot(revID int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*CommitStateDB) SetBalance

func (csdb *CommitStateDB) SetBalance(addr ethcmn.Address, amount *big.Int)

SetBalance sets the balance of an account.

func (*CommitStateDB) SetCode

func (csdb *CommitStateDB) SetCode(addr ethcmn.Address, code []byte)

SetCode sets the code for a given account.

func (*CommitStateDB) SetNonce

func (csdb *CommitStateDB) SetNonce(addr ethcmn.Address, nonce uint64)

SetNonce sets the nonce (sequence number) of an account.

func (*CommitStateDB) SetState

func (csdb *CommitStateDB) SetState(addr ethcmn.Address, key, value ethcmn.Hash)

SetState sets the storage state with a key, value pair for an account.

func (*CommitStateDB) Snapshot

func (csdb *CommitStateDB) Snapshot() int

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

func (*CommitStateDB) StorageTrie

func (csdb *CommitStateDB) StorageTrie(addr ethcmn.Address) ethstate.Trie

StorageTrie returns nil as the state in Ethermint does not use a direct storage trie.

func (*CommitStateDB) SubBalance

func (csdb *CommitStateDB) SubBalance(addr ethcmn.Address, amount *big.Int)

SubBalance subtracts amount from the account associated with addr.

func (*CommitStateDB) SubRefund

func (csdb *CommitStateDB) SubRefund(gas uint64)

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

func (*CommitStateDB) Suicide

func (csdb *CommitStateDB) Suicide(addr ethcmn.Address) bool

Suicide marks the given account as suicided and 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.

Jump to

Keyboard shortcuts

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