all: switch gas limits from big.Int to uint64

This commit is contained in:
Péter Szilágyi
2017-11-13 13:47:27 +02:00
parent b8caba9709
commit 6f69cdd109
82 changed files with 606 additions and 642 deletions

View File

@ -16,31 +16,34 @@
package core
import "math/big"
import (
"fmt"
"math"
)
// GasPool tracks the amount of gas available during
// execution of the transactions in a block.
// The zero value is a pool with zero gas available.
type GasPool big.Int
// GasPool tracks the amount of gas available during execution of the transactions
// in a block. The zero value is a pool with zero gas available.
type GasPool uint64
// AddGas makes gas available for execution.
func (gp *GasPool) AddGas(amount *big.Int) *GasPool {
i := (*big.Int)(gp)
i.Add(i, amount)
func (gp *GasPool) AddGas(amount uint64) *GasPool {
if uint64(*gp) > math.MaxUint64-amount {
panic("gas pool pushed above uint64")
}
*(*uint64)(gp) += amount
return gp
}
// SubGas deducts the given amount from the pool if enough gas is
// available and returns an error otherwise.
func (gp *GasPool) SubGas(amount *big.Int) error {
i := (*big.Int)(gp)
if i.Cmp(amount) < 0 {
func (gp *GasPool) SubGas(amount uint64) error {
if uint64(*gp) < amount {
return ErrGasLimitReached
}
i.Sub(i, amount)
*(*uint64)(gp) -= amount
return nil
}
func (gp *GasPool) String() string {
return (*big.Int)(gp).String()
return fmt.Sprintf("%d", *gp)
}