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

Integrate zstd compression into chain exchange #842

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

masih
Copy link
Member

@masih masih commented Jan 22, 2025

The GPBFT message exchange over pubsub already uses zstd compression on top of CBOR encoded messages. The work here integrates the same style of compression for chain exchange messages, with additional unification of the encoding mechanism across the two.

The work refactors the root level encoding implementation into a generic encoder decoder that both chain exchange and gpbft used. Tests and benchmarks are updated to reflect this.

The benchmarking of partial gmessage encoding is also adjusted to fix a few redundant statements and bugs in testing.

Fixes #819

The GPBFT message exchange over pubsub already uses zstd compression on
top of CBOR encoded messages. The work here integrates the same style
of compression for chain exchange messages, with additional
unification of the encoding mechanism across the two.

The work refactors the root level encoding implementation into a generic
encoder decoder that both chain exchange and gpbft used. Tests and
benchmarks are updated to reflect this.

The benchmarking of partial gmessage encoding is also adjusted to fix a
few redundant statements and bugs in testing.

Fixes #819
@masih masih self-assigned this Jan 22, 2025
@masih masih requested a review from Kubuxu January 22, 2025 14:50
Copy link

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 60.37736% with 21 lines in your changes missing coverage. Please review.

Project coverage is 67.45%. Comparing base (9c11ba3) to head (7e3205a).

Files with missing lines Patch % Lines
internal/encoding/encoding.go 60.52% 10 Missing and 5 partials ⚠️
chainexchange/pubsub.go 44.44% 2 Missing and 3 partials ⚠️
host.go 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #842      +/-   ##
==========================================
+ Coverage   67.39%   67.45%   +0.06%     
==========================================
  Files          84       84              
  Lines        8915     8918       +3     
==========================================
+ Hits         6008     6016       +8     
+ Misses       2380     2376       -4     
+ Partials      527      526       -1     
Files with missing lines Coverage Δ
host.go 64.92% <83.33%> (+0.67%) ⬆️
chainexchange/pubsub.go 77.15% <44.44%> (-0.92%) ⬇️
internal/encoding/encoding.go 60.52% <60.52%> (ø)

... and 3 files with indirect coverage changes

@Stebalien
Copy link
Member

Can we add a compression bomb test? I think we're fine, but it would be nice to have a test.

  • The fact that we're stream decoding into the CBOR decoder coupled with the fact that the CBOR decoder has a bunch of limits should protect us against memory issues.
  • The fact that our CBOR decoder won't read through unlimited input (e.g., doesn't have logic that skips unknown fields, etc.) means we can't get "stuck" when decoding. But it would be nice if we could wrap the decompressed reader in a limited reader before passing it off to the CBOR decoder, just in case. That way we can guarantee that we'll process at most N bytes of CBOR before giving up.

}

func NewPubSubChainExchange(o ...Option) (*PubSubChainExchange, error) {
opts, err := newOptions(o...)
if err != nil {
return nil, err
}
zstd, err := encoding.NewZSTD[*Message]()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going with ZSTD by default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For chain exchange yes. For GPBFT it's configurable via manifest.

Happy to make it configurable for chain exchange too if you think it's worth doing.

@masih
Copy link
Member Author

masih commented Jan 22, 2025

Can we add a compression bomb test?

Sure. Captured #843

@BigLep BigLep requested a review from Kubuxu January 23, 2025 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

Integrate compression into chainexchange topic
3 participants