Documentation ¶
Index ¶
- Constants
- Variables
- func PublicKeyToAccountAddress(pub ed25519.PublicKey) types.Address
- type AccountState
- type DB
- func (state *DB) AddBalance(addr types.Address, amount uint64)
- 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) GetAllAccounts() (*types.MultipleAccountsState, error)
- 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() types.MultipleAccountsState
- func (state *DB) SetBalance(addr types.Address, amount uint64)
- func (state *DB) SetNonce(addr types.Address, nonce uint64)
- func (state *DB) SubBalance(addr types.Address, amount uint64)
- func (state *DB) TrieDB() *trie.Database
- type Database
- type Object
- func (state *Object) AddBalance(amount uint64)
- func (state *Object) Address() types.Address
- func (state *Object) Balance() uint64
- 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 uint64)
- func (state *Object) SetNonce(nonce uint64)
- func (state *Object) SubBalance(amount uint64)
- func (state *Object) Value() *big.Int
- type PreImages
- type Projector
- type TransactionProcessor
- func (tp *TransactionProcessor) AddTxToPool(tx *types.Transaction)
- func (tp *TransactionProcessor) AddressExists(addr types.Address) bool
- func (tp *TransactionProcessor) ApplyRewards(layer types.LayerID, rewards map[types.Address]uint64)
- func (tp *TransactionProcessor) ApplyTransaction(tx *types.Transaction, layerID types.LayerID) error
- func (tp *TransactionProcessor) ApplyTransactions(layer types.LayerID, txs []*types.Transaction) ([]*types.Transaction, error)
- func (tp *TransactionProcessor) GetLayerApplied(txID types.TransactionID) *types.LayerID
- func (tp *TransactionProcessor) GetLayerStateRoot(layer types.LayerID) (types.Hash32, error)
- 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 ¶
const IncomingTxProtocol = "TxGossip"
IncomingTxProtocol is the protocol identifier for tx received by gossip that is used by the p2p.
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() uint64 GetNonce() uint64 SetNonce(newNonce uint64) AddBalance(amount uint64) SubBalance(amount uint64) SetBalance(amount uint64) GetAddress() types.Address }
AccountState is the interface defined to query a single account state.
type DB ¶
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 ¶
AddBalance adds amount to the account associated with addr.
func (*DB) Copy ¶
Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.
func (*DB) CreateAccount ¶
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 ¶
Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0).
func (*DB) Exist ¶
Exist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.
func (*DB) GetAllAccounts ¶
func (state *DB) GetAllAccounts() (*types.MultipleAccountsState, error)
GetAllAccounts returns a dump of all accounts in global state.
func (*DB) GetBalance ¶
GetBalance Retrieve the balance from the given address or 0 if object not found.
func (*DB) GetNonce ¶
GetNonce gets the current nonce of the given addr, if the address is not found it returns 0.
func (*DB) GetOrNewStateObj ¶
GetOrNewStateObj retrieve a state object or create a new state object if nil.
func (*DB) IntermediateRoot ¶
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) RawDump ¶
func (state *DB) RawDump() types.MultipleAccountsState
RawDump returns a Dump struct for the receivers state.
func (*DB) SetBalance ¶
SetBalance sets balance to the specific address, it does not return error if address was not found.
func (*DB) SetNonce ¶
SetNonce sets nonce to the specific address, it does not return error if address was not found.
func (*DB) SubBalance ¶
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 Object ¶
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 ¶
AddBalance removes amount from c's balance. It is used to add funds to the destination account of a transfer.
func (*Object) ReturnGas ¶
ReturnGas Return the gas back to the origin. Used by the Virtual machine or Closures.
func (*Object) SetBalance ¶
SetBalance sets the balance for current account.
func (*Object) SubBalance ¶
SubBalance removes amount from c's balance. It is used to remove funds from the origin account of a transfer.
type PreImages ¶
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, txPool *mempool.TxMempool, logger log.Log) *TransactionProcessor
NewTransactionProcessor returns a new state processor.
func (*TransactionProcessor) AddTxToPool ¶
func (tp *TransactionProcessor) AddTxToPool(tx *types.Transaction)
AddTxToPool exports mempool functionality for adding tx to the pool.
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 ¶
ApplyRewards applies reward reward to miners vector for layer.
func (*TransactionProcessor) ApplyTransaction ¶
func (tp *TransactionProcessor) ApplyTransaction(tx *types.Transaction, layerID types.LayerID) error
ApplyTransaction applies provided transaction to the current state, but does not commit it to persistent storage. It returns an error if the transaction is invalid, i.e., if there is not enough balance in the source account to perform the transaction and pay the fee or if the nonce is incorrect.
func (*TransactionProcessor) ApplyTransactions ¶
func (tp *TransactionProcessor) ApplyTransactions(layer types.LayerID, txs []*types.Transaction) ([]*types.Transaction, error)
ApplyTransactions receives a batch of transactions to apply to state. Returns the number of transactions that we 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) GetLayerStateRoot ¶
GetLayerStateRoot returns the state root at a given layer.
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.