Skip to content

Commit 6d17546

Browse files
authored
cmd, core, eth, miner: deprecate miner.gastarget flag (#23213)
1 parent 520f256 commit 6d17546

File tree

13 files changed

+32
-71
lines changed

13 files changed

+32
-71
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ var (
118118
utils.MiningEnabledFlag,
119119
utils.MinerThreadsFlag,
120120
utils.MinerNotifyFlag,
121-
utils.MinerGasTargetFlag,
121+
utils.LegacyMinerGasTargetFlag,
122122
utils.MinerGasLimitFlag,
123123
utils.MinerGasPriceFlag,
124124
utils.MinerEtherbaseFlag,

cmd/geth/usage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ var AppHelpFlagGroups = []flags.FlagGroup{
182182
utils.MinerNotifyFlag,
183183
utils.MinerNotifyFullFlag,
184184
utils.MinerGasPriceFlag,
185-
utils.MinerGasTargetFlag,
186185
utils.MinerGasLimitFlag,
187186
utils.MinerEtherbaseFlag,
188187
utils.MinerExtraDataFlag,
@@ -226,6 +225,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
226225
utils.LegacyRPCCORSDomainFlag,
227226
utils.LegacyRPCVirtualHostsFlag,
228227
utils.LegacyRPCApiFlag,
228+
utils.LegacyMinerGasTargetFlag,
229229
},
230230
},
231231
{

cmd/utils/flags.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,6 @@ var (
444444
Name: "miner.notify.full",
445445
Usage: "Notify with pending block headers instead of work packages",
446446
}
447-
MinerGasTargetFlag = cli.Uint64Flag{
448-
Name: "miner.gastarget",
449-
Usage: "Target gas floor for mined blocks",
450-
Value: ethconfig.Defaults.Miner.GasFloor,
451-
}
452447
MinerGasLimitFlag = cli.Uint64Flag{
453448
Name: "miner.gaslimit",
454449
Usage: "Target gas ceiling for mined blocks",
@@ -1386,9 +1381,6 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
13861381
if ctx.GlobalIsSet(MinerExtraDataFlag.Name) {
13871382
cfg.ExtraData = []byte(ctx.GlobalString(MinerExtraDataFlag.Name))
13881383
}
1389-
if ctx.GlobalIsSet(MinerGasTargetFlag.Name) {
1390-
cfg.GasFloor = ctx.GlobalUint64(MinerGasTargetFlag.Name)
1391-
}
13921384
if ctx.GlobalIsSet(MinerGasLimitFlag.Name) {
13931385
cfg.GasCeil = ctx.GlobalUint64(MinerGasLimitFlag.Name)
13941386
}
@@ -1401,6 +1393,9 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
14011393
if ctx.GlobalIsSet(MinerNoVerfiyFlag.Name) {
14021394
cfg.Noverify = ctx.GlobalBool(MinerNoVerfiyFlag.Name)
14031395
}
1396+
if ctx.GlobalIsSet(LegacyMinerGasTargetFlag.Name) {
1397+
log.Warn("The generic --miner.gastarget flag is deprecated and will be removed in the future!")
1398+
}
14041399
}
14051400

14061401
func setWhitelist(ctx *cli.Context, cfg *ethconfig.Config) {

cmd/utils/flags_legacy.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"strings"
2222

23+
"github.com/ethereum/go-ethereum/eth/ethconfig"
2324
"github.com/ethereum/go-ethereum/node"
2425
"gopkg.in/urfave/cli.v1"
2526
)
@@ -33,7 +34,9 @@ var ShowDeprecated = cli.Command{
3334
Description: "Show flags that have been deprecated and will soon be removed",
3435
}
3536

36-
var DeprecatedFlags = []cli.Flag{}
37+
var DeprecatedFlags = []cli.Flag{
38+
LegacyMinerGasTargetFlag,
39+
}
3740

3841
var (
3942
// (Deprecated May 2020, shown in aliased flags section)
@@ -66,6 +69,12 @@ var (
6669
Usage: "API's offered over the HTTP-RPC interface (deprecated and will be removed June 2021, use --http.api)",
6770
Value: "",
6871
}
72+
// (Deprecated July 2021, shown in aliased flags section)
73+
LegacyMinerGasTargetFlag = cli.Uint64Flag{
74+
Name: "miner.gastarget",
75+
Usage: "Target gas floor for mined blocks (deprecated)",
76+
Value: ethconfig.Defaults.Miner.GasFloor,
77+
}
6978
)
7079

7180
// showDeprecated displays deprecated flags that will be soon removed from the codebase.
@@ -74,7 +83,8 @@ func showDeprecated(*cli.Context) {
7483
fmt.Println("The following flags are deprecated and will be removed in the future!")
7584
fmt.Println("--------------------------------------------------------------------")
7685
fmt.Println()
77-
// TODO remove when there are newly deprecated flags
78-
fmt.Println("no deprecated flags to show at this time")
86+
for _, flag := range DeprecatedFlags {
87+
fmt.Println(flag.String())
88+
}
7989
fmt.Println()
8090
}

core/block_validator.go

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -103,44 +103,9 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
103103
}
104104

105105
// CalcGasLimit computes the gas limit of the next block after parent. It aims
106-
// to keep the baseline gas above the provided floor, and increase it towards the
107-
// ceil if the blocks are full. If the ceil is exceeded, it will always decrease
108-
// the gas allowance.
109-
func CalcGasLimit(parentGasUsed, parentGasLimit, gasFloor, gasCeil uint64) uint64 {
110-
// contrib = (parentGasUsed * 3 / 2) / 1024
111-
contrib := (parentGasUsed + parentGasUsed/2) / params.GasLimitBoundDivisor
112-
113-
// decay = parentGasLimit / 1024 -1
114-
decay := parentGasLimit/params.GasLimitBoundDivisor - 1
115-
116-
/*
117-
strategy: gasLimit of block-to-mine is set based on parent's
118-
gasUsed value. if parentGasUsed > parentGasLimit * (2/3) then we
119-
increase it, otherwise lower it (or leave it unchanged if it's right
120-
at that usage) the amount increased/decreased depends on how far away
121-
from parentGasLimit * (2/3) parentGasUsed is.
122-
*/
123-
limit := parentGasLimit - decay + contrib
124-
if limit < params.MinGasLimit {
125-
limit = params.MinGasLimit
126-
}
127-
// If we're outside our allowed gas range, we try to hone towards them
128-
if limit < gasFloor {
129-
limit = parentGasLimit + decay
130-
if limit > gasFloor {
131-
limit = gasFloor
132-
}
133-
} else if limit > gasCeil {
134-
limit = parentGasLimit - decay
135-
if limit < gasCeil {
136-
limit = gasCeil
137-
}
138-
}
139-
return limit
140-
}
141-
142-
// CalcGasLimit1559 calculates the next block gas limit under 1559 rules.
143-
func CalcGasLimit1559(parentGasLimit, desiredLimit uint64) uint64 {
106+
// to keep the baseline gas close to the provided target, and increase it towards
107+
// the target if the baseline gas is lower.
108+
func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64 {
144109
delta := parentGasLimit/params.GasLimitBoundDivisor - 1
145110
limit := parentGasLimit
146111
if desiredLimit < params.MinGasLimit {

core/block_validator_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ func testHeaderConcurrentAbortion(t *testing.T, threads int) {
198198
}
199199
}
200200

201-
func TestCalcGasLimit1559(t *testing.T) {
202-
201+
func TestCalcGasLimit(t *testing.T) {
203202
for i, tc := range []struct {
204203
pGasLimit uint64
205204
max uint64
@@ -209,23 +208,23 @@ func TestCalcGasLimit1559(t *testing.T) {
209208
{40000000, 40039061, 39960939},
210209
} {
211210
// Increase
212-
if have, want := CalcGasLimit1559(tc.pGasLimit, 2*tc.pGasLimit), tc.max; have != want {
211+
if have, want := CalcGasLimit(tc.pGasLimit, 2*tc.pGasLimit), tc.max; have != want {
213212
t.Errorf("test %d: have %d want <%d", i, have, want)
214213
}
215214
// Decrease
216-
if have, want := CalcGasLimit1559(tc.pGasLimit, 0), tc.min; have != want {
215+
if have, want := CalcGasLimit(tc.pGasLimit, 0), tc.min; have != want {
217216
t.Errorf("test %d: have %d want >%d", i, have, want)
218217
}
219218
// Small decrease
220-
if have, want := CalcGasLimit1559(tc.pGasLimit, tc.pGasLimit-1), tc.pGasLimit-1; have != want {
219+
if have, want := CalcGasLimit(tc.pGasLimit, tc.pGasLimit-1), tc.pGasLimit-1; have != want {
221220
t.Errorf("test %d: have %d want %d", i, have, want)
222221
}
223222
// Small increase
224-
if have, want := CalcGasLimit1559(tc.pGasLimit, tc.pGasLimit+1), tc.pGasLimit+1; have != want {
223+
if have, want := CalcGasLimit(tc.pGasLimit, tc.pGasLimit+1), tc.pGasLimit+1; have != want {
225224
t.Errorf("test %d: have %d want %d", i, have, want)
226225
}
227226
// No change
228-
if have, want := CalcGasLimit1559(tc.pGasLimit, tc.pGasLimit), tc.pGasLimit; have != want {
227+
if have, want := CalcGasLimit(tc.pGasLimit, tc.pGasLimit), tc.pGasLimit; have != want {
229228
t.Errorf("test %d: have %d want %d", i, have, want)
230229
}
231230
}

core/chain_makers.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,10 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.S
273273
}
274274
if chain.Config().IsLondon(header.Number) {
275275
header.BaseFee = misc.CalcBaseFee(chain.Config(), parent.Header())
276-
parentGasLimit := parent.GasLimit()
277276
if !chain.Config().IsLondon(parent.Number()) {
278-
parentGasLimit = parent.GasLimit() * params.ElasticityMultiplier
277+
parentGasLimit := parent.GasLimit() * params.ElasticityMultiplier
278+
header.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit)
279279
}
280-
header.GasLimit = CalcGasLimit1559(parentGasLimit, parentGasLimit)
281280
}
282281
return header
283282
}

eth/ethconfig/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ var Defaults = Config{
8383
TrieTimeout: 60 * time.Minute,
8484
SnapshotCache: 102,
8585
Miner: miner.Config{
86-
GasFloor: 8000000,
8786
GasCeil: 8000000,
8887
GasPrice: big.NewInt(params.GWei),
8988
Recommit: 3 * time.Second,

miner/stress/1559/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ func makeMiner(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
242242
GPO: ethconfig.Defaults.GPO,
243243
Ethash: ethconfig.Defaults.Ethash,
244244
Miner: miner.Config{
245-
GasFloor: genesis.GasLimit * 9 / 10,
246245
GasCeil: genesis.GasLimit * 11 / 10,
247246
GasPrice: big.NewInt(1),
248247
Recommit: time.Second,

miner/stress/clique/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ func makeSealer(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
193193
TxPool: core.DefaultTxPoolConfig,
194194
GPO: ethconfig.Defaults.GPO,
195195
Miner: miner.Config{
196-
GasFloor: genesis.GasLimit * 9 / 10,
197196
GasCeil: genesis.GasLimit * 11 / 10,
198197
GasPrice: big.NewInt(1),
199198
Recommit: time.Second,

0 commit comments

Comments
 (0)