Skip to content

Commit b560110

Browse files
committed
Revert some changes
1 parent 7393c44 commit b560110

File tree

1 file changed

+54
-54
lines changed

1 file changed

+54
-54
lines changed

syncer/malsync/syncer.go

+54-54
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ func (s *Syncer) downloadLegacyMalfeasanceProofs(ctx context.Context, initial bo
529529
batch, err := sst.missing(s.cfg.MaxBatchSize, func(nodeID types.NodeID) (bool, error) {
530530
// TODO(ivan4th): check multiple node IDs at once in a single SQL query
531531
isMalicious, err := identities.IsMalicious(s.db, nodeID)
532-
if errors.Is(err, sql.ErrNotFound) {
532+
if err != nil && errors.Is(err, sql.ErrNotFound) {
533533
return false, nil
534534
}
535535
return isMalicious, err
@@ -539,36 +539,36 @@ func (s *Syncer) downloadLegacyMalfeasanceProofs(ctx context.Context, initial bo
539539
}
540540

541541
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",
555544
log.ZContext(ctx),
556-
log.NiceZapError(err),
545+
zap.Int("count", len(batch)),
557546
)
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()
570550
}
551+
s.logger.Debug("failed to download malfeasance proofs",
552+
log.ZContext(ctx),
553+
log.NiceZapError(err),
554+
)
571555
}
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))
572572
}
573573
}
574574
}
@@ -624,7 +624,7 @@ func (s *Syncer) downloadMalfeasanceProofs(ctx context.Context, initial bool, up
624624
batch, err := sst.missing(s.cfg.MaxBatchSize, func(nodeID types.NodeID) (bool, error) {
625625
// TODO(mafa): check multiple node IDs at once in a single SQL query
626626
isMalicious, err := malfeasance.IsMalicious(s.db, nodeID)
627-
if errors.Is(err, sql.ErrNotFound) {
627+
if err != nil && errors.Is(err, sql.ErrNotFound) {
628628
return false, nil
629629
}
630630
return isMalicious, err
@@ -634,36 +634,36 @@ func (s *Syncer) downloadMalfeasanceProofs(ctx context.Context, initial bool, up
634634
}
635635

636636
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",
650639
log.ZContext(ctx),
651-
log.NiceZapError(err),
640+
zap.Int("count", len(batch)),
652641
)
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()
665645
}
646+
s.logger.Debug("failed to download malfeasance proofs",
647+
log.ZContext(ctx),
648+
log.NiceZapError(err),
649+
)
666650
}
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))
667667
}
668668
}
669669
}

0 commit comments

Comments
 (0)