@@ -529,7 +529,7 @@ func (s *Syncer) downloadLegacyMalfeasanceProofs(ctx context.Context, initial bo
529
529
batch , err := sst .missing (s .cfg .MaxBatchSize , func (nodeID types.NodeID ) (bool , error ) {
530
530
// TODO(ivan4th): check multiple node IDs at once in a single SQL query
531
531
isMalicious , err := identities .IsMalicious (s .db , nodeID )
532
- if errors .Is (err , sql .ErrNotFound ) {
532
+ if err != nil && errors .Is (err , sql .ErrNotFound ) {
533
533
return false , nil
534
534
}
535
535
return isMalicious , err
@@ -539,36 +539,36 @@ func (s *Syncer) downloadLegacyMalfeasanceProofs(ctx context.Context, initial bo
539
539
}
540
540
541
541
nothingToDownload = len (batch ) == 0
542
- if len (batch ) == 0 {
543
- s .logger .Debug ("no new legacy malicious identities" , log .ZContext (ctx ))
544
- continue
545
- }
546
- s .logger .Debug ("retrieving legacy malicious identities" ,
547
- log .ZContext (ctx ),
548
- zap .Int ("count" , len (batch )),
549
- )
550
- if err := s .fetcher .LegacyMalfeasanceProofs (ctx , batch ); err != nil {
551
- if errors .Is (err , context .Canceled ) {
552
- return ctx .Err ()
553
- }
554
- s .logger .Debug ("failed to download malfeasance proofs" ,
542
+ if len (batch ) != 0 {
543
+ s .logger .Debug ("retrieving legacy malicious identities" ,
555
544
log .ZContext (ctx ),
556
- log . NiceZapError ( err ),
545
+ zap . Int ( "count" , len ( batch ) ),
557
546
)
558
- }
559
- batchError := & fetch.BatchError {}
560
- if errors .As (err , & batchError ) {
561
- for hash , err := range batchError .Errors {
562
- nodeID := types .NodeID (hash )
563
- switch {
564
- case ! sst .has (nodeID ):
565
- continue
566
- case errors .Is (err , pubsub .ErrValidationReject ):
567
- sst .rejected (nodeID )
568
- default :
569
- sst .failed (nodeID )
547
+ if err := s .fetcher .LegacyMalfeasanceProofs (ctx , batch ); err != nil {
548
+ if errors .Is (err , context .Canceled ) {
549
+ return ctx .Err ()
570
550
}
551
+ s .logger .Debug ("failed to download malfeasance proofs" ,
552
+ log .ZContext (ctx ),
553
+ log .NiceZapError (err ),
554
+ )
571
555
}
556
+ batchError := & fetch.BatchError {}
557
+ if errors .As (err , & batchError ) {
558
+ for hash , err := range batchError .Errors {
559
+ nodeID := types .NodeID (hash )
560
+ switch {
561
+ case ! sst .has (nodeID ):
562
+ continue
563
+ case errors .Is (err , pubsub .ErrValidationReject ):
564
+ sst .rejected (nodeID )
565
+ default :
566
+ sst .failed (nodeID )
567
+ }
568
+ }
569
+ }
570
+ } else {
571
+ s .logger .Debug ("no new legacy malicious identities" , log .ZContext (ctx ))
572
572
}
573
573
}
574
574
}
@@ -624,7 +624,7 @@ func (s *Syncer) downloadMalfeasanceProofs(ctx context.Context, initial bool, up
624
624
batch , err := sst .missing (s .cfg .MaxBatchSize , func (nodeID types.NodeID ) (bool , error ) {
625
625
// TODO(mafa): check multiple node IDs at once in a single SQL query
626
626
isMalicious , err := malfeasance .IsMalicious (s .db , nodeID )
627
- if errors .Is (err , sql .ErrNotFound ) {
627
+ if err != nil && errors .Is (err , sql .ErrNotFound ) {
628
628
return false , nil
629
629
}
630
630
return isMalicious , err
@@ -634,36 +634,36 @@ func (s *Syncer) downloadMalfeasanceProofs(ctx context.Context, initial bool, up
634
634
}
635
635
636
636
nothingToDownload = len (batch ) == 0
637
- if len (batch ) == 0 {
638
- s .logger .Debug ("no new malicious identities" , log .ZContext (ctx ))
639
- continue
640
- }
641
- s .logger .Debug ("retrieving malicious identities" ,
642
- log .ZContext (ctx ),
643
- zap .Int ("count" , len (batch )),
644
- )
645
- if err := s .fetcher .MalfeasanceProofs (ctx , batch ); err != nil {
646
- if errors .Is (err , context .Canceled ) {
647
- return ctx .Err ()
648
- }
649
- s .logger .Debug ("failed to download malfeasance proofs" ,
637
+ if len (batch ) != 0 {
638
+ s .logger .Debug ("retrieving malicious identities" ,
650
639
log .ZContext (ctx ),
651
- log . NiceZapError ( err ),
640
+ zap . Int ( "count" , len ( batch ) ),
652
641
)
653
- }
654
- batchError := & fetch.BatchError {}
655
- if errors .As (err , & batchError ) {
656
- for hash , err := range batchError .Errors {
657
- nodeID := types .NodeID (hash )
658
- switch {
659
- case ! sst .has (nodeID ):
660
- continue
661
- case errors .Is (err , pubsub .ErrValidationReject ):
662
- sst .rejected (nodeID )
663
- default :
664
- sst .failed (nodeID )
642
+ if err := s .fetcher .MalfeasanceProofs (ctx , batch ); err != nil {
643
+ if errors .Is (err , context .Canceled ) {
644
+ return ctx .Err ()
665
645
}
646
+ s .logger .Debug ("failed to download malfeasance proofs" ,
647
+ log .ZContext (ctx ),
648
+ log .NiceZapError (err ),
649
+ )
666
650
}
651
+ batchError := & fetch.BatchError {}
652
+ if errors .As (err , & batchError ) {
653
+ for hash , err := range batchError .Errors {
654
+ nodeID := types .NodeID (hash )
655
+ switch {
656
+ case ! sst .has (nodeID ):
657
+ continue
658
+ case errors .Is (err , pubsub .ErrValidationReject ):
659
+ sst .rejected (nodeID )
660
+ default :
661
+ sst .failed (nodeID )
662
+ }
663
+ }
664
+ }
665
+ } else {
666
+ s .logger .Debug ("no new malicious identities" , log .ZContext (ctx ))
667
667
}
668
668
}
669
669
}
0 commit comments