Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gusin13 committed Jan 10, 2025
1 parent 8f94b8a commit a8d63b3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions internal/db/expiry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions internal/services/pollers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions tests/mocks/mock_db_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a8d63b3

Please sign in to comment.