From d29cbcf9e96b362db0095501554781d3b01cf370 Mon Sep 17 00:00:00 2001 From: Chenyao Yu <4844716+chenyaoy@users.noreply.github.com> Date: Fri, 27 Dec 2024 10:34:56 -0600 Subject: [PATCH] Fix sidecar version checker (#2671) (cherry picked from commit 6973144812dd1fdd62b25dc78ca8595a9d328469) --- .../slinky/client/sidecar_version_checker.go | 9 +++++- .../client/sidecar_version_checker_test.go | 31 +++++++++++++++++++ protocol/docker-compose.yml | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/protocol/daemons/slinky/client/sidecar_version_checker.go b/protocol/daemons/slinky/client/sidecar_version_checker.go index 8e654f9ea8..66e98e1e82 100644 --- a/protocol/daemons/slinky/client/sidecar_version_checker.go +++ b/protocol/daemons/slinky/client/sidecar_version_checker.go @@ -3,6 +3,7 @@ package client import ( "context" "fmt" + "strings" "cosmossdk.io/log" "github.com/hashicorp/go-version" @@ -50,7 +51,13 @@ func (s *SidecarVersionCheckerImpl) CheckSidecarVersion(ctx context.Context) err if err != nil { return err } - current, err := version.NewVersion(slinkyResponse.Version) + + versionStr := slinkyResponse.Version + if idx := strings.LastIndex(versionStr, "/"); idx != -1 { + versionStr = versionStr[idx+1:] + } + + current, err := version.NewVersion(versionStr) if err != nil { return fmt.Errorf("failed to parse current version: %w", err) } diff --git a/protocol/daemons/slinky/client/sidecar_version_checker_test.go b/protocol/daemons/slinky/client/sidecar_version_checker_test.go index 11eb2d47fa..5bd25393df 100644 --- a/protocol/daemons/slinky/client/sidecar_version_checker_test.go +++ b/protocol/daemons/slinky/client/sidecar_version_checker_test.go @@ -2,6 +2,7 @@ package client_test import ( "context" + "strings" "testing" "cosmossdk.io/log" @@ -46,6 +47,36 @@ func TestSidecarVersionChecker(t *testing.T) { fetcher.Stop() }) + t.Run("Checks sidecar version passes with prefix before version", func(t *testing.T) { + slinky := mocks.NewOracleClient(t) + slinky.On("Stop").Return(nil) + slinky.On("Start", mock.Anything).Return(nil).Once() + require.True(t, strings.HasPrefix(client.MinSidecarVersion, "v"), "MinSidecarVersion must start with 'v'") + + slinky.On("Version", mock.Anything, mock.Anything). + Return(&types.QueryVersionResponse{ + Version: client.MinSidecarVersion[1:], // Remove the "v" prefix + }, nil) + fetcher = client.NewSidecarVersionChecker(slinky, logger) + require.NoError(t, fetcher.Start(context.Background())) + require.NoError(t, fetcher.CheckSidecarVersion(context.Background())) + fetcher.Stop() + }) + + t.Run("Checks sidecar version passes without v prefix", func(t *testing.T) { + slinky := mocks.NewOracleClient(t) + slinky.On("Stop").Return(nil) + slinky.On("Start", mock.Anything).Return(nil).Once() + slinky.On("Version", mock.Anything, mock.Anything). + Return(&types.QueryVersionResponse{ + Version: "tests/integration/v1.2.0", + }, nil) + fetcher = client.NewSidecarVersionChecker(slinky, logger) + require.NoError(t, fetcher.Start(context.Background())) + require.NoError(t, fetcher.CheckSidecarVersion(context.Background())) + fetcher.Stop() + }) + t.Run("Checks sidecar version incorrectly formatted", func(t *testing.T) { slinky := mocks.NewOracleClient(t) slinky.On("Stop").Return(nil) diff --git a/protocol/docker-compose.yml b/protocol/docker-compose.yml index 6c0e0d2eaf..021c6ff571 100644 --- a/protocol/docker-compose.yml +++ b/protocol/docker-compose.yml @@ -116,7 +116,7 @@ services: volumes: - ./localnet/dydxprotocol3:/dydxprotocol/chain/.dave/data slinky0: - image: ghcr.io/skip-mev/slinky-sidecar:v1.0.13 + image: ghcr.io/skip-mev/slinky-sidecar:v1.1.0 entrypoint: > sh -c "slinky --marketmap-provider dydx_migration_api --oracle-config /etc/slinky/oracle.json --log-std-out-level error" environment: