diff --git a/internal/db/expiry.go b/internal/db/expiry.go index 7f2da10..30a1a31 100644 --- a/internal/db/expiry.go +++ b/internal/db/expiry.go @@ -10,11 +10,11 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func (db *Database) FindExpiredDelegations(ctx context.Context, btcTipHeight uint64, limit int64) ([]model.TimeLockDocument, error) { +func (db *Database) FindExpiredDelegations(ctx context.Context, btcTipHeight uint64) ([]model.TimeLockDocument, error) { client := db.client.Database(db.dbName).Collection(model.TimeLockCollection) filter := bson.M{"expire_height": bson.M{"$lte": btcTipHeight}} - opts := options.Find().SetLimit(limit) // to prevent large result sets + opts := options.Find().SetLimit(db.cfg.MaxPaginationLimit) // to prevent large result sets cursor, err := client.Find(ctx, filter, opts) if err != nil { return nil, err diff --git a/internal/db/interface.go b/internal/db/interface.go index 6ae3264..a9b5800 100644 --- a/internal/db/interface.go +++ b/internal/db/interface.go @@ -11,7 +11,7 @@ import ( type DbInterface interface { Ping(ctx context.Context) error FindExpiredDelegations( - ctx context.Context, btcTipHeight uint64, limit int64, + ctx context.Context, btcTipHeight uint64, ) ([]model.TimeLockDocument, error) DeleteExpiredDelegation( ctx context.Context, id primitive.ObjectID, diff --git a/internal/services/pollers.go b/internal/services/pollers.go index 5168a0a..9f3ffe4 100644 --- a/internal/services/pollers.go +++ b/internal/services/pollers.go @@ -78,10 +78,7 @@ func (s *Service) processExpiredDelegations(ctx context.Context) *types.Error { // Process a single batch of expired delegations without pagination. // Since we delete each delegation after processing it, pagination is not needed. - // Delegations are deleted to prevent duplicate processing in subsequent poller runs. - // The batch size is configured via ExpiryChecker.BatchSize in the config. - limit := s.cfg.Pollers.ExpiryChecker.BatchSize - expiredDelegations, err := s.db.FindExpiredDelegations(ctx, uint64(btcTip), limit) + expiredDelegations, err := s.db.FindExpiredDelegations(ctx, uint64(btcTip)) if err != nil { log.Error().Err(err).Msg("Error finding expired delegations") return types.NewInternalServiceError(err) diff --git a/tests/mocks/mock_db_client.go b/tests/mocks/mock_db_client.go index b0297e0..0318805 100644 --- a/tests/mocks/mock_db_client.go +++ b/tests/mocks/mock_db_client.go @@ -38,9 +38,9 @@ func (_m *DbInterface) DeleteExpiredDelegation(ctx context.Context, id primitive return r0 } -// FindExpiredDelegations provides a mock function with given fields: ctx, btcTipHeight, limit -func (_m *DbInterface) FindExpiredDelegations(ctx context.Context, btcTipHeight uint64, limit int64) ([]model.TimeLockDocument, error) { - ret := _m.Called(ctx, btcTipHeight, limit) +// FindExpiredDelegations provides a mock function with given fields: ctx, btcTipHeight +func (_m *DbInterface) FindExpiredDelegations(ctx context.Context, btcTipHeight uint64) ([]model.TimeLockDocument, error) { + ret := _m.Called(ctx, btcTipHeight) if len(ret) == 0 { panic("no return value specified for FindExpiredDelegations") @@ -48,19 +48,19 @@ func (_m *DbInterface) FindExpiredDelegations(ctx context.Context, btcTipHeight var r0 []model.TimeLockDocument var r1 error - if rf, ok := ret.Get(0).(func(context.Context, uint64, int64) ([]model.TimeLockDocument, error)); ok { - return rf(ctx, btcTipHeight, limit) + if rf, ok := ret.Get(0).(func(context.Context, uint64) ([]model.TimeLockDocument, error)); ok { + return rf(ctx, btcTipHeight) } - if rf, ok := ret.Get(0).(func(context.Context, uint64, int64) []model.TimeLockDocument); ok { - r0 = rf(ctx, btcTipHeight, limit) + if rf, ok := ret.Get(0).(func(context.Context, uint64) []model.TimeLockDocument); ok { + r0 = rf(ctx, btcTipHeight) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]model.TimeLockDocument) } } - if rf, ok := ret.Get(1).(func(context.Context, uint64, int64) error); ok { - r1 = rf(ctx, btcTipHeight, limit) + if rf, ok := ret.Get(1).(func(context.Context, uint64) error); ok { + r1 = rf(ctx, btcTipHeight) } else { r1 = ret.Error(1) }