Skip to content

Commit

Permalink
chore: solve discovery test problem
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior committed Sep 23, 2024
1 parent ee3380b commit 51e281c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions dot/peerset/peerstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func newNode(n int) *node {

return &node{
state: sets,
reputation: 0,
lastConnected: lastConnected,
}
}
Expand Down
1 change: 1 addition & 0 deletions dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ func (nodeBuilder) newSyncService(config *cfg.Config, st *state.Service, fg sync
sync.WithBlockState(st.Block),
sync.WithSlotDuration(slotDuration),
sync.WithStrategies(fullSync, nil),
sync.WithMinPeers(config.Network.MinPeers),
), nil
}

Expand Down
6 changes: 6 additions & 0 deletions dot/sync/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ func WithSlotDuration(slotDuration time.Duration) ServiceConfig {
svc.slotDuration = slotDuration
}
}

func WithMinPeers(min int) ServiceConfig {
return func(svc *SyncService) {
svc.minPeers = min
}
}
4 changes: 2 additions & 2 deletions dot/sync/fullsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ func (f *FullSyncStrategy) OnBlockAnnounce(from peer.ID, msg *network.BlockAnnou
},
}

return repChange, fmt.Errorf("%w: peer %s, block number #%d (%s)",
errPeerOnInvalidFork, from, blockAnnounceHeader.Number, blockAnnounceHeaderHash.String())
return repChange, nil
}

logger.Infof("relevant announced block #%d (%s)", blockAnnounceHeader.Number, blockAnnounceHeaderHash.Short())
Expand Down Expand Up @@ -397,6 +396,7 @@ func (f *FullSyncStrategy) IsSynced() bool {
return false
}

logger.Infof("highest block: %d target %d", highestBlock, f.peers.getTarget())
return uint32(highestBlock) >= f.peers.getTarget()
}

Expand Down
6 changes: 2 additions & 4 deletions dot/sync/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

const (
waitPeersDefaultTimeout = 2 * time.Second
waitPeersDefaultTimeout = 10 * time.Second
minPeersDefault = 3
)

Expand Down Expand Up @@ -119,16 +119,13 @@ func NewSyncService(cfgs ...ServiceConfig) *SyncService {
}

func (s *SyncService) waitWorkers() {
waitPeersTimer := time.NewTimer(s.waitPeersDuration)
bestBlockHeader, err := s.blockState.BestBlockHeader()
if err != nil {
panic(fmt.Sprintf("failed to get highest finalised header: %v", err))
}

for {
total := s.workerPool.totalWorkers()
logger.Debugf("waiting peers...")
logger.Debugf("total workers: %d, min peers: %d", total, s.minPeers)
if total >= s.minPeers {
return
}
Expand All @@ -143,6 +140,7 @@ func (s *SyncService) waitWorkers() {
break
}

waitPeersTimer := time.NewTimer(s.waitPeersDuration)
select {
case <-waitPeersTimer.C:
waitPeersTimer.Reset(s.waitPeersDuration)
Expand Down

0 comments on commit 51e281c

Please sign in to comment.