validateTx checks whether a transaction is valid according to the consensus rules and adheres to some heuristic limits of the local node (price and size).
(tx *types.Transaction, local bool)
| 663 | // validateTx checks whether a transaction is valid according to the consensus |
| 664 | // rules and adheres to some heuristic limits of the local node (price and size). |
| 665 | func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { |
| 666 | // Return early if the tx type is not supported! |
| 667 | if !types.SupportTxType(tx.Type()) { |
| 668 | return types.ErrNotSupportedTxType |
| 669 | } |
| 670 | // Heuristic limit, reject transactions over 32KB to prevent DOS attacks |
| 671 | if tx.Size() > 32*1024 { |
| 672 | return ErrOversizedData |
| 673 | } |
| 674 | // Transactions can't be negative. This may never happen using RLP decoded |
| 675 | // transactions but may occur if you create a transaction using the RPC. |
| 676 | if tx.Value().Sign() < 0 { |
| 677 | return ErrNegativeValue |
| 678 | } |
| 679 | // Ensure the transaction doesn't exceed the current block limit gas. |
| 680 | if pool.currentMaxGas < tx.Gas() { |
| 681 | return ErrGasLimit |
| 682 | } |
| 683 | // Make sure the transaction is signed properly |
| 684 | from, err := types.Sender(pool.signer, tx) |
| 685 | if err != nil { |
| 686 | return ErrInvalidSender |
| 687 | } |
| 688 | // Drop non-local transactions under our own minimal accepted gas price |
| 689 | local = local || pool.locals.contains(from) // account may be local even if the transaction arrived from the network |
| 690 | if !local && pool.gasPrice.Cmp(tx.GasPrice()) > 0 { |
| 691 | return ErrUnderpriced |
| 692 | } |
| 693 | // Ensure the transaction adheres to nonce ordering |
| 694 | if pool.currentState.GetNonce(from) > tx.Nonce() { |
| 695 | return ErrNonceTooLow |
| 696 | } |
| 697 | // Transactor should have enough funds to cover the costs |
| 698 | // cost == V + GP * GL |
| 699 | if pool.currentState.GetBalance(from).Cmp(tx.Cost()) < 0 { |
| 700 | return ErrInsufficientFunds |
| 701 | } |
| 702 | intrGas, err := IntrinsicGas(tx.Data(), tx.To() == nil) |
| 703 | if err != nil { |
| 704 | return err |
| 705 | } |
| 706 | if tx.Gas() < intrGas { |
| 707 | return ErrIntrinsicGas |
| 708 | } |
| 709 | return nil |
| 710 | } |
| 711 | |
| 712 | // add validates a transaction and inserts it into the non-executable queue for |
| 713 | // later pending promotion and execution. If the transaction is a replacement for |
no test coverage detected