Skip to content

Commit 762f3a4

Browse files
authored
Merge pull request #15466 from karalabe/uint64-gas-limit
all: switch gas limits from big.Int to uint64
2 parents b47285f + 6f69cdd commit 762f3a4

82 files changed

Lines changed: 606 additions & 642 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎accounts/abi/bind/backend.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type ContractTransactor interface {
8585
// There is no guarantee that this is the true gas limit requirement as other
8686
// transactions may be added or removed by miners, but it should provide a basis
8787
// for setting a reasonable default.
88-
EstimateGas(ctx context.Context, call ethereum.CallMsg) (usedGas *big.Int, err error)
88+
EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)
8989
// SendTransaction injects the transaction into the pending pool for execution.
9090
SendTransaction(ctx context.Context, tx *types.Transaction) error
9191
}

‎accounts/abi/bind/backends/simulated.go‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (b *SimulatedBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error
200200

201201
// EstimateGas executes the requested code against the currently pending block/state and
202202
// returns the used amount of gas.
203-
func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (*big.Int, error) {
203+
func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error) {
204204
b.mu.Lock()
205205
defer b.mu.Unlock()
206206

@@ -210,16 +210,16 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
210210
hi uint64
211211
cap uint64
212212
)
213-
if call.Gas != nil && call.Gas.Uint64() >= params.TxGas {
214-
hi = call.Gas.Uint64()
213+
if call.Gas >= params.TxGas {
214+
hi = call.Gas
215215
} else {
216-
hi = b.pendingBlock.GasLimit().Uint64()
216+
hi = b.pendingBlock.GasLimit()
217217
}
218218
cap = hi
219219

220220
// Create a helper to check if a gas allowance results in an executable transaction
221221
executable := func(gas uint64) bool {
222-
call.Gas = new(big.Int).SetUint64(gas)
222+
call.Gas = gas
223223

224224
snapshot := b.pendingState.Snapshot()
225225
_, _, failed, err := b.callContract(ctx, call, b.pendingBlock, b.pendingState)
@@ -242,21 +242,21 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
242242
// Reject the transaction as invalid if it still fails at the highest allowance
243243
if hi == cap {
244244
if !executable(hi) {
245-
return nil, errGasEstimationFailed
245+
return 0, errGasEstimationFailed
246246
}
247247
}
248-
return new(big.Int).SetUint64(hi), nil
248+
return hi, nil
249249
}
250250

251251
// callContract implemens common code between normal and pending contract calls.
252252
// state is modified during execution, make sure to copy it if necessary.
253-
func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallMsg, block *types.Block, statedb *state.StateDB) ([]byte, *big.Int, bool, error) {
253+
func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallMsg, block *types.Block, statedb *state.StateDB) ([]byte, uint64, bool, error) {
254254
// Ensure message is initialized properly.
255255
if call.GasPrice == nil {
256256
call.GasPrice = big.NewInt(1)
257257
}
258-
if call.Gas == nil || call.Gas.Sign() == 0 {
259-
call.Gas = big.NewInt(50000000)
258+
if call.Gas == 0 {
259+
call.Gas = 50000000
260260
}
261261
if call.Value == nil {
262262
call.Value = new(big.Int)
@@ -271,9 +271,9 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
271271
// Create a new environment which holds all relevant information
272272
// about the transaction and calling mechanisms.
273273
vmenv := vm.NewEVM(evmContext, statedb, b.config, vm.Config{})
274-
gaspool := new(core.GasPool).AddGas(math.MaxBig256)
275-
ret, gasUsed, _, failed, err := core.NewStateTransition(vmenv, msg, gaspool).TransitionDb()
276-
return ret, gasUsed, failed, err
274+
gaspool := new(core.GasPool).AddGas(math.MaxUint64)
275+
276+
return core.NewStateTransition(vmenv, msg, gaspool).TransitionDb()
277277
}
278278

279279
// SendTransaction updates the pending block to include the given transaction.
@@ -328,6 +328,6 @@ func (m callmsg) Nonce() uint64 { return 0 }
328328
func (m callmsg) CheckNonce() bool { return false }
329329
func (m callmsg) To() *common.Address { return m.CallMsg.To }
330330
func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
331-
func (m callmsg) Gas() *big.Int { return m.CallMsg.Gas }
331+
func (m callmsg) Gas() uint64 { return m.CallMsg.Gas }
332332
func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
333333
func (m callmsg) Data() []byte { return m.CallMsg.Data }

‎accounts/abi/bind/base.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type TransactOpts struct {
5050

5151
Value *big.Int // Funds to transfer along along the transaction (nil = 0 = no funds)
5252
GasPrice *big.Int // Gas price to use for the transaction execution (nil = gas price oracle)
53-
GasLimit *big.Int // Gas limit to set for the transaction execution (nil = estimate + 10%)
53+
GasLimit uint64 // Gas limit to set for the transaction execution (0 = estimate)
5454

5555
Context context.Context // Network context to support cancellation and timeouts (nil = no timeout)
5656
}
@@ -189,7 +189,7 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
189189
}
190190
}
191191
gasLimit := opts.GasLimit
192-
if gasLimit == nil {
192+
if gasLimit == 0 {
193193
// Gas estimation cannot succeed without code for method invocations
194194
if contract != nil {
195195
if code, err := c.transactor.PendingCodeAt(ensureContext(opts.Context), c.address); err != nil {

‎accounts/abi/bind/bind_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ var bindTests = []struct {
399399
sim.Commit()
400400
401401
// Set the field with automatic estimation and check that it succeeds
402-
auth.GasLimit = nil
403402
if _, err := limiter.SetField(auth, "automatic"); err != nil {
404403
t.Fatalf("Failed to call automatically gased transaction: %v", err)
405404
}

‎accounts/abi/bind/util_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d
3434

3535
var waitDeployedTests = map[string]struct {
3636
code string
37-
gas *big.Int
37+
gas uint64
3838
wantAddress common.Address
3939
wantErr error
4040
}{
4141
"successful deploy": {
4242
code: `6060604052600a8060106000396000f360606040526008565b00`,
43-
gas: big.NewInt(3000000),
43+
gas: 3000000,
4444
wantAddress: common.HexToAddress("0x3a220f351252089d385b29beca14e27f204c296a"),
4545
},
4646
"empty code": {
4747
code: ``,
48-
gas: big.NewInt(300000),
48+
gas: 300000,
4949
wantErr: bind.ErrNoCodeAfterDeploy,
5050
wantAddress: common.HexToAddress("0x3a220f351252089d385b29beca14e27f204c296a"),
5151
},

‎accounts/usbwallet/trezor.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (w *trezorDriver) trezorSign(derivationPath []uint32, tx *types.Transaction
180180
AddressN: derivationPath,
181181
Nonce: new(big.Int).SetUint64(tx.Nonce()).Bytes(),
182182
GasPrice: tx.GasPrice().Bytes(),
183-
GasLimit: tx.Gas().Bytes(),
183+
GasLimit: new(big.Int).SetUint64(tx.Gas()).Bytes(),
184184
Value: tx.Value().Bytes(),
185185
DataLength: &length,
186186
}

‎cmd/faucet/faucet.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
473473
amount = new(big.Int).Mul(amount, new(big.Int).Exp(big.NewInt(5), big.NewInt(int64(msg.Tier)), nil))
474474
amount = new(big.Int).Div(amount, new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(msg.Tier)), nil))
475475

476-
tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, big.NewInt(21000), f.price, nil)
476+
tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, 21000, f.price, nil)
477477
signed, err := f.keystore.SignTx(f.account, tx, f.config.ChainId)
478478
if err != nil {
479479
f.lock.Unlock()

‎cmd/puppeth/genesis.go‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type cppEthereumGenesisSpec struct {
4444
MaximumExtraDataSize hexutil.Uint64 `json:"maximumExtraDataSize"`
4545
MinGasLimit hexutil.Uint64 `json:"minGasLimit"`
4646
MaxGasLimit hexutil.Uint64 `json:"maxGasLimit"`
47-
GasLimitBoundDivisor *hexutil.Big `json:"gasLimitBoundDivisor"`
47+
GasLimitBoundDivisor hexutil.Uint64 `json:"gasLimitBoundDivisor"`
4848
MinimumDifficulty *hexutil.Big `json:"minimumDifficulty"`
4949
DifficultyBoundDivisor *hexutil.Big `json:"difficultyBoundDivisor"`
5050
DurationLimit *hexutil.Big `json:"durationLimit"`
@@ -107,11 +107,11 @@ func newCppEthereumGenesisSpec(network string, genesis *core.Genesis) (*cppEther
107107
spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainId.Uint64())
108108

109109
spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize)
110-
spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit.Uint64())
110+
spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit)
111111
spec.Params.MaxGasLimit = (hexutil.Uint64)(math.MaxUint64)
112112
spec.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty)
113113
spec.Params.DifficultyBoundDivisor = (*hexutil.Big)(params.DifficultyBoundDivisor)
114-
spec.Params.GasLimitBoundDivisor = (*hexutil.Big)(params.GasLimitBoundDivisor)
114+
spec.Params.GasLimitBoundDivisor = (hexutil.Uint64)(params.GasLimitBoundDivisor)
115115
spec.Params.DurationLimit = (*hexutil.Big)(params.DurationLimit)
116116
spec.Params.BlockReward = (*hexutil.Big)(ethash.FrontierBlockReward)
117117

@@ -168,26 +168,26 @@ type parityChainSpec struct {
168168
Engine struct {
169169
Ethash struct {
170170
Params struct {
171-
MinimumDifficulty *hexutil.Big `json:"minimumDifficulty"`
172-
DifficultyBoundDivisor *hexutil.Big `json:"difficultyBoundDivisor"`
173-
GasLimitBoundDivisor *hexutil.Big `json:"gasLimitBoundDivisor"`
174-
DurationLimit *hexutil.Big `json:"durationLimit"`
175-
BlockReward *hexutil.Big `json:"blockReward"`
176-
HomesteadTransition uint64 `json:"homesteadTransition"`
177-
EIP150Transition uint64 `json:"eip150Transition"`
178-
EIP160Transition uint64 `json:"eip160Transition"`
179-
EIP161abcTransition uint64 `json:"eip161abcTransition"`
180-
EIP161dTransition uint64 `json:"eip161dTransition"`
181-
EIP649Reward *hexutil.Big `json:"eip649Reward"`
182-
EIP100bTransition uint64 `json:"eip100bTransition"`
183-
EIP649Transition uint64 `json:"eip649Transition"`
171+
MinimumDifficulty *hexutil.Big `json:"minimumDifficulty"`
172+
DifficultyBoundDivisor *hexutil.Big `json:"difficultyBoundDivisor"`
173+
GasLimitBoundDivisor hexutil.Uint64 `json:"gasLimitBoundDivisor"`
174+
DurationLimit *hexutil.Big `json:"durationLimit"`
175+
BlockReward *hexutil.Big `json:"blockReward"`
176+
HomesteadTransition uint64 `json:"homesteadTransition"`
177+
EIP150Transition uint64 `json:"eip150Transition"`
178+
EIP160Transition uint64 `json:"eip160Transition"`
179+
EIP161abcTransition uint64 `json:"eip161abcTransition"`
180+
EIP161dTransition uint64 `json:"eip161dTransition"`
181+
EIP649Reward *hexutil.Big `json:"eip649Reward"`
182+
EIP100bTransition uint64 `json:"eip100bTransition"`
183+
EIP649Transition uint64 `json:"eip649Transition"`
184184
} `json:"params"`
185185
} `json:"Ethash"`
186186
} `json:"engine"`
187187

188188
Params struct {
189189
MaximumExtraDataSize hexutil.Uint64 `json:"maximumExtraDataSize"`
190-
MinGasLimit *hexutil.Big `json:"minGasLimit"`
190+
MinGasLimit hexutil.Uint64 `json:"minGasLimit"`
191191
NetworkID hexutil.Uint64 `json:"networkID"`
192192
MaxCodeSize uint64 `json:"maxCodeSize"`
193193
EIP155Transition uint64 `json:"eip155Transition"`
@@ -270,7 +270,7 @@ func newParityChainSpec(network string, genesis *core.Genesis, bootnodes []strin
270270
}
271271
spec.Engine.Ethash.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty)
272272
spec.Engine.Ethash.Params.DifficultyBoundDivisor = (*hexutil.Big)(params.DifficultyBoundDivisor)
273-
spec.Engine.Ethash.Params.GasLimitBoundDivisor = (*hexutil.Big)(params.GasLimitBoundDivisor)
273+
spec.Engine.Ethash.Params.GasLimitBoundDivisor = (hexutil.Uint64)(params.GasLimitBoundDivisor)
274274
spec.Engine.Ethash.Params.DurationLimit = (*hexutil.Big)(params.DurationLimit)
275275
spec.Engine.Ethash.Params.BlockReward = (*hexutil.Big)(ethash.FrontierBlockReward)
276276
spec.Engine.Ethash.Params.HomesteadTransition = genesis.Config.HomesteadBlock.Uint64()
@@ -283,7 +283,7 @@ func newParityChainSpec(network string, genesis *core.Genesis, bootnodes []strin
283283
spec.Engine.Ethash.Params.EIP649Transition = genesis.Config.ByzantiumBlock.Uint64()
284284

285285
spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize)
286-
spec.Params.MinGasLimit = (*hexutil.Big)(params.MinGasLimit)
286+
spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit)
287287
spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainId.Uint64())
288288
spec.Params.MaxCodeSize = params.MaxCodeSize
289289
spec.Params.EIP155Transition = genesis.Config.EIP155Block.Uint64()

