Skip to content

Commit

Permalink
GasLimit adjustment steps for the Testnet
Browse files Browse the repository at this point in the history
GasLimit  ceiling target changes based on 4 steps
Each step is 150,000 blocks (i.e expected blocks for 3 weeks)

GasCeil is changed to 110M because it is enough to accomodate the 1700 testnet
target

These changes are for the testnet and probably is not a long term
controller
  • Loading branch information
gameofpointers committed Sep 12, 2023
1 parent 0d0da91 commit c45b913
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 75 deletions.
18 changes: 16 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1240,43 +1240,57 @@ func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {
}
}

func setDurationLimit(ctx *cli.Context, cfg *ethconfig.Config) {
func setConsensusEngineConfig(ctx *cli.Context, cfg *ethconfig.Config) {
if cfg.ConsensusEngine == "blake3" {
// Override any default configs for hard coded networks.
switch {
case ctx.GlobalBool(ColosseumFlag.Name):
cfg.Blake3Pow.DurationLimit = params.DurationLimit
cfg.Blake3Pow.GasCeil = params.ColosseumGasCeil
case ctx.GlobalBool(GardenFlag.Name):
cfg.Blake3Pow.DurationLimit = params.GardenDurationLimit
cfg.Blake3Pow.GasCeil = params.GardenGasCeil
case ctx.GlobalBool(OrchardFlag.Name):
cfg.Blake3Pow.DurationLimit = params.OrchardDurationLimit
cfg.Blake3Pow.GasCeil = params.OrchardGasCeil
case ctx.GlobalBool(LighthouseFlag.Name):
cfg.Blake3Pow.DurationLimit = params.LighthouseDurationLimit
cfg.Blake3Pow.GasCeil = params.LighthouseGasCeil
case ctx.GlobalBool(LocalFlag.Name):
cfg.Blake3Pow.DurationLimit = params.LocalDurationLimit
cfg.Blake3Pow.GasCeil = params.LocalGasCeil
case ctx.GlobalBool(DeveloperFlag.Name):
cfg.Blake3Pow.DurationLimit = params.DurationLimit
cfg.Blake3Pow.GasCeil = params.LocalGasCeil
default:
cfg.Blake3Pow.DurationLimit = params.DurationLimit
cfg.Blake3Pow.GasCeil = params.GasCeil

}
} else {
// Override any default configs for hard coded networks.
switch {
case ctx.GlobalBool(ColosseumFlag.Name):
cfg.Progpow.DurationLimit = params.DurationLimit
cfg.Progpow.GasCeil = params.ColosseumGasCeil
case ctx.GlobalBool(GardenFlag.Name):
cfg.Progpow.DurationLimit = params.GardenDurationLimit
cfg.Progpow.GasCeil = params.GardenGasCeil
case ctx.GlobalBool(OrchardFlag.Name):
cfg.Progpow.DurationLimit = params.OrchardDurationLimit
cfg.Progpow.GasCeil = params.OrchardGasCeil
case ctx.GlobalBool(LighthouseFlag.Name):
cfg.Progpow.DurationLimit = params.LighthouseDurationLimit
cfg.Progpow.GasCeil = params.LighthouseGasCeil
case ctx.GlobalBool(LocalFlag.Name):
cfg.Progpow.DurationLimit = params.LocalDurationLimit
cfg.Progpow.GasCeil = params.LocalGasCeil
case ctx.GlobalBool(DeveloperFlag.Name):
cfg.Progpow.DurationLimit = params.DurationLimit
cfg.Progpow.GasCeil = params.LocalGasCeil
default:
cfg.Progpow.DurationLimit = params.DurationLimit
cfg.Progpow.GasCeil = params.GasCeil

}
}
Expand Down Expand Up @@ -1425,7 +1439,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
} else {
cfg.ConsensusEngine = "progpow"
}
setDurationLimit(ctx, cfg)
setConsensusEngineConfig(ctx, cfg)

setWhitelist(ctx, cfg)

Expand Down
2 changes: 2 additions & 0 deletions consensus/blake3pow/blake3pow.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type Config struct {

DurationLimit *big.Int

GasCeil uint64

// When set, notifications sent by the remote sealer will
// be block header JSON objects instead of work package arrays.
NotifyFull bool
Expand Down
6 changes: 4 additions & 2 deletions consensus/blake3pow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,10 @@ func (blake3pow *Blake3pow) verifyHeader(chain consensus.ChainHeaderReader, head
}
// Verify the block's gas usage and verify the base fee.
// Verify that the gas limit remains within allowed bounds
if err := misc.VerifyGaslimit(parent.GasLimit(), header.GasLimit()); err != nil {
return err
expectedGasLimit := core.CalcGasLimit(parent, blake3pow.config.GasCeil)
if expectedGasLimit != header.GasLimit() {
return fmt.Errorf("invalid gasLimit: have %d, want %d",
header.GasLimit(), expectedGasLimit)
}
// Verify the header is not malformed
if header.BaseFee() == nil {
Expand Down
42 changes: 0 additions & 42 deletions consensus/misc/gaslimit.go

This file was deleted.

6 changes: 4 additions & 2 deletions consensus/progpow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,10 @@ func (progpow *Progpow) verifyHeader(chain consensus.ChainHeaderReader, header,
}
// Verify the block's gas usage and verify the base fee.
// Verify that the gas limit remains within allowed bounds
if err := misc.VerifyGaslimit(parent.GasLimit(), header.GasLimit()); err != nil {
return err
expectedGasLimit := core.CalcGasLimit(parent, progpow.config.GasCeil)
if expectedGasLimit != header.GasLimit() {
return fmt.Errorf("invalid gasLimit: have %d, want %d",
header.GasLimit(), expectedGasLimit)
}
// Verify the header is not malformed
if header.BaseFee() == nil {
Expand Down
1 change: 1 addition & 0 deletions consensus/progpow/progpow.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ type Config struct {
CachesOnDisk int
CachesLockMmap bool
DurationLimit *big.Int
GasCeil uint64

// When set, notifications sent by the remote sealer will
// be block header JSON objects instead of work package arrays.
Expand Down
47 changes: 32 additions & 15 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,42 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
// CalcGasLimit computes the gas limit of the next block after parent. It aims
// to keep the baseline gas close to the provided target, and increase it towards
// the target if the baseline gas is lower.
func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64 {
func CalcGasLimit(parent *types.Header, gasCeil uint64) uint64 {

parentGasLimit := parent.GasLimit()

delta := parentGasLimit/params.GasLimitBoundDivisor - 1
limit := parentGasLimit
if desiredLimit < params.MinGasLimit {

var desiredLimit uint64
percentGasUsed := parent.GasUsed() * 100 / parent.GasLimit()
if percentGasUsed > params.PercentGasUsedThreshold {
desiredLimit = CalcGasCeil(parent.NumberU64(), gasCeil)
if desiredLimit > gasCeil {
desiredLimit = gasCeil
}
if limit+delta > desiredLimit {
return desiredLimit
} else {
return limit + delta
}
} else {
desiredLimit = params.MinGasLimit
}
// If we're outside our allowed gas range, we try to hone towards them
if limit < desiredLimit {
limit = parentGasLimit + delta
if limit > desiredLimit {
limit = desiredLimit
if limit-delta/2 < desiredLimit {
return desiredLimit
} else {
return limit - delta/2
}
return limit
}
if limit > desiredLimit {
limit = parentGasLimit - delta
if limit < desiredLimit {
limit = desiredLimit
}
}

func CalcGasCeil(blockNumber uint64, gasCeil uint64) uint64 {
if blockNumber < params.GasLimitStepOneBlockThreshold {
return gasCeil / 4
} else if blockNumber < params.GasLimitStepTwoBlockThreshold {
return gasCeil / 2
} else if blockNumber < params.GasLimitStepThreeBlockThreshold {
return gasCeil * 3 / 4
}
return limit
return gasCeil
}
2 changes: 1 addition & 1 deletion core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (sl *Slice) Append(header *types.Header, domPendingHeader *types.Header, do
log.Info("times during sub append:", "t6_1:", time6_1, "t6_2:", time6_2, "t6_3:", time6_3)
log.Info("Appended new block", "number", block.Header().Number(), "hash", block.Hash(),
"difficulty", block.Header().Difficulty(),
"uncles", len(block.Uncles()), "txs", len(block.Transactions()), "etxs", len(block.ExtTransactions()), "gas", block.GasUsed(),
"uncles", len(block.Uncles()), "txs", len(block.Transactions()), "etxs", len(block.ExtTransactions()), "gas", block.GasUsed(), "gasLimit", block.GasLimit(),
"root", block.Root(),
"order", order,
"location", block.Header().Location(),
Expand Down
7 changes: 1 addition & 6 deletions core/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,12 +881,7 @@ func (w *worker) fillTransactions(interrupt *int32, env *environment, block *typ
// into the given sealing block. The transaction selection and ordering strategy can
// be customized with the plugin in the future.
func (w *worker) adjustGasLimit(interrupt *int32, env *environment, parent *types.Block) {
percentGasUsed := parent.GasUsed() * 100 / parent.GasLimit()
if percentGasUsed > params.PercentGasUsedThreshold {
env.header.SetGasLimit(CalcGasLimit(parent.GasLimit(), w.config.GasCeil))
} else {
env.header.SetGasLimit(CalcGasLimit(parent.GasLimit(), w.config.GasFloor))
}
env.header.SetGasLimit(CalcGasLimit(parent.Header(), w.config.GasCeil))
}

// ComputeManifestHash given a header computes the manifest hash for the header
Expand Down
2 changes: 2 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func CreateProgpowConsensusEngine(stack *node.Node, chainConfig *params.ChainCon
PowMode: config.PowMode,
NotifyFull: config.NotifyFull,
DurationLimit: config.DurationLimit,
GasCeil: config.GasCeil,
}, notify, noverify)
engine.SetThreads(-1) // Disable CPU mining
return engine
Expand All @@ -201,6 +202,7 @@ func CreateBlake3ConsensusEngine(stack *node.Node, chainConfig *params.ChainConf
PowMode: config.PowMode,
NotifyFull: config.NotifyFull,
DurationLimit: config.DurationLimit,
GasCeil: config.GasCeil,
}, notify, noverify)
engine.SetThreads(-1) // Disable CPU mining
return engine
Expand Down
14 changes: 9 additions & 5 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ import (
)

const (
GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations.
PercentGasUsedThreshold uint64 = 95 // Percent Gas used threshold at which the gas limit adjusts
MinGasLimit uint64 = 5000000 // Minimum the gas limit may ever be.
GenesisGasLimit uint64 = 5000000 // Gas limit of the Genesis block.
GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations.
PercentGasUsedThreshold uint64 = 50 // Percent Gas used threshold at which the gas limit adjusts
GasLimitStepOneBlockThreshold uint64 = 150000
GasLimitStepTwoBlockThreshold uint64 = 300000
GasLimitStepThreeBlockThreshold uint64 = 450000
MinGasLimit uint64 = 5000000 // Minimum the gas limit may ever be.
GenesisGasLimit uint64 = 5000000 // Gas limit of the Genesis block.

MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis.
ExpByteGas uint64 = 10 // Times ceil(log256(exponent)) for the EXP instruction.
Expand Down Expand Up @@ -138,7 +141,8 @@ const (
)

var (
ColosseumGasCeil uint64 = 160000000
GasCeil uint64 = 20000000
ColosseumGasCeil uint64 = 110000000
GardenGasCeil uint64 = 160000000
OrchardGasCeil uint64 = 50000000
LighthouseGasCeil uint64 = 160000000
Expand Down

0 comments on commit c45b913

Please sign in to comment.