aboutsummaryrefslogtreecommitdiffstats
path: root/core/gaspool.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/gaspool.go')
-rw-r--r--core/gaspool.go29
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)
}