Skip to content

Commit 9dfdc74

Browse files
committed
Fix TestWebsocketVoteCompression
1 parent 26b0dae commit 9dfdc74

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

network/msgCompressor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ func makeWsPeerMsgDataDecoder(wp *wsPeer) *wsPeerMsgDataDecoder {
159159
}
160160

161161
c.ppdec = zstdProposalDecompressor{}
162-
if wp.vpackVoteCompressionSupported() {
162+
// have both ends advertised support for compression?
163+
if wp.enableVoteCompression && wp.vpackVoteCompressionSupported() {
163164
c.avdec = vpackVoteDecompressor{
164165
enabled: true,
165166
dec: vpack.NewStatelessDecoder(),

network/wsNetwork.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,18 +1042,19 @@ func (wn *WebsocketNetwork) ServeHTTP(response http.ResponseWriter, request *htt
10421042

10431043
client, _ := wn.GetHTTPClient(trackedRequest.remoteAddress())
10441044
peer := &wsPeer{
1045-
wsPeerCore: makePeerCore(wn.ctx, wn, wn.log, wn.handler.readBuffer, trackedRequest.remoteAddress(), client, trackedRequest.remoteHost),
1046-
conn: wsPeerWebsocketConnImpl{conn},
1047-
outgoing: false,
1048-
InstanceName: trackedRequest.otherInstanceName,
1049-
incomingMsgFilter: wn.incomingMsgFilter,
1050-
prioChallenge: challenge,
1051-
createTime: trackedRequest.created,
1052-
version: matchingVersion,
1053-
identity: peerID,
1054-
identityChallenge: peerIDChallenge,
1055-
identityVerified: atomic.Uint32{},
1056-
features: decodePeerFeatures(matchingVersion, request.Header.Get(PeerFeaturesHeader)),
1045+
wsPeerCore: makePeerCore(wn.ctx, wn, wn.log, wn.handler.readBuffer, trackedRequest.remoteAddress(), client, trackedRequest.remoteHost),
1046+
conn: wsPeerWebsocketConnImpl{conn},
1047+
outgoing: false,
1048+
InstanceName: trackedRequest.otherInstanceName,
1049+
incomingMsgFilter: wn.incomingMsgFilter,
1050+
prioChallenge: challenge,
1051+
createTime: trackedRequest.created,
1052+
version: matchingVersion,
1053+
identity: peerID,
1054+
identityChallenge: peerIDChallenge,
1055+
identityVerified: atomic.Uint32{},
1056+
features: decodePeerFeatures(matchingVersion, request.Header.Get(PeerFeaturesHeader)),
1057+
enableVoteCompression: wn.config.EnableVoteCompression,
10571058
}
10581059
peer.TelemetryGUID = trackedRequest.otherTelemetryGUID
10591060
peer.init(wn.config, wn.outgoingMessagesBufferSize)
@@ -1394,6 +1395,8 @@ func (wn *msgBroadcaster) innerBroadcast(request broadcastRequest, prio bool, pe
13941395
continue
13951396
}
13961397
dataToSend := data
1398+
// check whether to send a compressed vote. dataWithCompression will be empty if this node
1399+
// has not enabled vote compression.
13971400
if peer.vpackVoteCompressionSupported() && len(dataWithCompression) > 0 {
13981401
dataToSend = dataWithCompression
13991402
}
@@ -2148,6 +2151,7 @@ func (wn *WebsocketNetwork) tryConnect(netAddr, gossipAddr string) {
21482151
version: matchingVersion,
21492152
identity: peerID,
21502153
features: decodePeerFeatures(matchingVersion, response.Header.Get(PeerFeaturesHeader)),
2154+
enableVoteCompression: wn.config.EnableVoteCompression,
21512155
}
21522156
peer.TelemetryGUID, peer.InstanceName, _ = getCommonHeaders(response.Header)
21532157

network/wsNetwork_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,14 +507,18 @@ func TestWebsocketVoteCompression(t *testing.T) {
507507

508508
for _, test := range tests {
509509
t.Run(fmt.Sprintf("A_compression_%v+B_compression_%v", test.netAEnableCompression, test.netBEnableCompression), func(t *testing.T) {
510-
netA := makeTestWebsocketNode(t)
511-
netA.config.GossipFanout = 1
512-
netA.config.EnableVoteCompression = test.netAEnableCompression
510+
cfgA := defaultConfig
511+
cfgA.GossipFanout = 1
512+
cfgA.EnableVoteCompression = test.netAEnableCompression
513+
netA := makeTestWebsocketNodeWithConfig(t, cfgA)
513514
netA.Start()
514515
defer netStop(t, netA, "A")
515-
netB := makeTestWebsocketNode(t)
516-
netB.config.GossipFanout = 1
517-
netB.config.EnableVoteCompression = test.netBEnableCompression
516+
517+
cfgB := defaultConfig
518+
cfgB.GossipFanout = 1
519+
cfgB.EnableVoteCompression = test.netBEnableCompression
520+
netB := makeTestWebsocketNodeWithConfig(t, cfgB)
521+
518522
addrA, postListen := netA.Address()
519523
require.True(t, postListen)
520524
t.Log(addrA)
@@ -527,7 +531,7 @@ func TestWebsocketVoteCompression(t *testing.T) {
527531
"r": map[string]any{"rnd": uint64(2), "snd": [32]byte{3}},
528532
"sig": map[string]any{
529533
"p": [32]byte{4}, "p1s": [64]byte{5}, "p2": [32]byte{6},
530-
"p2s": [64]byte{7}, "ps": [64]byte{8}, "s": [64]byte{9},
534+
"p2s": [64]byte{7}, "ps": [64]byte{}, "s": [64]byte{9},
531535
},
532536
}
533537
vote2 := map[string]any{

network/wsPeer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ type wsPeer struct {
238238
// peer features derived from the peer version
239239
features peerFeatureFlag
240240

241+
// enableCompression specifies whether this node can compress or decompress votes (and whether it has advertised this)
242+
enableVoteCompression bool
243+
241244
// responseChannels used by the client to wait on the response of the request
242245
responseChannels map[uint64]chan *Response
243246

network/wsPeer_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ func TestVersionToFeature(t *testing.T) {
166166
{"2.2", PeerFeatureProposalCompression, pfCompressedProposal},
167167
{"2.2", strings.Join([]string{PeerFeatureProposalCompression, "test"}, ","), pfCompressedProposal},
168168
{"2.2", strings.Join([]string{PeerFeatureProposalCompression, "test"}, ", "), pfCompressedProposal},
169+
{"2.2", strings.Join([]string{PeerFeatureProposalCompression, PeerFeatureVoteVpackCompression}, ","), pfCompressedVoteVpack | pfCompressedProposal},
170+
{"2.2", PeerFeatureVoteVpackCompression, pfCompressedVoteVpack},
169171
{"2.3", PeerFeatureProposalCompression, pfCompressedProposal},
170172
}
171173
for i, test := range tests {

0 commit comments

Comments
 (0)