@ -122,14 +122,12 @@ type intervalAdjust struct {
// worker is the main object which takes care of submitting new work to consensus engine
// and gathering the sealing result.
type worker struct {
config * params . ChainConfig
config * Config
chainConfig * params . ChainConfig
engine consensus . Engine
eth Backend
chain * core . BlockChain
gasFloor uint64
gasCeil uint64
// Subscriptions
mux * event . TypeMux
txsCh chan core . NewTxsEvent
@ -178,15 +176,14 @@ type worker struct {
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 {
config : config ,
chainConfig : chainConfig ,
engine : engine ,
eth : eth ,
mux : mux ,
chain : eth . BlockChain ( ) ,
gasFloor : gasFloor ,
gasCeil : gasCeil ,
isLocalBlock : isLocalBlock ,
localUncles : 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 )
// Sanitize recommit interval if the user-specified one is too short.
recommit := worker . config . Recommit
if recommit < minRecommitInterval {
log . Warn ( "Sanitizing miner recommit interval" , "provided" , recommit , "updated" , minRecommitInterval )
recommit = minRecommitInterval
@ -354,7 +352,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
case <- timer . C :
// If mining is running resubmit a new work cycle periodically to pull in
// 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 . chainC onfig . Clique == nil || w . chainC onfig . Clique . Period > 0 ) {
// Short circuit if no new transaction arrives.
if atomic . LoadInt32 ( & w . newTxs ) == 0 {
timer . Reset ( recommit )
@ -468,9 +466,10 @@ func (w *worker) mainLoop() {
w . commitTransactions ( txset , coinbase , nil )
w . updateSnapshot ( )
} 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 ) ) )
@ -618,7 +617,7 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error {
return err
}
env := & environment {
signer : types . NewEIP155Signer ( w . config . ChainID ) ,
signer : types . NewEIP155Signer ( w . chainC onfig . ChainID ) ,
state : state ,
ancestors : 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 ) {
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 . chainC onfig , w . chain , & coinbase , w . current . gasPool , w . current . state , w . current . header , tx , & w . current . header . GasUsed , * w . chain . GetVMConfig ( ) )
if err != nil {
w . current . state . RevertToSnapshot ( snap )
return nil , err
@ -757,8 +756,8 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin
from , _ := types . Sender ( w . current . signer , tx )
// Check whether the tx is replay protected. If we're not in the EIP155 hf
// 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 . chainC onfig . IsEIP155 ( w . current . header . Number ) {
log . Trace ( "Ignoring reply protected transaction" , "hash" , tx . Hash ( ) , "eip155" , w . chainC onfig . EIP155Block )
txs . Pop ( )
continue
@ -842,7 +841,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
header := & types . Header {
ParentHash : parent . Hash ( ) ,
Number : num . Add ( num , common . Big1 ) ,
GasLimit : core . CalcGasLimit ( parent , w . gasFloor , w . gasCeil ) ,
GasLimit : core . CalcGasLimit ( parent , w . confi g. G asFloor, w . confi g. G asCeil) ,
Extra : w . extra ,
Time : uint64 ( timestamp ) ,
}
@ -859,12 +858,12 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
return
}
// 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 . chainC onfig . DAOForkBlock ; daoBlock != nil {
// Check whether the block is among the fork extra-override range
limit := new ( big . Int ) . Add ( daoBlock , params . DAOForkExtraRange )
if header . Number . Cmp ( daoBlock ) >= 0 && header . Number . Cmp ( limit ) < 0 {
// Depending whether we support or oppose the fork, override differently
if w . config . DAOForkSupport {
if w . chainC onfig . DAOForkSupport {
header . Extra = common . CopyBytes ( 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
@ -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
env := w . current
if w . config . DAOForkSupport && w . config . DAOForkBlock != nil && w . config . DAOForkBlock . Cmp ( header . Number ) == 0 {
if w . chainC onfig . DAOForkSupport && w . chainC onfig . DAOForkBlock != nil && w . chainC onfig . DAOForkBlock . Cmp ( header . Number ) == 0 {
misc . ApplyDAOHardFork ( env . state )
}
// Accumulate the uncles for the current block