vmdb

package
v0.0.0-...-5fb9e85 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package vmdb

@author: xwc1125

Package vmdb

@author: xwc1125

Package vmdb

@author: xwc1125

Package vmdb

@author: xwc1125

Package vmdb

@author: xwc1125

Package vmdb

@author: xwc1125

Package vmdb

@author: xwc1125

Package vmdb

@author: xwc1125

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDatabase

func NewDatabase(db kvstore.Database) basedb.Database

func NewDatabaseWithCache

func NewDatabaseWithCache(db kvstore.Database, cache int) basedb.Database

NewDatabaseWithCache 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 NewStateSync

func NewStateSync(root types.Hash, database kvstore.KeyValueReader, bloom *tree.SyncBloom) *tree.Sync

NewStateSync create a new state trie download scheduler.

Types

type BzStateDb

type BzStateDb interface {
	AddBalance(addr types.Address, amount *big.Int)
	SubBalance(addr types.Address, amount *big.Int)
	GetBalance(addr types.Address) *big.Int
	SetBalance(addr types.Address, amount *big.Int)

	GetNonce(addr types.Address) *big.Int
	SetNonce(addr types.Address, nonce *big.Int)

	AddLog(log *statetype.Log)
	GetLogs(hash types.Hash) []*statetype.Log
	Logs() []*statetype.Log

	AddRefund(gas uint64)
	SubRefund(gas uint64)
	GetRefund() uint64

	GetCode(addr types.Address) []byte
	GetCodeSize(addr types.Address) int
	GetCodeHash(addr types.Address) types.Hash
	SetCode(addr types.Address, code []byte)
}

type StateDB

type StateDB struct {

	// Measurements gathered during execution for debugging purposes
	AccountReads   time.Duration
	AccountHashes  time.Duration
	AccountUpdates time.Duration
	AccountCommits time.Duration
	StorageReads   time.Duration
	StorageHashes  time.Duration
	StorageUpdates time.Duration
	StorageCommits time.Duration
	// contains filtered or unexported fields
}

StateDB 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

func New

func New(root types.Hash, db basedb.Database, accountDB *accountdb.AccountDB) (*StateDB, error)

Create a new state from a given trie.

func (*StateDB) AddBalance

func (s *StateDB) AddBalance(addr types.DomainAddress, amount *big.Int)

AddBalance adds amount to the account associated with addr.

func (*StateDB) AddLog

func (s *StateDB) AddLog(logger *statetype.Log)

func (*StateDB) AddPreimage

func (s *StateDB) AddPreimage(hash types.Hash, preimage []byte)

AddPreimage records a SHA3 preimage seen by the VM.

func (*StateDB) AddRefund

func (s *StateDB) AddRefund(gas uint64)

AddRefund adds gas to the refund counter

func (*StateDB) AddTokenBalance

func (s *StateDB) AddTokenBalance(addr types.DomainAddress, token types.DomainAddress, amount *big.Int)

func (*StateDB) BlockHash

func (s *StateDB) BlockHash() types.Hash

BlockHash returns the current block hash set by Prepare.

func (*StateDB) Commit

func (s *StateDB) Commit(deleteEmptyObjects bool) (types.Hash, error)

Commit writes the state to the underlying in-memory trie database.

func (*StateDB) Copy

func (s *StateDB) Copy() *StateDB

Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.

func (*StateDB) CreateAccount

func (s *StateDB) CreateAccount(addr types.DomainAddress)

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 (*StateDB) Database

func (s *StateDB) Database() basedb.Database

Database retrieves the low level database supporting the lower level trie ops.

func (*StateDB) Empty

func (s *StateDB) Empty(addr types.DomainAddress) bool

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

func (*StateDB) Error

func (s *StateDB) Error() error

func (*StateDB) Exist

func (s *StateDB) Exist(addr types.DomainAddress) bool

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

func (*StateDB) Finalise

func (s *StateDB) Finalise(deleteEmptyObjects bool)

Finalise finalises the state by removing the s destructed objects and clears the journal as well as the refunds. Finalise, however, will not push any updates into the tries just yet. Only IntermediateRoot or Commit will do that.

func (*StateDB) ForEachStorage

func (db *StateDB) ForEachStorage(addr types.DomainAddress, cb func(key, value types.Hash) bool) error

func (*StateDB) GetBalance

func (s *StateDB) GetBalance(addr types.DomainAddress) *big.Int

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

func (*StateDB) GetCode

func (s *StateDB) GetCode(addr types.DomainAddress) []byte

func (*StateDB) GetCodeHash

func (s *StateDB) GetCodeHash(addr types.DomainAddress) types.Hash

func (*StateDB) GetCodeSize

func (s *StateDB) GetCodeSize(addr types.DomainAddress) int

func (*StateDB) GetCommittedState

func (s *StateDB) GetCommittedState(addr types.DomainAddress, hash types.Hash) types.Hash

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

func (*StateDB) GetContractInfo

func (s *StateDB) GetContractInfo(addr types.DomainAddress) []byte

func (*StateDB) GetLogs

func (s *StateDB) GetLogs(hash types.Hash) []*statetype.Log

