|
@@ -122,13 +122,11 @@ type intervalAdjust struct {
|
|
|
// worker is the main object which takes care of submitting new work to consensus engine
|
|
// worker is the main object which takes care of submitting new work to consensus engine
|
|
|
// and gathering the sealing result.
|
|
// and gathering the sealing result.
|
|
|
type worker struct {
|
|
type worker struct {
|
|
|
- config *params.ChainConfig
|
|
|
|
|
- engine consensus.Engine
|
|
|
|
|
- eth Backend
|
|
|
|
|
- chain *core.BlockChain
|
|
|
|
|
-
|
|
|
|
|
- gasFloor uint64
|
|
|
|
|
- gasCeil uint64
|
|
|
|
|
|
|
+ config *Config
|
|
|
|
|
+ chainConfig *params.ChainConfig
|
|
|
|
|
+ engine consensus.Engine
|
|
|
|
|
+ eth Backend
|
|
|
|
|
+ chain *core.BlockChain
|
|
|
|
|
|
|
|
// Subscriptions
|
|
// Subscriptions
|
|
|
mux *event.TypeMux
|
|
mux *event.TypeMux
|
|
@@ -178,15 +176,14 @@ type worker struct {
|
|
|
resubmitHook func(time.Duration, time.Duration) // Method to call upon updating resubmitting interval.
|
|
resubmitHook func(time.Duration, time.Duration) // Method to call upon updating resubmitting interval.
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, recommit time.Duration, gasFloor, gasCeil uint64, isLocalBlock func(*types.Block) bool) *worker {
|
|
|
|
|
|
|
+func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, isLocalBlock func(*types.Block) bool) *worker {
|
|
|
worker := &worker{
|
|
worker := &worker{
|
|
|
config: config,
|
|
config: config,
|
|
|
|
|
+ chainConfig: chainConfig,
|
|
|
engine: engine,
|
|
engine: engine,
|
|
|
eth: eth,
|
|
eth: eth,
|
|
|
mux: mux,
|
|
mux: mux,
|
|
|
chain: eth.BlockChain(),
|
|
chain: eth.BlockChain(),
|
|
|
- gasFloor: gasFloor,
|
|
|
|
|
- gasCeil: gasCeil,
|
|
|
|
|
isLocalBlock: isLocalBlock,
|
|
isLocalBlock: isLocalBlock,
|
|
|
localUncles: make(map[common.Hash]*types.Block),
|
|
localUncles: make(map[common.Hash]*types.Block),
|
|
|
remoteUncles: make(map[common.Hash]*types.Block),
|
|
remoteUncles: make(map[common.Hash]*types.Block),
|
|
@@ -210,6 +207,7 @@ func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend,
|
|
|
worker.chainSideSub = eth.BlockChain().SubscribeChainSideEvent(worker.chainSideCh)
|
|
worker.chainSideSub = eth.BlockChain().SubscribeChainSideEvent(worker.chainSideCh)
|
|
|
|
|
|
|
|
// Sanitize recommit interval if the user-specified one is too short.
|
|
// Sanitize recommit interval if the user-specified one is too short.
|
|
|
|
|
+ recommit := worker.config.Recommit
|
|
|
if recommit < minRecommitInterval {
|
|
if recommit < minRecommitInterval {
|
|
|
log.Warn("Sanitizing miner recommit interval", "provided", recommit, "updated", minRecommitInterval)
|
|
log.Warn("Sanitizing miner recommit interval", "provided", recommit, "updated", minRecommitInterval)
|
|
|
recommit = minRecommitInterval
|
|
recommit = minRecommitInterval
|
|
@@ -354,7 +352,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
|
|
|
case <-timer.C:
|
|
case <-timer.C:
|
|
|
// If mining is running resubmit a new work cycle periodically to pull in
|
|
// If mining is running resubmit a new work cycle periodically to pull in
|
|
|
// higher priced transactions. Disable this overhead for pending blocks.
|
|
// higher priced transactions. Disable this overhead for pending blocks.
|
|
|
- if w.isRunning() && (w.config.Clique == nil || w.config.Clique.Period > 0) {
|
|
|
|
|
|
|
+ if w.isRunning() && (w.chainConfig.Clique == nil || w.chainConfig.Clique.Period > 0) {
|
|
|
// Short circuit if no new transaction arrives.
|
|
// Short circuit if no new transaction arrives.
|
|
|
if atomic.LoadInt32(&w.newTxs) == 0 {
|
|
if atomic.LoadInt32(&w.newTxs) == 0 {
|
|
|
timer.Reset(recommit)
|
|
timer.Reset(recommit)
|
|
@@ -468,9 +466,10 @@ func (w *worker) mainLoop() {
|
|
|
w.commitTransactions(txset, coinbase, nil)
|
|
w.commitTransactions(txset, coinbase, nil)
|
|
|
w.updateSnapshot()
|
|
w.updateSnapshot()
|
|
|
} else {
|
|
} else {
|
|
|
- // If we're mining, but nothing is being processed, wake on new transactions
|
|
|
|
|
- if w.config.Clique != nil && w.config.Clique.Period == 0 {
|
|
|
|
|
- w.commitNewWork(nil, false, time.Now().Unix())
|
|
|
|
|
|
|
+ // If clique is running in dev mode(period is 0), disable
|
|
|
|
|
+ // advance sealing here.
|
|
|
|
|
+ if w.chainConfig.Clique != nil && w.chainConfig.Clique.Period == 0 {
|
|
|
|
|
+ w.commitNewWork(nil, true, time.Now().Unix())
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
atomic.AddInt32(&w.newTxs, int32(len(ev.Txs)))
|
|
atomic.AddInt32(&w.newTxs, int32(len(ev.Txs)))
|
|
@@ -618,7 +617,7 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
env := &environment{
|
|
env := &environment{
|
|
|
- signer: types.NewEIP155Signer(w.config.ChainID),
|
|
|
|
|
|
|
+ signer: types.NewEIP155Signer(w.chainConfig.ChainID),
|
|
|
state: state,
|
|
state: state,
|
|
|
ancestors: mapset.NewSet(),
|
|
ancestors: mapset.NewSet(),
|
|
|
family: mapset.NewSet(),
|
|
family: mapset.NewSet(),
|
|
@@ -696,7 +695,7 @@ func (w *worker) updateSnapshot() {
|
|
|
func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Address) ([]*types.Log, error) {
|
|
func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Address) ([]*types.Log, error) {
|
|
|
snap := w.current.state.Snapshot()
|
|
snap := w.current.state.Snapshot()
|
|
|
|
|
|
|
|
- receipt, _, err := core.ApplyTransaction(w.config, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
|
|
|
|
|
|
|
+ receipt, _, err := core.ApplyTransaction(w.chainConfig, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
w.current.state.RevertToSnapshot(snap)
|
|
w.current.state.RevertToSnapshot(snap)
|
|
|
return nil, err
|
|
return nil, err
|
|
@@ -757,8 +756,8 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin
|
|
|
from, _ := types.Sender(w.current.signer, tx)
|
|
from, _ := types.Sender(w.current.signer, tx)
|
|
|
// Check whether the tx is replay protected. If we're not in the EIP155 hf
|
|
// Check whether the tx is replay protected. If we're not in the EIP155 hf
|
|
|
// phase, start ignoring the sender until we do.
|
|
// phase, start ignoring the sender until we do.
|
|
|
- if tx.Protected() && !w.config.IsEIP155(w.current.header.Number) {
|
|
|
|
|
- log.Trace("Ignoring reply protected transaction", "hash", tx.Hash(), "eip155", w.config.EIP155Block)
|
|
|
|
|
|
|
+ if tx.Protected() && !w.chainConfig.IsEIP155(w.current.header.Number) {
|
|
|
|
|
+ log.Trace("Ignoring reply protected transaction", "hash", tx.Hash(), "eip155", w.chainConfig.EIP155Block)
|
|
|
|
|
|
|
|
txs.Pop()
|
|
txs.Pop()
|
|
|
continue
|
|
continue
|
|
@@ -842,7 +841,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
|
|
|
header := &types.Header{
|
|
header := &types.Header{
|
|
|
ParentHash: parent.Hash(),
|
|
ParentHash: parent.Hash(),
|
|
|
Number: num.Add(num, common.Big1),
|
|
Number: num.Add(num, common.Big1),
|
|
|
- GasLimit: core.CalcGasLimit(parent, w.gasFloor, w.gasCeil),
|
|
|
|
|
|
|
+ GasLimit: core.CalcGasLimit(parent, w.config.GasFloor, w.config.GasCeil),
|
|
|
Extra: w.extra,
|
|
Extra: w.extra,
|
|
|
Time: uint64(timestamp),
|
|
Time: uint64(timestamp),
|
|
|
}
|
|
}
|
|
@@ -859,12 +858,12 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
// If we are care about TheDAO hard-fork check whether to override the extra-data or not
|
|
// If we are care about TheDAO hard-fork check whether to override the extra-data or not
|
|
|
- if daoBlock := w.config.DAOForkBlock; daoBlock != nil {
|
|
|
|
|
|
|
+ if daoBlock := w.chainConfig.DAOForkBlock; daoBlock != nil {
|
|
|
// Check whether the block is among the fork extra-override range
|
|
// Check whether the block is among the fork extra-override range
|
|
|
limit := new(big.Int).Add(daoBlock, params.DAOForkExtraRange)
|
|
limit := new(big.Int).Add(daoBlock, params.DAOForkExtraRange)
|
|
|
if header.Number.Cmp(daoBlock) >= 0 && header.Number.Cmp(limit) < 0 {
|
|
if header.Number.Cmp(daoBlock) >= 0 && header.Number.Cmp(limit) < 0 {
|
|
|
// Depending whether we support or oppose the fork, override differently
|
|
// Depending whether we support or oppose the fork, override differently
|
|
|
- if w.config.DAOForkSupport {
|
|
|
|
|
|
|
+ if w.chainConfig.DAOForkSupport {
|
|
|
header.Extra = common.CopyBytes(params.DAOForkBlockExtra)
|
|
header.Extra = common.CopyBytes(params.DAOForkBlockExtra)
|
|
|
} else if bytes.Equal(header.Extra, params.DAOForkBlockExtra) {
|
|
} else if bytes.Equal(header.Extra, params.DAOForkBlockExtra) {
|
|
|
header.Extra = []byte{} // If miner opposes, don't let it use the reserved extra-data
|
|
header.Extra = []byte{} // If miner opposes, don't let it use the reserved extra-data
|
|
@@ -879,7 +878,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
|
|
|
}
|
|
}
|
|
|
// Create the current work task and check any fork transitions needed
|
|
// Create the current work task and check any fork transitions needed
|
|
|
env := w.current
|
|
env := w.current
|
|
|
- if w.config.DAOForkSupport && w.config.DAOForkBlock != nil && w.config.DAOForkBlock.Cmp(header.Number) == 0 {
|
|
|
|
|
|
|
+ if w.chainConfig.DAOForkSupport && w.chainConfig.DAOForkBlock != nil && w.chainConfig.DAOForkBlock.Cmp(header.Number) == 0 {
|
|
|
misc.ApplyDAOHardFork(env.state)
|
|
misc.ApplyDAOHardFork(env.state)
|
|
|
}
|
|
}
|
|
|
// Accumulate the uncles for the current block
|
|
// Accumulate the uncles for the current block
|