@@ -23,7 +23,6 @@ import (
2323 "github.com/ethereum/go-ethereum/consensus"
2424 "github.com/ethereum/go-ethereum/core/state"
2525 "github.com/ethereum/go-ethereum/core/types"
26- "github.com/ethereum/go-ethereum/core/utils"
2726 "github.com/ethereum/go-ethereum/params"
2827 "github.com/ethereum/go-ethereum/trie"
2928)
@@ -146,6 +145,28 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
146145 return nil
147146}
148147
148+ // CalcGasLimit computes the gas limit of the next block after parent. It aims
149+ // to keep the baseline gas close to the provided target, and increase it towards
150+ // the target if the baseline gas is lower.
149151func CalcGasLimit (parentGasLimit , desiredLimit uint64 ) uint64 {
150- return utils .CalcGasLimit (parentGasLimit , desiredLimit )
152+ delta := parentGasLimit / params .GasLimitBoundDivisor - 1
153+ limit := parentGasLimit
154+ if desiredLimit < params .MinGasLimit {
155+ desiredLimit = params .MinGasLimit
156+ }
157+ // If we're outside our allowed gas range, we try to hone towards them
158+ if limit < desiredLimit {
159+ limit = parentGasLimit + delta
160+ if limit > desiredLimit {
161+ limit = desiredLimit
162+ }
163+ return limit
164+ }
165+ if limit > desiredLimit {
166+ limit = parentGasLimit - delta
167+ if limit < desiredLimit {
168+ limit = desiredLimit
169+ }
170+ }
171+ return limit
151172}
0 commit comments