holepunchto / hypercore

Hypercore is a secure, distributed append-only log.
https://docs.holepunch.to
MIT License
2.59k stars 182 forks source link

Don't send unneeded 'wireRange' messages #513

Closed HDegroote closed 6 months ago

HDegroote commented 6 months ago

Currently broadcastRange sends a wireRange message to every peer on every update. This PR avoids sending this message to peers when we already know they have those blocks available.

Failing tests (skipped for now) indicate that we rely on the broadcastRange spam to update the contiguousLength, so I marked this as draft until that's clarified.

HDegroote commented 6 months ago

A potential extension is to also avoid sending wireRange messages if we know the other peer is not downloading (this.remoteDownloading === false), but that's relying on different logic so I haven't included it in this PR

HDegroote commented 6 months ago

The tests were no longer relevant: they were checking the writer peer's perception of the downloading peers' contiguous length. I wrote some new tests for the current behaviour on broadcasting the contiguouslength, from the point of view of reader peers.

HDegroote commented 6 months ago

I think the logic might be flawed, marking as draft while I debug some more

HDegroote commented 6 months ago

False alarm, what I detected was unrelated to this PR (fixed here https://github.com/holepunchto/hypercore/pull/517)