@@ -517,8 +517,16 @@ func (r *Reactor) poolRoutine(ctx context.Context, stateSynced bool, blockSyncCh
517517 // NOTE: We can probably make this more efficient, but note that calling
518518 // first.Hash() doesn't verify the tx contents, so MakePartSet() is
519519 // currently necessary.
520- if err = state .Validators .VerifyCommitLight (chainID , firstID , first .Height , second .LastCommit ); err != nil {
521- err = fmt .Errorf ("invalid last commit: %w" , err )
520+ err = state .Validators .VerifyCommitLight (chainID , firstID , first .Height , second .LastCommit )
521+
522+ if err == nil {
523+ // validate the block before we persist it
524+ err = r .blockExec .ValidateBlock (ctx , state , first )
525+ }
526+
527+ // If either of the checks failed we log the error and request for a new block
528+ // at that height
529+ if err != nil {
522530 r .logger .Error (
523531 err .Error (),
524532 "last_commit" , second .LastCommit ,
@@ -545,37 +553,35 @@ func (r *Reactor) poolRoutine(ctx context.Context, stateSynced bool, blockSyncCh
545553 return
546554 }
547555 }
548- } else {
549- r . pool . PopRequest ()
556+ return
557+ }
550558
551- // TODO: batch saves so we do not persist to disk every block
552- r .store .SaveBlock (first , firstParts , second .LastCommit )
559+ r .pool .PopRequest ()
553560
554- var err error
561+ // TODO: batch saves so we do not persist to disk every block
562+ r .store .SaveBlock (first , firstParts , second .LastCommit )
555563
556- // TODO: Same thing for app - but we would need a way to get the hash
557- // without persisting the state.
558- state , err = r .blockExec .ApplyBlock (ctx , state , firstID , first )
559- if err != nil {
560- // TODO: This is bad, are we zombie?
561- panic (fmt .Sprintf ("failed to process committed block (%d:%X): %v" , first .Height , first .Hash (), err ))
562- }
564+ // TODO: Same thing for app - but we would need a way to get the hash
565+ // without persisting the state.
566+ state , err = r .blockExec .ApplyBlock (ctx , state , firstID , first )
567+ if err != nil {
568+ panic (fmt .Sprintf ("failed to process committed block (%d:%X): %v" , first .Height , first .Hash (), err ))
569+ }
563570
564- r .metrics .RecordConsMetrics (first )
571+ r .metrics .RecordConsMetrics (first )
565572
566- blocksSynced ++
573+ blocksSynced ++
567574
568- if blocksSynced % 100 == 0 {
569- lastRate = 0.9 * lastRate + 0.1 * (100 / time .Since (lastHundred ).Seconds ())
570- r .logger .Info (
571- "block sync rate" ,
572- "height" , r .pool .height ,
573- "max_peer_height" , r .pool .MaxPeerHeight (),
574- "blocks/s" , lastRate ,
575- )
575+ if blocksSynced % 100 == 0 {
576+ lastRate = 0.9 * lastRate + 0.1 * (100 / time .Since (lastHundred ).Seconds ())
577+ r .logger .Info (
578+ "block sync rate" ,
579+ "height" , r .pool .height ,
580+ "max_peer_height" , r .pool .MaxPeerHeight (),
581+ "blocks/s" , lastRate ,
582+ )
576583
577- lastHundred = time .Now ()
578- }
584+ lastHundred = time .Now ()
579585 }
580586 }
581587 }
0 commit comments