Skip to content

Commit e993b85

Browse files
committed
change miner gas floor ceil
1 parent 094e5be commit e993b85

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed

cmd/utils/flags.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ var (
306306
Name: "cache.preimages",
307307
Usage: "Enable recording the SHA3/keccak preimages of trie keys",
308308
}
309+
MinerGasTargetFlag = cli.Uint64Flag{
310+
Name: "miner.gastarget",
311+
Usage: "Target gas floor for mined blocks",
312+
Value: ethconfig.Defaults.Miner.GasFloor,
313+
}
314+
MinerGasLimitFlag = cli.Uint64Flag{
315+
Name: "miner.gaslimit",
316+
Usage: "Target gas ceiling for mined blocks",
317+
Value: ethconfig.Defaults.Miner.GasCeil,
318+
}
309319
MinerGasPriceFlag = BigFlag{
310320
Name: "miner.gasprice",
311321
Usage: "Minimum gas price for mining a transaction",
@@ -1143,6 +1153,12 @@ func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {
11431153
}
11441154

11451155
func setMiner(ctx *cli.Context, cfg *miner.Config) {
1156+
if ctx.GlobalIsSet(MinerGasTargetFlag.Name) {
1157+
cfg.GasFloor = ctx.GlobalUint64(MinerGasTargetFlag.Name)
1158+
}
1159+
if ctx.GlobalIsSet(MinerGasLimitFlag.Name) {
1160+
cfg.GasCeil = ctx.GlobalUint64(MinerGasLimitFlag.Name)
1161+
}
11461162
if ctx.GlobalIsSet(MinerGasPriceFlag.Name) {
11471163
cfg.GasPrice = GlobalBig(ctx, MinerGasPriceFlag.Name)
11481164
}
@@ -1155,7 +1171,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
11551171

11561172
setGPO(ctx, &cfg.GPO)
11571173
setTxPool(ctx, &cfg.TxPool)
1158-
1174+
setMiner(ctx, &cfg.Miner)
11591175
// Cap the cache allowance and tune the garbage collector
11601176
mem, err := gopsutil.VirtualMemory()
11611177
if err == nil {

core/block_validator.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
103103
// to keep the baseline gas above the provided floor, and increase it towards the
104104
// ceil if the blocks are full. If the ceil is exceeded, it will always decrease
105105
// the gas allowance.
106-
func CalcGasLimit(parent *types.Block, gasFloor /*, gasCeil*/ uint64) uint64 {
107-
var gasCeil = CalcGasCeil(parent)
106+
func CalcGasLimit(parent *types.Block, gasFloor, gasCeil uint64) uint64 {
108107
if gasFloor > gasCeil {
109108
gasFloor = gasCeil
110109
}

eth/ethconfig/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ var Defaults = Config{
7979
TrieCleanCacheRejournal: 60 * time.Minute,
8080
TrieDirtyCache: 256,
8181
Miner: miner.Config{
82-
GasFloor: params.GenesisGasLimit,
82+
GasFloor: 50000 * 20000,
83+
GasCeil: 50000 * 30000,
8384
GasPrice: big.NewInt(params.GVon),
8485
Recommit: 3 * time.Second,
8586
},

miner/miner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Backend interface {
4444
type Config struct {
4545
ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner
4646
GasFloor uint64 // Target gas floor for mined blocks.
47+
GasCeil uint64 // Target gas ceiling for mined blocks.
4748
GasPrice *big.Int // Minimum gas price for mining a transaction
4849
Recommit time.Duration // The time interval for miner to re-create mining work.
4950
Noverify bool // Disable remote mining solution verification(only useful in ethash).

miner/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
10551055
header := &types.Header{
10561056
ParentHash: parent.Hash(),
10571057
Number: num.Add(num, common.Big1),
1058-
GasLimit: core.CalcGasLimit(parent, w.config.GasFloor),
1058+
GasLimit: core.CalcGasLimit(parent, w.config.GasFloor, w.config.GasCeil),
10591059
Time: timestamp,
10601060
}
10611061

sdk/app/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ var (
8989
utils.MaxPeersFlag,
9090
utils.MaxConsensusPeersFlag,
9191
utils.MaxPendingPeersFlag,
92+
utils.MinerGasTargetFlag,
93+
utils.MinerGasLimitFlag,
9294
utils.MinerGasPriceFlag,
9395
utils.NATFlag,
9496
utils.NoDiscoverFlag,

0 commit comments

Comments
 (0)