mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 12:16:44 +00:00
core: simplify function CalcGasLimit
This commit is contained in:
parent
ef815c59a2
commit
5818015798
1 changed files with 5 additions and 13 deletions
|
|
@ -173,23 +173,15 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
|
||||||
// the target if the baseline gas is lower.
|
// the target if the baseline gas is lower.
|
||||||
func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64 {
|
func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64 {
|
||||||
delta := parentGasLimit/params.GasLimitBoundDivisor - 1
|
delta := parentGasLimit/params.GasLimitBoundDivisor - 1
|
||||||
limit := parentGasLimit
|
|
||||||
if desiredLimit < params.MinGasLimit {
|
if desiredLimit < params.MinGasLimit {
|
||||||
desiredLimit = params.MinGasLimit
|
desiredLimit = params.MinGasLimit
|
||||||
}
|
}
|
||||||
// If we're outside our allowed gas range, we try to hone towards them
|
// If we're outside our allowed gas range, we try to hone towards them
|
||||||
if limit < desiredLimit {
|
if parentGasLimit < desiredLimit {
|
||||||
limit = parentGasLimit + delta
|
return min(parentGasLimit+delta, desiredLimit)
|
||||||
if limit > desiredLimit {
|
|
||||||
limit = desiredLimit
|
|
||||||
}
|
}
|
||||||
return limit
|
if parentGasLimit > desiredLimit {
|
||||||
|
return max(parentGasLimit-delta, desiredLimit)
|
||||||
}
|
}
|
||||||
if limit > desiredLimit {
|
return parentGasLimit
|
||||||
limit = parentGasLimit - delta
|
|
||||||
if limit < desiredLimit {
|
|
||||||
limit = desiredLimit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return limit
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue