txpool

package
v0.0.0-...-91a82d4 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: LGPL-3.0 Imports: 19 Imported by: 4

README

txpool

  1. receive transactions
  2. verify transactions
  3. prepare transactions for consensus
  4. maintaining all cached transactions

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOutOfGas is returned if the transaction executing out of gas
	ErrOutOfGas = errors.New("out of gas")

	// ErrInvalidSender is returned if the transaction contains an invalid signature.
	ErrInvalidSender = errors.New("invalid sender")

	// ErrNonceTooLow is returned if the nonce of a transaction is lower than the
	// one present in the local chain.
	ErrNonceTooLow = errors.New("nonce too low")

	// ErrUnderpriced is returned if a transaction's gas price is below the minimum
	// configured for the transaction pool.
	ErrUnderPriced = errors.New("transaction underpriced")

	// ErrReplaceUnderpriced is returned if a transaction is attempted to be replaced
	// with a different one without the required price bump.
	ErrReplaceUnderpriced = errors.New("replacement transaction underpriced")

	// ErrInsufficientFunds is returned if the total cost of executing a transaction
	// is higher than the balance of the user's account.
	ErrInsufficientFunds = errors.New("insufficient funds for gas * price + value")

	// ErrInsufficientLockedFunds is returned if the value of executing a transaction
	// is higher than the balance of the user's locked account.
	ErrInsufficientLockedFunds = errors.New("insufficient locked funds for value")
	// ErrInsufficientFeeFunds is returned if the fee of executing a transaction
	// is higher than the balance of the user's account.
	ErrInsufficientFeeFunds = errors.New("insufficient fee funds for gas * price")

	// ErrIntrinsicGas is returned if the transaction is specified to use less gas
	// than required to start the invocation.
	ErrIntrinsicGas = errors.New("intrinsic gas too low")

	// ErrGasLimit is returned if a transaction's requested gas limit exceeds the
	// maximum allowance of the current block.
	ErrGasLimit = errors.New("exceeds block gas limit")

	// ErrNegativeValue is a sanity error to ensure noone is able to specify a
	// transaction with a negative value.
	ErrNegativeValue = errors.New("negative value")

	// ErrOversizedData is returned if the input data of a transaction is greater
	// than some meaningful limit a user might use. This is not a consensus error
	// making the transaction invalid, rather a DOS protection.
	ErrOversizedData = errors.New("oversized data")
)
View Source
var DefaultTxPoolConfig = Config{

	PriceLimit: 1,
	PriceBump:  10,

	AccountSlots: 16,
	GlobalSlots:  4096,
	AccountQueue: 64,
	GlobalQueue:  1024,

	TimeoutDuration: 3 * time.Hour,
}

DefaultTxPoolConfig contains the default configurations for the transaction pool.

Functions

func IntrinsicGas

func IntrinsicGas(data []byte, tp types.TxType, contractCreation bool) (uint64, error)

IntrinsicGas computes the 'intrinsic gas' for a message with the given data.

func TxDifference

func TxDifference(a, b types.Transactions) types.Transactions

TxDifference returns a new set which is the difference between a and b.

Types

type Config

type Config struct {
	PriceLimit uint64 `mapstructure:"txpool-pricelimit"`
	PriceBump  uint64 `mapstructure:"txpool-pricebump"`

	AccountSlots uint64 `mapstructure:"txpool-accountslots"`
	GlobalSlots  uint64 `mapstructure:"txpool-globalslots"`
	AccountQueue uint64 `mapstructure:"txpool-accountqueue"`
	GlobalQueue  uint64 `mapstructure:"txpool-globalqueue"`

	TimeoutDuration time.Duration `mapstructure:"txpool-timeout"`
}

Config are the configuration parameters of the transaction pool.

type TxPool

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

TxPool contains all currently known transactions.

func New

func New(config *Config, chainconfig *params.ChainConfig, chain blockChainHelper) *TxPool

New creates a new transaction pool to gather, sort and filter inbound transactions from the network.

func (*TxPool) Actions

func (tp *TxPool) Actions() []*types.Action

Actions get actions

func (*TxPool) AddAction

func (tp *TxPool) AddAction(a *types.Action)

func (*TxPool) AddTx

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

func (*TxPool) AddTxs

func (tp *TxPool) AddTxs(txs []*types.Transaction) []error

func (*TxPool) AddTxsChan

func (tp *TxPool) AddTxsChan(txs types.Transactions) bool

func (*TxPool) Content

Content retrieves the data content of the transaction pool, returning all the pending as well as queued transactions, grouped by account and sorted by nonce.

func (*TxPool) GasPrice

func (tp *TxPool) GasPrice() *big.Int

GasPrice returns the current gas price enforced by the transaction tp.

func (*TxPool) Get

func (tp *TxPool) Get(hash utils.Hash) *types.Transaction

Get returns a transaction if it is contained in the pool and nil otherwise.

func (*TxPool) Pending

func (tp *TxPool) Pending() (map[utils.Address]types.Transactions, error)

Pending retrieves all currently processable transactions, groupped by origin account and sorted by nonce. The returned transaction set is a copy and can be freely modified by calling code.

func (*TxPool) SetGasPrice

func (tp *TxPool) SetGasPrice(price *big.Int)

SetGasPrice updates the minimum price required by the transaction pool for a new transaction, and drops all transactions below this threshold.

func (*TxPool) State

func (tp *TxPool) State() *state.ManagedState

State returns the virtual managed state of the transaction tp.

func (*TxPool) Stats

func (tp *TxPool) Stats() (int, int)

Stats retrieves the current pool stats, namely the number of pending and the number of queued (non-executable) transactions.

func (*TxPool) Status

func (tp *TxPool) Status(hashes []utils.Hash) []TxStatus

Status returns the status (unknown/pending/queued) of a batch of transactions identified by their hashes.

func (*TxPool) Stop

func (tp *TxPool) Stop()

Stop stop the transaction pool.

func (*TxPool) SubscribeNewTxsEvent

func (tp *TxPool) SubscribeNewTxsEvent(ch chan<- feed.NewTxsEvent) feed.Subscription

SubscribeNewTxsEvent registers a subscription of NewTxsEvent and starts sending event to the given channel.

type TxStatus

type TxStatus uint

TxStatus is the current status of a transaction as seen by the pool.

const (
	TxStatusUnknown TxStatus = iota
	TxStatusQueued
	TxStatusPending
)

Jump to

Keyboard shortcuts

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