mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
Simplify miner gas limit post EIP-1559. Default to 30M (#3205)
This commit is contained in:
parent
195eb9abaa
commit
d14c223881
@ -40,8 +40,7 @@ func must(err error) {
|
|||||||
func withMining(cmd *cobra.Command) {
|
func withMining(cmd *cobra.Command) {
|
||||||
cmd.Flags().Bool("mine", false, "Enable mining")
|
cmd.Flags().Bool("mine", false, "Enable mining")
|
||||||
cmd.Flags().StringArray("miner.notify", nil, "Comma separated HTTP URL list to notify of new work packages")
|
cmd.Flags().StringArray("miner.notify", nil, "Comma separated HTTP URL list to notify of new work packages")
|
||||||
cmd.Flags().Uint64("miner.gastarget", ethconfig.Defaults.Miner.GasFloor, "Target gas floor for mined blocks")
|
cmd.Flags().Uint64("miner.gaslimit", ethconfig.Defaults.Miner.GasLimit, "Target gas limit for mined blocks")
|
||||||
cmd.Flags().Uint64("miner.gaslimit", ethconfig.Defaults.Miner.GasCeil, "Target gas ceiling for mined blocks")
|
|
||||||
cmd.Flags().Int64("miner.gasprice", ethconfig.Defaults.Miner.GasPrice.Int64(), "Target gas price for mined blocks")
|
cmd.Flags().Int64("miner.gasprice", ethconfig.Defaults.Miner.GasPrice.Int64(), "Target gas price for mined blocks")
|
||||||
cmd.Flags().String("miner.etherbase", "0", "Public address for block mining rewards (default = first account")
|
cmd.Flags().String("miner.etherbase", "0", "Public address for block mining rewards (default = first account")
|
||||||
cmd.Flags().String("miner.extradata", "", "Block extra data set by the miner (default = client version)")
|
cmd.Flags().String("miner.extradata", "", "Block extra data set by the miner (default = client version)")
|
||||||
|
@ -233,15 +233,10 @@ var (
|
|||||||
Name: "miner.notify",
|
Name: "miner.notify",
|
||||||
Usage: "Comma separated HTTP URL list to notify of new work packages",
|
Usage: "Comma separated HTTP URL list to notify of new work packages",
|
||||||
}
|
}
|
||||||
MinerGasTargetFlag = cli.Uint64Flag{
|
|
||||||
Name: "miner.gastarget",
|
|
||||||
Usage: "Target gas floor for mined blocks",
|
|
||||||
Value: ethconfig.Defaults.Miner.GasFloor,
|
|
||||||
}
|
|
||||||
MinerGasLimitFlag = cli.Uint64Flag{
|
MinerGasLimitFlag = cli.Uint64Flag{
|
||||||
Name: "miner.gaslimit",
|
Name: "miner.gaslimit",
|
||||||
Usage: "Target gas ceiling for mined blocks",
|
Usage: "Target gas limit for mined blocks",
|
||||||
Value: ethconfig.Defaults.Miner.GasCeil,
|
Value: ethconfig.Defaults.Miner.GasLimit,
|
||||||
}
|
}
|
||||||
MinerGasPriceFlag = BigFlag{
|
MinerGasPriceFlag = BigFlag{
|
||||||
Name: "miner.gasprice",
|
Name: "miner.gasprice",
|
||||||
@ -1098,11 +1093,7 @@ func SetupMinerCobra(cmd *cobra.Command, cfg *params.MiningConfig) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
cfg.ExtraData = []byte(extraDataStr)
|
cfg.ExtraData = []byte(extraDataStr)
|
||||||
cfg.GasFloor, err = flags.GetUint64(MinerGasTargetFlag.Name)
|
cfg.GasLimit, err = flags.GetUint64(MinerGasLimitFlag.Name)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
cfg.GasCeil, err = flags.GetUint64(MinerGasLimitFlag.Name)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -1166,11 +1157,8 @@ func setMiner(ctx *cli.Context, cfg *params.MiningConfig) {
|
|||||||
if ctx.GlobalIsSet(MinerExtraDataFlag.Name) {
|
if ctx.GlobalIsSet(MinerExtraDataFlag.Name) {
|
||||||
cfg.ExtraData = []byte(ctx.GlobalString(MinerExtraDataFlag.Name))
|
cfg.ExtraData = []byte(ctx.GlobalString(MinerExtraDataFlag.Name))
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(MinerGasTargetFlag.Name) {
|
|
||||||
cfg.GasFloor = ctx.GlobalUint64(MinerGasTargetFlag.Name)
|
|
||||||
}
|
|
||||||
if ctx.GlobalIsSet(MinerGasLimitFlag.Name) {
|
if ctx.GlobalIsSet(MinerGasLimitFlag.Name) {
|
||||||
cfg.GasCeil = ctx.GlobalUint64(MinerGasLimitFlag.Name)
|
cfg.GasLimit = ctx.GlobalUint64(MinerGasLimitFlag.Name)
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(MinerGasPriceFlag.Name) {
|
if ctx.GlobalIsSet(MinerGasPriceFlag.Name) {
|
||||||
cfg.GasPrice = GlobalBig(ctx, MinerGasPriceFlag.Name)
|
cfg.GasPrice = GlobalBig(ctx, MinerGasPriceFlag.Name)
|
||||||
|
@ -21,37 +21,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// CalcGasLimit computes the gas limit of the next block after parent. It aims
|
// 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
|
// to keep the baseline gas close to the provided target, and increase it towards
|
||||||
// ceil if the blocks are full. If the ceil is exceeded, it will always decrease
|
// the target if the baseline gas is lower.
|
||||||
// the gas allowance.
|
func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64 {
|
||||||
func CalcGasLimit(parentGasUsed, parentGasLimit, gasFloor, gasCeil uint64) uint64 {
|
delta := parentGasLimit/params.GasLimitBoundDivisor - 1
|
||||||
// contrib = (parentGasUsed * 3 / 2) / 1024
|
limit := parentGasLimit
|
||||||
contrib := (parentGasUsed + parentGasUsed/2) / params.GasLimitBoundDivisor
|
if desiredLimit < params.MinGasLimit {
|
||||||
|
desiredLimit = params.MinGasLimit
|
||||||
// decay = parentGasLimit / 1024 -1
|
|
||||||
decay := parentGasLimit/params.GasLimitBoundDivisor - 1
|
|
||||||
|
|
||||||
/*
|
|
||||||
strategy: gasLimit of block-to-mine is set based on parent's
|
|
||||||
gasUsed value. if parentGasUsed > parentGasLimit * (2/3) then we
|
|
||||||
increase it, otherwise lower it (or leave it unchanged if it's right
|
|
||||||
at that usage) the amount increased/decreased depends on how far away
|
|
||||||
from parentGasLimit * (2/3) parentGasUsed is.
|
|
||||||
*/
|
|
||||||
limit := parentGasLimit - decay + contrib
|
|
||||||
if limit < params.MinGasLimit {
|
|
||||||
limit = params.MinGasLimit
|
|
||||||
}
|
}
|
||||||
// If we're outside our allowed gas range, we try to hone towards them
|
// If we're outside our allowed gas range, we try to hone towards them
|
||||||
if limit < gasFloor {
|
if limit < desiredLimit {
|
||||||
limit = parentGasLimit + decay
|
limit = parentGasLimit + delta
|
||||||
if limit > gasFloor {
|
if limit > desiredLimit {
|
||||||
limit = gasFloor
|
limit = desiredLimit
|
||||||
}
|
}
|
||||||
} else if limit > gasCeil {
|
return limit
|
||||||
limit = parentGasLimit - decay
|
}
|
||||||
if limit < gasCeil {
|
if limit > desiredLimit {
|
||||||
limit = gasCeil
|
limit = parentGasLimit - delta
|
||||||
|
if limit < desiredLimit {
|
||||||
|
limit = desiredLimit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return limit
|
return limit
|
||||||
|
@ -413,7 +413,7 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.I
|
|||||||
parent.UncleHash(),
|
parent.UncleHash(),
|
||||||
parent.Seal(),
|
parent.Seal(),
|
||||||
),
|
),
|
||||||
GasLimit: CalcGasLimit(parent.GasUsed(), parent.GasLimit(), parent.GasLimit(), parent.GasLimit()),
|
GasLimit: CalcGasLimit(parent.GasLimit(), parent.GasLimit()),
|
||||||
Number: new(big.Int).Add(parent.Number(), common.Big1),
|
Number: new(big.Int).Add(parent.Number(), common.Big1),
|
||||||
Time: time,
|
Time: time,
|
||||||
}
|
}
|
||||||
@ -422,6 +422,10 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.I
|
|||||||
if chain.Config().IsLondon(header.Number.Uint64()) {
|
if chain.Config().IsLondon(header.Number.Uint64()) {
|
||||||
header.BaseFee = misc.CalcBaseFee(chain.Config(), parent.Header())
|
header.BaseFee = misc.CalcBaseFee(chain.Config(), parent.Header())
|
||||||
header.Eip1559 = true
|
header.Eip1559 = true
|
||||||
|
if !chain.Config().IsLondon(parent.NumberU64()) {
|
||||||
|
parentGasLimit := parent.GasLimit() * params.ElasticityMultiplier
|
||||||
|
header.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
header.WithSeal = chain.Config().IsHeaderWithSeal()
|
header.WithSeal = chain.Config().IsHeaderWithSeal()
|
||||||
|
|
||||||
|
@ -78,8 +78,7 @@ var Defaults = Config{
|
|||||||
NetworkID: 1,
|
NetworkID: 1,
|
||||||
Prune: prune.DefaultMode,
|
Prune: prune.DefaultMode,
|
||||||
Miner: params.MiningConfig{
|
Miner: params.MiningConfig{
|
||||||
GasFloor: 8000000,
|
GasLimit: 30_000_000,
|
||||||
GasCeil: 8000000,
|
|
||||||
GasPrice: big.NewInt(params.GWei),
|
GasPrice: big.NewInt(params.GWei),
|
||||||
Recommit: 3 * time.Second,
|
Recommit: 3 * time.Second,
|
||||||
},
|
},
|
||||||
|
@ -193,7 +193,7 @@ func SpawnMiningCreateBlockStage(s *StageState, tx kv.RwTx, cfg MiningCreateBloc
|
|||||||
header := &types.Header{
|
header := &types.Header{
|
||||||
ParentHash: parent.Hash(),
|
ParentHash: parent.Hash(),
|
||||||
Number: num.Add(num, common.Big1),
|
Number: num.Add(num, common.Big1),
|
||||||
GasLimit: core.CalcGasLimit(parent.GasUsed, parent.GasLimit, cfg.miner.MiningConfig.GasFloor, cfg.miner.MiningConfig.GasCeil),
|
GasLimit: core.CalcGasLimit(parent.GasLimit, cfg.miner.MiningConfig.GasLimit),
|
||||||
Extra: cfg.miner.MiningConfig.ExtraData,
|
Extra: cfg.miner.MiningConfig.ExtraData,
|
||||||
Time: uint64(timestamp),
|
Time: uint64(timestamp),
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ func SpawnMiningCreateBlockStage(s *StageState, tx kv.RwTx, cfg MiningCreateBloc
|
|||||||
header.BaseFee = misc.CalcBaseFee(&cfg.chainConfig, parent)
|
header.BaseFee = misc.CalcBaseFee(&cfg.chainConfig, parent)
|
||||||
if !cfg.chainConfig.IsLondon(parent.Number.Uint64()) {
|
if !cfg.chainConfig.IsLondon(parent.Number.Uint64()) {
|
||||||
parentGasLimit := parent.GasLimit * params.ElasticityMultiplier
|
parentGasLimit := parent.GasLimit * params.ElasticityMultiplier
|
||||||
header.GasLimit = core.CalcGasLimit(parent.GasUsed, parentGasLimit, cfg.miner.MiningConfig.GasFloor, cfg.miner.MiningConfig.GasCeil)
|
header.GasLimit = core.CalcGasLimit(parentGasLimit, cfg.miner.MiningConfig.GasLimit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Info(fmt.Sprintf("[%s] Start mine", logPrefix), "block", executionAt+1, "baseFee", header.BaseFee, "gasLimit", header.GasLimit)
|
log.Info(fmt.Sprintf("[%s] Start mine", logPrefix), "block", executionAt+1, "baseFee", header.BaseFee, "gasLimit", header.GasLimit)
|
||||||
|
@ -18,8 +18,7 @@ type MiningConfig struct {
|
|||||||
SigKey *ecdsa.PrivateKey // ECDSA private key for signing blocks
|
SigKey *ecdsa.PrivateKey // ECDSA private key for signing blocks
|
||||||
Notify []string `toml:",omitempty"` // HTTP URL list to be notified of new work packages(only useful in ethash).
|
Notify []string `toml:",omitempty"` // HTTP URL list to be notified of new work packages(only useful in ethash).
|
||||||
ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner
|
ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner
|
||||||
GasFloor uint64 // Target gas floor for mined blocks.
|
GasLimit uint64 // Target gas limit for mined blocks.
|
||||||
GasCeil uint64 // Target gas ceiling for mined blocks.
|
|
||||||
GasPrice *big.Int // Minimum gas price for mining a transaction
|
GasPrice *big.Int // Minimum gas price for mining a transaction
|
||||||
Recommit time.Duration // The time interval for miner to re-create mining work.
|
Recommit time.Duration // The time interval for miner to re-create mining work.
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,6 @@ var DefaultFlags = []cli.Flag{
|
|||||||
utils.MiningEnabledFlag,
|
utils.MiningEnabledFlag,
|
||||||
utils.ProposingEnabledFlag,
|
utils.ProposingEnabledFlag,
|
||||||
utils.MinerNotifyFlag,
|
utils.MinerNotifyFlag,
|
||||||
utils.MinerGasTargetFlag,
|
|
||||||
utils.MinerGasLimitFlag,
|
utils.MinerGasLimitFlag,
|
||||||
utils.MinerEtherbaseFlag,
|
utils.MinerEtherbaseFlag,
|
||||||
utils.MinerExtraDataFlag,
|
utils.MinerExtraDataFlag,
|
||||||
|
Loading…
Reference in New Issue
Block a user