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

lnwire: implement cautious zlib decoding for channel range queries #1399

Merged
merged 4 commits into from
Jun 26, 2018

Conversation

Roasbeef
Copy link
Member

In this commit, we implement zlib decoding and encoding for the EncodingSortedZlib encoding type. Before this commit, we only supported the sorted plain encoding. When decoding we utilize an io.LimitedReader to ensure that we can precisely (as much given the runtime+GC) control how much memory we allocate during decoding. On top of that, we also add a package level mutex to limit the total number of decoding instances to one. This ensures that we don't multiply our allocation limit across all peers.

erkarl
erkarl previously approved these changes Jun 16, 2018
@robtex
Copy link

robtex commented Jun 16, 2018

nice work. however it doesn't seem to play nicely with ACINQ.
ACINQ: 03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f@34.239.230.56:9735
lnd ( moneni.com ): 03295d2e292565743a40bd44da227a820f8730877bc3dfadebade8785bcf355258@159.203.122.47:9735

2018-06-16 20:24:32.780 [DBG] PEER: Received ReplyShortChanIDsEnd(chain_hash=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f, complete=1) from 34.239.230.56:9735
2018-06-16 20:24:32.784 [ERR] DISC: unable to reply to peer query: unknown message: *lnwire.ReplyShortChanIDsEnd

@Roasbeef
Copy link
Member Author

@robtex there's no issue there. Basically right now we don't also track that we sent out a query, they respond, but then we say we didn't send out the query. It's due to the fact that the gossiper doesn't tell the syncer that it has a new querying incoming. So that's just a logging issue.

In this commit, we implement zlib encoding and decoding for the channel
range queries. Notably, we utilize an io.LimitedReader to ensure that we
can enforce a hard cap on the total number of bytes we'll ever allocate
in a decoding attempt.
…odings

In this commit, we add a new package level mutex. Each time we decode a
new set of chan IDs w/ zlib, we also grab this mutex. The purpose here
is to ensure that we only EVER allocate the maxZlibBufSize globally
across all peers. Otherwise, it may be possible for us to allocate up to
64 MB for _each_ peer, exposing an easy OOM attack vector.
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.

None yet

3 participants