Skip to content

Commit 6cbdbf5

Browse files
committed
feat: node is warming up
1 parent 8beece5 commit 6cbdbf5

File tree

6 files changed

+17
-3
lines changed

6 files changed

+17
-3
lines changed

openapi/SwarmCommon.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,8 @@ components:
932932
type: integer
933933
committedDepth:
934934
type: integer
935+
isWarmingUp:
936+
type: boolean
935937

936938
StatusPeersResponse:
937939
type: object

pkg/api/api.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ import (
5050
"github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20"
5151
"github.com/ethersphere/bee/v2/pkg/status"
5252
"github.com/ethersphere/bee/v2/pkg/steward"
53-
storage "github.com/ethersphere/bee/v2/pkg/storage"
53+
"github.com/ethersphere/bee/v2/pkg/storage"
5454
"github.com/ethersphere/bee/v2/pkg/storageincentives"
5555
"github.com/ethersphere/bee/v2/pkg/storageincentives/staking"
56-
storer "github.com/ethersphere/bee/v2/pkg/storer"
56+
"github.com/ethersphere/bee/v2/pkg/storer"
5757
"github.com/ethersphere/bee/v2/pkg/swarm"
5858
"github.com/ethersphere/bee/v2/pkg/topology"
5959
"github.com/ethersphere/bee/v2/pkg/topology/lightnode"
@@ -220,6 +220,7 @@ type Service struct {
220220
redistributionAgent *storageincentives.Agent
221221

222222
statusService *status.Service
223+
warmupTime time.Time
223224
}
224225

225226
func (s *Service) SetP2P(p2p p2p.DebugService) {
@@ -387,6 +388,10 @@ func (s *Service) SetProbe(probe *Probe) {
387388
s.probe = probe
388389
}
389390

391+
func (s *Service) SetWarmupTime(t time.Time) {
392+
s.warmupTime = t
393+
}
394+
390395
// Close hangs up running websockets on shutdown.
391396
func (s *Service) Close() error {
392397
s.logger.Info("api shutting down")

pkg/api/api_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ type testServerOptions struct {
135135
FullAPIDisabled bool
136136
ChequebookDisabled bool
137137
SwapDisabled bool
138+
WarmupTime time.Duration
138139
}
139140

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

226227
s.SetSwarmAddress(&o.Overlay)
227228
s.SetProbe(o.Probe)
229+
s.SetWarmupTime(time.Now().Add(o.WarmupTime))
228230

229231
noOpTracer, tracerCloser, _ := tracing.NewTracer(&tracing.Options{
230232
Enabled: false,

pkg/api/status.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type statusSnapshotResponse struct {
3131
IsReachable bool `json:"isReachable"`
3232
LastSyncedBlock uint64 `json:"lastSyncedBlock"`
3333
CommittedDepth uint8 `json:"committedDepth"`
34+
IsWarmingUp bool `json:"isWarmingUp"`
3435
}
3536

3637
type statusResponse struct {
@@ -96,6 +97,7 @@ func (s *Service) statusGetHandler(w http.ResponseWriter, _ *http.Request) {
9697
IsReachable: ss.IsReachable,
9798
LastSyncedBlock: ss.LastSyncedBlock,
9899
CommittedDepth: uint8(ss.CommittedDepth),
100+
IsWarmingUp: time.Now().Before(s.warmupTime),
99101
})
100102
}
101103

pkg/api/status_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"net/http"
1010
"testing"
11+
"time"
1112

1213
"github.com/ethersphere/bee/v2/pkg/api"
1314
"github.com/ethersphere/bee/v2/pkg/jsonhttp"
@@ -41,6 +42,7 @@ func TestGetStatus(t *testing.T) {
4142
IsReachable: true,
4243
LastSyncedBlock: 6092500,
4344
CommittedDepth: 1,
45+
IsWarmingUp: true,
4446
}
4547

4648
ssMock := &statusSnapshotMock{
@@ -67,6 +69,7 @@ func TestGetStatus(t *testing.T) {
6769
client, _, _, _ := newTestServer(t, testServerOptions{
6870
BeeMode: mode,
6971
NodeStatus: statusSvc,
72+
WarmupTime: time.Second,
7073
})
7174

7275
jsonhttptest.Request(t, client, http.MethodGet, url, http.StatusOK,

pkg/node/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ func NewBee(
461461

462462
apiService.Mount()
463463
apiService.SetProbe(probe)
464-
464+
apiService.SetWarmupTime(time.Now().Add(o.WarmupTime))
465465
apiService.SetSwarmAddress(&swarmAddress)
466466

467467
apiServer := &http.Server{

0 commit comments

Comments
 (0)