Documentation ¶
Index ¶
- Constants
- type SVM
- func (svm *SVM) AddTxToPool(tx *types.Transaction) error
- func (svm *SVM) AddressExists(addr types.Address) bool
- func (svm *SVM) ApplyLayer(layerID types.LayerID, transactions []*types.Transaction, ...) ([]*types.Transaction, error)
- func (svm *SVM) GetAllAccounts() (*types.MultipleAccountsState, error)
- func (svm *SVM) GetBalance(addr types.Address) uint64
- func (svm *SVM) GetLayerApplied(txID types.TransactionID) *types.LayerID
- func (svm *SVM) GetLayerStateRoot(layer types.LayerID) (types.Hash32, error)
- func (svm *SVM) GetNonce(addr types.Address) uint64
- func (svm *SVM) GetStateRoot() types.Hash32
- func (svm *SVM) HandleGossipTransaction(ctx context.Context, _ p2p.Peer, msg []byte) pubsub.ValidationResult
- func (svm *SVM) HandleSyncTransaction(data []byte) error
- func (svm *SVM) Rewind(layer types.LayerID) (types.Hash32, error)
- func (svm *SVM) SetupGenesis(conf *config.GenesisConfig) error
- func (svm *SVM) ValidateNonceAndBalance(transaction *types.Transaction) error
Constants ¶
const IncomingTxProtocol = state.IncomingTxProtocol
IncomingTxProtocol is the protocol identifier for tx received by gossip that is used by the p2p.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SVM ¶
type SVM struct {
// contains filtered or unexported fields
}
SVM is an entry point for all SVM operations.
func New ¶
func New(allStates, processorDb database.Database, projector state.Projector, txPool *mempool.TxMempool, logger log.Log) *SVM
New creates a new `SVM` instance from the given `state` and `logger`.
func (*SVM) AddTxToPool ¶
func (svm *SVM) AddTxToPool(tx *types.Transaction) error
AddTxToPool adds the provided transaction to the transaction pool. The caller is responsible for validating tx beforehand with ValidateNonceAndBalance.
func (*SVM) AddressExists ¶
AddressExists checks if an account address exists in this node's global state.
func (*SVM) ApplyLayer ¶
func (svm *SVM) ApplyLayer(layerID types.LayerID, transactions []*types.Transaction, rewards map[types.Address]uint64) ([]*types.Transaction, error)
ApplyLayer applies the given rewards to some miners as well as a vector of transactions for the given layer. to miners vector for layer. It returns an error on failure, as well as a vector of failed transactions.
func (*SVM) GetAllAccounts ¶
func (svm *SVM) GetAllAccounts() (*types.MultipleAccountsState, error)
GetAllAccounts returns a dump of all accounts in global state.
func (*SVM) GetBalance ¶
GetBalance Retrieve the balance from the given address or 0 if object not found.
func (*SVM) GetLayerApplied ¶
func (svm *SVM) GetLayerApplied(txID types.TransactionID) *types.LayerID
GetLayerApplied gets the layer id at which this tx was applied.
func (*SVM) GetLayerStateRoot ¶
GetLayerStateRoot returns the state root at a given layer.
func (*SVM) GetNonce ¶
GetNonce gets the current nonce of the given addr, if the address is not found it returns 0.
func (*SVM) GetStateRoot ¶
GetStateRoot gets the current state root hash.
func (*SVM) HandleGossipTransaction ¶
func (svm *SVM) HandleGossipTransaction(ctx context.Context, _ p2p.Peer, msg []byte) pubsub.ValidationResult
HandleGossipTransaction handles data received on the transactions gossip channel.
func (*SVM) HandleSyncTransaction ¶
HandleSyncTransaction handles transactions received via sync. Unlike HandleGossipTransaction, which only stores valid transactions, HandleSyncTransaction only deserializes transactions and stores them regardless of validity. This is because transactions received via sync are necessarily referenced somewhere meaning that we must have them stored, even if they're invalid, for the data availability of the referencing block.
func (*SVM) Rewind ¶
Rewind loads the given layer state from persistent storage. On success, it also returns the current state root hash *after* rewinding.
func (*SVM) SetupGenesis ¶
func (svm *SVM) SetupGenesis(conf *config.GenesisConfig) error
SetupGenesis creates new accounts and adds balances as dictated by `conf`.
func (*SVM) ValidateNonceAndBalance ¶
func (svm *SVM) ValidateNonceAndBalance(transaction *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.