txpool

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: LGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIntrinsicGas        = errors.New("intrinsic gas too low")
	ErrNegativeValue       = errors.New("negative value")
	ErrNonEncryptedTxn     = errors.New("non-encrypted transaction")
	ErrInvalidSender       = errors.New("invalid sender")
	ErrTxPoolOverflow      = errors.New("txpool is full")
	ErrUnderpriced         = errors.New("transaction underpriced")
	ErrNonceTooLow         = errors.New("nonce too low")
	ErrInsufficientFunds   = errors.New("insufficient funds for gas * price + value")
	ErrInvalidAccountState = errors.New("invalid account state")
	ErrAlreadyKnown        = errors.New("already known")
	// ErrOversizedData is returned if size of a transction is greater than the specified limit
	ErrOversizedData = errors.New("oversized data")
)

Functions

This section is empty.

Types

type Metrics

type Metrics struct {
	// Pending transactions
	PendingTxs metrics.Gauge
}

Metrics represents the txpool metrics

func GetPrometheusMetrics

func GetPrometheusMetrics(namespace string, labelsWithValues ...string) *Metrics

GetPrometheusMetrics return the txpool metrics instance

func NilMetrics

func NilMetrics() *Metrics

NilMetrics will return the non operational txpool metrics

type TxOrigin

type TxOrigin = string
const (
	OriginAddTxn TxOrigin = "addTxn"
	OriginReorg  TxOrigin = "reorg"
	OriginGossip TxOrigin = "gossip"
)

type TxPool

type TxPool struct {

	// Notification channel used so signal added transactions to the pool
	NotifyCh chan struct{}

	// Indicates which txpool operator commands should be implemented
	proto.UnimplementedTxnPoolOperatorServer
	// contains filtered or unexported fields
}

TxPool is module that handles pending transactions.

There are fundamentally 2 queues in the txpool module: - Account based transactions (accountQueues) - Global valid transactions, from any account (pendingQueue)

func NewTxPool

func NewTxPool(
	logger hclog.Logger,
	sealing bool,
	locals []types.Address,
	noLocals bool,
	priceLimit uint64,
	maxSlots uint64,
	forks chain.ForksInTime,
	store store,
	grpcServer *grpc.Server,
	network *network.Server,
	metrics *Metrics,
) (*TxPool, error)

NewTxPool creates a new pool for transactions

func (*TxPool) AddSigner

func (t *TxPool) AddSigner(s signer)

func (*TxPool) AddTx

func (t *TxPool) AddTx(tx *types.Transaction) error

AddTx adds a new transaction to the pool and broadcasts it if networking is enabled

func (*TxPool) AddTxn

func (t *TxPool) AddTxn(ctx context.Context, raw *proto.AddTxnReq) (*proto.AddTxnResp, error)

AddTxn adds a local transaction to the pool

func (*TxPool) DecreaseAccountNonce

func (t *TxPool) DecreaseAccountNonce(tx *types.Transaction)

DecreaseAccountNonce resets the nonce attached to an account whenever a transaction produce an error which is not recoverable, meaning the transaction will be discarded.

Since any discarded transaction should not affect the world state, the nextNonce should be reset to the value it was set to before the transaction appeared.

func (*TxPool) Discard

func (t *TxPool) Discard(slotsToRemove uint64, force bool) ([]*types.Transaction, bool)

func (*TxPool) EnableDev

func (t *TxPool) EnableDev()

EnableDev enables dev mode for the txpool

func (*TxPool) GetCapacity

func (t *TxPool) GetCapacity() (uint64, uint64)

GetCapacity returns the current number of slots occupied and the max slot limit

func (*TxPool) GetNonce

func (t *TxPool) GetNonce(addr types.Address) uint64

GetNonce returns the next nonce for the account -> Returns the value from the TxPool if the account is initialized in-memory -> Returns the value from the world state otherwise

func (*TxPool) GetPendingTx

func (t *TxPool) GetPendingTx(txHash types.Hash) (*types.Transaction, bool)

GetPendingTx returns the transaction by hash in the TxPool (pending txn) [Thread-safe]

func (*TxPool) GetTxs

func (t *TxPool) GetTxs(inclQueued bool) (map[types.Address]map[uint64]*types.Transaction, map[types.Address]map[uint64]*types.Transaction)

GetTxs gets pending and queued transactions

func (*TxPool) Length

func (t *TxPool) Length() uint64

Length returns the size of the valid transactions in the txpool

func (*TxPool) NumAccountTxs

func (t *TxPool) NumAccountTxs(address types.Address) int

NumAccountTxs Returns the number of transactions in the account specific queue

func (*TxPool) Pop

func (t *TxPool) Pop() (*types.Transaction, func())

Pop returns the max priced transaction from the valid transactions heap in txpool

func (*TxPool) ProcessEvent

func (t *TxPool) ProcessEvent(evnt *blockchain.Event)

ProcessEvent processes the blockchain event and updates the txpool accordingly

func (*TxPool) ResetWithHeaders added in v0.1.0

func (t *TxPool) ResetWithHeaders(headers ...*types.Header)

ResetWithHeader does basic txpool housekeeping after a block write

func (*TxPool) Status

func (t *TxPool) Status(ctx context.Context, req *empty.Empty) (*proto.TxnPoolStatusResp, error)

Status implements the GRPC status endpoint. Returns the number of transactions in the pool

func (*TxPool) Subscribe

func (t *TxPool) Subscribe(req *empty.Empty, stream proto.TxnPoolOperator_SubscribeServer) error

Subscribe implements the operator endpoint. It subscribes to new events in the tx pool

func (*TxPool) Underpriced

func (t *TxPool) Underpriced(tx *types.Transaction) bool

Underpriced checks whether given tx's price is less than any in remote transactions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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