From 26c6e3b206bcf95b6b042ab529522ab7f2bc6f08 Mon Sep 17 00:00:00 2001 From: Gustav Simonsson Date: Mon, 3 Aug 2015 02:46:34 +0200 Subject: [PATCH] miner: gas limit strategy, target 3141592 & def gas price 50 Shannon --- cmd/utils/flags.go | 6 +++--- core/chain_util.go | 17 +++++++++++++++-- eth/fetcher/fetcher_test.go | 3 ++- params/protocol_params.go | 4 ++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index d283329f1..815d48124 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -158,7 +158,7 @@ var ( GasPriceFlag = cli.StringFlag{ Name: "gasprice", Usage: "Sets the minimal gasprice when mining transactions", - Value: new(big.Int).Mul(big.NewInt(500), common.Shannon).String(), + Value: new(big.Int).Mul(big.NewInt(50), common.Shannon).String(), } UnlockedAccountFlag = cli.StringFlag{ @@ -318,12 +318,12 @@ var ( GpoMinGasPriceFlag = cli.StringFlag{ Name: "gpomin", Usage: "Minimum suggested gas price", - Value: new(big.Int).Mul(big.NewInt(1), common.Szabo).String(), + Value: new(big.Int).Mul(big.NewInt(50), common.Shannon).String(), } GpoMaxGasPriceFlag = cli.StringFlag{ Name: "gpomax", Usage: "Maximum suggested gas price", - Value: new(big.Int).Mul(big.NewInt(100), common.Szabo).String(), + Value: new(big.Int).Mul(big.NewInt(500), common.Shannon).String(), } GpoFullBlockRatioFlag = cli.IntFlag{ Name: "gpofull", 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)) diff --git a/eth/fetcher/fetcher_test.go b/eth/fetcher/fetcher_test.go index 499d6d546..ecbb3f868 100644 --- a/eth/fetcher/fetcher_test.go +++ b/eth/fetcher/fetcher_test.go @@ -28,12 +28,13 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/params" ) var ( testdb, _ = ethdb.NewMemDatabase() genesis = core.GenesisBlockForTesting(testdb, common.Address{}, big.NewInt(0)) - unknownBlock = types.NewBlock(&types.Header{}, nil, nil, nil) + unknownBlock = types.NewBlock(&types.Header{GasLimit: params.GenesisGasLimit}, nil, nil, nil) ) // makeChain creates a chain of n blocks starting at and including parent. diff --git a/params/protocol_params.go b/params/protocol_params.go index b1a6757b1..dcc17e05d 100755 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -39,8 +39,8 @@ var ( EcrecoverGas = big.NewInt(3000) // Sha256WordGas = big.NewInt(12) // - MinGasLimit = big.NewInt(5000) // Minimum the gas limit may ever be. - GenesisGasLimit = big.NewInt(5000) // Gas limit of the Genesis block. + MinGasLimit = big.NewInt(5000) // Minimum the gas limit may ever be. + GenesisGasLimit = big.NewInt(3141592) // Gas limit of the Genesis block. Sha3Gas = big.NewInt(30) // Once per SHA3 operation. Sha256Gas = big.NewInt(60) //