txpool

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DDosWhiteList = "whitelist"
	DDosBlackList = "blacklist"
)
View Source
const (
	DefaultPruneTickSeconds      = 300  // ticker duration for pruning account future transactions
	DefaultPromoteOutdateSeconds = 3600 // not promoted account for a long time would be pruned
	// txpool transaction max slots. tx <= 32kB would only take 1 slot. tx > 32kB would take
	// ceil(tx.size / 32kB) slots.
	DefaultMaxSlots = 4096
)

Variables

View Source
var (
	ErrIntrinsicGas        = errors.New("intrinsic gas too low")
	ErrBlockLimitExceeded  = errors.New("exceeds block gas limit")
	ErrNegativeValue       = errors.New("negative value")
	ErrExtractSignature    = errors.New("cannot extract signature")
	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       = errors.New("oversized data")
	ErrReplaceUnderpriced  = errors.New("replacement transaction underpriced")
	ErrBlackList           = errors.New("address in blacklist")
	ErrContractDDOSList    = errors.New("contract in ddos list")
	ErrTxPoolClosed        = errors.New("txpool is close")
	ErrContractDestructive = errors.New("contract is destructive")
)

errors

Functions

This section is empty.

Types

type Config

type Config struct {
	PriceLimit            uint64
	MaxSlots              uint64
	Sealing               bool
	PruneTickSeconds      uint64
	PromoteOutdateSeconds uint64
	BlackList             []types.Address
	DDOSProtection        bool
	DestructiveContracts  []types.Address
}

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

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

func (*Metrics) AddEnqueueTxs added in v1.2.2

func (m *Metrics) AddEnqueueTxs(v float64)

func (*Metrics) AddPendingTxs added in v1.2.2

func (m *Metrics) AddPendingTxs(v float64)

func (*Metrics) Register added in v1.2.2

func (m *Metrics) Register()

func (*Metrics) SetEnqueueTxs added in v1.2.2

func (m *Metrics) SetEnqueueTxs(v float64)

func (*Metrics) SetPendingTxs added in v1.2.2

func (m *Metrics) SetPendingTxs(v float64)

type TxPool

type TxPool struct {

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

TxPool is a module that handles pending transactions. All transactions are handled within their respective accounts. An account contains 2 queues a transaction needs to go through:

1. Enqueued (entry point) 2. Promoted (exit point)

both queues are min nonce ordered

When consensus needs to process promoted transactions, the pool generates a queue of "executable" transactions. These transactions are the first-in-line of some promoted queue, ready to be written to the state (primaries).

TODO: Refactor its interface, only expose input methods and events subscription for those who interest in. Its state shouldn't be manipulated by other components. This means it is self-contained and self-consistent. Get enough promotable txs once and for all. Enough is enough, so we could keep it consise and bug-free.

func NewTxPool

func NewTxPool(
	logger hclog.Logger,
	forks chain.ForksInTime,
	store store,
	grpcServer *grpc.Server,
	network network.Server,
	metrics *Metrics,
	config *Config,
) (*TxPool, error)

NewTxPool returns a new pool for processing incoming transactions.

func (*TxPool) AddTx

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

AddTx adds a new transaction to the pool (sent from json-RPC/gRPC endpoints) and broadcasts it to the network (if enabled).

func (*TxPool) AddTxn

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

AddTxn adds a local transaction to the pool

func (*TxPool) AddWhitelistContracts added in v1.2.2

func (p *TxPool) AddWhitelistContracts(contracts []string) (count int)

func (*TxPool) Close

func (p *TxPool) Close()

Close shuts down the pool's main loop.

func (*TxPool) DeleteWhitelistContracts added in v1.2.2

func (p *TxPool) DeleteWhitelistContracts(contracts []string) (count int)

func (*TxPool) DemoteAllPromoted added in v1.1.3

func (p *TxPool) DemoteAllPromoted(tx *types.Transaction, correctNonce uint64)

DemoteAllPromoted clears all promoted transactions of the account which might be not promotable

clears all promoted transactions of the account, re-add them to the txpool, and reset the nonce

func (*TxPool) Drop

func (p *TxPool) Drop(tx *types.Transaction)

Drop clears the entire account associated with the given transaction and reverts its next (expected) nonce.

func (*TxPool) GetCapacity

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

GetCapacity returns the current number of slots occupied in the pool as well as the max limit

func (*TxPool) GetDDosContractList added in v1.2.2

func (p *TxPool) GetDDosContractList() map[string]map[types.Address]int

GetDDosContractList shows current white list and black list contracts

func (*TxPool) GetNonce

func (p *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 (p *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 (p *TxPool) GetTxs(inclQueued bool) (
	allPromoted, allEnqueued map[types.Address][]*types.Transaction,
)

GetTxs gets pending and queued transactions

func (*TxPool) IsDDOSTx added in v1.2.1

func (p *TxPool) IsDDOSTx(tx *types.Transaction) bool

IsDDOSTx returns whether a contract transaction marks as ddos attack

func (*TxPool) IsDestructiveTx added in v1.2.4

func (p *TxPool) IsDestructiveTx(tx *types.Transaction) bool

func (*TxPool) Length

func (p *TxPool) Length() uint64

Length returns the total number of all promoted transactions.

func (*TxPool) MarkDDOSTx added in v1.2.1

func (p *TxPool) MarkDDOSTx(tx *types.Transaction)

MarkDDOSTx marks resource consuming transaction as a might-be attack

func (*TxPool) Pending added in v1.2.0

func (p *TxPool) Pending() map[types.Address][]*types.Transaction

func (*TxPool) Pop

func (p *TxPool) Pop() *types.Transaction

Pop returns the best-price selected transaction ready for execution.

func (*TxPool) Prepare

func (p *TxPool) Prepare()

Prepare generates all the transactions ready for execution. (primaries)

func (*TxPool) RemoveExecuted added in v1.1.3

func (p *TxPool) RemoveExecuted(tx *types.Transaction)

RemoveExecuted removes the executed transaction from promoted queue

Will update executables with the next primary from that account (if any).

func (*TxPool) ResetWithHeaders

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

ResetWithHeaders processes the transactions from the new headers to sync the pool with the new state.

func (*TxPool) SetSealing added in v1.1.4

func (p *TxPool) SetSealing(sealing bool)

SetSealing sets the sealing flag

func (*TxPool) SetSigner

func (p *TxPool) SetSigner(s signer)

SetSigner sets the signer the pool will use to validate a transaction's signature.

func (*TxPool) Start

func (p *TxPool) Start()

Start runs the pool's main loop in the background. On each request received, the appropriate handler is invoked in a separate goroutine.

func (*TxPool) Status

func (p *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

Length is deprecated. Use pendingLength, enqueuedLength instead.

func (*TxPool) Subscribe

func (p *TxPool) Subscribe(
	request *proto.SubscribeRequest,
	stream proto.TxnPoolOperator_SubscribeServer,
) error

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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