Skip to content

Commit 9830971

Browse files
committed
chore: add service_type in query for session usage validate worker
1 parent 249a4e6 commit 9830971

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

workers/session.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func NewSessionUsageSyncWithBlockchainWorker(c *core.Context, interval time.Dura
9696

9797
// Wait until all routines complete.
9898
if err := jobGroup.Wait(); err != nil {
99-
return err
99+
return fmt.Errorf("waiting job group: %w", err)
100100
}
101101

102102
// Broadcast the prepared messages as a transaction.
@@ -175,7 +175,7 @@ func NewSessionUsageSyncWithDatabaseWorker(c *core.Context, interval time.Durati
175175

176176
// Wait until all routines complete.
177177
if err := jobGroup.Wait(); err != nil {
178-
return err
178+
return fmt.Errorf("waiting job group: %w", err)
179179
}
180180

181181
return nil
@@ -195,7 +195,8 @@ func NewSessionUsageValidateWorker(c *core.Context, interval time.Duration) cron
195195
handlerFunc := func(ctx context.Context) error {
196196
// Retrieve session records from the database.
197197
query := map[string]interface{}{
198-
"node_addr": c.NodeAddr().String(),
198+
"node_addr": c.NodeAddr().String(),
199+
"service_type": c.Service().Type().String(),
199200
}
200201

201202
items, err := operations.SessionFind(c.Database(), query)
@@ -238,15 +239,6 @@ func NewSessionUsageValidateWorker(c *core.Context, interval time.Duration) cron
238239
removePeer = true
239240
}
240241

241-
// Ensure that only sessions of the current service type are validated.
242-
if item.GetServiceType() != c.Service().Type() {
243-
log.Debug("Skipping peer",
244-
"id", item.GetID(), "peer_id", item.GetPeerID(), "cause", "invalid service type",
245-
"got", item.GetServiceType(), "expected", c.Service().Type(),
246-
)
247-
removePeer = false
248-
}
249-
250242
// If the session exceeded any limits, remove the associated peer.
251243
if removePeer {
252244
log.Debug("Removing peer from service", "id", item.GetID(), "peer_id", item.GetPeerID())
@@ -261,7 +253,7 @@ func NewSessionUsageValidateWorker(c *core.Context, interval time.Duration) cron
261253

262254
// Wait until all routines complete.
263255
if err := jobGroup.Wait(); err != nil {
264-
return err
256+
return fmt.Errorf("waiting job group: %w", err)
265257
}
266258

267259
return nil
@@ -371,7 +363,7 @@ func NewSessionValidateWorker(c *core.Context, interval time.Duration) cron.Work
371363

372364
// Wait until all routines complete.
373365
if err := jobGroup.Wait(); err != nil {
374-
return err
366+
return fmt.Errorf("waiting job group: %w", err)
375367
}
376368

377369
return nil

0 commit comments

Comments
 (0)