2016-04-14 16:18:24 +00:00
|
|
|
// Copyright 2015 The go-ethereum Authors
|
2015-10-19 14:08:17 +00:00
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/params"
|
2015-11-27 14:40:29 +00:00
|
|
|
)
|
|
|
|
|
2018-08-29 09:21:12 +00:00
|
|
|
// CalcGasLimit computes the gas limit of the next block after parent. It aims
|
2022-01-05 09:36:24 +00:00
|
|
|
// to keep the baseline gas close to the provided target, and increase it towards
|
|
|
|
// the target if the baseline gas is lower.
|
|
|
|
func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64 {
|
|
|
|
delta := parentGasLimit/params.GasLimitBoundDivisor - 1
|
|
|
|
limit := parentGasLimit
|
|
|
|
if desiredLimit < params.MinGasLimit {
|
|
|
|
desiredLimit = params.MinGasLimit
|
2017-11-13 11:47:27 +00:00
|
|
|
}
|
2018-08-29 09:21:12 +00:00
|
|
|
// If we're outside our allowed gas range, we try to hone towards them
|
2022-01-05 09:36:24 +00:00
|
|
|
if limit < desiredLimit {
|
|
|
|
limit = parentGasLimit + delta
|
|
|
|
if limit > desiredLimit {
|
|
|
|
limit = desiredLimit
|
2018-08-29 09:21:12 +00:00
|
|
|
}
|
2022-01-05 09:36:24 +00:00
|
|
|
return limit
|
|
|
|
}
|
|
|
|
if limit > desiredLimit {
|
|
|
|
limit = parentGasLimit - delta
|
|
|
|
if limit < desiredLimit {
|
|
|
|
limit = desiredLimit
|
2017-11-13 11:47:27 +00:00
|
|
|
}
|
2015-11-27 14:40:29 +00:00
|
|
|
}
|
2017-11-13 11:47:27 +00:00
|
|
|
return limit
|
2015-11-27 14:40:29 +00:00
|
|
|
}
|