mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
cmd, core, params: use gas-per-second block limiting
This commit is contained in:
parent
d7e8ec61f0
commit
8bd421fb0b
5 changed files with 22 additions and 21 deletions
|
|
@ -150,7 +150,7 @@ participating.
|
||||||
utils.MiningGPUFlag,
|
utils.MiningGPUFlag,
|
||||||
utils.AutoDAGFlag,
|
utils.AutoDAGFlag,
|
||||||
utils.TargetGasLimitFlag,
|
utils.TargetGasLimitFlag,
|
||||||
utils.BlockTimeLimitFlag,
|
utils.GasPerSecondFlag,
|
||||||
utils.NATFlag,
|
utils.NATFlag,
|
||||||
utils.NatspecEnabledFlag,
|
utils.NatspecEnabledFlag,
|
||||||
utils.NoDiscoverFlag,
|
utils.NoDiscoverFlag,
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ var AppHelpFlagGroups = []flagGroup{
|
||||||
utils.AutoDAGFlag,
|
utils.AutoDAGFlag,
|
||||||
utils.EtherbaseFlag,
|
utils.EtherbaseFlag,
|
||||||
utils.TargetGasLimitFlag,
|
utils.TargetGasLimitFlag,
|
||||||
utils.BlockTimeLimitFlag,
|
utils.GasPerSecondFlag,
|
||||||
utils.GasPriceFlag,
|
utils.GasPriceFlag,
|
||||||
utils.ExtraDataFlag,
|
utils.ExtraDataFlag,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -183,10 +183,10 @@ var (
|
||||||
Usage: "Sets the artificial target gas floor for the blocks to mine",
|
Usage: "Sets the artificial target gas floor for the blocks to mine",
|
||||||
Value: params.GenesisGasLimit.String(),
|
Value: params.GenesisGasLimit.String(),
|
||||||
}
|
}
|
||||||
BlockTimeLimitFlag = cli.IntFlag{
|
GasPerSecondFlag = cli.StringFlag{
|
||||||
Name: "blocktimelimit",
|
Name: "gaspersec",
|
||||||
Usage: "Time limit for processing a block after which to halve the hard gas limit",
|
Usage: "Gas consumption per second below which to tighten the block limits",
|
||||||
Value: 5,
|
Value: params.GasPerSecondThreshold.String(),
|
||||||
}
|
}
|
||||||
AutoDAGFlag = cli.BoolFlag{
|
AutoDAGFlag = cli.BoolFlag{
|
||||||
Name: "autodag",
|
Name: "autodag",
|
||||||
|
|
@ -752,7 +752,7 @@ func SetupNetwork(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
params.TargetGasLimit = common.String2Big(ctx.GlobalString(TargetGasLimitFlag.Name))
|
params.TargetGasLimit = common.String2Big(ctx.GlobalString(TargetGasLimitFlag.Name))
|
||||||
params.CurrentGasCeil.Set(params.TargetGasLimit)
|
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.
|
// MustMakeChainConfig reads the chain configuration from the database in ctx.Datadir.
|
||||||
|
|
|
||||||
|
|
@ -980,8 +980,9 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
|
||||||
stats.processed++
|
stats.processed++
|
||||||
|
|
||||||
// Update the current gas limit (mining only) based on import times
|
// Update the current gas limit (mining only) based on import times
|
||||||
|
if gasUsed := chain[i].GasUsed(); gasUsed.Cmp(common.Big0) > 0 {
|
||||||
params.CurrentGasCeilLock.Lock()
|
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)
|
ceil := new(big.Int).Div(params.CurrentGasCeil, params.CurrentGasCeilCutDiv)
|
||||||
params.CurrentGasCeil.Set(common.BigMax(ceil, params.MinGasLimit))
|
params.CurrentGasCeil.Set(common.BigMax(ceil, params.MinGasLimit))
|
||||||
} else {
|
} 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)
|
glog.V(logger.Debug).Infof("block gas ceiling changed to %v", params.CurrentGasCeil)
|
||||||
params.CurrentGasCeilLock.Unlock()
|
params.CurrentGasCeilLock.Unlock()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (stats.queued > 0 || stats.processed > 0 || stats.ignored > 0) && bool(glog.V(logger.Info)) {
|
if (stats.queued > 0 || stats.processed > 0 || stats.ignored > 0) && bool(glog.V(logger.Info)) {
|
||||||
start, end := chain[0], chain[len(chain)-1]
|
start, end := chain[0], chain[len(chain)-1]
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,12 @@ package params
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
GenesisGasLimit = big.NewInt(4712388) // Gas limit of the Genesis block.
|
GenesisGasLimit = big.NewInt(4712388) // Gas limit of the Genesis block.
|
||||||
TargetGasLimit = new(big.Int).Set(GenesisGasLimit) // The artificial target
|
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!!!)
|
// Temp hack to get a dynamic gas limit in palace (clean up!!!)
|
||||||
CurrentGasCeil = new(big.Int).Set(GenesisGasLimit)
|
CurrentGasCeil = new(big.Int).Set(GenesisGasLimit)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue