aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-08-05 02:53:39 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-08-05 02:53:39 +0800
commit56219a5e7a9ed4762870a891bf962558ee846b74 (patch)
treee2bac06257d04188dcf34b18363756639176e01b /core
parentb01f2c29ae48dba0ba4a90a4c6dbbadfc313f5b1 (diff)
parent26c6e3b206bcf95b6b042ab529522ab7f2bc6f08 (diff)
downloaddexon-56219a5e7a9ed4762870a891bf962558ee846b74.tar
dexon-56219a5e7a9ed4762870a891bf962558ee846b74.tar.gz
dexon-56219a5e7a9ed4762870a891bf962558ee846b74.tar.bz2
dexon-56219a5e7a9ed4762870a891bf962558ee846b74.tar.lz
dexon-56219a5e7a9ed4762870a891bf962558ee846b74.tar.xz
dexon-56219a5e7a9ed4762870a891bf962558ee846b74.tar.zst
dexon-56219a5e7a9ed4762870a891bf962558ee846b74.zip
Merge pull request #1578 from Gustav-Simonsson/frontier_thawing
miner: gas limit strategy, target 3141592 & def gas price 50 Shannon
Diffstat (limited to 'core')
-rw-r--r--core/chain_util.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/core/chain_util.go b/core/chain_util.go
index 326bf13fb..104670195 100644
--- a/core/chain_util.go
+++ b/core/chain_util.go
@@ -69,17 +69,30 @@ func CalcTD(block, parent *types.Block) *big.Int {
// CalcGasLimit computes the gas limit of the next block after parent.
// The result may be modified by the caller.
+// This is miner strategy, not consensus protocol.
func CalcGasLimit(parent *types.Block) *big.Int {
- decay := new(big.Int).Div(parent.GasLimit(), params.GasLimitBoundDivisor)
+ // contrib = (parentGasUsed * 3 / 2) / 1024
contrib := new(big.Int).Mul(parent.GasUsed(), big.NewInt(3))
contrib = contrib.Div(contrib, big.NewInt(2))
contrib = contrib.Div(contrib, params.GasLimitBoundDivisor)
+ // decay = parentGasLimit / 1024 -1
+ decay := new(big.Int).Div(parent.GasLimit(), params.GasLimitBoundDivisor)
+ decay.Sub(decay, big.NewInt(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.
+ */
gl := new(big.Int).Sub(parent.GasLimit(), decay)
gl = gl.Add(gl, contrib)
- gl = gl.Add(gl, big.NewInt(1))
gl.Set(common.BigMax(gl, params.MinGasLimit))
+ // however, if we're now below the target (GenesisGasLimit) we increase the
+ // limit as much as we can (parentGasLimit / 1024 -1)
if gl.Cmp(params.GenesisGasLimit) < 0 {
gl.Add(parent.GasLimit(), decay)
gl.Set(common.BigMin(gl, params.GenesisGasLimit))