Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sidecar version checker #2671

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion protocol/daemons/slinky/client/sidecar_version_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"context"
"fmt"
"strings"

"cosmossdk.io/log"
"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -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)
}
Expand Down
31 changes: 31 additions & 0 deletions protocol/daemons/slinky/client/sidecar_version_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client_test

import (
"context"
"strings"
"testing"

"cosmossdk.io/log"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion protocol/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading