cmd, core, params: use gas-per-second block limiting

This commit is contained in:
Péter Szilágyi 2016-09-28 13:17:17 +03:00
parent d7e8ec61f0
commit 8bd421fb0b
5 changed files with 22 additions and 21 deletions

View file

@ -150,7 +150,7 @@ participating.
utils.MiningGPUFlag,
utils.AutoDAGFlag,
utils.TargetGasLimitFlag,
utils.BlockTimeLimitFlag,
utils.GasPerSecondFlag,
utils.NATFlag,
utils.NatspecEnabledFlag,
utils.NoDiscoverFlag,

View file

@ -126,7 +126,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.AutoDAGFlag,
utils.EtherbaseFlag,
utils.TargetGasLimitFlag,
utils.BlockTimeLimitFlag,
utils.GasPerSecondFlag,
utils.GasPriceFlag,
utils.ExtraDataFlag,
},

View file

@ -183,10 +183,10 @@ var (
Usage: "Sets the artificial target gas floor for the blocks to mine",
Value: params.GenesisGasLimit.String(),
}
BlockTimeLimitFlag = cli.IntFlag{
Name: "blocktimelimit",
Usage: "Time limit for processing a block after which to halve the hard gas limit",
Value: 5,
GasPerSecondFlag = cli.StringFlag{
Name: "gaspersec",
Usage: "Gas consumption per second below which to tighten the block limits",
Value: params.GasPerSecondThreshold.String(),
}
AutoDAGFlag = cli.BoolFlag{
Name: "autodag",
@ -752,7 +752,7 @@ func SetupNetwork(ctx *cli.Context) {
}
params.TargetGasLimit = common.String2Big(ctx.GlobalString(TargetGasLimitFlag.Name))
params.CurrentGasCeil.Set(params.TargetGasLimit)
params.BlockTimeLimit = time.Duration(ctx.GlobalInt(BlockTimeLimitFlag.Name)) * time.Second
params.GasPerSecondThreshold = common.String2Big(ctx.GlobalString(GasPerSecondFlag.Name))
}
// MustMakeChainConfig reads the chain configuration from the database in ctx.Datadir.

View file

@ -980,8 +980,9 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
stats.processed++
// Update the current gas limit (mining only) based on import times
if gasUsed := chain[i].GasUsed(); gasUsed.Cmp(common.Big0) > 0 {
params.CurrentGasCeilLock.Lock()
if time.Since(bstart) > params.BlockTimeLimit {
if gasPerSecond := gasUsed.Uint64() * uint64(time.Second) / uint64(time.Since(bstart)); gasPerSecond < params.GasPerSecondThreshold.Uint64() {
ceil := new(big.Int).Div(params.CurrentGasCeil, params.CurrentGasCeilCutDiv)
params.CurrentGasCeil.Set(common.BigMax(ceil, params.MinGasLimit))
} else {
@ -992,6 +993,7 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
glog.V(logger.Debug).Infof("block gas ceiling changed to %v", params.CurrentGasCeil)
params.CurrentGasCeilLock.Unlock()
}
}
if (stats.queued > 0 || stats.processed > 0 || stats.ignored > 0) && bool(glog.V(logger.Info)) {
start, end := chain[0], chain[len(chain)-1]

View file

@ -19,13 +19,12 @@ package params
import (
"math/big"
"sync"
"time"
)
var (
GenesisGasLimit = big.NewInt(4712388) // Gas limit of the Genesis block.
TargetGasLimit = new(big.Int).Set(GenesisGasLimit) // The artificial target
BlockTimeLimit = 5 * time.Second // Block processing time limit to reduce gas after
GasPerSecondThreshold = big.NewInt(4712388 / 2) // Threshold below which to start reducing block gas limits
// Temp hack to get a dynamic gas limit in palace (clean up!!!)
CurrentGasCeil = new(big.Int).Set(GenesisGasLimit)