Skip to content

Commit

Permalink
fix(p2p/peerTracker): remove timeout during bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Apr 2, 2024
1 parent ca440ae commit daf1d68
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions p2p/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (ex *Exchange[H]) Start(ctx context.Context) error {

// bootstrap the peerTracker with trusted peers as well as previously seen
// peers if provided.
return ex.peerTracker.bootstrap(ctx, ex.trustedPeers())
return ex.peerTracker.bootstrap(ex.trustedPeers())
}

func (ex *Exchange[H]) Stop(ctx context.Context) error {
Expand Down Expand Up @@ -172,7 +172,7 @@ func (ex *Exchange[H]) Head(ctx context.Context, opts ...header.HeadOption[H]) (
trace.WithAttributes(attribute.String("peerID", from.String())),
)
defer newSpan.End()

headers, err := ex.request(reqCtx, from, headerReq)
if err != nil {
newSpan.SetStatus(codes.Error, err.Error())
Expand Down
11 changes: 4 additions & 7 deletions p2p/peer_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,23 @@ func newPeerTracker(
//
// NOTE: bootstrap is intended to be used with an on-disk peerstore.Peerstore as
// the peerTracker needs access to the previously-seen peers' AddrInfo on start.
func (p *peerTracker) bootstrap(ctx context.Context, trusted []libpeer.ID) error {
connectCtx, cancel := context.WithTimeout(context.Background(), time.Second*60)
defer cancel()

func (p *peerTracker) bootstrap(trusted []libpeer.ID) error {
for _, trust := range trusted {
go p.connectToPeer(connectCtx, trust)
go p.connectToPeer(p.ctx, trust)
}

// short-circuit if pidstore was not provided
if p.pidstore == nil {
return nil
}

prevSeen, err := p.pidstore.Load(ctx)
prevSeen, err := p.pidstore.Load(p.ctx)
if err != nil {
return err
}

for _, peer := range prevSeen {
go p.connectToPeer(connectCtx, peer)
go p.connectToPeer(p.ctx, peer)
}
return nil
}
Expand Down

0 comments on commit daf1d68

Please sign in to comment.