@@ -167,6 +167,10 @@ type WebsocketNetwork struct {
167167
168168 config config.Local
169169
170+ // voteCompressionDynamicTableSize is the validated/normalized table size for VP compression.
171+ // It is set during setup() by validating config.VoteCompressionDynamicTableSize.
172+ voteCompressionDynamicTableSize uint
173+
170174 log logging.Logger
171175
172176 wg sync.WaitGroup
@@ -557,6 +561,9 @@ func (wn *WebsocketNetwork) setup() error {
557561 }
558562 wn .dialer = limitcaller .MakeRateLimitingDialer (wn .phonebook , preferredResolver )
559563
564+ // Validate and normalize vote compression table size
565+ wn .voteCompressionDynamicTableSize = config .NormalizeVoteCompressionTableSize (wn .config .VoteCompressionDynamicTableSize , wn .log )
566+
560567 wn .upgrader .ReadBufferSize = 4096
561568 wn .upgrader .WriteBufferSize = 4096
562569 wn .upgrader .EnableCompression = false
@@ -842,7 +849,8 @@ type peerMetadataProvider interface {
842849 PublicAddress () string
843850 RandomID () string
844851 SupportedProtoVersions () []string
845- Config () config.Local
852+ EnableVoteCompression () bool
853+ VoteCompressionDynamicTableSize () uint
846854}
847855
848856// TelemetryGUID returns the telemetry GUID of this node.
@@ -870,6 +878,16 @@ func (wn *WebsocketNetwork) Config() config.Local {
870878 return wn .config
871879}
872880
881+ // VoteCompressionDynamicTableSize returns the validated/normalized vote compression table size.
882+ func (wn * WebsocketNetwork ) VoteCompressionDynamicTableSize () uint {
883+ return wn .voteCompressionDynamicTableSize
884+ }
885+
886+ // EnableVoteCompression returns whether vote compression is enabled for this node.
887+ func (wn * WebsocketNetwork ) EnableVoteCompression () bool {
888+ return wn .config .EnableVoteCompression
889+ }
890+
873891func setHeaders (header http.Header , netProtoVer string , meta peerMetadataProvider ) {
874892 header .Set (TelemetryIDHeader , meta .TelemetryGUID ())
875893 header .Set (InstanceNameHeader , meta .InstanceName ())
@@ -883,14 +901,14 @@ func setHeaders(header http.Header, netProtoVer string, meta peerMetadataProvide
883901
884902 // set the features header (comma-separated list)
885903 features := []string {peerFeatureProposalCompression }
886- if meta .Config (). EnableVoteCompression {
904+ if meta .EnableVoteCompression () {
887905 features = append (features , peerFeatureVoteVpackCompression )
888906
889907 // Announce our maximum supported dynamic table size
890908 // Both sides will independently calculate min(ourSize, theirSize)
891909 // Only advertise dynamic features if stateless compression is enabled
892910 // Supported values: 16, 32, 64, 128, 256, 512, 1024 (or higher, which advertises 1024)
893- switch dtSize := uint32 (meta .Config (). VoteCompressionDynamicTableSize ); {
911+ switch dtSize := uint32 (meta .VoteCompressionDynamicTableSize () ); {
894912 case dtSize >= 1024 :
895913 features = append (features , peerFeatureVoteVpackDynamic1024 )
896914 case dtSize >= 512 :
@@ -1143,7 +1161,7 @@ func (wn *WebsocketNetwork) ServeHTTP(response http.ResponseWriter, request *htt
11431161 identityVerified : atomic.Uint32 {},
11441162 features : decodePeerFeatures (matchingVersion , request .Header .Get (PeerFeaturesHeader )),
11451163 enableVoteCompression : wn .config .EnableVoteCompression ,
1146- voteCompressionDynamicTableSize : wn .config . VoteCompressionDynamicTableSize ,
1164+ voteCompressionDynamicTableSize : wn .voteCompressionDynamicTableSize ,
11471165 }
11481166 peer .TelemetryGUID = trackedRequest .otherTelemetryGUID
11491167 wn .log .Debugf ("Server: client features '%s', decoded %x, our response '%s'" , request .Header .Get (PeerFeaturesHeader ), peer .features , responseHeader .Get (PeerFeaturesHeader ))
@@ -2211,7 +2229,7 @@ func (wn *WebsocketNetwork) tryConnect(netAddr, gossipAddr string) {
22112229 identity : peerID ,
22122230 features : decodePeerFeatures (matchingVersion , response .Header .Get (PeerFeaturesHeader )),
22132231 enableVoteCompression : wn .config .EnableVoteCompression ,
2214- voteCompressionDynamicTableSize : wn .config . VoteCompressionDynamicTableSize ,
2232+ voteCompressionDynamicTableSize : wn .voteCompressionDynamicTableSize ,
22152233 }
22162234 peer .TelemetryGUID , peer .InstanceName , _ = getCommonHeaders (response .Header )
22172235 wn .log .Debugf ("Client: server features '%s', decoded %x" , response .Header .Get (PeerFeaturesHeader ), peer .features )
0 commit comments