Don't mine transactions if they would go over the GasLimit implements ethereum/go-ethereum#77 further.

This commit is contained in:
Maran 2014-06-10 17:23:32 +02:00
parent 69044fe577
commit bdc206885a
2 changed files with 35 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package ethchain
import ( import (
"fmt" "fmt"
"math/big"
) )
// Parent error. In case a parent is unknown this error will be thrown // Parent error. In case a parent is unknown this error will be thrown
@ -43,6 +44,23 @@ func IsValidationErr(err error) bool {
return ok return ok
} }
type GasLimitErr struct {
Message string
Is, Max *big.Int
}
func IsGasLimitErr(err error) bool {
_, ok := err.(*GasLimitErr)
return ok
}
func (err *GasLimitErr) Error() string {
return err.Message
}
func GasLimitError(is, max *big.Int) *GasLimitErr {
return &GasLimitErr{Message: fmt.Sprintf("GasLimit error. Max %s, transaction would take it to %s", max, is), Is: is, Max: max}
}
type NonceErr struct { type NonceErr struct {
Message string Message string
Is, Exp uint64 Is, Exp uint64

View File

@ -114,6 +114,8 @@ func (sm *StateManager) ApplyTransactions(state *State, block *Block, txs []*Tra
// Process each transaction/contract // Process each transaction/contract
var receipts []*Receipt var receipts []*Receipt
var validTxs []*Transaction var validTxs []*Transaction
var ignoredTxs []*Transaction // Transactions which go over the gasLimit
totalUsedGas := big.NewInt(0) totalUsedGas := big.NewInt(0)
for _, tx := range txs { for _, tx := range txs {
usedGas, err := sm.ApplyTransaction(state, block, tx) usedGas, err := sm.ApplyTransaction(state, block, tx)
@ -121,6 +123,12 @@ func (sm *StateManager) ApplyTransactions(state *State, block *Block, txs []*Tra
if IsNonceErr(err) { if IsNonceErr(err) {
continue continue
} }
if IsGasLimitErr(err) {
ignoredTxs = append(ignoredTxs, tx)
// We need to figure out if we want to do something with thse txes
ethutil.Config.Log.Debugln("Gastlimit:", err)
continue
}
ethutil.Config.Log.Infoln(err) ethutil.Config.Log.Infoln(err)
} }
@ -151,6 +159,7 @@ func (sm *StateManager) ApplyTransaction(state *State, block *Block, tx *Transac
script []byte script []byte
) )
totalGasUsed = big.NewInt(0) totalGasUsed = big.NewInt(0)
snapshot := state.Snapshot()
// Apply the transaction to the current state // Apply the transaction to the current state
gas, err = sm.Ethereum.TxPool().ProcessTransaction(tx, state, false) gas, err = sm.Ethereum.TxPool().ProcessTransaction(tx, state, false)
@ -190,6 +199,14 @@ func (sm *StateManager) ApplyTransaction(state *State, block *Block, tx *Transac
} }
} }
parent := sm.bc.GetBlock(block.PrevHash)
total := new(big.Int).Add(block.GasUsed, totalGasUsed)
limit := block.CalcGasLimit(parent)
if total.Cmp(limit) > 0 {
state.Revert(snapshot)
err = GasLimitError(total, limit)
}
return return
} }