txs

package
v0.2.15-beta.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const IncomingTxProtocol = "TxGossip"

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 CSConfig

type CSConfig struct {
	BlockGasLimit      uint64
	NumTXsPerProposal  int
	OptFilterThreshold int
}

CSConfig is the config for the conservative state/cache.

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) Add

func (c ConservativeState) Add(tx *types.Transaction, received time.Time, blockSeed []byte) error

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

func (c ConservativeState) CheckApplyOrder(toApply types.LayerID) error

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

func (c ConservativeState) GetMempool() map[types.Address][]*txtypes.NanoTX

GetMempool returns all the transactions that eligible for a proposal/block.

func (ConservativeState) GetMeshHash

func (c ConservativeState) GetMeshHash(lid types.LayerID) (types.Hash32, error)

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

func (c ConservativeState) GetProjection(addr types.Address) (uint64, uint64)

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) MoreInDB

func (c ConservativeState) MoreInDB(addr types.Address) bool

func (*ConservativeState) RevertState

func (cs *ConservativeState) RevertState(revertTo types.LayerID) (types.Hash32, error)

RevertState reverts the VM state and database to the given layer.

func (ConservativeState) RevertToLayer

func (c ConservativeState) RevertToLayer(revertTo types.LayerID) error

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:

  1. 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
  2. put the output of step 0 in a stable order
  3. 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

func NewTxHandler(s conservativeState, l log.Log) *TxHandler

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

func (th *TxHandler) HandleSyncTransaction(ctx context.Context, data []byte) error

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.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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