mev-boost icon indicating copy to clipboard operation
mev-boost copied to clipboard

accept gzip encoding

Open dmarzzz opened this issue 2 years ago • 10 comments

📝 Summary

From a discussion with @zeroecco on how to lower bandwidth on the blocknative relay we came to the idea that we could utilize well known compression like gzip, but only if requests coming from mev-boost specified that.

Minimum transmittable unit is 1500 Bytes total w/ 1250 Bytes realistically usable and a block is around ~12KB, gzip will compress ~60% to ~6Kb which would be a packet reduction from 10 to 5 for the total packet train. This also reduces time to last packet and bandwidth, which could be 1 - 5ms based on response time at this size.

If a system doesn't have this enabled the content-encoding will simply be ignored. On top of that, this improvement will really only be visible for GetPayload response.

To benefit from this in your relay or other components make sure you configure your reverse proxy [HA Proxy, NGINX, etc] to support gzip!

⛱ Motivation and Context

I want to go fast

📚 References

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding

https://www.rfc-editor.org/rfc/rfc2616#section-3.5

✅ I have run these commands

  • [x] make lint
  • [x] make test-race
  • [x] go mod tidy

dmarzzz avatar Oct 01 '22 21:10 dmarzzz

Codecov Report

Merging #365 (1939207) into main (496bf59) will increase coverage by 0.47%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #365      +/-   ##
==========================================
+ Coverage   80.94%   81.41%   +0.47%     
==========================================
  Files           5        5              
  Lines         677      678       +1     
==========================================
+ Hits          548      552       +4     
+ Misses         99       97       -2     
+ Partials       30       29       -1     
Flag Coverage Δ
unittests 81.41% <100.00%> (+0.47%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
server/utils.go 72.85% <100.00%> (+0.39%) :arrow_up:
server/service.go 79.15% <0.00%> (+0.74%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov-commenter avatar Oct 01 '22 21:10 codecov-commenter

Could you add a little bit of context please?

metachris avatar Oct 07 '22 06:10 metachris

Internally our testing of the [edit] math on whether this would work or not[end edit] did show a time to last packet reduction in deliveries of blocks of roughly 1-5ms depending on the resources of the validator.

Additionally this change can lead to more time for validators to propose on chain and thereby potentially lead fewer missing proposals though more efficient packet transport over the wider internet.

zeroecco avatar Oct 11 '22 20:10 zeroecco

added some more context @metachris , didn't realize drafts showed up in public repos whoops!

dmarzzz avatar Oct 11 '22 21:10 dmarzzz

Thanks. It seems gzip would automatically be decoded, but deflate not?

metachris avatar Oct 12 '22 09:10 metachris

Very cool feature btw and just 1 line of code with significant impact. I strongly support this.

metachris avatar Oct 12 '22 10:10 metachris

Awesome good fix! I added a note to the PR as well that for relays and others to enable this make sure you configure your reverse proxy [HA Proxy, NGINX, etc] to support gzip!

dmarzzz avatar Oct 13 '22 15:10 dmarzzz

The test that lint is tripping up passes for me locally 🤔

dmarzzz avatar Oct 13 '22 16:10 dmarzzz

Failing lint step fixed in https://github.com/flashbots/mev-boost/pull/374

metachris avatar Oct 13 '22 19:10 metachris

@dmarzzz could you add a test where the mockserver returns a gzipped response?

metachris avatar Oct 14 '22 07:10 metachris

Added a test for the gzip response: https://github.com/dmarzzz/mev-boost/pull/1 (needs to be merged by @dmarzzz into his repo to update this PR)

metachris avatar Oct 19 '22 11:10 metachris

@metachris thanks appreciate it, wasn't able to get to it till this weekend. When I merged it auto dismissed @jtraglia review

dmarzzz avatar Oct 19 '22 13:10 dmarzzz