aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-08-29 17:21:12 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-08-29 17:40:12 +0800
commite8f229b82ef99213f8f84b8a71f752b236024494 (patch)
tree62f4d24ddfcb9fba0573531995739bcfdbf8b143 /core
parentc1c003e4ff36c22d67662ca661fc78cde850d401 (diff)
downloadgo-tangerine-e8f229b82ef99213f8f84b8a71f752b236024494.tar
go-tangerine-e8f229b82ef99213f8f84b8a71f752b236024494.tar.gz
go-tangerine-e8f229b82ef99213f8f84b8a71f752b236024494.tar.bz2
go-tangerine-e8f229b82ef99213f8f84b8a71f752b236024494.tar.lz
go-tangerine-e8f229b82ef99213f8f84b8a71f752b236024494.tar.xz
go-tangerine-e8f229b82ef99213f8f84b8a71f752b236024494.tar.zst
go-tangerine-e8f229b82ef99213f8f84b8a71f752b236024494.zip
cmd, core, eth, miner, params: configurable gas floor and ceil
Diffstat (limited to 'core')
-rw-r--r--core/bench_test.go3
-rw-r--r--core/block_validator.go22
-rw-r--r--core/chain_makers.go2
3 files changed, 17 insertions, 10 deletions
diff --git a/core/bench_test.go b/core/bench_test.go
index 748aebe40..8d95456e9 100644
--- a/core/bench_test.go
+++ b/core/bench_test.go
@@ -111,7 +111,8 @@ func init() {
func genTxRing(naccounts int) func(int, *BlockGen) {
from := 0
return func(i int, gen *BlockGen) {
- gas := CalcGasLimit(gen.PrevBlock(i - 1))
+ block := gen.PrevBlock(i - 1)
+ gas := CalcGasLimit(block, block.GasLimit(), block.GasLimit())
for {
gas -= params.TxGas
if gas < params.TxGas {
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
diff --git a/core/chain_makers.go b/core/chain_makers.go
index c1e4b4264..de0fc6be9 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -240,7 +240,7 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.S
Difficulty: parent.Difficulty(),
UncleHash: parent.UncleHash(),
}),
- GasLimit: CalcGasLimit(parent),
+ GasLimit: CalcGasLimit(parent, parent.GasLimit(), parent.GasLimit()),
Number: new(big.Int).Add(parent.Number(), common.Big1),
Time: time,
}