Skip to content

Commit

Permalink
remove checkCompressible
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy committed Aug 8, 2024
1 parent b133b24 commit 39bc6c7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 41 deletions.
12 changes: 0 additions & 12 deletions network/msgCompressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ var zstdCompressionMagic = [4]byte{0x28, 0xb5, 0x2f, 0xfd}

const zstdCompressionLevel = zstd.BestSpeed

// checkCompressible checks if there is an proposal payload message
func checkCompressible(request broadcastRequest) bool {
hasPP := false
for _, tag := range request.tags {
if tag == protocol.ProposalPayloadTag {
hasPP = true
break
}
}
return hasPP
}

// zstdCompressMsg returns a concatenation of a tag and compressed data
func zstdCompressMsg(tbytes []byte, d []byte) ([]byte, string) {
bound := zstd.CompressBound(len(d))
Expand Down
16 changes: 0 additions & 16 deletions network/msgCompressor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,6 @@ func TestZstdDecompress(t *testing.T) {
require.Nil(t, decompressed)
}

func TestCheckCompressible(t *testing.T) {
partitiontest.PartitionTest(t)

req := broadcastRequest{}
r := checkCompressible(req)
require.False(t, r)

req.tags = []protocol.Tag{protocol.AgreementVoteTag}
r = checkCompressible(req)
require.False(t, r)

req.tags = []protocol.Tag{protocol.AgreementVoteTag, protocol.ProposalPayloadTag}
r = checkCompressible(req)
require.True(t, r)
}

func TestZstdCompressMsg(t *testing.T) {
partitiontest.PartitionTest(t)

Expand Down
18 changes: 5 additions & 13 deletions network/wsNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -1389,12 +1389,6 @@ func (wn *WebsocketNetwork) getPeersChangeCounter() int32 {
// preparePeerData prepares batches of data for sending.
// It performs zstd compression for proposal massages if they this is a prio request and has proposal.
func (wn *msgBroadcaster) preparePeerData(request broadcastRequest, prio bool) ([][]byte, []crypto.Digest) {
// determine if there is a payload proposal and if so compress proposal portion of the request
shouldCompress := false
if prio {
shouldCompress = checkCompressible(request)
}

digests := make([]crypto.Digest, len(request.data))
data := make([][]byte, len(request.data))
for i, d := range request.data {
Expand All @@ -1407,14 +1401,12 @@ func (wn *msgBroadcaster) preparePeerData(request broadcastRequest, prio bool) (
digests[i] = crypto.Hash(mbytes)
}

if shouldCompress {
if request.tags[i] == protocol.ProposalPayloadTag {
compressed, logMsg := zstdCompressMsg(tbytes, d)
if len(logMsg) > 0 {
wn.log.Warn(logMsg)
}
data[i] = compressed
if prio && request.tags[i] == protocol.ProposalPayloadTag {
compressed, logMsg := zstdCompressMsg(tbytes, d)
if len(logMsg) > 0 {
wn.log.Warn(logMsg)

Check warning on line 1407 in network/wsNetwork.go

View check run for this annotation

Codecov / codecov/patch

network/wsNetwork.go#L1407

Added line #L1407 was not covered by tests
}
data[i] = compressed
}
}
return data, digests
Expand Down

0 comments on commit 39bc6c7

Please sign in to comment.