Skip to content

Commit

Permalink
Merge branch 'master' into validator-rankings
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Mar 9, 2024
2 parents 9e6fe69 + b15c743 commit 0d0277c
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 492 deletions.
4 changes: 0 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ var (
errCannotReadDirectory = errors.New("cannot read directory")
errUnmarshalling = errors.New("unmarshalling failed")
errFileDoesNotExist = errors.New("file does not exist")
errGzipDeprecatedMsg = errors.New("gzip compression is not supported, use zstd or no compression")
)

func getConsensusConfig(v *viper.Viper) snowball.Parameters {
Expand Down Expand Up @@ -266,9 +265,6 @@ func getNetworkConfig(
if err != nil {
return network.Config{}, err
}
if compressionType == compression.TypeGzip {
return network.Config{}, errGzipDeprecatedMsg
}

allowPrivateIPs := !constants.ProductionNetworkIDs.Contains(networkID)
if v.IsSet(NetworkAllowPrivateIPsKey) {
Expand Down
23 changes: 0 additions & 23 deletions message/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ func (m *outboundMessage) BytesSavedCompression() int {
type msgBuilder struct {
log logging.Logger

// TODO: Remove gzip once v1.11.x is out.
gzipCompressor compression.Compressor
gzipDecompressTimeMetrics map[Op]metric.Averager

zstdCompressor compression.Compressor
zstdCompressTimeMetrics map[Op]metric.Averager
zstdDecompressTimeMetrics map[Op]metric.Averager
Expand All @@ -148,10 +144,6 @@ func newMsgBuilder(
metrics prometheus.Registerer,
maxMessageTimeout time.Duration,
) (*msgBuilder, error) {
gzipCompressor, err := compression.NewGzipCompressor(constants.DefaultMaxMessageSize)
if err != nil {
return nil, err
}
zstdCompressor, err := compression.NewZstdCompressor(constants.DefaultMaxMessageSize)
if err != nil {
return nil, err
Expand All @@ -160,9 +152,6 @@ func newMsgBuilder(
mb := &msgBuilder{
log: log,

gzipCompressor: gzipCompressor,
gzipDecompressTimeMetrics: make(map[Op]metric.Averager, len(ExternalOps)),

zstdCompressor: zstdCompressor,
zstdCompressTimeMetrics: make(map[Op]metric.Averager, len(ExternalOps)),
zstdDecompressTimeMetrics: make(map[Op]metric.Averager, len(ExternalOps)),
Expand All @@ -172,13 +161,6 @@ func newMsgBuilder(

errs := wrappers.Errs{}
for _, op := range ExternalOps {
mb.gzipDecompressTimeMetrics[op] = metric.NewAveragerWithErrs(
namespace,
fmt.Sprintf("gzip_%s_decompress_time", op),
fmt.Sprintf("time (in ns) to decompress %s messages with gzip", op),
metrics,
&errs,
)
mb.zstdCompressTimeMetrics[op] = metric.NewAveragerWithErrs(
namespace,
fmt.Sprintf("zstd_%s_compress_time", op),
Expand Down Expand Up @@ -271,14 +253,9 @@ func (mb *msgBuilder) unmarshal(b []byte) (*p2p.Message, int, Op, error) {
opToDecompressTimeMetrics map[Op]metric.Averager
compressor compression.Compressor
compressedBytes []byte
gzipCompressed = m.GetCompressedGzip()
zstdCompressed = m.GetCompressedZstd()
)
switch {
case len(gzipCompressed) > 0:
opToDecompressTimeMetrics = mb.gzipDecompressTimeMetrics
compressor = mb.gzipCompressor
compressedBytes = gzipCompressed
case len(zstdCompressed) > 0:
opToDecompressTimeMetrics = mb.zstdDecompressTimeMetrics
compressor = mb.zstdCompressor
Expand Down
6 changes: 1 addition & 5 deletions proto/p2p/p2p.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ option go_package = "github.com/ava-labs/avalanchego/proto/pb/p2p";
// Represents peer-to-peer messages.
// Only one type can be non-null.
message Message {
reserved 1; // Until E upgrade is activated.
reserved 36; // Next unused field number.
// NOTES
// Use "oneof" for each message type and set rest to null if not used.
// That is because when the compression is enabled, we don't want to include uncompressed fields.
oneof message {
// Gzip-compressed bytes of a "p2p.Message" whose "oneof" "message" field is
// NOT compressed_* BUT one of the message types (e.g. ping, pong, etc.).
// This field is only set if the message type supports compression.
bytes compressed_gzip = 1;

// zstd-compressed bytes of a "p2p.Message" whose "oneof" "message" field is
// NOT compressed_* BUT one of the message types (e.g. ping, pong, etc.).
// This field is only set if the message type supports compression.
Expand Down
666 changes: 323 additions & 343 deletions proto/pb/p2p/p2p.pb.go

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions utils/compression/compressor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,13 @@ var (
TypeNone: func(int64) (Compressor, error) { //nolint:unparam // an error is needed to be returned to compile
return NewNoCompressor(), nil
},
TypeGzip: NewGzipCompressor,
TypeZstd: NewZstdCompressor,
}

//go:embed gzip_zip_bomb.bin
gzipZipBomb []byte

//go:embed zstd_zip_bomb.bin
zstdZipBomb []byte

zipBombs = map[Type][]byte{
TypeGzip: gzipZipBomb,
TypeZstd: zstdZipBomb,
}
)
Expand Down Expand Up @@ -154,10 +149,6 @@ func TestNewCompressorWithInvalidLimit(t *testing.T) {
}
}

func FuzzGzipCompressor(f *testing.F) {
fuzzHelper(f, TypeGzip)
}

func FuzzZstdCompressor(f *testing.F) {
fuzzHelper(f, TypeZstd)
}
Expand All @@ -168,9 +159,6 @@ func fuzzHelper(f *testing.F, compressionType Type) {
err error
)
switch compressionType {
case TypeGzip:
compressor, err = NewGzipCompressor(maxMessageSize)
require.NoError(f, err)
case TypeZstd:
compressor, err = NewZstdCompressor(maxMessageSize)
require.NoError(f, err)
Expand Down
91 changes: 0 additions & 91 deletions utils/compression/gzip_compressor.go

This file was deleted.

Binary file removed utils/compression/gzip_zip_bomb.bin
Binary file not shown.
3 changes: 0 additions & 3 deletions utils/compression/no_compressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ var _ Compressor = (*noCompressor)(nil)

type noCompressor struct{}

// Compress returns [msg]
func (*noCompressor) Compress(msg []byte) ([]byte, error) {
return msg, nil
}

// Decompress returns [msg].
func (*noCompressor) Decompress(msg []byte) ([]byte, error) {
return msg, nil
}

// NewNoCompressor returns a Compressor that does nothing
func NewNoCompressor() Compressor {
return &noCompressor{}
}
5 changes: 0 additions & 5 deletions utils/compression/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ type Type byte

const (
TypeNone Type = iota + 1
TypeGzip // Remove once v1.11.x is out.
TypeZstd
)

func (t Type) String() string {
switch t {
case TypeNone:
return "none"
case TypeGzip:
return "gzip"
case TypeZstd:
return "zstd"
default:
Expand All @@ -35,8 +32,6 @@ func TypeFromString(s string) (Type, error) {
switch s {
case TypeNone.String():
return TypeNone, nil
case TypeGzip.String():
return TypeGzip, nil
case TypeZstd.String():
return TypeZstd, nil
default:
Expand Down
6 changes: 1 addition & 5 deletions utils/compression/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestTypeString(t *testing.T) {
require := require.New(t)

for _, compressionType := range []Type{TypeNone, TypeGzip, TypeZstd} {
for _, compressionType := range []Type{TypeNone, TypeZstd} {
s := compressionType.String()
parsedType, err := TypeFromString(s)
require.NoError(err)
Expand All @@ -34,10 +34,6 @@ func TestTypeMarshalJSON(t *testing.T) {
Type: TypeNone,
expected: `"none"`,
},
{
Type: TypeGzip,
expected: `"gzip"`,
},
{
Type: TypeZstd,
expected: `"zstd"`,
Expand Down
9 changes: 8 additions & 1 deletion utils/compression/zstd_compressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ package compression

import (
"bytes"
"errors"
"fmt"
"io"
"math"

"github.com/DataDog/zstd"
)

var _ Compressor = (*zstdCompressor)(nil)
var (
_ Compressor = (*zstdCompressor)(nil)

ErrInvalidMaxSizeCompressor = errors.New("invalid compressor max size")
ErrDecompressedMsgTooLarge = errors.New("decompressed msg too large")
ErrMsgTooLarge = errors.New("msg too large to be compressed")
)

func NewZstdCompressor(maxSize int64) (Compressor, error) {
if maxSize == math.MaxInt64 {
Expand Down

0 comments on commit 0d0277c

Please sign in to comment.