@@ -185,7 +185,7 @@ func (f *FarmerBot) serve(ctx context.Context) error {
185
185
return nil , fmt .Errorf ("failed to include node with id %d with error: %w" , nodeID , err )
186
186
}
187
187
188
- f .state . addNode (node )
188
+ f .addNode (node )
189
189
return nil , nil
190
190
})
191
191
@@ -206,7 +206,7 @@ func (f *FarmerBot) serve(ctx context.Context) error {
206
206
// Exclude node from farmerbot management
207
207
// (It is not allowed if we tried to power on a node the farmer decided to power off)
208
208
// the farmer should include it again if he wants to the bot to manage it
209
- f .state . deleteNode (nodeID )
209
+ f .deleteNode (nodeID )
210
210
return nil , nil
211
211
})
212
212
@@ -227,7 +227,7 @@ func (f *FarmerBot) serve(ctx context.Context) error {
227
227
// Exclude node from farmerbot management
228
228
// (It is not allowed if we tried to power off a node the farmer decided to power on)
229
229
// the farmer should include it again if he wants to the bot to manage it
230
- f .state . deleteNode (nodeID )
230
+ f .deleteNode (nodeID )
231
231
return nil , nil
232
232
})
233
233
@@ -240,7 +240,6 @@ func (f *FarmerBot) serve(ctx context.Context) error {
240
240
peer .WithSession (fmt .Sprintf ("farmerbot-%d" , f .farm .ID )),
241
241
peer .WithKeyType (f .keyType ),
242
242
)
243
-
244
243
if err != nil {
245
244
return fmt .Errorf ("failed to create farmerbot direct peer with error: %w" , err )
246
245
}
@@ -253,28 +252,28 @@ func (f *FarmerBot) iterateOnNodes(ctx context.Context, subConn Substrate) error
253
252
var wakeUpCalls uint8
254
253
255
254
log .Debug ().Msg ("Fetch nodes" )
256
- farmNodes , err := subConn .GetNodes (uint32 (f .state . farm .ID ))
255
+ farmNodes , err := subConn .GetNodes (uint32 (f .farm .ID ))
257
256
if err != nil {
258
257
return err
259
258
}
260
259
261
260
// remove nodes that don't exist anymore in the farm
262
- for _ , node := range f .state . nodes {
261
+ for _ , node := range f .nodes {
263
262
if ! slices .Contains (farmNodes , uint32 (node .ID )) {
264
- f .state . deleteNode (uint32 (node .ID ))
263
+ f .deleteNode (uint32 (node .ID ))
265
264
}
266
265
}
267
266
268
- farmNodes = addPriorityToNodes (f .state . config .PriorityNodes , farmNodes )
267
+ farmNodes = addPriorityToNodes (f .config .PriorityNodes , farmNodes )
269
268
270
269
for _ , nodeID := range farmNodes {
271
- if slices .Contains (f .state . config .ExcludedNodes , nodeID ) {
270
+ if slices .Contains (f .config .ExcludedNodes , nodeID ) {
272
271
continue
273
272
}
274
273
275
274
// if the user specified included nodes or
276
275
// no nodes are specified so all nodes will be added (except excluded)
277
- if ! slices .Contains (f .state . config .IncludedNodes , nodeID ) && len (f . state .config .IncludedNodes ) > 0 {
276
+ if ! slices .Contains (f .config .IncludedNodes , nodeID ) && len (f .config .IncludedNodes ) > 0 {
278
277
continue
279
278
}
280
279
@@ -284,7 +283,7 @@ func (f *FarmerBot) iterateOnNodes(ctx context.Context, subConn Substrate) error
284
283
log .Error ().Err (err ).Send ()
285
284
}
286
285
287
- _ , node , err := f .state . getNode (nodeID )
286
+ _ , node , err := f .getNode (nodeID )
288
287
if err != nil {
289
288
log .Error ().Err (err ).Send ()
290
289
}
@@ -300,14 +299,14 @@ func (f *FarmerBot) iterateOnNodes(ctx context.Context, subConn Substrate) error
300
299
if roundStart .Day () == 1 && roundStart .Hour () == 1 && roundStart .Minute () < int (timeoutUpdate .Minutes ()) {
301
300
log .Debug ().Uint32 ("nodeID" , nodeID ).Msg ("Reset random wake-up times the first day of the month" )
302
301
node .timesRandomWakeUps = 0
303
- err = f .state . updateNode (node )
302
+ err = f .updateNode (node )
304
303
if err != nil {
305
304
log .Error ().Err (err ).Send ()
306
305
}
307
306
}
308
307
309
308
if f .shouldWakeUp (ctx , & node , roundStart , wakeUpCalls ) {
310
- err = f .state . updateNode (node )
309
+ err = f .updateNode (node )
311
310
if err != nil {
312
311
log .Error ().Err (err ).Send ()
313
312
}
@@ -355,14 +354,14 @@ func addPriorityToNodes(priorityNodes, farmNodes []uint32) []uint32 {
355
354
}
356
355
357
356
func (f * FarmerBot ) addOrUpdateNode (ctx context.Context , subConn Substrate , nodeID uint32 ) error {
358
- neverShutDown := slices .Contains (f .state . config .NeverShutDownNodes , nodeID )
357
+ neverShutDown := slices .Contains (f .config .NeverShutDownNodes , nodeID )
359
358
360
- _ , oldNode , err := f .state . getNode (nodeID )
359
+ _ , oldNode , err := f .getNode (nodeID )
361
360
if err == nil { // node exists
362
- updateErr := oldNode .update (ctx , subConn , f .rmbNodeClient , neverShutDown , f .state . farm .DedicatedFarm , f .config .ContinueOnPoweringOnErr )
361
+ updateErr := oldNode .update (ctx , subConn , f .rmbNodeClient , neverShutDown , f .farm .DedicatedFarm , f .config .ContinueOnPoweringOnErr )
363
362
364
363
// update old node state even if it failed
365
- if err := f .state . updateNode (oldNode ); err != nil {
364
+ if err := f .updateNode (oldNode ); err != nil {
366
365
return fmt .Errorf ("failed to update node state %d with error: %w" , uint32 (oldNode .ID ), err )
367
366
}
368
367
@@ -375,12 +374,12 @@ func (f *FarmerBot) addOrUpdateNode(ctx context.Context, subConn Substrate, node
375
374
}
376
375
377
376
// if node doesn't exist, we should add it
378
- nodeObj , err := getNode (ctx , subConn , f .rmbNodeClient , nodeID , f .config .ContinueOnPoweringOnErr , neverShutDown , false , f .state . farm .DedicatedFarm , on )
377
+ nodeObj , err := getNode (ctx , subConn , f .rmbNodeClient , nodeID , f .config .ContinueOnPoweringOnErr , neverShutDown , false , f .farm .DedicatedFarm , on )
379
378
if err != nil {
380
379
return fmt .Errorf ("failed to get node %d: %w" , nodeID , err )
381
380
}
382
381
383
- f .state . addNode (nodeObj )
382
+ f .addNode (nodeObj )
384
383
log .Debug ().Uint32 ("nodeID" , nodeID ).Msg ("Node is added with latest changes successfully" )
385
384
return nil
386
385
}
0 commit comments