Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save meowsbits/7e3cc5eb68a316c4db85ecb7cf59fb4b to your computer and use it in GitHub Desktop.
Save meowsbits/7e3cc5eb68a316c4db85ecb7cf59fb4b to your computer and use it in GitHub Desktop.
Maximized block gas limit steps for miners with strong opinions.
diff --git a/core/block_validator.go b/core/block_validator.go
index 37bea2b246..862ee952cc 100644
--- a/core/block_validator.go
+++ b/core/block_validator.go
@@ -107,34 +107,19 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
// ceil if the blocks are full. If the ceil is exceeded, it will always decrease
// the gas allowance.
func CalcGasLimit(parent *types.Block, gasFloor, gasCeil uint64) uint64 {
- // contrib = (parentGasUsed * 3 / 2) / 1024
- contrib := (parent.GasUsed() + parent.GasUsed()/2) / vars.GasLimitBoundDivisor
// decay = parentGasLimit / 1024 -1
- decay := parent.GasLimit()/vars.GasLimitBoundDivisor - 1
+ ethashMaxDelta := parent.GasLimit()/vars.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 := parent.GasLimit() - decay + contrib
- if limit < vars.MinGasLimit {
- limit = vars.MinGasLimit
+ next := parent.GasLimit()
+ if parent.GasLimit() < gasFloor {
+ next = parent.GasLimit() + ethashMaxDelta
+ } else if parent.GasLimit() > gasCeil {
+ next = parent.GasLimit() - ethashMaxDelta
}
- // If we're outside our allowed gas range, we try to hone towards them
- if limit < gasFloor {
- limit = parent.GasLimit() + decay
- if limit > gasFloor {
- limit = gasFloor
- }
- } else if limit > gasCeil {
- limit = parent.GasLimit() - decay
- if limit < gasCeil {
- limit = gasCeil
- }
+ if next < vars.MinGasLimit {
+ next = vars.MinGasLimit
}
- return limit
+
+ return next
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment