Skip to content

Commit 56219a5

Browse files
committed
Merge pull request ethereum#1578 from Gustav-Simonsson/frontier_thawing
miner: gas limit strategy, target 3141592 & def gas price 50 Shannon
2 parents b01f2c2 + 26c6e3b commit 56219a5

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

cmd/utils/flags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ var (
158158
GasPriceFlag = cli.StringFlag{
159159
Name: "gasprice",
160160
Usage: "Sets the minimal gasprice when mining transactions",
161-
Value: new(big.Int).Mul(big.NewInt(500), common.Shannon).String(),
161+
Value: new(big.Int).Mul(big.NewInt(50), common.Shannon).String(),
162162
}
163163

164164
UnlockedAccountFlag = cli.StringFlag{
@@ -318,12 +318,12 @@ var (
318318
GpoMinGasPriceFlag = cli.StringFlag{
319319
Name: "gpomin",
320320
Usage: "Minimum suggested gas price",
321-
Value: new(big.Int).Mul(big.NewInt(1), common.Szabo).String(),
321+
Value: new(big.Int).Mul(big.NewInt(50), common.Shannon).String(),
322322
}
323323
GpoMaxGasPriceFlag = cli.StringFlag{
324324
Name: "gpomax",
325325
Usage: "Maximum suggested gas price",
326-
Value: new(big.Int).Mul(big.NewInt(100), common.Szabo).String(),
326+
Value: new(big.Int).Mul(big.NewInt(500), common.Shannon).String(),
327327
}
328328
GpoFullBlockRatioFlag = cli.IntFlag{
329329
Name: "gpofull",

core/chain_util.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,30 @@ func CalcTD(block, parent *types.Block) *big.Int {
6969

7070
// CalcGasLimit computes the gas limit of the next block after parent.
7171
// The result may be modified by the caller.
72+
// This is miner strategy, not consensus protocol.
7273
func CalcGasLimit(parent *types.Block) *big.Int {
73-
decay := new(big.Int).Div(parent.GasLimit(), params.GasLimitBoundDivisor)
74+
// contrib = (parentGasUsed * 3 / 2) / 1024
7475
contrib := new(big.Int).Mul(parent.GasUsed(), big.NewInt(3))
7576
contrib = contrib.Div(contrib, big.NewInt(2))
7677
contrib = contrib.Div(contrib, params.GasLimitBoundDivisor)
7778

79+
// decay = parentGasLimit / 1024 -1
80+
decay := new(big.Int).Div(parent.GasLimit(), params.GasLimitBoundDivisor)
81+
decay.Sub(decay, big.NewInt(1))
82+
83+
/*
84+
strategy: gasLimit of block-to-mine is set based on parent's
85+
gasUsed value. if parentGasUsed > parentGasLimit * (2/3) then we
86+
increase it, otherwise lower it (or leave it unchanged if it's right
87+
at that usage) the amount increased/decreased depends on how far away
88+
from parentGasLimit * (2/3) parentGasUsed is.
89+
*/
7890
gl := new(big.Int).Sub(parent.GasLimit(), decay)
7991
gl = gl.Add(gl, contrib)
80-
gl = gl.Add(gl, big.NewInt(1))
8192
gl.Set(common.BigMax(gl, params.MinGasLimit))
8293

94+
// however, if we're now below the target (GenesisGasLimit) we increase the
95+
// limit as much as we can (parentGasLimit / 1024 -1)
8396
if gl.Cmp(params.GenesisGasLimit) < 0 {
8497
gl.Add(parent.GasLimit(), decay)
8598
gl.Set(common.BigMin(gl, params.GenesisGasLimit))

eth/fetcher/fetcher_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ import (
2828
"github.com/ethereum/go-ethereum/core"
2929
"github.com/ethereum/go-ethereum/core/types"
3030
"github.com/ethereum/go-ethereum/ethdb"
31+
"github.com/ethereum/go-ethereum/params"
3132
)
3233

3334
var (
3435
testdb, _ = ethdb.NewMemDatabase()
3536
genesis = core.GenesisBlockForTesting(testdb, common.Address{}, big.NewInt(0))
36-
unknownBlock = types.NewBlock(&types.Header{}, nil, nil, nil)
37+
unknownBlock = types.NewBlock(&types.Header{GasLimit: params.GenesisGasLimit}, nil, nil, nil)
3738
)
3839

3940
// makeChain creates a chain of n blocks starting at and including parent.

params/protocol_params.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ var (
3939
EcrecoverGas = big.NewInt(3000) //
4040
Sha256WordGas = big.NewInt(12) //
4141

42-
MinGasLimit = big.NewInt(5000) // Minimum the gas limit may ever be.
43-
GenesisGasLimit = big.NewInt(5000) // Gas limit of the Genesis block.
42+
MinGasLimit = big.NewInt(5000) // Minimum the gas limit may ever be.
43+
GenesisGasLimit = big.NewInt(3141592) // Gas limit of the Genesis block.
4444

4545
Sha3Gas = big.NewInt(30) // Once per SHA3 operation.
4646
Sha256Gas = big.NewInt(60) //

0 commit comments

Comments
 (0)