func (*StateDB) GetNonce

func (s *StateDB) GetNonce(addr types.DomainAddress) uint64

func (*StateDB) GetOrNewStateObject

func (s *StateDB) GetOrNewStateObject(addr types.DomainAddress) *stateObject

Retrieve a state object or create a new state object if nil.

func (*StateDB) GetProof

func (s *StateDB) GetProof(a types.DomainAddress) ([][]byte, error)

GetProof returns the MerkleProof for a given Account

func (*StateDB) GetRefund

func (s *StateDB) GetRefund() uint64

GetRefund returns the current value of the refund counter.

func (*StateDB) GetState

func (s *StateDB) GetState(addr types.DomainAddress, hash types.Hash) types.Hash

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

func (*StateDB) GetStorageProof

func (s *StateDB) GetStorageProof(a types.DomainAddress, key types.Hash) ([][]byte, error)

GetProof returns the StorageProof for given key

func (*StateDB) GetTokenBalance

func (s *StateDB) GetTokenBalance(addr types.DomainAddress, token types.DomainAddress) *big.Int

func (*StateDB) GetTokenBalances

func (s *StateDB) GetTokenBalances(addr types.DomainAddress) statetype.TokenValues

func (*StateDB) HasSuicided

func (s *StateDB) HasSuicided(addr types.DomainAddress) bool

func (*StateDB) IntermediateRoot

func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) types.Hash

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

func (*StateDB) Logs

func (s *StateDB) Logs() []*statetype.Log

func (*StateDB) Preimages

func (s *StateDB) Preimages() map[types.Hash][]byte

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

func (*StateDB) Prepare

func (s *StateDB) Prepare(thash, bhash types.Hash, ti int)

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

func (*StateDB) Reset

func (s *StateDB) Reset(root types.Hash) error

Reset clears out all ephemeral state objects from the state db, but keeps the underlying state trie to avoid reloading data for the next operations.

func (*StateDB) RevertToSnapshot

func (s *StateDB) RevertToSnapshot(revid int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*StateDB) SetBalance

func (s *StateDB) SetBalance(addr types.DomainAddress, amount *big.Int)

func (*StateDB) SetCode

func (s *StateDB) SetCode(addr types.DomainAddress, code []byte)

func (*StateDB) SetContractInfo

func (s *StateDB) SetContractInfo(addr types.DomainAddress, info []byte)

func (*StateDB) SetNonce

func (s *StateDB) SetNonce(addr types.DomainAddress, nonce uint64)

func (*StateDB) SetState

func (s *StateDB) SetState(addr types.DomainAddress, key, value types.Hash)

func (*StateDB) SetTokenBalance

func (s *StateDB) SetTokenBalance(addr types.DomainAddress, token types.DomainAddress, amount *big.Int)

func (*StateDB) Snapshot

func (s *StateDB) Snapshot() int

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

func (*StateDB) StorageTree

func (s *StateDB) StorageTree(addr types.DomainAddress) tree.Tree

StorageTrie returns the storage trie of an account. The return value is a copy and is nil for non-existent accounts.

func (*StateDB) SubBalance

func (s *StateDB) SubBalance(addr types.DomainAddress, amount *big.Int)

SubBalance subtracts amount from the account associated with addr.

func (*StateDB) SubRefund

func (s *StateDB) SubRefund(gas uint64)

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

func (*StateDB) SubTokenBalance

func (s *StateDB) SubTokenBalance(addr types.DomainAddress, token types.DomainAddress, amount *big.Int)

func (*StateDB) Suicide

func (s *StateDB) Suicide(addr types.DomainAddress) bool

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

func (*StateDB) TxIndex

func (s *StateDB) TxIndex() int

TxIndex returns the current transaction index set by Prepare.

type StateDBFace

type StateDBFace interface {
	Error() error
	Reset(root types.Hash) error
	Exist(addr types.Address) bool
	Empty(addr types.Address) bool
	Copy() *StateDB

	GetState(addr types.Address, hash types.Hash) types.Hash
	GetCommittedState(addr types.Address, hash types.Hash) types.Hash
	SetState(addr types.Address, key, value types.Hash)

	GetProof(a types.Address) ([][]byte, error)
	GetStorageProof(a types.Address, key types.Hash) ([][]byte, error)

	TxIndex() int
	BlockHash() types.Hash

	AddPreimage(hash types.Hash, preimage []byte)
	Preimages() map[types.Hash][]byte

	StorageTree(addr types.Address) tree.Tree

	HasSuicided(addr types.Address) bool
	Suicide(addr types.Address) bool

	Snapshot() int
	RevertToSnapshot(revid int)

	IntermediateRoot(deleteEmptyObjects bool) types.Hash
	Finalise(deleteEmptyObjects bool)
	Prepare(thash, bhash types.Hash, ti int)
	Commit(deleteEmptyObjects bool) (types.Hash, error)
}

Directories

Path Synopsis
Package model @author: xwc1125 Package model @author: xwc1125 Package model @author: xwc1125
Package model @author: xwc1125 Package model @author: xwc1125 Package model @author: xwc1125

Jump to

Keyboard shortcuts

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