Skip to content

Commit

Permalink
fix: several api fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Jun 11, 2024
1 parent 8c61408 commit 0c6a7d5
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 54 deletions.
8 changes: 4 additions & 4 deletions openapi/SwarmCommon.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: 3.0.3
info:
version: 3.2.8
version: 4.0.0
title: Common Data Types
description: |
\*****bzzz*****
Expand Down Expand Up @@ -731,8 +731,8 @@ components:
type: integer
lastSelectedRound:
type: integer
lastSampleDuration:
$ref: "#/components/schemas/Duration"
lastSampleDurationSeconds:
type: number
block:
type: integer
reward:
Expand Down Expand Up @@ -835,7 +835,7 @@ components:
StatusSnapshotResponse:
type: object
properties:
peer:
overlay:
$ref: "#/components/schemas/SwarmAddress"
beeMode:
type: string
Expand Down
61 changes: 30 additions & 31 deletions pkg/api/redistribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,28 @@ package api

import (
"net/http"
"time"

"github.com/ethersphere/bee/v2/pkg/bigint"
"github.com/ethersphere/bee/v2/pkg/jsonhttp"
"github.com/ethersphere/bee/v2/pkg/tracing"
)

type redistributionStatusResponse struct {
MinimumGasFunds *bigint.BigInt `json:"minimumGasFunds"`
HasSufficientFunds bool `json:"hasSufficientFunds"`
IsFrozen bool `json:"isFrozen"`
IsFullySynced bool `json:"isFullySynced"`
Phase string `json:"phase"`
Round uint64 `json:"round"`
LastWonRound uint64 `json:"lastWonRound"`
LastPlayedRound uint64 `json:"lastPlayedRound"`
LastFrozenRound uint64 `json:"lastFrozenRound"`
LastSelectedRound uint64 `json:"lastSelectedRound"`
LastSampleDuration time.Duration `json:"lastSampleDuration"`
Block uint64 `json:"block"`
Reward *bigint.BigInt `json:"reward"`
Fees *bigint.BigInt `json:"fees"`
IsHealthy bool `json:"isHealthy"`
MinimumGasFunds *bigint.BigInt `json:"minimumGasFunds"`
HasSufficientFunds bool `json:"hasSufficientFunds"`
IsFrozen bool `json:"isFrozen"`
IsFullySynced bool `json:"isFullySynced"`
Phase string `json:"phase"`
Round uint64 `json:"round"`
LastWonRound uint64 `json:"lastWonRound"`
LastPlayedRound uint64 `json:"lastPlayedRound"`
LastFrozenRound uint64 `json:"lastFrozenRound"`
LastSelectedRound uint64 `json:"lastSelectedRound"`
LastSampleDurationSeconds float64 `json:"lastSampleDurationSeconds"`
Block uint64 `json:"block"`
Reward *bigint.BigInt `json:"reward"`
Fees *bigint.BigInt `json:"fees"`
IsHealthy bool `json:"isHealthy"`
}

func (s *Service) redistributionStatusHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -56,20 +55,20 @@ func (s *Service) redistributionStatusHandler(w http.ResponseWriter, r *http.Req
}

jsonhttp.OK(w, redistributionStatusResponse{
MinimumGasFunds: bigint.Wrap(minGasFunds),
HasSufficientFunds: hasSufficientFunds,
IsFrozen: status.IsFrozen,
IsFullySynced: status.IsFullySynced,
Phase: status.Phase.String(),
LastWonRound: status.LastWonRound,
LastPlayedRound: status.LastPlayedRound,
LastFrozenRound: status.LastFrozenRound,
LastSelectedRound: status.LastSelectedRound,
LastSampleDuration: status.SampleDuration,
Round: status.Round,
Block: status.Block,
Reward: bigint.Wrap(status.Reward),
Fees: bigint.Wrap(status.Fees),
IsHealthy: status.IsHealthy,
MinimumGasFunds: bigint.Wrap(minGasFunds),
HasSufficientFunds: hasSufficientFunds,
IsFrozen: status.IsFrozen,
IsFullySynced: status.IsFullySynced,
Phase: status.Phase.String(),
LastWonRound: status.LastWonRound,
LastPlayedRound: status.LastPlayedRound,
LastFrozenRound: status.LastFrozenRound,
LastSelectedRound: status.LastSelectedRound,
LastSampleDurationSeconds: status.SampleDuration.Seconds(),
Round: status.Round,
Block: status.Block,
Reward: bigint.Wrap(status.Reward),
Fees: bigint.Wrap(status.Fees),
IsHealthy: status.IsHealthy,
})
}
11 changes: 6 additions & 5 deletions pkg/api/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
)

