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

Stream Merkle root computation when downloading #30

Merged
merged 3 commits into from
Feb 14, 2020

Conversation

lukechampine
Copy link
Owner

Partially implements #29. See that issue for benchmarks.

These enable streaming sector downloads. The Go 1.13 bump is due
to a single occurrence of 1 << int. Not really worth it, but Go 1.14
is due to be released soon, and I like to stay within at least one
release of master.
This is some gnarly code, and it took quite some time to get it
right, but ultimately I'm quite happy with it. Chaining all those
Readers and Writers together is really satisfying.

Anyway, this lets callers stream RPC messages without authenticating
them first. Which is generally a bad idea -- there's a reason AEAD is
a thing! But for our purposes, this allows us to start hashing sector
data immediately, which is a Big Deal for performance (since BLAKE2b
is currently our primary bottleneck). You just need to be careful to
not do anything reckless with the data before verifying it, like
writing it directly to disk or streaming it to a client over HTTP.
Fortunately, Sia's design makes this difficult to do anyway; we
still wait for the full message to arrive before proceeding to the
erasure decoding step, so as long as verify the poly1305 tag before
decoding, there's no loss of security.

I do still feel a bit guilty about introducing API surface that, if
misused, could constitute an attack vector. If our hashing was on
par with our encryption and erasure coding (that is, >10 Gbps), I
would happily skip this optimization. Alas.
This significantly increases download throughput when network
bandwidth is between 100-2000 Mbps -- about 1.5x faster than
non-streaming. Unfortunately I ran into bug after bug when
implementing this, which gives me reduced confidence in its
correctness. Maybe some fuzzing is warranted. Also, as mentioned
in the docstring, callers now need to be a bit more careful with
the data written to w.
@lukechampine
Copy link
Owner Author

Goober, please test and merge.

@goober-the-friendly-robutt goober-the-friendly-robutt bot merged commit f1526d2 into master Feb 14, 2020
@lukechampine lukechampine deleted the stream-sector branch February 28, 2020 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant