Documentation ¶
Index ¶
- Variables
- type Database
- func (db *Database) Commit() types.CommitID
- func (db *Database) ContractCode(addrHash, codeHash ethcommon.Hash) ([]byte, error)
- func (db *Database) ContractCodeSize(addrHash, codeHash ethcommon.Hash) (int, error)
- func (db *Database) CopyTrie(ethstate.Trie) ethstate.Trie
- func (db *Database) OpenStorageTrie(addrHash, root ethcommon.Hash) (ethstate.Trie, error)
- func (db *Database) OpenTrie(root ethcommon.Hash) (ethstate.Trie, error)
- func (db *Database) TrieDB() *ethtrie.Database
- type Trie
- func (t *Trie) Commit(_ ethtrie.LeafCallback) (ethcommon.Hash, error)
- func (t *Trie) GetKey(key []byte) []byte
- func (t *Trie) Hash() ethcommon.Hash
- func (t *Trie) NodeIterator(startKey []byte) ethtrie.NodeIterator
- func (t *Trie) Prove(key []byte, fromLevel uint, proofDB ethdb.Putter) error
- func (t *Trie) TryDelete(key []byte) error
- func (t *Trie) TryGet(key []byte) ([]byte, error)
- func (t *Trie) TryUpdate(key, value []byte) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
Commit commits the underlying Cosmos SDK multi-store returning the commit ID.
func (*Database) ContractCode ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
Trie implements the Ethereum state.Trie interface.
func (*Trie) Commit ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.