type statusSnapshotResponse struct {
Peer string `json:"peer"`
Proximity uint8 `json:"proximity"`
Overlay string `json:"overlay"`
Proximity uint `json:"proximity"`
BeeMode string `json:"beeMode"`
ReserveSize uint64 `json:"reserveSize"`
ReserveSizeWithinRadius uint64 `json:"reserveSizeWithinRadius"`
Expand Down Expand Up @@ -71,7 +71,8 @@ func (s *Service) statusGetHandler(w http.ResponseWriter, _ *http.Request) {
}

jsonhttp.OK(w, statusSnapshotResponse{
Peer: s.overlay.String(),
Proximity: 256,
Overlay: s.overlay.String(),
BeeMode: ss.BeeMode,
ReserveSize: ss.ReserveSize,
ReserveSizeWithinRadius: ss.ReserveSizeWithinRadius,
Expand Down Expand Up @@ -109,8 +110,8 @@ func (s *Service) statusGetPeersHandler(w http.ResponseWriter, r *http.Request)
defer wg.Done()

snapshot := statusSnapshotResponse{
Peer: address.String(),
Proximity: po,
Overlay: address.String(),
Proximity: uint(po),
}

ss, err := s.statusService.PeerSnapshot(ctx, address)
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ func TestGetStatus(t *testing.T) {

mode := api.FullMode
ssr := api.StatusSnapshotResponse{
Proximity: 256,
BeeMode: mode.String(),
ReserveSize: 128,
ReserveSizeWithinRadius: 64,
PullsyncRate: 64,
StorageRadius: 8,
ConnectedPeers: 0,
NeighborhoodSize: 0,
NeighborhoodSize: 1,
BatchCommitment: 1,
IsReachable: true,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *Service) LocalSnapshot() (*Snapshot, error) {
PullsyncRate: syncRate,
StorageRadius: uint32(storageRadius),
ConnectedPeers: connectedPeers,
NeighborhoodSize: neighborhoodSize,
NeighborhoodSize: neighborhoodSize + 1, // include self
BatchCommitment: commitment,
IsReachable: s.topologyDriver.IsReachable(),
}, nil
Expand Down
26 changes: 14 additions & 12 deletions pkg/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ func TestStatus(t *testing.T) {
t.Parallel()

want := &pb.Snapshot{
BeeMode: api.FullMode.String(),
ReserveSize: 128,
PullsyncRate: 64,
StorageRadius: 8,
BatchCommitment: 1024,
IsReachable: true,
BeeMode: api.FullMode.String(),
ReserveSize: 128,
PullsyncRate: 64,
StorageRadius: 8,
BatchCommitment: 1024,
NeighborhoodSize: 1,
IsReachable: true,
}

sssMock := &statusSnapshotMock{want}
Expand Down Expand Up @@ -96,12 +97,13 @@ func TestStatusLightNode(t *testing.T) {
t.Parallel()

want := &pb.Snapshot{
BeeMode: api.LightMode.String(),
ReserveSize: 0,
PullsyncRate: 0,
StorageRadius: 0,
BatchCommitment: 1024,
IsReachable: true,
BeeMode: api.LightMode.String(),
ReserveSize: 0,
PullsyncRate: 0,
StorageRadius: 0,
BatchCommitment: 1024,
IsReachable: true,
NeighborhoodSize: 1,
}

sssMock := &statusSnapshotMock{&pb.Snapshot{
Expand Down

0 comments on commit 0c6a7d5

Please sign in to comment.