@@ -18,7 +18,6 @@ import (
18
18
"github.com/spacemeshos/go-spacemesh/p2p/pubsub"
19
19
"github.com/spacemeshos/go-spacemesh/sql"
20
20
"github.com/spacemeshos/go-spacemesh/sql/identities"
21
- "github.com/spacemeshos/go-spacemesh/sql/malfeasance"
22
21
"github.com/spacemeshos/go-spacemesh/sql/malsync"
23
22
)
24
23
@@ -573,100 +572,100 @@ func (s *Syncer) downloadLegacyMalfeasanceProofs(ctx context.Context, initial bo
573
572
}
574
573
}
575
574
576
- func (s * Syncer ) downloadMalfeasanceProofs (ctx context.Context , initial bool , updates <- chan malUpdate ) error {
577
- var (
578
- update malUpdate
579
- sst = newSyncState (s .cfg .RequestsLimit , initial )
580
- nothingToDownload = true
581
- gotUpdate = false
582
- )
583
- for {
584
- if nothingToDownload {
585
- sst .done ()
586
- if initial && sst .numSyncedPeers () >= s .cfg .MinSyncPeers {
587
- if err := s .updateState (ctx ); err != nil {
588
- return err
589
- }
590
- s .logger .Info ("initial sync of malfeasance proofs completed" , log .ZContext (ctx ))
591
- return nil
592
- } else if ! initial && gotUpdate {
593
- if err := s .updateState (ctx ); err != nil {
594
- return err
595
- }
596
- }
597
- select {
598
- case <- ctx .Done ():
599
- return ctx .Err ()
600
- case update = <- updates :
601
- s .logger .Debug ("malfeasance sync update" ,
602
- log .ZContext (ctx ),
603
- zap .Int ("count" , len (update .nodeIDs )),
604
- )
605
- sst .update (update )
606
- gotUpdate = true
607
- }
608
- } else {
609
- select {
610
- case <- ctx .Done ():
611
- return ctx .Err ()
612
- case update = <- updates :
613
- s .logger .Debug ("malfeasance sync update" ,
614
- log .ZContext (ctx ),
615
- zap .Int ("count" , len (update .nodeIDs )),
616
- )
617
- sst .update (update )
618
- gotUpdate = true
619
- default :
620
- // If we have some hashes to fetch already, don't wait for
621
- // another update
622
- }
623
- }
624
- batch , err := sst .missing (s .cfg .MaxBatchSize , func (nodeID types.NodeID ) (bool , error ) {
625
- // TODO(mafa): check multiple node IDs at once in a single SQL query
626
- isMalicious , err := malfeasance .IsMalicious (s .db , nodeID )
627
- if err != nil && errors .Is (err , sql .ErrNotFound ) {
628
- return false , nil
629
- }
630
- return isMalicious , err
631
- })
632
- if err != nil {
633
- return fmt .Errorf ("error checking malicious node IDs: %w" , err )
634
- }
635
-
636
- nothingToDownload = len (batch ) == 0
637
- if len (batch ) != 0 {
638
- s .logger .Debug ("retrieving malicious identities" ,
639
- log .ZContext (ctx ),
640
- zap .Int ("count" , len (batch )),
641
- )
642
- if err := s .fetcher .MalfeasanceProofs (ctx , batch ); err != nil {
643
- if errors .Is (err , context .Canceled ) {
644
- return ctx .Err ()
645
- }
646
- s .logger .Debug ("failed to download malfeasance proofs" ,
647
- log .ZContext (ctx ),
648
- log .NiceZapError (err ),
649
- )
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
- }
668
- }
669
- }
575
+ // func (s *Syncer) downloadMalfeasanceProofs(ctx context.Context, initial bool, updates <-chan malUpdate) error {
576
+ // var (
577
+ // update malUpdate
578
+ // sst = newSyncState(s.cfg.RequestsLimit, initial)
579
+ // nothingToDownload = true
580
+ // gotUpdate = false
581
+ // )
582
+ // for {
583
+ // if nothingToDownload {
584
+ // sst.done()
585
+ // if initial && sst.numSyncedPeers() >= s.cfg.MinSyncPeers {
586
+ // if err := s.updateState(ctx); err != nil {
587
+ // return err
588
+ // }
589
+ // s.logger.Info("initial sync of malfeasance proofs completed", log.ZContext(ctx))
590
+ // return nil
591
+ // } else if !initial && gotUpdate {
592
+ // if err := s.updateState(ctx); err != nil {
593
+ // return err
594
+ // }
595
+ // }
596
+ // select {
597
+ // case <-ctx.Done():
598
+ // return ctx.Err()
599
+ // case update = <-updates:
600
+ // s.logger.Debug("malfeasance sync update",
601
+ // log.ZContext(ctx),
602
+ // zap.Int("count", len(update.nodeIDs)),
603
+ // )
604
+ // sst.update(update)
605
+ // gotUpdate = true
606
+ // }
607
+ // } else {
608
+ // select {
609
+ // case <-ctx.Done():
610
+ // return ctx.Err()
611
+ // case update = <-updates:
612
+ // s.logger.Debug("malfeasance sync update",
613
+ // log.ZContext(ctx),
614
+ // zap.Int("count", len(update.nodeIDs)),
615
+ // )
616
+ // sst.update(update)
617
+ // gotUpdate = true
618
+ // default:
619
+ // // If we have some hashes to fetch already, don't wait for
620
+ // // another update
621
+ // }
622
+ // }
623
+ // batch, err := sst.missing(s.cfg.MaxBatchSize, func(nodeID types.NodeID) (bool, error) {
624
+ // // TODO(mafa): check multiple node IDs at once in a single SQL query
625
+ // isMalicious, err := malfeasance.IsMalicious(s.db, nodeID)
626
+ // if err != nil && errors.Is(err, sql.ErrNotFound) {
627
+ // return false, nil
628
+ // }
629
+ // return isMalicious, err
630
+ // })
631
+ // if err != nil {
632
+ // return fmt.Errorf("error checking malicious node IDs: %w", err)
633
+ // }
634
+
635
+ // nothingToDownload = len(batch) == 0
636
+ // if len(batch) != 0 {
637
+ // s.logger.Debug("retrieving malicious identities",
638
+ // log.ZContext(ctx),
639
+ // zap.Int("count", len(batch)),
640
+ // )
641
+ // if err := s.fetcher.MalfeasanceProofs(ctx, batch); err != nil {
642
+ // if errors.Is(err, context.Canceled) {
643
+ // return ctx.Err()
644
+ // }
645
+ // s.logger.Debug("failed to download malfeasance proofs",
646
+ // log.ZContext(ctx),
647
+ // log.NiceZapError(err),
648
+ // )
649
+ // }
650
+ // batchError := &fetch.BatchError{}
651
+ // if errors.As(err, &batchError) {
652
+ // for hash, err := range batchError.Errors {
653
+ // nodeID := types.NodeID(hash)
654
+ // switch {
655
+ // case !sst.has(nodeID):
656
+ // continue
657
+ // case errors.Is(err, pubsub.ErrValidationReject):
658
+ // sst.rejected(nodeID)
659
+ // default:
660
+ // sst.failed(nodeID)
661
+ // }
662
+ // }
663
+ // }
664
+ // } else {
665
+ // s.logger.Debug("no new malicious identities", log.ZContext(ctx))
666
+ // }
667
+ // }
668
+ // }
670
669
671
670
func (s * Syncer ) EnsureLegacyInSync (ctx context.Context , epochStart , epochEnd time.Time ) error {
672
671
if shouldSync , err := s .shouldSyncLegacy (epochStart , epochEnd ); err != nil {
0 commit comments