Documentation
¶
Index ¶
- Constants
- type CSConfig
- type ConservativeState
- func (c ConservativeState) Add(tx *types.Transaction, received time.Time, blockSeed []byte) error
- func (cs *ConservativeState) AddToCache(tx *types.Transaction, newTX bool) error
- func (c ConservativeState) AddToDB(tx *types.Transaction, received time.Time) error
- func (cs *ConservativeState) ApplyLayer(toApply *types.Block) ([]*types.Transaction, error)
- func (c ConservativeState) BuildFromScratch() error
- func (c ConservativeState) BuildFromTXs(mtxs []*types.MeshTransaction, blockSeed []byte) error
- func (c ConservativeState) CheckApplyOrder(toApply types.LayerID) error
- func (c ConservativeState) Get(tid types.TransactionID) *txtypes.NanoTX
- func (c ConservativeState) GetMempool() map[types.Address][]*txtypes.NanoTX
- func (c ConservativeState) GetMeshHash(lid types.LayerID) (types.Hash32, error)
- func (c ConservativeState) GetMeshTransaction(id types.TransactionID) (*types.MeshTransaction, error)
- func (c ConservativeState) GetMeshTransactions(ids []types.TransactionID) ([]*types.MeshTransaction, map[types.TransactionID]struct{})
- func (c ConservativeState) GetProjection(addr types.Address) (uint64, uint64)
- func (c ConservativeState) GetTransactionsByAddress(from, to types.LayerID, address types.Address) ([]*types.MeshTransaction, error)
- func (c ConservativeState) HasTx(tid types.TransactionID) (bool, error)
- func (c ConservativeState) LinkTXsWithBlock(lid types.LayerID, bid types.BlockID, tids []types.TransactionID) error
- func (c ConservativeState) LinkTXsWithProposal(lid types.LayerID, pid types.ProposalID, tids []types.TransactionID) error
- func (c ConservativeState) MoreInDB(addr types.Address) bool
- func (cs *ConservativeState) RevertState(revertTo types.LayerID) (types.Hash32, error)
- func (c ConservativeState) RevertToLayer(revertTo types.LayerID) error
- func (cs *ConservativeState) SelectBlockTXs(lid types.LayerID, proposals []*types.Proposal) ([]types.TransactionID, error)
- func (cs *ConservativeState) SelectProposalTXs(numEligibility int) []types.TransactionID
- func (cs *ConservativeState) Transactions() database.Getter
- type ConservativeStateOpt
- type TxHandler
Constants ¶
const IncomingTxProtocol = "TxGossip/1"
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 ConservativeState ¶
type ConservativeState struct {
// contains filtered or unexported fields
}
ConservativeState provides the conservative version of the VM state by taking into accounts of nonce and balances for pending transactions in un-applied blocks and mempool.
func NewConservativeState ¶
func NewConservativeState(state vmState, db *sql.Database, opts ...ConservativeStateOpt) *ConservativeState
NewConservativeState returns a ConservativeState.
func (*ConservativeState) AddToCache ¶
func (cs *ConservativeState) AddToCache(tx *types.Transaction, newTX bool) error
AddToCache adds the provided transaction to the conservative cache.
func (ConservativeState) AddToDB ¶
func (c ConservativeState) AddToDB(tx *types.Transaction, received time.Time) error
AddToDB adds a transaction to the database.
func (*ConservativeState) ApplyLayer ¶
func (cs *ConservativeState) ApplyLayer(toApply *types.Block) ([]*types.Transaction, error)
ApplyLayer applies the transactions specified by the ids to the state.
func (ConservativeState) BuildFromScratch ¶
func (c ConservativeState) BuildFromScratch() error
BuildFromScratch builds the cache from database.
func (ConservativeState) BuildFromTXs ¶
func (c ConservativeState) BuildFromTXs(mtxs []*types.MeshTransaction, blockSeed []byte) error
BuildFromTXs builds the cache from the provided transactions.
func (ConservativeState) CheckApplyOrder ¶
CheckApplyOrder returns an error if layers were not applied in order.
func (ConservativeState) Get ¶
func (c ConservativeState) Get(tid types.TransactionID) *txtypes.NanoTX
Get gets a transaction from the cache.
func (ConservativeState) GetMempool ¶
GetMempool returns all the transactions that eligible for a proposal/block.
func (ConservativeState) GetMeshHash ¶
GetMeshHash gets the aggregated layer hash at the specified layer.
func (ConservativeState) GetMeshTransaction ¶
func (c ConservativeState) GetMeshTransaction(id types.TransactionID) (*types.MeshTransaction, error)
GetMeshTransaction retrieves a tx by its id.
func (ConservativeState) GetMeshTransactions ¶
func (c ConservativeState) GetMeshTransactions(ids []types.TransactionID) ([]*types.MeshTransaction, map[types.TransactionID]struct{})
GetMeshTransactions retrieves a list of txs by their id's.
func (ConservativeState) GetProjection ¶
GetProjection returns the projected nonce and balance for an account, including pending transactions that are paced in proposals/blocks but not yet applied to the state.
func (ConservativeState) GetTransactionsByAddress ¶
func (c ConservativeState) GetTransactionsByAddress(from, to types.LayerID, address types.Address) ([]*types.MeshTransaction, error)
GetTransactionsByAddress retrieves txs for a single address in between layers [from, to]. Guarantees that transaction will appear exactly once, even if origin and recipient is the same, and in insertion order.
func (ConservativeState) HasTx ¶
func (c ConservativeState) HasTx(tid types.TransactionID) (bool, error)
HasTx returns true if transaction exists in the cache.
func (ConservativeState) LinkTXsWithBlock ¶
func (c ConservativeState) LinkTXsWithBlock(lid types.LayerID, bid types.BlockID, tids []types.TransactionID) error
LinkTXsWithBlock associates the transactions to a block.
func (ConservativeState) LinkTXsWithProposal ¶
func (c ConservativeState) LinkTXsWithProposal(lid types.LayerID, pid types.ProposalID, tids []types.TransactionID) error
LinkTXsWithProposal associates the transactions to a proposal.
func (*ConservativeState) RevertState ¶
RevertState reverts the VM state and database to the given layer.
func (ConservativeState) RevertToLayer ¶
func (*ConservativeState) SelectBlockTXs ¶
func (cs *ConservativeState) SelectBlockTXs(lid types.LayerID, proposals []*types.Proposal) ([]types.TransactionID, error)
SelectBlockTXs combined the transactions in the proposals and put them in a stable order. the steps are:
- do optimistic filtering if the proposals agree on the mesh hash and state root this mean the following transactions will be filtered out. transactions that - fail nonce check - fail balance check - are already applied in previous layer if the proposals don't agree on the mesh hash and state root, we keep all transactions
- put the output of step 0 in a stable order
- pick the transactions in step 1 until the gas limit runs out.
func (*ConservativeState) SelectProposalTXs ¶
func (cs *ConservativeState) SelectProposalTXs(numEligibility int) []types.TransactionID
SelectProposalTXs picks a specific number of random txs for miner to pack in a proposal.
func (*ConservativeState) Transactions ¶
func (cs *ConservativeState) Transactions() database.Getter
Transactions exports the transactions DB.
type ConservativeStateOpt ¶
type ConservativeStateOpt func(cs *ConservativeState)
ConservativeStateOpt for configuring conservative state.
func WithCSConfig ¶
func WithCSConfig(cfg CSConfig) ConservativeStateOpt
WithCSConfig defines the config used for the conservative state.
func WithLogger ¶
func WithLogger(logger log.Log) ConservativeStateOpt
WithLogger defines logger for conservative state.
type TxHandler ¶
type TxHandler struct {
// contains filtered or unexported fields
}
TxHandler handles the transactions received via gossip or sync.
func NewTxHandler ¶
NewTxHandler returns a new TxHandler.
func (*TxHandler) HandleGossipTransaction ¶
func (th *TxHandler) HandleGossipTransaction(ctx context.Context, _ p2p.Peer, msg []byte) pubsub.ValidationResult
HandleGossipTransaction handles data received on the transactions gossip channel.
func (*TxHandler) 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.