Merge pull request #680 from jpmorganchase/fix/raft-calcgaslimit

raft: pass gas floor and gas ceil to calcGasLimit when minting block
This commit is contained in:
Samer Falah 2019-05-31 09:49:30 -04:00 committed by GitHub
commit 1c07c0c8c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 14 deletions

View File

@ -557,3 +557,7 @@ func (s *Ethereum) Stop() error {
close(s.shutdownChan) close(s.shutdownChan)
return nil return nil
} }
func (s *Ethereum) CalcGasLimit(block *types.Block) uint64 {
return core.CalcGasLimit(block, s.config.MinerGasFloor, s.config.MinerGasCeil)
}

View File

@ -49,8 +49,8 @@ var DefaultConfig = Config{
DatabaseCache: 768, DatabaseCache: 768,
TrieCache: 256, TrieCache: 256,
TrieTimeout: 60 * time.Minute, TrieTimeout: 60 * time.Minute,
MinerGasFloor: 8000000, MinerGasFloor: params.MinGasLimit,
MinerGasCeil: 8000000, MinerGasCeil: params.GenesisGasLimit,
MinerGasPrice: big.NewInt(params.GWei), MinerGasPrice: big.NewInt(params.GWei),
MinerRecommit: 3 * time.Second, MinerRecommit: 3 * time.Second,

View File

@ -5,6 +5,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
@ -31,21 +33,23 @@ type RaftService struct {
startPeers []*enode.Node startPeers []*enode.Node
// we need an event mux to instantiate the blockchain // we need an event mux to instantiate the blockchain
eventMux *event.TypeMux eventMux *event.TypeMux
minter *minter minter *minter
nodeKey *ecdsa.PrivateKey nodeKey *ecdsa.PrivateKey
calcGasLimitFunc func(block *types.Block) uint64
} }
func New(ctx *node.ServiceContext, chainConfig *params.ChainConfig, raftId, raftPort uint16, joinExisting bool, blockTime time.Duration, e *eth.Ethereum, startPeers []*enode.Node, datadir string) (*RaftService, error) { func New(ctx *node.ServiceContext, chainConfig *params.ChainConfig, raftId, raftPort uint16, joinExisting bool, blockTime time.Duration, e *eth.Ethereum, startPeers []*enode.Node, datadir string) (*RaftService, error) {
service := &RaftService{ service := &RaftService{
eventMux: ctx.EventMux, eventMux: ctx.EventMux,
chainDb: e.ChainDb(), chainDb: e.ChainDb(),
blockchain: e.BlockChain(), blockchain: e.BlockChain(),
txPool: e.TxPool(), txPool: e.TxPool(),
accountManager: e.AccountManager(), accountManager: e.AccountManager(),
downloader: e.Downloader(), downloader: e.Downloader(),
startPeers: startPeers, startPeers: startPeers,
nodeKey: ctx.NodeKey(), nodeKey: ctx.NodeKey(),
calcGasLimitFunc: e.CalcGasLimit,
} }
service.minter = newMinter(chainConfig, service, blockTime) service.minter = newMinter(chainConfig, service, blockTime)

View File

@ -262,7 +262,7 @@ func (minter *minter) createWork() *work {
ParentHash: parent.Hash(), ParentHash: parent.Hash(),
Number: parentNumber.Add(parentNumber, common.Big1), Number: parentNumber.Add(parentNumber, common.Big1),
Difficulty: ethash.CalcDifficulty(minter.config, uint64(tstamp), parent.Header()), Difficulty: ethash.CalcDifficulty(minter.config, uint64(tstamp), parent.Header()),
GasLimit: core.CalcGasLimit(parent, parent.GasLimit(), parent.GasLimit()), GasLimit: minter.eth.calcGasLimitFunc(parent),
GasUsed: 0, GasUsed: 0,
Coinbase: minter.coinbase, Coinbase: minter.coinbase,
Time: big.NewInt(tstamp), Time: big.NewInt(tstamp),