Documentation ¶
Index ¶
- Variables
- func IntrinsicGas(tx types.Transaction) (uint64, error)
- func IsValidIP(ip string) bool
- type Config
- type EffectiveGasPrice
- func (e *EffectiveGasPrice) CalculateBreakEvenGasPrice(rawTx []byte, txGasPrice *big.Int, txGasUsed uint64, l1GasPrice uint64) (*big.Int, error)
- func (e *EffectiveGasPrice) CalculateEffectiveGasPrice(rawTx []byte, txGasPrice *big.Int, txGasUsed uint64, l1GasPrice uint64, ...) (*big.Int, error)
- func (e *EffectiveGasPrice) CalculateEffectiveGasPricePercentage(gasPrice *big.Int, effectiveGasPrice *big.Int) (uint8, error)
- func (e *EffectiveGasPrice) GetFinalDeviation() uint64
- func (e *EffectiveGasPrice) GetTxAndL2GasPrice(txGasPrice *big.Int, l1GasPrice uint64, l2GasPrice uint64) (egpTxGasPrice *big.Int, egpL2GasPrice uint64)
- func (e *EffectiveGasPrice) IsEnabled() bool
- type EffectiveGasPriceCfg
- type GasPrices
- type Pool
- func (p *Pool) AddTx(ctx context.Context, tx types.Transaction, ip string) error
- func (p *Pool) CalculateEffectiveGasPrice(rawTx []byte, txGasPrice *big.Int, txGasUsed uint64, l1GasPrice uint64, ...) (*big.Int, error)
- func (p *Pool) CalculateEffectiveGasPricePercentage(gasPrice *big.Int, effectiveGasPrice *big.Int) (uint8, error)
- func (p *Pool) CountPendingTransactions(ctx context.Context) (uint64, error)
- func (p *Pool) DeleteGasPricesHistoryOlderThan(ctx context.Context, date time.Time) error
- func (p *Pool) DeleteReorgedTransactions(ctx context.Context, transactions []*types.Transaction) error
- func (p *Pool) EffectiveGasPriceEnabled() bool
- func (p *Pool) GetDefaultMinGasPriceAllowed() uint64
- func (p *Pool) GetGasPrices(ctx context.Context) (GasPrices, error)
- func (p *Pool) GetL1AndL2GasPrice() (uint64, uint64)
- func (p *Pool) GetNonWIPPendingTxs(ctx context.Context) ([]Transaction, error)
- func (p *Pool) GetPendingTxHashesSince(ctx context.Context, since time.Time) ([]common.Hash, error)
- func (p *Pool) GetPendingTxs(ctx context.Context, limit uint64) ([]Transaction, error)
- func (p *Pool) GetSelectedTxs(ctx context.Context, limit uint64) ([]Transaction, error)
- func (p *Pool) IsTxPending(ctx context.Context, hash common.Hash) (bool, error)
- func (p *Pool) SetGasPrices(ctx context.Context, l2GasPrice uint64, l1GasPrice uint64) error
- func (p *Pool) StartPollingMinSuggestedGasPrice(ctx context.Context)
- func (p *Pool) StartRefreshingBlockedAddressesPeriodically()
- func (p *Pool) StoreTx(ctx context.Context, tx types.Transaction, ip string, isWIP bool) error
- func (p *Pool) UpdateTxStatus(ctx context.Context, hash common.Hash, newStatus TxStatus, isWIP bool, ...) error
- func (p *Pool) UpdateTxWIPStatus(ctx context.Context, hash common.Hash, isWIP bool) error
- func (p *Pool) ValidateBreakEvenGasPrice(ctx context.Context, tx types.Transaction, preExecutionGasUsed uint64, ...) error
- type Transaction
- type TxStatus
- type TxStatusUpdateInfo
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEffectiveGasPriceEmpty happens when the effectiveGasPrice or gasPrice is nil or zero ErrEffectiveGasPriceEmpty = errors.New("effectiveGasPrice or gasPrice cannot be nil or zero") // ErrEffectiveGasPriceIsZero happens when the calculated EffectiveGasPrice is zero ErrEffectiveGasPriceIsZero = errors.New("effectiveGasPrice cannot be zero") )
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") // 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") // ErrTxPoolAccountOverflow is returned if the account sending the transaction // has already reached the limit of transactions in the pool set by the config // AccountQueue and can't accept another remote transaction. ErrTxPoolAccountOverflow = errors.New("account has reached the tx limit in the txpool") // ErrTxPoolOverflow is returned if the transaction pool is full and can't accept // another remote transaction. ErrTxPoolOverflow = errors.New("txpool is full") // 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") // ErrNonceTooHigh is returned if the nonce of a transaction is higher than the // current + the configured AccountQueue. ErrNonceTooHigh = errors.New("nonce too high") // 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") // ErrReceivedZeroL1GasPrice is returned if the L1 gas price is 0. ErrReceivedZeroL1GasPrice = errors.New("received L1 gas price 0") // ErrInvalidIP is returned if the IP address is invalid. ErrInvalidIP = errors.New("invalid IP address") // ErrOutOfCounters is returned if the pool is out of counters. ErrOutOfCounters = errors.New("out of counters") // ErrZeroL1GasPrice is returned if the L1 gas price is 0. ErrZeroL1GasPrice = errors.New("L1 gas price 0") )
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") // ErrEffectiveGasPriceGasPriceTooLow the tx gas price is lower than breakEvenGasPrice and lower than L2GasPrice ErrEffectiveGasPriceGasPriceTooLow = errors.New("effective gas price: gas price too low") )
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"` // IntervalToRefreshGasPrices is the time to wait to refresh the gas prices IntervalToRefreshGasPrices types.Duration `mapstructure:"IntervalToRefreshGasPrices"` // 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"` // AccountQueue represents the maximum number of non-executable transaction slots permitted per account AccountQueue uint64 `mapstructure:"AccountQueue"` // GlobalQueue represents the maximum number of non-executable transaction slots for all accounts GlobalQueue uint64 `mapstructure:"GlobalQueue"` // EffectiveGasPrice is the config for the effective gas price calculation EffectiveGasPrice EffectiveGasPriceCfg `mapstructure:"EffectiveGasPrice"` // ForkID is the current fork ID of the chain ForkID uint64 `mapstructure:"ForkID"` }
Config is the pool configuration
type EffectiveGasPrice ¶ added in v0.4.0
type EffectiveGasPrice struct {
// contains filtered or unexported fields
}
EffectiveGasPrice implements the effective gas prices calculations and checks
func NewEffectiveGasPrice ¶ added in v0.4.0
func NewEffectiveGasPrice(cfg EffectiveGasPriceCfg) *EffectiveGasPrice
NewEffectiveGasPrice creates and initializes an instance of EffectiveGasPrice
func (*EffectiveGasPrice) CalculateBreakEvenGasPrice ¶ added in v0.4.0
func (e *EffectiveGasPrice) CalculateBreakEvenGasPrice(rawTx []byte, txGasPrice *big.Int, txGasUsed uint64, l1GasPrice uint64) (*big.Int, error)
CalculateBreakEvenGasPrice calculates the break even gas price for a transaction
func (*EffectiveGasPrice) CalculateEffectiveGasPrice ¶ added in v0.4.0
func (e *EffectiveGasPrice) CalculateEffectiveGasPrice(rawTx []byte, txGasPrice *big.Int, txGasUsed uint64, l1GasPrice uint64, l2GasPrice uint64) (*big.Int, error)
CalculateEffectiveGasPrice calculates the final effective gas price for a tx
func (*EffectiveGasPrice) CalculateEffectiveGasPricePercentage ¶ added in v0.4.0
func (e *EffectiveGasPrice) CalculateEffectiveGasPricePercentage(gasPrice *big.Int, effectiveGasPrice *big.Int) (uint8, error)
CalculateEffectiveGasPricePercentage calculates the gas price's effective percentage
func (*EffectiveGasPrice) GetFinalDeviation ¶ added in v0.4.0
func (e *EffectiveGasPrice) GetFinalDeviation() uint64
GetFinalDeviation return the value for the config parameter FinalDeviationPct
func (*EffectiveGasPrice) GetTxAndL2GasPrice ¶ added in v0.4.0
func (e *EffectiveGasPrice) GetTxAndL2GasPrice(txGasPrice *big.Int, l1GasPrice uint64, l2GasPrice uint64) (egpTxGasPrice *big.Int, egpL2GasPrice uint64)
GetTxAndL2GasPrice return the tx gas price and l2 suggested gas price to use in egp calculations If egp is disabled we will use a "simulated" tx and l2 gas price, that is calculated using the L2GasPriceSuggesterFactor config param
func (*EffectiveGasPrice) IsEnabled ¶ added in v0.4.0
func (e *EffectiveGasPrice) IsEnabled() bool
IsEnabled return if effectiveGasPrice calculation is enabled
type EffectiveGasPriceCfg ¶ added in v0.4.0
type EffectiveGasPriceCfg struct { // Enabled is a flag to enable/disable the effective gas price Enabled bool `mapstructure:"Enabled"` // L1GasPriceFactor is the percentage of the L1 gas price that will be used as the L2 min gas price L1GasPriceFactor float64 `mapstructure:"L1GasPriceFactor"` // ByteGasCost is the gas cost per byte that is not 0 ByteGasCost uint64 `mapstructure:"ByteGasCost"` // ZeroByteGasCost is the gas cost per byte that is 0 ZeroByteGasCost uint64 `mapstructure:"ZeroByteGasCost"` // NetProfit is the profit margin to apply to the calculated breakEvenGasPrice NetProfit float64 `mapstructure:"NetProfit"` // BreakEvenFactor is the factor to apply to the calculated breakevenGasPrice when comparing it with the gasPriceSigned of a tx BreakEvenFactor float64 `mapstructure:"BreakEvenFactor"` // FinalDeviationPct is the max allowed deviation percentage BreakEvenGasPrice on re-calculation FinalDeviationPct uint64 `mapstructure:"FinalDeviationPct"` // EthTransferGasPrice is the fixed gas price returned as effective gas price for txs tha are ETH transfers (0 means disabled) // Only one of EthTransferGasPrice or EthTransferL1GasPriceFactor params can be different than 0. If both params are set to 0, the sequencer will halt and log an error EthTransferGasPrice uint64 `mapstructure:"EthTransferGasPrice"` // EthTransferL1GasPriceFactor is the percentage of L1 gas price returned as effective gas price for txs tha are ETH transfers (0 means disabled) // Only one of EthTransferGasPrice or EthTransferL1GasPriceFactor params can be different than 0. If both params are set to 0, the sequencer will halt and log an error EthTransferL1GasPriceFactor float64 `mapstructure:"EthTransferL1GasPriceFactor"` // L2GasPriceSuggesterFactor is the factor to apply to L1 gas price to get the suggested L2 gas price used in the // calculations when the effective gas price is disabled (testing/metrics purposes) L2GasPriceSuggesterFactor float64 `mapstructure:"L2GasPriceSuggesterFactor"` }
EffectiveGasPriceCfg contains the configuration properties for the effective gas price
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, batchConstraintsCfg state.BatchConstraintsCfg, s storage, st stateInterface, chainID uint64, eventLog *event.EventLog) *Pool
NewPool creates and initializes an instance of Pool
func (*Pool) CalculateEffectiveGasPrice ¶ added in v0.4.5
func (p *Pool) CalculateEffectiveGasPrice(rawTx []byte, txGasPrice *big.Int, txGasUsed uint64, l1GasPrice uint64, l2GasPrice uint64) (*big.Int, error)
CalculateEffectiveGasPrice calculates the final effective gas price for a tx
func (*Pool) CalculateEffectiveGasPricePercentage ¶ added in v0.4.6
func (p *Pool) CalculateEffectiveGasPricePercentage(gasPrice *big.Int, effectiveGasPrice *big.Int) (uint8, error)
CalculateEffectiveGasPricePercentage calculates the gas price's effective percentage
func (*Pool) CountPendingTransactions ¶
CountPendingTransactions get number of pending transactions used in bench tests
func (*Pool) DeleteGasPricesHistoryOlderThan ¶ added in v0.0.990
DeleteGasPricesHistoryOlderThan deletes gas prices older than a given date except the most recent one
func (*Pool) DeleteReorgedTransactions ¶
func (p *Pool) DeleteReorgedTransactions(ctx context.Context, transactions []*types.Transaction) error
DeleteReorgedTransactions deletes transactions from the pool
func (*Pool) EffectiveGasPriceEnabled ¶ added in v0.4.5
EffectiveGasPriceEnabled returns if effective gas price calculation is enabled or not
func (*Pool) GetDefaultMinGasPriceAllowed ¶ added in v0.0.990
GetDefaultMinGasPriceAllowed return the configured DefaultMinGasPriceAllowed value
func (*Pool) GetGasPrices ¶ added in v0.0.990
GetGasPrices returns the current L2 Gas Price and L1 Gas Price
func (*Pool) GetL1AndL2GasPrice ¶ added in v0.4.0
GetL1AndL2GasPrice returns the L1 and L2 gas price from memory struct
func (*Pool) GetNonWIPPendingTxs ¶
func (p *Pool) GetNonWIPPendingTxs(ctx context.Context) ([]Transaction, error)
GetNonWIPPendingTxs from the pool
func (*Pool) GetPendingTxHashesSince ¶
GetPendingTxHashesSince returns the hashes of pending tx since the given date.
func (*Pool) GetPendingTxs ¶
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 ¶
GetSelectedTxs gets selected txs from the pool db
func (*Pool) IsTxPending ¶
IsTxPending check if tx is still pending
func (*Pool) SetGasPrices ¶ added in v0.0.990
SetGasPrices sets the current L2 Gas Price and L1 Gas Price
func (*Pool) StartPollingMinSuggestedGasPrice ¶
StartPollingMinSuggestedGasPrice starts polling the minimum suggested gas price
func (*Pool) StartRefreshingBlockedAddressesPeriodically ¶ added in v0.0.990
func (p *Pool) StartRefreshingBlockedAddressesPeriodically()
StartRefreshingBlockedAddressesPeriodically will make this instance of the pool to check periodically(accordingly to the configuration) for updates regarding the blocked address and update the in memory blocked addresses
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 ¶
UpdateTxWIPStatus updates a transaction wip status accordingly to the provided WIP status and hash
func (*Pool) ValidateBreakEvenGasPrice ¶ added in v0.4.0
func (p *Pool) ValidateBreakEvenGasPrice(ctx context.Context, tx types.Transaction, preExecutionGasUsed uint64, gasPrices GasPrices) error
ValidateBreakEvenGasPrice validates the effective gas price
type Transaction ¶
type Transaction struct { types.Transaction Status TxStatus state.ZKCounters ReservedZKCounters 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) *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 TxStatusFailed TxStatus = "failed" )