Created
October 12, 2016 10:16
-
-
Save obscuren/a39c43ce9aa29522917801a165aefd95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (pool *TxPool) validateTx(tx *types.Transaction) error { | |
local := pool.localTx.contains(tx.Hash()) | |
// Drop transactions under our own minimal accepted gas price | |
if !local && pool.minGasPrice.Cmp(tx.GasPrice()) > 0 { | |
return ErrCheap | |
} | |
currentState, err := pool.currentState() | |
if err != nil { | |
return err | |
} | |
from, err := tx.From() | |
if err != nil { | |
return ErrInvalidSender | |
} | |
// Make sure the account exist. Non existent accounts | |
// haven't got funds and well therefor never pass. | |
if !currentState.Exist(from) { | |
return ErrNonExistentAccount | |
} | |
// Last but not least check for nonce errors | |
if currentState.GetNonce(from) > tx.Nonce() { | |
return ErrNonce | |
} | |
// Check the transaction doesn't exceed the current | |
// block limit gas. | |
if pool.gasLimit().Cmp(tx.Gas()) < 0 { | |
return ErrGasLimit | |
} | |
// Transactions can't be negative. This may never happen | |
// using RLP decoded transactions but may occur if you create | |
// a transaction using the RPC for example. | |
if tx.Value().Cmp(common.Big0) < 0 { | |
return ErrNegativeValue | |
} | |
// Transactor should have enough funds to cover the costs | |
// cost == V + GP * GL | |
if currentState.GetBalance(from).Cmp(tx.Cost()) < 0 { | |
return ErrInsufficientFunds | |
} | |
intrGas := IntrinsicGas(tx.Data(), MessageCreatesContract(tx), pool.homestead) | |
if tx.Gas().Cmp(intrGas) < 0 { | |
return ErrIntrinsicGas | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment