Skip to content

Commit

Permalink
Fix sidecar version checker (backport #2671) (#2672)
Browse files Browse the repository at this point in the history
Co-authored-by: Chenyao Yu <[email protected]>
  • Loading branch information
mergify[bot] and chenyaoy authored Dec 27, 2024
1 parent 1fe7fee commit e942e7b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
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

0 comments on commit e942e7b

Please sign in to comment.