diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-24 23:45:51 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-24 23:48:13 +0800 |
commit | 405720b218c74ec730541cdcb360db54deb75474 (patch) | |
tree | b403e8c1e35884aac71bd51cff8489e4305adba8 /core/transaction_pool.go | |
parent | 3bb6da9bd3111c8083cdefde1aa93a7ac55d19d2 (diff) | |
download | go-tangerine-405720b218c74ec730541cdcb360db54deb75474.tar.gz go-tangerine-405720b218c74ec730541cdcb360db54deb75474.tar.zst go-tangerine-405720b218c74ec730541cdcb360db54deb75474.zip |
xeth, core, cmd/utils: Transaction can not be over block gas limit
Transactions will be invalidated when the tx.gas_limit > block.gas_limit
Diffstat (limited to 'core/transaction_pool.go')
-rw-r--r-- | core/transaction_pool.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/core/transaction_pool.go b/core/transaction_pool.go index 392e17856..f6414a882 100644 --- a/core/transaction_pool.go +++ b/core/transaction_pool.go @@ -23,6 +23,7 @@ var ( ErrNonExistentAccount = errors.New("Account does not exist") ErrInsufficientFunds = errors.New("Insufficient funds") ErrIntrinsicGas = errors.New("Intrinsic gas too low") + ErrGasLimit = errors.New("Exceeds block gas limit") ) const txPoolQueueSize = 50 @@ -52,6 +53,8 @@ type TxPool struct { quit chan bool // The state function which will allow us to do some pre checkes currentState stateFn + // The current gas limit function callback + gasLimit func() *big.Int // The actual pool txs map[common.Hash]*types.Transaction invalidHashes *set.Set @@ -63,7 +66,7 @@ type TxPool struct { eventMux *event.TypeMux } -func NewTxPool(eventMux *event.TypeMux, currentStateFn stateFn) *TxPool { +func NewTxPool(eventMux *event.TypeMux, currentStateFn stateFn, gasLimitFn func() *big.Int) *TxPool { txPool := &TxPool{ txs: make(map[common.Hash]*types.Transaction), queue: make(map[common.Address]types.Transactions), @@ -72,6 +75,7 @@ func NewTxPool(eventMux *event.TypeMux, currentStateFn stateFn) *TxPool { eventMux: eventMux, invalidHashes: set.New(), currentState: currentStateFn, + gasLimit: gasLimitFn, } return txPool } @@ -116,6 +120,10 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error { return ErrNonExistentAccount } + if pool.gasLimit().Cmp(tx.GasLimit) < 0 { + return ErrGasLimit + } + if pool.currentState().GetBalance(from).Cmp(new(big.Int).Mul(tx.Price, tx.GasLimit)) < 0 { return ErrInsufficientFunds } |