state

package
v0.0.0-...-ebde1c0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AccountsKey is the key used for storing Ethereum accounts in the Cosmos
	// SDK multi-store.
	AccountsKey = types.NewKVStoreKey("account")

	// StorageKey is the key used for storing Ethereum contract storage in the
	// Cosmos SDK multi-store.
	StorageKey = types.NewKVStoreKey("storage")

	// CodeKey is the key used for storing Ethereum contract code in the Cosmos
	// SDK multi-store.
	CodeKey = types.NewKVStoreKey("code")
)

Functions

This section is empty.

Types

type Database

type Database struct {

	// TODO: Do we need this/document?
	Tracing bool
	// contains filtered or unexported fields
}

Database implements the Ethereum state.Database interface.

func NewDatabase

func NewDatabase(stateDB, codeDB dbm.DB) (*Database, error)

NewDatabase returns a reference to an initialized Database type which implements Ethereum's state.Database interface. An error is returned if the latest state failed to load. The underlying storage structure is defined by the Cosmos SDK IAVL tree.

func (*Database) Commit

func (db *Database) Commit() types.CommitID

Commit commits the underlying Cosmos SDK multi-store returning the commit ID.

func (*Database) ContractCode

func (db *Database) ContractCode(addrHash, codeHash ethcommon.Hash) ([]byte, error)

ContractCode implements Ethereum's state.Database interface. It will return the contract byte code for a given code hash. It will not return an error.

func (*Database) ContractCodeSize

func (db *Database) ContractCodeSize(addrHash, codeHash ethcommon.Hash) (int, error)

ContractCodeSize implements Ethereum's state.Database interface. It will return the contract byte code size for a given code hash. It will not return an error.

func (*Database) CopyTrie

func (db *Database) CopyTrie(ethstate.Trie) ethstate.Trie

CopyTrie implements Ethereum's state.Database interface. For now, it performs a no-op as the underlying Cosmos SDK IAVL tree does not support such an operation.

TODO: Does the IAVL tree need to support this operation? If so, why and how?

func (*Database) OpenStorageTrie

func (db *Database) OpenStorageTrie(addrHash, root ethcommon.Hash) (ethstate.Trie, error)

OpenStorageTrie implements Ethereum's state.Database interface. It returns a Trie type which implements the Ethereum state.Trie interface. It is used for storage of contract storage (state). Also, this trie is never committed separately as all the data is in a single multi-store and is committed when the account IAVL tree is committed.

NOTE: It is assumed that the account state has already been loaded via OpenTrie.

CONTRACT: The root parameter is not interpreted as a state root hash, but as an encoding of an IAVL tree version.

func (*Database) OpenTrie

func (db *Database) OpenTrie(root ethcommon.Hash) (ethstate.Trie, error)

OpenTrie implements Ethereum's state.Database interface. It returns a Trie type which implements the Ethereum state.Trie interface. It us used for storage of accounts. An error is returned if state cannot load for a given version. The account cache is reset if the state is successfully loaded and the version is not the latest.

CONTRACT: The root parameter is not interpreted as a state root hash, but as an encoding of an Cosmos SDK IAVL tree version.

func (*Database) TrieDB

func (db *Database) TrieDB() *ethtrie.Database

TrieDB implements Ethereum's state.Database interface. It returns Ethereum's trie.Database low level trie database used for contract state storage. In the context of Ethermint, it'll be used to solely store mappings of codeHash => code.

type Trie

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

Trie implements the Ethereum state.Trie interface.

func (*Trie) Commit

func (t *Trie) Commit(_ ethtrie.LeafCallback) (ethcommon.Hash, error)

Commit implements the Ethereum state.Trie interface. It persists transient state. State is held by a merkelized multi-store IAVL tree. Commitment will only occur through an account trie, in other words, when the prefix of the trie is nil. In such a case, if either the accountCache or the storageCache are not nil, they are persisted. In addition, all the mappings of codeHash => code are also persisted. All these operations are performed in a deterministic order. Transient state is built up in a CacheKVStore. Finally, a root hash is returned or an error if any operation fails.

CONTRACT: The root is an encoded IAVL tree version and each new commitment increments the version by one.

func (*Trie) GetKey

func (t *Trie) GetKey(key []byte) []byte

GetKey implements the Ethereum state.Trie interface. Since the IAVL does not need to store preimages of keys, a simple identity can be returned.

func (*Trie) Hash

func (t *Trie) Hash() ethcommon.Hash

Hash implements the Ethereum state.Trie interface. It returns the state root of the Trie which is an encoding of the underlying IAVL tree.

CONTRACT: The root is an encoded IAVL tree version.

func (*Trie) NodeIterator

func (t *Trie) NodeIterator(startKey []byte) ethtrie.NodeIterator

NodeIterator implements the Ethereum state.Trie interface. Such a node iterator is used primarily for the implementation of RPC API functions. It performs a no-op.

TODO: Determine if we need to implement such functionality for an IAVL tree. This will ultimately be related to if we want to support web3.

func (*Trie) Prove

func (t *Trie) Prove(key []byte, fromLevel uint, proofDB ethdb.Putter) error

Prove implements the Ethereum state.Trie interface. It writes a Merkle proof to a ethdb.Putter, proofDB, for a given key starting at fromLevel.

TODO: Determine how to integrate this with Cosmos SDK to provide such proofs.

func (*Trie) TryDelete

func (t *Trie) TryDelete(key []byte) error

TryDelete implements the Ethereum state.Trie interface. It removes any existing value for a given key from the trie.

CONTRACT: The order of deletions must be deterministic due to the nature of the IAVL tree. Since a CacheKVStore is used as the storage type, the keys will be sorted giving us a deterministic ordering.

func (*Trie) TryGet

func (t *Trie) TryGet(key []byte) ([]byte, error)

TryGet implements the Ethereum state.Trie interface. It returns the value for key stored in the trie. The value bytes must not be modified by the caller.

func (*Trie) TryUpdate

func (t *Trie) TryUpdate(key, value []byte) error

TryUpdate implements the Ethereum state.Trie interface. It associates a given key with a value in the trie. Subsequent calls to Get will return a value. It also marks the tree as not empty.

CONTRACT: The order of insertions must be deterministic due to the nature of the IAVL tree. Since a CacheKVStore is used as the storage type, the keys will be sorted giving us a deterministic ordering.

Jump to

Keyboard shortcuts

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