pool

package
v0.1.0-RC2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: AGPL-3.0, AGPL-3.0-or-later Imports: 17 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidChainID is returned when the transaction has a different chain id
	// than the chain id of the network
	ErrInvalidChainID = errors.New("invalid chain id")

	// ErrTxTypeNotSupported is returned if a transaction is not supported in the
	// current network configuration.
	ErrTxTypeNotSupported = types.ErrTxTypeNotSupported

	// 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")

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

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

	// ErrBlockedSender is returned if the transaction is sent by a blocked account.
	ErrBlockedSender = errors.New("blocked 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")

	// 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")

	// 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")

	// ErrGasUintOverflow is returned when calculating gas usage.
	ErrGasUintOverflow = errors.New("gas uint64 overflow")

	// ErrGasPrice is returned if the transaction has specified lower gas price than the minimum allowed.
	ErrGasPrice = errors.New("gas price too low")
)
View Source
var (
	// ErrNotFound indicates an object has not been found for the search criteria used
	ErrNotFound = errors.New("object not found")

	// ErrAlreadyKnown is returned if the transactions is already contained
	// within the pool.
	ErrAlreadyKnown = errors.New("already known")

	// 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")
)

Functions

func IntrinsicGas

func IntrinsicGas(tx types.Transaction) (uint64, error)

IntrinsicGas computes the 'intrinsic gas' for a given transaction.

Types

type Config

type Config struct {
	// IntervalToRefreshBlockedAddresses is the time it takes to sync the
	// blocked address list from db to memory
	IntervalToRefreshBlockedAddresses types.Duration `mapstructure:"IntervalToRefreshBlockedAddresses"`

	// MaxTxBytesSize is the max size of a transaction in bytes
	MaxTxBytesSize uint64 `mapstructure:"MaxTxBytesSize"`

	// MaxTxDataBytesSize is the max size of the data field of a transaction in bytes
	MaxTxDataBytesSize int `mapstructure:"MaxTxDataBytesSize"`

	// DB is the database configuration
	DB db.Config `mapstructure:"DB"`

	// DefaultMinGasPriceAllowed is the default min gas price to suggest
	DefaultMinGasPriceAllowed uint64 `mapstructure:"DefaultMinGasPriceAllowed"`

	// MinAllowedGasPriceInterval is the interval to look back of the suggested min gas price for a tx
	MinAllowedGasPriceInterval types.Duration `mapstructure:"MinAllowedGasPriceInterval"`

	// PollMinAllowedGasPriceInterval is the interval to poll the suggested min gas price for a tx
	PollMinAllowedGasPriceInterval types.Duration `mapstructure:"PollMinAllowedGasPriceInterval"`
}

Config is the pool configuration

type Pool

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

Pool is an implementation of the Pool interface that uses a postgres database to store the data

func NewPool

func NewPool(cfg Config, s storage, st stateInterface, l2BridgeAddr common.Address, chainID uint64, eventLog *event.EventLog) *Pool

NewPool creates and initializes an instance of Pool

func (*Pool) AddTx

func (p *Pool) AddTx(ctx context.Context, tx types.Transaction, ip string) error

AddTx adds a transaction to the pool with the pending state

func (*Pool) CountPendingTransactions

func (p *Pool) CountPendingTransactions(ctx context.Context) (uint64, error)

CountPendingTransactions get number of pending transactions used in bench tests

func (*Pool) DeleteReorgedTransactions

func (p *Pool) DeleteReorgedTransactions(ctx context.Context, transactions []*types.Transaction) error

DeleteReorgedTransactions deletes transactions from the pool

func (*Pool) GetGasPrice

func (p *Pool) GetGasPrice(ctx context.Context) (uint64, error)

GetGasPrice returns the current gas price

func (*Pool) GetNonWIPPendingTxs

func (p *Pool) GetNonWIPPendingTxs(ctx context.Context, limit uint64) ([]Transaction, error)

GetNonWIPPendingTxs from the pool limit parameter is used to limit amount of pending txs from the db, if limit = 0, then there is no limit

func (*Pool) GetPendingTxHashesSince

func (p *Pool) GetPendingTxHashesSince(ctx context.Context, since time.Time) ([]common.Hash, error)

GetPendingTxHashesSince returns the hashes of pending tx since the given date.

func (*Pool) GetPendingTxs

func (p *Pool) GetPendingTxs(ctx context.Context, limit uint64) ([]Transaction, error)

GetPendingTxs from the pool limit parameter is used to limit amount of pending txs from the db, if limit = 0, then there is no limit

func (*Pool) GetSelectedTxs

func (p *Pool) GetSelectedTxs(ctx context.Context, limit uint64) ([]Transaction, error)

GetSelectedTxs gets selected txs from the pool db

func (*Pool) IsTxPending

func (p *Pool) IsTxPending(ctx context.Context, hash common.Hash) (bool, error)

IsTxPending check if tx is still pending

func (*Pool) PreExecuteTx

func (p *Pool) PreExecuteTx(ctx context.Context, tx types.Transaction) (preExecutionResponse, error)

PreExecuteTx executes a transaction to calculate its zkCounters

func (*Pool) SetGasPrice

func (p *Pool) SetGasPrice(ctx context.Context, gasPrice uint64) error

SetGasPrice allows an external component to define the gas price

func (*Pool) StartPollingMinSuggestedGasPrice

func (p *Pool) StartPollingMinSuggestedGasPrice(ctx context.Context)

StartPollingMinSuggestedGasPrice starts polling the minimum suggested gas price

func (*Pool) StoreTx

func (p *Pool) StoreTx(ctx context.Context, tx types.Transaction, ip string, isWIP bool) error

StoreTx adds a transaction to the pool with the pending state

func (*Pool) UpdateTxStatus

func (p *Pool) UpdateTxStatus(ctx context.Context, hash common.Hash, newStatus TxStatus, isWIP bool, failedReason *string) error

UpdateTxStatus updates a transaction state accordingly to the provided state and hash

func (*Pool) UpdateTxWIPStatus

func (p *Pool) UpdateTxWIPStatus(ctx context.Context, hash common.Hash, isWIP bool) error

UpdateTxWIPStatus updates a transaction wip status accordingly to the provided WIP status and hash

type Transaction

type Transaction struct {
	types.Transaction
	Status TxStatus
	state.ZKCounters
	ReceivedAt            time.Time
	PreprocessedStateRoot common.Hash
	IsWIP                 bool
	IP                    string
	FailedReason          *string
}

Transaction represents a pool tx

func NewTransaction

func NewTransaction(tx types.Transaction, ip string, isWIP bool, p *Pool) *Transaction

NewTransaction creates a new transaction

type TxStatus

type TxStatus string

TxStatus represents the state of a tx

const (
	// TxStatusPending represents a tx that has not been processed
	TxStatusPending TxStatus = "pending"
	// TxStatusInvalid represents an invalid tx
	TxStatusInvalid TxStatus = "invalid"
	// TxStatusSelected represents a tx that has been selected
	TxStatusSelected TxStatus = "selected"
	// TxStatusFailed represents a tx that has been failed after processing, but can be processed in the future
	TxStatusFailed TxStatus = "failed"
)

func (TxStatus) String

func (s TxStatus) String() string

String returns a representation of the tx state in a string format

type TxStatusUpdateInfo added in v0.0.990

type TxStatusUpdateInfo struct {
	Hash         common.Hash
	NewStatus    TxStatus
	IsWIP        bool
	FailedReason *string
}

TxStatusUpdateInfo represents the information needed to update the status of a tx

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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