2018-04-06 16:52:10 +02:00
|
|
|
# Nimbus
|
2025-01-25 10:36:43 +00:00
|
|
|
# Copyright (c) 2018-2025 Status Research & Development GmbH
|
2018-04-06 16:52:10 +02:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2025-01-25 10:36:43 +00:00
|
|
|
{.push raises: [].}
|
2018-04-06 16:52:10 +02:00
|
|
|
|
2025-01-25 10:36:43 +00:00
|
|
|
from ./difficulty import GAS_LIMIT_ADJUSTMENT_FACTOR, GAS_LIMIT_MINIMUM, GasInt
|
2021-08-24 14:34:58 +07:00
|
|
|
|
2021-08-18 19:40:33 +07:00
|
|
|
# CalcGasLimit1559 calculates the next block gas limit under 1559 rules.
|
|
|
|
func calcGasLimit1559*(parentGasLimit, desiredLimit: GasInt): GasInt =
|
2021-08-24 18:30:52 +07:00
|
|
|
let delta = parentGasLimit div GAS_LIMIT_ADJUSTMENT_FACTOR - 1.GasInt
|
2021-08-18 19:40:33 +07:00
|
|
|
var limit = parentGasLimit
|
|
|
|
var desiredLimit = desiredLimit
|
|
|
|
|
|
|
|
if desiredLimit < GAS_LIMIT_MINIMUM:
|
|
|
|
desiredLimit = GAS_LIMIT_MINIMUM
|
|
|
|
|
|
|
|
# If we're outside our allowed gas range, we try to hone towards them
|
|
|
|
if limit < desiredLimit:
|
|
|
|
limit = parentGasLimit + delta
|
|
|
|
if limit > desiredLimit:
|
|
|
|
limit = desiredLimit
|
|
|
|
return limit
|
|
|
|
|
|
|
|
if limit > desiredLimit:
|
|
|
|
limit = parentGasLimit - delta
|
|
|
|
if limit < desiredLimit:
|
|
|
|
limit = desiredLimit
|
|
|
|
|
2025-01-25 10:36:43 +00:00
|
|
|
limit
|