Skip to content

Commit

Permalink
Merge pull request #680 from jpmorganchase/fix/raft-calcgaslimit
Browse files Browse the repository at this point in the history
raft: pass gas floor and gas ceil to calcGasLimit when minting block
  • Loading branch information
jpmsam authored May 31, 2019
2 parents 43806e1 + 10e01f4 commit 1c07c0c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
4 changes: 4 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,7 @@ func (s *Ethereum) Stop() error {
close(s.shutdownChan)
return nil
}

func (s *Ethereum) CalcGasLimit(block *types.Block) uint64 {
return core.CalcGasLimit(block, s.config.MinerGasFloor, s.config.MinerGasCeil)
}
4 changes: 2 additions & 2 deletions eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ var DefaultConfig = Config{
DatabaseCache: 768,
TrieCache: 256,
TrieTimeout: 60 * time.Minute,
MinerGasFloor: 8000000,
MinerGasCeil: 8000000,
MinerGasFloor: params.MinGasLimit,
MinerGasCeil: params.GenesisGasLimit,
MinerGasPrice: big.NewInt(params.GWei),
MinerRecommit: 3 * time.Second,

Expand Down
26 changes: 15 additions & 11 deletions raft/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"sync"
"time"

"github.com/ethereum/go-ethereum/core/types"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth"
Expand All @@ -31,21 +33,23 @@ type RaftService struct {
startPeers []*enode.Node

// we need an event mux to instantiate the blockchain
eventMux *event.TypeMux
minter *minter
nodeKey *ecdsa.PrivateKey
eventMux *event.TypeMux
minter *minter
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) {
service := &RaftService{
eventMux: ctx.EventMux,
chainDb: e.ChainDb(),
blockchain: e.BlockChain(),
txPool: e.TxPool(),
accountManager: e.AccountManager(),
downloader: e.Downloader(),
startPeers: startPeers,
nodeKey: ctx.NodeKey(),
eventMux: ctx.EventMux,
chainDb: e.ChainDb(),
blockchain: e.BlockChain(),
txPool: e.TxPool(),
accountManager: e.AccountManager(),
downloader: e.Downloader(),
startPeers: startPeers,
nodeKey: ctx.NodeKey(),
calcGasLimitFunc: e.CalcGasLimit,
}

service.minter = newMinter(chainConfig, service, blockTime)
Expand Down
2 changes: 1 addition & 1 deletion raft/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (minter *minter) createWork() *work {
ParentHash: parent.Hash(),
Number: parentNumber.Add(parentNumber, common.Big1),
Difficulty: ethash.CalcDifficulty(minter.config, uint64(tstamp), parent.Header()),
GasLimit: core.CalcGasLimit(parent, parent.GasLimit(), parent.GasLimit()),
GasLimit: minter.eth.calcGasLimitFunc(parent),
GasUsed: 0,
Coinbase: minter.coinbase,
Time: big.NewInt(tstamp),
Expand Down

0 comments on commit 1c07c0c

Please sign in to comment.