public AcceptTxResult Accept(Transaction tx, TxHandlingOptions handlingOptions) { int numberOfSenderTxsInPending = _txs.GetBucketCount(tx.SenderAddress); bool isTxPoolFull = _txs.IsFull(); UInt256 currentNonce = _accounts.GetAccount(tx.SenderAddress !).Nonce; long nextNonceInOrder = (long)currentNonce + numberOfSenderTxsInPending; bool isTxNonceNextInOrder = tx.Nonce <= nextNonceInOrder; if (isTxPoolFull && !isTxNonceNextInOrder) { Metrics.PendingTransactionsNonceGap++; if (_logger.IsTrace) { _logger.Trace($"Skipped adding transaction {tx.ToString(" ")}, nonce in future."); } return(AcceptTxResult.NonceGap.WithMessage($"Future nonce. Expected nonce: {nextNonceInOrder}")); } return(AcceptTxResult.Accepted); }
public AcceptTxResult Accept(Transaction tx, TxHandlingOptions handlingOptions) { IReleaseSpec spec = _specProvider.GetCurrentHeadSpec(); Account account = _accounts.GetAccount(tx.SenderAddress !); UInt256 balance = account.Balance; UInt256 affordableGasPrice = tx.CalculateAffordableGasPrice(spec.IsEip1559Enabled, _headInfo.CurrentBaseFee, balance); bool isNotLocal = (handlingOptions & TxHandlingOptions.PersistentBroadcast) != TxHandlingOptions.PersistentBroadcast; if (_txs.IsFull() && _txs.TryGetLast(out Transaction? lastTx) && affordableGasPrice <= lastTx?.GasBottleneck && isNotLocal) { Metrics.PendingTransactionsTooLowFee++; if (_logger.IsTrace) { _logger.Trace($"Skipped adding transaction {tx.ToString(" ")}, too low payable gas price."); } return(AcceptTxResult.FeeTooLow.WithMessage($"FeePerGas needs to be higher than {lastTx.GasBottleneck.Value} to be added to the TxPool. Affordable FeePerGas of rejected tx: {affordableGasPrice}.")); } return(AcceptTxResult.Accepted); }