Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions openapi/SwarmCommon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,8 @@ components:
type: integer
committedDepth:
type: integer
isWarmingUp:
type: boolean

StatusPeersResponse:
type: object
Expand Down
9 changes: 7 additions & 2 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ import (
"github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20"
"github.com/ethersphere/bee/v2/pkg/status"
"github.com/ethersphere/bee/v2/pkg/steward"
storage "github.com/ethersphere/bee/v2/pkg/storage"
"github.com/ethersphere/bee/v2/pkg/storage"
"github.com/ethersphere/bee/v2/pkg/storageincentives"
"github.com/ethersphere/bee/v2/pkg/storageincentives/staking"
storer "github.com/ethersphere/bee/v2/pkg/storer"
"github.com/ethersphere/bee/v2/pkg/storer"
"github.com/ethersphere/bee/v2/pkg/swarm"
"github.com/ethersphere/bee/v2/pkg/topology"
"github.com/ethersphere/bee/v2/pkg/topology/lightnode"
Expand Down Expand Up @@ -220,6 +220,7 @@ type Service struct {
redistributionAgent *storageincentives.Agent

statusService *status.Service
warmupTime time.Time
}

func (s *Service) SetP2P(p2p p2p.DebugService) {
Expand Down Expand Up @@ -387,6 +388,10 @@ func (s *Service) SetProbe(probe *Probe) {
s.probe = probe
}

func (s *Service) SetWarmupTime(t time.Time) {
s.warmupTime = t
}

// Close hangs up running websockets on shutdown.
func (s *Service) Close() error {
s.logger.Info("api shutting down")
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ type testServerOptions struct {
FullAPIDisabled bool
ChequebookDisabled bool
SwapDisabled bool
WarmupTime time.Duration
}

func newTestServer(t *testing.T, o testServerOptions) (*http.Client, *websocket.Conn, string, *chanStorer) {
Expand Down Expand Up @@ -225,6 +226,7 @@ func newTestServer(t *testing.T, o testServerOptions) (*http.Client, *websocket.

s.SetSwarmAddress(&o.Overlay)
s.SetProbe(o.Probe)
s.SetWarmupTime(time.Now().Add(o.WarmupTime))

noOpTracer, tracerCloser, _ := tracing.NewTracer(&tracing.Options{
Enabled: false,
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type statusSnapshotResponse struct {
IsReachable bool `json:"isReachable"`
LastSyncedBlock uint64 `json:"lastSyncedBlock"`
CommittedDepth uint8 `json:"committedDepth"`
IsWarmingUp bool `json:"isWarmingUp"`
}

type statusResponse struct {
Expand Down Expand Up @@ -96,6 +97,7 @@ func (s *Service) statusGetHandler(w http.ResponseWriter, _ *http.Request) {
IsReachable: ss.IsReachable,
LastSyncedBlock: ss.LastSyncedBlock,
CommittedDepth: uint8(ss.CommittedDepth),
IsWarmingUp: time.Now().Before(s.warmupTime),
})
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/api/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"net/http"
"testing"
"time"

"github.com/ethersphere/bee/v2/pkg/api"
"github.com/ethersphere/bee/v2/pkg/jsonhttp"
Expand Down Expand Up @@ -41,6 +42,7 @@ func TestGetStatus(t *testing.T) {
IsReachable: true,
LastSyncedBlock: 6092500,
CommittedDepth: 1,
IsWarmingUp: true,
}

ssMock := &statusSnapshotMock{
Expand All @@ -67,6 +69,7 @@ func TestGetStatus(t *testing.T) {
client, _, _, _ := newTestServer(t, testServerOptions{
BeeMode: mode,
NodeStatus: statusSvc,
WarmupTime: time.Second,
})

jsonhttptest.Request(t, client, http.MethodGet, url, http.StatusOK,
Expand Down
2 changes: 1 addition & 1 deletion pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func NewBee(

apiService.Mount()
apiService.SetProbe(probe)

apiService.SetWarmupTime(time.Now().Add(o.WarmupTime))
Copy link
Contributor

@istae istae Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here 's the tricky thing, if the postage batches are syncing, then setting this up here becomes inaccurate as we have not run this line yet https://github.com/ethersphere/bee/pull/5047/files#diff-515b2d0691202c4ea5e578ec896258ae9c440c381b608ed1eb7116a27847057dR782

maybe it would help if instead of passing a time to the api pkg, it can be done by toggling a bool externally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Then we can just move it downwards after the sync.
Like where we initialize salud. https://github.com/ethersphere/bee/pull/5047/files#diff-515b2d0691202c4ea5e578ec896258ae9c440c381b608ed1eb7116a27847057dR920

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think of it again, the setter is better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the next PR we'll improve how we detect and set the warmup

apiService.SetSwarmAddress(&swarmAddress)

apiServer := &http.Server{
Expand Down
Loading