-
Notifications
You must be signed in to change notification settings - Fork 112
Be less aggressive when pruning peers from session #276
Conversation
@@ -56,7 +56,7 @@ func (sw *sessionWants) GetNextWants(limit int) []cid.Cid { | |||
func (sw *sessionWants) WantsSent(ks []cid.Cid) { | |||
now := time.Now() | |||
for _, c := range ks { | |||
if _, ok := sw.liveWants[c]; !ok { | |||
if _, ok := sw.liveWants[c]; !ok && sw.toFetch.Has(c) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was causing us to sometimes re-broadcast a want for which a block had already been received
// If we already received a block for the want, ignore any HAVE for | ||
// the want | ||
if blkCids.Has(c) { | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this prevent us from adding this peer to the session?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the peer to the session happens before processUpdates()
gets called. However this does interfere with consecutive DONT_HAVE counting so I refactored to avoid interference.
// Before removing the peer from the session, check if the peer | ||
// sent us a HAVE for a block that we want | ||
peerHasWantedBlock := false | ||
for c := range sws.wants { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in a goroutine. Is this safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
bba02f3
to
f74c469
Compare
f74c469
to
22f0c79
Compare
(rebasing to get the tests working) |
Let me take a look at that failed test now... |
@@ -340,7 +340,7 @@ func (s *Session) broadcastWantHaves(ctx context.Context, wants []cid.Cid) { | |||
// Search for providers who have the first want in the list. | |||
// Typically if the provider has the first block they will have | |||
// the rest of the blocks also. | |||
log.Warnf("Ses%d: FindMorePeers with want 0 of %d wants", s.id, len(wants)) | |||
log.Warnf("Ses%d: FindMorePeers with want %s (1st of %d wants)", s.id, lu.C(wants[0]), len(wants)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OT note: this should be an info at best.
Be less aggressive when pruning peers from session This commit was moved from ipfs/go-bitswap@418d88c
Currently we prune peers from the session when they send us several DONT_HAVEs in a row.
However if the peer sent us a HAVE for a block that we want, we should not prune the peer.
Depends on #275