Skip to content

Commit b2edeaf

Browse files
authored
hack(gateway): Detect protocol version and dynamically enable gzip compression for 0.14.2 (#3524)
hack(gateway): Use global variable to detect protocol version for gzip support
1 parent 70f8a72 commit b2edeaf

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

clients/gateway/gateway.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212
"net/http/httptest"
1313
"strings"
14+
"sync/atomic"
1415
"testing"
1516
"time"
1617

@@ -43,6 +44,8 @@ var (
4344
// Payload size threshold for Gzip compression. 1KB
4445
const gzipMinSize = 1024
4546

47+
var IsProtocolVer0_14_2 atomic.Bool
48+
4649
type Client struct {
4750
url string
4851
client *http.Client
@@ -205,7 +208,7 @@ func (c *Client) doPost(ctx context.Context, url string, data any) (*http.Respon
205208
}
206209

207210
func prepareRequestBody(jsonBody []byte) (io.Reader, bool, error) {
208-
if len(jsonBody) <= gzipMinSize {
211+
if len(jsonBody) <= gzipMinSize || !IsProtocolVer0_14_2.Load() {
209212
return bytes.NewReader(jsonBody), false, nil
210213
}
211214

clients/gateway/gateway_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func TestAddInvokeTx(t *testing.T) {
2727
})
2828

2929
t.Run("Large requests are gzip compressed", func(t *testing.T) {
30+
gateway.IsProtocolVer0_14_2.Store(true)
31+
t.Cleanup(func() { gateway.IsProtocolVer0_14_2.Store(false) })
32+
3033
largeCalldata := make([]string, 200)
3134
for i := range largeCalldata {
3235
largeCalldata[i] = "0xcafebabe"

core/version.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var (
1313
Ver0_13_4 = semver.MustParse("0.13.4")
1414
Ver0_14_0 = semver.MustParse("0.14.0")
1515
Ver0_14_1 = semver.MustParse("0.14.1")
16+
Ver0_14_2 = semver.MustParse("0.14.2")
1617
LatestVer = Ver0_14_1
1718
)
1819

sync/sync.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/NethermindEth/juno/blockchain"
12+
"github.com/NethermindEth/juno/clients/gateway"
1213
"github.com/NethermindEth/juno/core"
1314
"github.com/NethermindEth/juno/core/felt"
1415
"github.com/NethermindEth/juno/db"
@@ -340,6 +341,12 @@ func (s *Synchronizer) verifierTask(
340341
}
341342

342343
s.listener.OnSyncStepDone(OpVerify, committedBlock.Block.Number, time.Since(verifyTimer))
344+
if !gateway.IsProtocolVer0_14_2.Load() {
345+
ver, err := core.ParseBlockVersion(committedBlock.Block.ProtocolVersion)
346+
if err == nil && !ver.LessThan(core.Ver0_14_2) {
347+
gateway.IsProtocolVer0_14_2.Store(true)
348+
}
349+
}
343350
return func() {
344351
s.storeTask(ctx, committedBlock, resetStreams, commitments)
345352
}

0 commit comments

Comments
 (0)