Skip to content
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/cometbft/cometbft v0.38.12
github.com/cosmos/cosmos-sdk v0.50.13
github.com/prometheus/client_golang v1.22.0
github.com/prometheus/client_model v0.6.1
github.com/spf13/cobra v1.9.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
Expand Down Expand Up @@ -112,7 +113,6 @@ require (
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
Expand Down
5 changes: 4 additions & 1 deletion internal/proxy/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ func (rr *LatencyBased) NextServer(_ *http.Request) *Server {
}

// Fallback, shouldn't be reached if rates are normalized
return rr.servers[len(rr.servers)-1].Server
if len(rr.servers) > 0 {
return rr.servers[len(rr.servers)-1].Server
}
return nil
}

// Update updates the list of available servers and their corresponding rates
Expand Down
11 changes: 11 additions & 0 deletions internal/proxy/balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ func TestRoundRobin_NextServer(t *testing.T) {
}
}

func TestLatencyBased_NextServer_EmptyServers(t *testing.T) {
lb := NewLatencyBased(slog.New(slog.NewTextHandler(os.Stdout, nil)))
lb.Update([]*Server{})

// Should return nil when no servers are available
server := lb.NextServer(nil)
if server != nil {
t.Errorf("expected nil server when no servers available, got %v", server)
}
}

func TestLatencyBased_NextServer(t *testing.T) {
servers := []*Server{
{
Expand Down
8 changes: 4 additions & 4 deletions internal/seed/probes.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func RESTProbe(ctx context.Context, node Node) (Status, error) {
start := time.Now()
client := &http.Client{}

req, err := http.NewRequest("GET", fmt.Sprintf("%s/syncing", node.Address), nil)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/syncing", node.Address), nil)
if err != nil {
return Status{}, fmt.Errorf("creating REST client request: %w", err)
}
Expand All @@ -130,7 +130,7 @@ func RESTProbe(ctx context.Context, node Node) (Status, error) {
defer resp.Body.Close()

if resp.StatusCode != 200 {
return Status{}, fmt.Errorf("unexpected status from REST client [%d %s]: %w", resp.StatusCode, resp.Status, err)
return Status{}, fmt.Errorf("unexpected status from REST client [%d %s]", resp.StatusCode, resp.Status)
}

body, err := io.ReadAll(resp.Body)
Expand All @@ -143,7 +143,7 @@ func RESTProbe(ctx context.Context, node Node) (Status, error) {
return Status{}, fmt.Errorf("unmarshaling body from REST client response: %w", err)
}

latestBlockReq, err := http.NewRequest("GET", fmt.Sprintf("%s/blocks/latest", node.Address), nil)
latestBlockReq, err := http.NewRequest("GET", fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/blocks/latest", node.Address), nil)
if err != nil {
return Status{}, fmt.Errorf("creating REST client request: %w", err)
}
Expand All @@ -155,7 +155,7 @@ func RESTProbe(ctx context.Context, node Node) (Status, error) {
defer latestBlockResp.Body.Close()

if latestBlockResp.StatusCode != 200 {
return Status{}, fmt.Errorf("unexpected status from REST client [%d %s]: %w", latestBlockResp.StatusCode, latestBlockResp.Status, err)
return Status{}, fmt.Errorf("unexpected status from REST client [%d %s]", latestBlockResp.StatusCode, latestBlockResp.Status)
}

latestBlockBody, err := io.ReadAll(latestBlockResp.Body)
Expand Down
Loading