diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-11-13 19:47:27 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-01-03 20:45:35 +0800 |
commit | 6f69cdd109b1dd692b8dfb15e7c53d2051fbc946 (patch) | |
tree | c92974f8b82209073ad1ee3faec6e149f834bf69 /core/gaspool.go | |
parent | b8caba97099ee5eed33c3b80dd4ea540722e7d8f (diff) | |
download | dexon-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar dexon-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar.gz dexon-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar.bz2 dexon-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar.lz dexon-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar.xz dexon-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.tar.zst dexon-6f69cdd109b1dd692b8dfb15e7c53d2051fbc946.zip |
all: switch gas limits from big.Int to uint64
Diffstat (limited to 'core/gaspool.go')
-rw-r--r-- | core/gaspool.go | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/core/gaspool.go b/core/gaspool.go index ef99908cf..c3ee5c198 100644 --- a/core/gaspool.go +++ b/core/gaspool.go @@ -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) } |