Documentation ¶
Index ¶
- Variables
- func PublicKeyToAccountAddress(pub ed25519.PublicKey) types.Address
- type Account
- type AccountState
- type DB
- func (state *DB) AddBalance(addr types.Address, amount *big.Int)
- func (state *DB) Commit() (root types.Hash32, err error)
- func (state *DB) Copy() *DB
- func (state *DB) CreateAccount(addr types.Address)
- func (state *DB) Dump() []byte
- func (state *DB) Empty(addr types.Address) bool
- func (state *DB) Error() error
- func (state *DB) Exist(addr types.Address) bool
- func (state *DB) GetBalance(addr types.Address) uint64
- func (state *DB) GetNonce(addr types.Address) uint64
- func (state *DB) GetOrNewStateObj(addr types.Address) *Object
- func (state *DB) IntermediateRoot(deleteEmptyObjects bool) types.Hash32
- func (state *DB) RawDump() Dump
- func (state *DB) SetBalance(addr types.Address, amount *big.Int)
- func (state *DB) SetNonce(addr types.Address, nonce uint64)
- func (state *DB) SubBalance(addr types.Address, amount *big.Int)
- func (state *DB) TrieDB() *trie.Database
- type Database
- type Dump
- type DumpAccount
- type Object
- func (state *Object) AddBalance(amount *big.Int)
- func (state *Object) Address() types.Address
- func (state *Object) Balance() *big.Int
- func (state *Object) EncodeRLP(w io.Writer) error
- func (state *Object) Nonce() uint64
- func (state *Object) ReturnGas(gas *big.Int)
- func (state *Object) SetBalance(amount *big.Int)
- func (state *Object) SetNonce(nonce uint64)
- func (state *Object) SubBalance(amount *big.Int)
- func (state *Object) Value() *big.Int
- type PreImages
- type Projector
- type TransactionProcessor
- func (tp *TransactionProcessor) AddressExists(addr types.Address) bool
- func (tp *TransactionProcessor) ApplyRewards(layer types.LayerID, miners []types.Address, reward *big.Int)
- func (tp *TransactionProcessor) ApplyTransaction(trans *types.Transaction, layerID types.LayerID) error
- func (tp *TransactionProcessor) ApplyTransactions(layer types.LayerID, txs []*types.Transaction) (int, error)
- func (tp *TransactionProcessor) GetLayerApplied(txID types.TransactionID) *types.LayerID
- func (tp *TransactionProcessor) GetStateRoot() types.Hash32
- func (tp *TransactionProcessor) LoadState(layer types.LayerID) error
- func (tp *TransactionProcessor) Process(txs []*types.Transaction, layerID types.LayerID) (remaining []*types.Transaction)
- func (tp *TransactionProcessor) ValidateNonceAndBalance(tx *types.Transaction) error
- type Trie
Constants ¶
This section is empty.
Variables ¶
var MaxTrieCacheGen = uint16(120)
MaxTrieCacheGen is Trie cache generation limit after which to evict trie nodes from memory.
Functions ¶
Types ¶
type AccountState ¶
type AccountState interface { GetBalance() *big.Int GetNonce() uint64 SetNonce(newNonce uint64) AddBalance(amount *big.Int) SubBalance(amount *big.Int) SetBalance(amount *big.Int) GetAddress() types.Address }
AccountState is the interface defined to query a single account state
type DB ¶ added in v0.1.11
type DB struct {
// contains filtered or unexported fields
}
DB is the struct that performs logging of all account states. It consists of a state trie that contains all account data in its leaves. It also stores a dirty object list to dump when state is committed into db
func (*DB) AddBalance ¶ added in v0.1.11
AddBalance adds amount to the account associated with addr.
func (*DB) Commit ¶ added in v0.1.11
Commit writes the state to the underlying in-memory trie database.
func (*DB) Copy ¶ added in v0.1.11
Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.
func (*DB) CreateAccount ¶ added in v0.1.11
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:
- sends funds to sha(account ++ (nonce + 1))
- tx_create(sha(account ++ nonce)) (note that this gets the address of 1)
Carrying over the balance ensures that Ether doesn't disappear.
func (*DB) Empty ¶ added in v0.1.11
Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0)
func (*DB) Exist ¶ added in v0.1.11
Exist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.
func (*DB) GetBalance ¶ added in v0.1.11
GetBalance Retrieve the balance from the given address or 0 if object not found
func (*DB) GetNonce ¶ added in v0.1.11
GetNonce gets the current nonce of the given addr, if the address is not found it returns 0
func (*DB) GetOrNewStateObj ¶ added in v0.1.11
GetOrNewStateObj retrieve a state object or create a new state object if nil.
func (*DB) IntermediateRoot ¶ added in v0.1.11
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 (*DB) SetBalance ¶ added in v0.1.11
SetBalance sets balance to the specific address, it does not return error if address was not found
func (*DB) SetNonce ¶ added in v0.1.11
SetNonce sets nonce to the specific address, it does not return error if address was not found
func (*DB) SubBalance ¶ added in v0.1.11
SubBalance subtracts amount from the account associated with addr.
type Database ¶
type Database interface { // OpenTrie opens the main account trie. OpenTrie(root types.Hash32) (Trie, error) // OpenStorageTrie opens the storage trie of an account. OpenStorageTrie(addrHash, root types.Hash32) (Trie, error) // CopyTrie returns an independent copy of the given trie. CopyTrie(Trie) Trie // TrieDB retrieves the low level trie database used for data storage. TrieDB() *trie.Database }
Database wraps access to tries and contract code.
func NewDatabase ¶
NewDatabase creates a backing store for state. The returned database is safe for concurrent use and retains cached trie nodes in memory. The pool is an optional intermediate trie-node memory pool between the low level storage layer and the high level trie abstraction.
type Dump ¶
type Dump struct { Root string `json:"root"` Accounts map[string]DumpAccount `json:"accounts"` }
Dump is a struct used to dump an entire state root into json form
type DumpAccount ¶
DumpAccount is a helper struct that helps dumping account balance and nonce in json form
type Object ¶ added in v0.1.11
type Object struct {
// contains filtered or unexported fields
}
Object is the struct in which account information is stored. It contains account info such as nonce and balance and also the accounts address, address hash and a reference to this structs containing database
func (*Object) AddBalance ¶ added in v0.1.11
AddBalance removes amount from c's balance. It is used to add funds to the destination account of a transfer.
func (*Object) ReturnGas ¶ added in v0.1.11
ReturnGas Return the gas back to the origin. Used by the Virtual machine or Closures
func (*Object) SetBalance ¶ added in v0.1.11
SetBalance sets the balance for current account
func (*Object) SubBalance ¶ added in v0.1.11
SubBalance removes amount from c's balance. It is used to remove funds from the origin account of a transfer.
type PreImages ¶ added in v0.1.11
type PreImages struct {
// contains filtered or unexported fields
}
PreImages is a struct that contains a root hash and the transactions that are in store of this root hash
type Projector ¶
type Projector interface {
GetProjection(addr types.Address, prevNonce, prevBalance uint64) (nonce, balance uint64, err error)
}
Projector interface defines the interface for a struct that can project the state of an account by applying txs from mem pool
type TransactionProcessor ¶
TransactionProcessor is the struct containing state db and is responsible for applying transactions into it
func NewTransactionProcessor ¶
func NewTransactionProcessor(allStates, processorDb database.Database, projector Projector, logger log.Log) *TransactionProcessor
NewTransactionProcessor returns a new state processor
func (*TransactionProcessor) AddressExists ¶
func (tp *TransactionProcessor) AddressExists(addr types.Address) bool
AddressExists checks if an account address exists in this node's global state
func (*TransactionProcessor) ApplyRewards ¶
func (tp *TransactionProcessor) ApplyRewards(layer types.LayerID, miners []types.Address, reward *big.Int)
ApplyRewards applies reward reward to miners vector miners in for layer
func (*TransactionProcessor) ApplyTransaction ¶
func (tp *TransactionProcessor) ApplyTransaction(trans *types.Transaction, layerID types.LayerID) error
ApplyTransaction applies provided transaction trans to the current state, but does not commit it to persistent storage. it returns error if there is not enough balance in src account to perform the transaction and pay fee or if the nonce is invalid
func (*TransactionProcessor) ApplyTransactions ¶
func (tp *TransactionProcessor) ApplyTransactions(layer types.LayerID, txs []*types.Transaction) (int, error)
ApplyTransactions receives a batch of transaction to apply on state. Returns the number of transaction that failed to apply.
func (*TransactionProcessor) GetLayerApplied ¶
func (tp *TransactionProcessor) GetLayerApplied(txID types.TransactionID) *types.LayerID
GetLayerApplied gets the layer id at which this tx was applied
func (*TransactionProcessor) GetStateRoot ¶
func (tp *TransactionProcessor) GetStateRoot() types.Hash32
GetStateRoot gets the current state root hash
func (*TransactionProcessor) LoadState ¶
func (tp *TransactionProcessor) LoadState(layer types.LayerID) error
LoadState loads the last state from persistent storage
func (*TransactionProcessor) Process ¶
func (tp *TransactionProcessor) Process(txs []*types.Transaction, layerID types.LayerID) (remaining []*types.Transaction)
Process applies transaction vector to current state, it returns the remaining transactions that failed
func (*TransactionProcessor) ValidateNonceAndBalance ¶
func (tp *TransactionProcessor) ValidateNonceAndBalance(tx *types.Transaction) error
ValidateNonceAndBalance validates that the tx origin account has enough balance to apply the tx, also, it checks that nonce in tx is correct, returns error otherwise
type Trie ¶
type Trie interface { TryGet(key []byte) ([]byte, error) TryUpdate(key, value []byte) error TryDelete(key []byte) error Commit(onleaf trie.LeafCallback) (types.Hash32, error) Hash() types.Hash32 NodeIterator(startKey []byte) trie.NodeIterator GetKey([]byte) []byte // TODO(fjl): remove this when SecureTrie is removed Prove(key []byte, fromLevel uint, proofDb database.Putter) error }
Trie is a Ethereum Merkle Trie.