Skip to content

Commit

Permalink
Comments fix
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Nov 6, 2023
1 parent bc10ca3 commit 415e050
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
2 changes: 1 addition & 1 deletion consensus/polybft/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func (tp *syncerMock) Sync(func(*types.FullBlock) bool) error {
return args.Error(0)
}

func (tp *syncerMock) IsSyncingWithPeer() bool {
func (tp *syncerMock) IsSyncing() bool {
args := tp.Called()

return args.Bool(0)
Expand Down
2 changes: 1 addition & 1 deletion consensus/polybft/polybft.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ func (p *Polybft) startConsensusProtocol() {
// wait until he stops syncing
p.logger.Info("waiting to stop syncing so that we can try to join consensus if node is a validator")

for p.syncer.IsSyncingWithPeer() {
for p.syncer.IsSyncing() {
}

p.logger.Info("node synced up on start. Trying to join consensus if validator")
Expand Down
17 changes: 3 additions & 14 deletions syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package syncer
import (
"errors"
"fmt"
"sync/atomic"
"time"

"github.com/0xPolygon/polygon-edge/helper/progress"
Expand Down Expand Up @@ -39,8 +38,6 @@ type syncer struct {

// Channel to notify Sync that a new status arrived
newStatusCh chan struct{}

isSyncing atomic.Bool
}

func NewSyncer(
Expand Down Expand Up @@ -222,9 +219,6 @@ func (s *syncer) bulkSyncWithPeer(peerID peer.ID, peerLatestBlock uint64,
return 0, false, err
}

s.setIsSyncing(true)
defer s.setIsSyncing(false)

// Create a blockchain subscription for the sync progression and start tracking
subscription := s.blockchain.SubscribeEvents()
s.syncProgression.StartProgression(localLatest+1, subscription)
Expand Down Expand Up @@ -278,14 +272,9 @@ func (s *syncer) bulkSyncWithPeer(peerID peer.ID, peerLatestBlock uint64,
}
}

// setIsSyncing updates the isSyncing field
func (s *syncer) setIsSyncing(isSyncing bool) {
s.isSyncing.Store(isSyncing)
}

// IsSyncingWithPeer indicates if node is syncing with peer
func (s *syncer) IsSyncingWithPeer() bool {
return s.isSyncing.Load()
// IsSyncing indicates if node is syncing with peer
func (s *syncer) IsSyncing() bool {
return s.GetSyncProgression() != nil
}

func updateMetrics(fullBlock *types.FullBlock) {
Expand Down
4 changes: 2 additions & 2 deletions syncer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ type Syncer interface {
HasSyncPeer() bool
// Sync starts routine to sync blocks
Sync(func(*types.FullBlock) bool) error

IsSyncingWithPeer() bool
// Indicates if syncer is syncing with the best peer
IsSyncing() bool
}

type Progression interface {
Expand Down

0 comments on commit 415e050

Please sign in to comment.