Repository navigation
Remove want-block sent tracking from sessionWantSender - #759
Conversation
Tracking want-blocks that were sent to a peer is not necessary to do in sessionwantsender. This is already handled in peermanager/peerwantmanager. Removing this tracking reduces unnecessary memory use.
Codecov ReportAll modified and coverable lines are covered by tests β
@@ Coverage Diff @@
## main #759 +/- ##
==========================================
- Coverage 60.51% 60.45% -0.06%
==========================================
Files 245 244 -1
Lines 31134 31102 -32
==========================================
- Hits 18841 18804 -37
- Misses 10618 10620 +2
- Partials 1675 1678 +3
|
| // Piggyback some other want-haves onto the request to the peer | ||
| for _, c := range sws.getPiggybackWantHaves(p, snd.wantBlocks) { | ||
| snd.wantHaves.Add(c) | ||
| } | ||
|
|
There was a problem hiding this comment.
Are we sure removing this has no effect?
swbt was introduced here: ipfs/go-bitswap@b3a47bc#diff-92a0b168d045013a05e87675741bb3cfa356a674c6f1535fbe88fc8e89d31e53
It is not explained what exactly motivated it, but it sounds like it is somehow keeping track of some wants that would otherwise not be sent?
There was a problem hiding this comment.
It seems that the only place where the use of sentWantBlocksTracker is questionable is getPiggybackWantHaves.
// sendNextWants sends wants to peers according to the latest information
// about which peers have / dont have blocks
func (sws *sessionWantSender) sendNextWants(newlyAvailable []peer.ID) {
toSend := make(allWants)
for c, wi := range sws.wants {
// Ensure we send want-haves to any newly available peers
for _, p := range newlyAvailable {
toSend.forPeer(p).wantHaves.Add(c)
}
// We already sent a want-block to a peer and haven't yet received a
// response yet
if wi.sentTo != "" {
continue
}
// All the peers have indicated that they don't have the block
// corresponding to this want, so we must wait to discover more peers
if wi.bestPeer == "" {
// TODO: work this out in real time instead of using bestP?
continue
}
// Send a want-block to the chosen peer
toSend.forPeer(wi.bestPeer).wantBlocks.Add(c)
// Send a want-have to each other peer
for _, op := range sws.spm.Peers() {
if op != wi.bestPeer {
toSend.forPeer(op).wantHaves.Add(c)
}
}
}
// Send any wants we've collected
sws.sendWants(toSend)
...
}getPiggybackWantHaves seems to cover a specific corner case (I doubt it was done voluntarily though).
- A new
WANT(k)is added to the client for cidk - A
WANT_BLOCKis sent towi.bestPeer, andWANT_HAVEs are sent to all other peers insws.spm.Peers() wi.bestPeerbecomes unavailable, triggeringwi.sentToto be reset. (this is the only place wherewi.sentTocan be reset).- At the next call of
sendNextWants,WANT_HAVE(k)will be sent to all peers insws.spm.Peers()again (as long as not peers have return aDONT_HAVE) getPiggybackWantHavesshould addWANT_HAVE(kk)for allkkinsws.wantswherekk != kandWANT_HAVE(kk)wasn't sent to that peer before, for peers that are part ofsws.spm.Peers()but NOTnewlyAvailable
However I would say that this set of peers will always be empty.
- If a peer was part of
sws.spm.Peers()at the time the newWANT(k)has been added, then it would already have received aWANT_HAVE. - If it wasn't part of
sws.spm.Peers()at the time the newWANT(k)has been added , then it means that it would have been part ofnewlyAvailableat some point, and hence would have received theWANT_HAVE.
So I would say that getPiggybackWantHaves and the whole sentWantBlocksTracker logic can be removed safely, without impacting Bitswap behaviour.
|
@guillaumemichel Thank you for this careful review and analysis of the logic. |
Tracking want-blocks that were sent to a peer is not necessary to do in sessionwantsender. This is already handled in peermanager/peerwantmanager.
Removing this tracking reduces unnecessary memory use.