Skip to content

Commit a4484f5

Browse files
authored
chore(syncing): avoid sending duplicate events to channel (#3207)
* chore(syncing): avoid sending duplicate events to channel * add comment * improve comment
1 parent 889da9a commit a4484f5

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

block/internal/syncing/syncer.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,11 @@ func (s *Syncer) waitForGenesis() bool {
517517
}
518518

519519
func (s *Syncer) PipeEvent(ctx context.Context, event common.DAHeightEvent) error {
520+
// Avoid sending already seen events to channel (would have been skipped in processHeightEvent anyway)
521+
if s.cache.IsHeaderSeen(event.Header.Hash().String()) {
522+
return nil
523+
}
524+
520525
select {
521526
case s.heightInCh <- event:
522527
return nil
@@ -537,6 +542,7 @@ func (s *Syncer) processHeightEvent(ctx context.Context, event *common.DAHeightE
537542
Uint64("height", height).
538543
Uint64("da_height", event.DaHeight).
539544
Str("hash", headerHash).
545+
Str("source", string(event.Source)).
540546
Msg("processing height event")
541547

542548
currentHeight, err := s.store.Height(ctx)
@@ -547,7 +553,10 @@ func (s *Syncer) processHeightEvent(ctx context.Context, event *common.DAHeightE
547553

548554
// Skip if already processed
549555
if height <= currentHeight || s.cache.IsHeaderSeen(headerHash) {
550-
s.logger.Debug().Uint64("height", height).Msg("height already processed")
556+
s.logger.Debug().
557+
Uint64("height", height).
558+
Str("source", string(event.Source)).
559+
Msg("height already processed")
551560
return
552561
}
553562

@@ -656,6 +665,7 @@ func (s *Syncer) processHeightEvent(ctx context.Context, event *common.DAHeightE
656665
s.logger.Error().Err(err).
657666
Uint64("event-height", event.Header.Height()).
658667
Uint64("state-height", s.getLastState().LastBlockHeight).
668+
Str("source", string(event.Source)).
659669
Msg("failed to sync next block")
660670
// If the error is not due to a validation error, re-store the event as pending
661671
switch {

0 commit comments

Comments
 (0)