diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-08-29 17:21:12 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-08-29 17:40:12 +0800 |
commit | e8f229b82ef99213f8f84b8a71f752b236024494 (patch) | |
tree | 62f4d24ddfcb9fba0573531995739bcfdbf8b143 /core/block_validator.go | |
parent | c1c003e4ff36c22d67662ca661fc78cde850d401 (diff) | |
download | dexon-e8f229b82ef99213f8f84b8a71f752b236024494.tar dexon-e8f229b82ef99213f8f84b8a71f752b236024494.tar.gz dexon-e8f229b82ef99213f8f84b8a71f752b236024494.tar.bz2 dexon-e8f229b82ef99213f8f84b8a71f752b236024494.tar.lz dexon-e8f229b82ef99213f8f84b8a71f752b236024494.tar.xz dexon-e8f229b82ef99213f8f84b8a71f752b236024494.tar.zst dexon-e8f229b82ef99213f8f84b8a71f752b236024494.zip |
cmd, core, eth, miner, params: configurable gas floor and ceil
Diffstat (limited to 'core/block_validator.go')
-rw-r--r-- | core/block_validator.go | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/core/block_validator.go b/core/block_validator.go index ecd6a89bc..1329f6242 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -101,9 +101,11 @@ func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *stat return nil } -// CalcGasLimit computes the gas limit of the next block after parent. -// This is miner strategy, not consensus protocol. -func CalcGasLimit(parent *types.Block) uint64 { +// CalcGasLimit computes the gas limit of the next block after parent. It aims +// to keep the baseline gas above the provided floor, and increase it towards the +// ceil if the blocks are full. If the ceil is exceeded, it will always decrease +// the gas allowance. +func CalcGasLimit(parent *types.Block, gasFloor, gasCeil uint64) uint64 { // contrib = (parentGasUsed * 3 / 2) / 1024 contrib := (parent.GasUsed() + parent.GasUsed()/2) / params.GasLimitBoundDivisor @@ -121,12 +123,16 @@ func CalcGasLimit(parent *types.Block) uint64 { if limit < params.MinGasLimit { limit = params.MinGasLimit } - // however, if we're now below the target (TargetGasLimit) we increase the - // limit as much as we can (parentGasLimit / 1024 -1) - if limit < params.TargetGasLimit { + // If we're outside our allowed gas range, we try to hone towards them + if limit < gasFloor { limit = parent.GasLimit() + decay - if limit > params.TargetGasLimit { - limit = params.TargetGasLimit + if limit > gasFloor { + limit = gasFloor + } + } else if limit > gasCeil { + limit = parent.GasLimit() - decay + if limit < gasCeil { + limit = gasCeil } } return limit |