‎cmd/utils/flags.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ var (
313313
TargetGasLimitFlag = cli.Uint64Flag{
314314
Name: "targetgaslimit",
315315
Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine",
316-
Value: params.GenesisGasLimit.Uint64(),
316+
Value: params.GenesisGasLimit,
317317
}
318318
EtherbaseFlag = cli.StringFlag{
319319
Name: "etherbase",
@@ -1138,7 +1138,7 @@ func RegisterEthStatsService(stack *node.Node, url string) {
11381138
// SetupNetwork configures the system for either the main net or some test network.
11391139
func SetupNetwork(ctx *cli.Context) {
11401140
// TODO(fjl): move target gas limit into config
1141-
params.TargetGasLimit = new(big.Int).SetUint64(ctx.GlobalUint64(TargetGasLimitFlag.Name))
1141+
params.TargetGasLimit = ctx.GlobalUint64(TargetGasLimitFlag.Name)
11421142
}
11431143

11441144
// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.

‎consensus/ethash/algorithm_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ func TestConcurrentDiskCacheGeneration(t *testing.T) {
688688
TxHash: common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"),
689689
ReceiptHash: common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"),
690690
Difficulty: big.NewInt(167925187834220),
691-
GasLimit: big.NewInt(4015682),
692-
GasUsed: big.NewInt(0),
691+
GasLimit: 4015682,
692+
GasUsed: 0,
693693
Time: big.NewInt(1488928920),
694694
Extra: []byte("www.bw.com"),
695695
MixDigest: common.HexToHash("0x3e140b0784516af5e5ec6730f2fb20cca22f32be399b9e4ad77d32541f798cd0"),

0 commit comments

Comments
 (0)