all: switch gas limits from big.Int to uint64
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user