@@ -284,10 +284,15 @@ func (w *worker) update() {
284284 defer w .chainHeadSub .Unsubscribe ()
285285 defer w .chainSideSub .Unsubscribe ()
286286
287+ xdposEngine , ok := w .engine .(* XDPoS.XDPoS )
288+ if ! ok {
289+ return
290+ }
291+
287292 // timeout waiting for v1 initial value
288293 minePeriod := 2
289- MinePeriodCh := w . engine .( * XDPoS. XDPoS ) .MinePeriodCh
290- NewRoundCh := w . engine .( * XDPoS. XDPoS ) .NewRoundCh
294+ MinePeriodCh := xdposEngine .MinePeriodCh
295+ NewRoundCh := xdposEngine .NewRoundCh
291296
292297 timeout := time .NewTimer (time .Duration (minePeriod ) * time .Second )
293298 defer timeout .Stop ()
@@ -662,15 +667,18 @@ func (w *worker) checkPreCommitWithLock() (*types.Block, bool) {
662667// checkPreCommit checks whether a new work commit is needed,
663668// returns the parent block and shouldReturn.
664669func (w * worker ) checkPreCommit () (* types.Block , bool ) {
665- c := w .engine .(* XDPoS.XDPoS )
670+ var xdposEngine * XDPoS.XDPoS
671+ if engine , ok := w .engine .(* XDPoS.XDPoS ); ok {
672+ xdposEngine = engine
673+ }
666674 var parent * types.Block
667675 currentHeader := w .chain .CurrentBlock ()
668676 // Guard against nil header (early startup or uninitialised chain).
669677 if currentHeader == nil {
670678 return nil , true
671679 }
672- if c != nil {
673- parent = c .FindParentBlockToAssign (w .chain , currentHeader )
680+ if xdposEngine != nil {
681+ parent = xdposEngine .FindParentBlockToAssign (w .chain , currentHeader )
674682 } else {
675683 parent = w .chain .GetBlock (currentHeader .Hash (), currentHeader .Number .Uint64 ())
676684 }
@@ -687,8 +695,8 @@ func (w *worker) checkPreCommit() (*types.Block, bool) {
687695 // Only try to commit new work if we are mining
688696 if atomic .LoadInt32 (& w .mining ) == 1 {
689697 // check if we are right after parent's coinbase in the list
690- if w .config .XDPoS != nil {
691- ok , err := c .YourTurn (w .chain , parent .Header (), w .coinbase )
698+ if w .config .XDPoS != nil && xdposEngine != nil {
699+ ok , err := xdposEngine .YourTurn (w .chain , parent .Header (), w .coinbase )
692700 if err != nil {
693701 log .Warn ("Failed when trying to commit new work" , "err" , err )
694702 return parent , true
0 commit comments