Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(p2p/peerTracker): remove timeout during bootstrapping #171

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 4 additions & 19 deletions p2p/peer_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,39 +78,24 @@ 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()

wg := sync.WaitGroup{}
wg.Add(len(trusted))
func (p *peerTracker) bootstrap(trusted []libpeer.ID) error {
for _, trust := range trusted {
trust := trust
go func() {
defer wg.Done()
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
}

wg.Add(len(prevSeen))
for _, peer := range prevSeen {
peer := peer
go func() {
defer wg.Done()
p.connectToPeer(connectCtx, peer)
}()
go p.connectToPeer(p.ctx, peer)
}
wg.Wait()
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion p2p/peer_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestPeerTracker_Bootstrap(t *testing.T) {

go tracker.track()

err = tracker.bootstrap(ctx, prevSeen[:2])
err = tracker.bootstrap(prevSeen[:2])
require.NoError(t, err)

assert.Eventually(t, func() bool {
Expand Down
Loading