core/tx_pool.go: enrich validate tx log

This commit is contained in:
ywzqwwt 2019-08-05 10:49:47 +08:00
parent a7de796840
commit d3b15f2ca8

View file

@ -509,7 +509,7 @@ func (pool *TxPool) local() map[common.Address]types.Transactions {
func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
// Heuristic limit, reject transactions over 32KB to prevent DOS attacks // Heuristic limit, reject transactions over 32KB to prevent DOS attacks
if tx.Size() > 32*1024 { if tx.Size() > 32*1024 {
return ErrOversizedData return fmt.Errorf("%v your txSize:%d;limitSize:%d", ErrOversizedData, tx.Size(), 32*1024)
} }
// Transactions can't be negative. This may never happen using RLP decoded // Transactions can't be negative. This may never happen using RLP decoded
// transactions but may occur if you create a transaction using the RPC. // transactions but may occur if you create a transaction using the RPC.
@ -518,26 +518,26 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
} }
// Ensure the transaction doesn't exceed the current block limit gas. // Ensure the transaction doesn't exceed the current block limit gas.
if pool.currentMaxGas < tx.Gas() { if pool.currentMaxGas < tx.Gas() {
return ErrGasLimit return fmt.Errorf("%v currentMaxGas:%d;tx.Gas():%d", ErrGasLimit, pool.currentMaxGas, tx.Gas())
} }
// Make sure the transaction is signed properly // Make sure the transaction is signed properly
from, err := types.Sender(pool.signer, tx) from, err := types.Sender(pool.signer, tx)
if err != nil { if err != nil {
return ErrInvalidSender return fmt.Errorf("%v err is:%v", ErrInvalidSender, err)
} }
// Drop non-local transactions under our own minimal accepted gas price // Drop non-local transactions under our own minimal accepted gas price
local = local || pool.locals.contains(from) // account may be local even if the transaction arrived from the network local = local || pool.locals.contains(from) // account may be local even if the transaction arrived from the network
if !local && pool.gasPrice.Cmp(tx.GasPrice()) > 0 { if !local && pool.gasPrice.Cmp(tx.GasPrice()) > 0 {
return ErrUnderpriced return fmt.Errorf("%v pool.gasPrice:%d;tx.GasPrice():%d", ErrUnderpriced, pool.gasPrice, tx.GasPrice())
} }
// Ensure the transaction adheres to nonce ordering // Ensure the transaction adheres to nonce ordering
if pool.currentState.GetNonce(from) > tx.Nonce() { if pool.currentState.GetNonce(from) > tx.Nonce() {
return ErrNonceTooLow return fmt.Errorf("%v current pool nonce:%d;tx.Nonce():%d", ErrNonceTooLow, pool.currentState.GetNonce(from), tx.Nonce())
} }
// Transactor should have enough funds to cover the costs // Transactor should have enough funds to cover the costs
// cost == V + GP * GL // cost == V + GP * GL
if pool.currentState.GetBalance(from).Cmp(tx.Cost()) < 0 { if pool.currentState.GetBalance(from).Cmp(tx.Cost()) < 0 {
return ErrInsufficientFunds return fmt.Errorf("%v your balance:%d;tx.Cost():%d", ErrInsufficientFunds, pool.currentState.GetBalance(from), tx.Cost())
} }
// Ensure the transaction has more gas than the basic tx fee. // Ensure the transaction has more gas than the basic tx fee.
intrGas, err := IntrinsicGas(tx.Data(), tx.To() == nil, true) intrGas, err := IntrinsicGas(tx.Data(), tx.To() == nil, true)
@ -545,7 +545,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return err return err
} }
if tx.Gas() < intrGas { if tx.Gas() < intrGas {
return ErrIntrinsicGas return fmt.Errorf("%v your intrGas:%d;tx.Gas():%d", ErrIntrinsicGas, intrGas, tx.Gas())
} }
return nil return nil
} }