Skip to content

Commit

Permalink
update logs
Browse files Browse the repository at this point in the history
  • Loading branch information
gusin13 committed Oct 20, 2024
1 parent 6872fff commit 27a54a6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 32 deletions.
17 changes: 1 addition & 16 deletions internal/db/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/babylonlabs-io/babylon-staking-indexer/internal/clients/bbnclient"
"github.com/babylonlabs-io/babylon-staking-indexer/internal/db/model"
"github.com/rs/zerolog/log"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
)
Expand Down Expand Up @@ -50,8 +49,6 @@ func (db *Database) SaveStakingParams(
func (db *Database) SaveCheckpointParams(
ctx context.Context, params *bbnclient.CheckpointParams,
) error {
log.Debug().Msg("Saving checkpoint params")

collection := db.client.Database(db.dbName).
Collection(model.GlobalParamsCollection)

Expand All @@ -68,22 +65,10 @@ func (db *Database) SaveCheckpointParams(
},
}

log.Debug().
Interface("filter", filter).
Interface("update", update).
Msg("Attempting to update checkpoint params")

result, err := collection.UpdateOne(ctx, filter, update, options.Update().SetUpsert(true))
_, err := collection.UpdateOne(ctx, filter, update, options.Update().SetUpsert(true))
if err != nil {
log.Error().Err(err).Msg("Failed to save checkpoint params")
return fmt.Errorf("failed to save checkpoint params: %w", err)
}

log.Info().
Int64("matched_count", result.MatchedCount).
Int64("modified_count", result.ModifiedCount).
Int64("upserted_count", result.UpsertedCount).
Msg("Successfully saved checkpoint params")

return nil
}
10 changes: 0 additions & 10 deletions internal/services/global-params.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func (s *Service) SyncGlobalParams(ctx context.Context) {
}

func (s *Service) fetchAndSaveParams(ctx context.Context) *types.Error {
log.Debug().Msg("Fetching and saving global parameters")

checkpointParams, err := s.bbn.GetCheckpointParams(ctx)
if err != nil {
// TODO: Add metrics and replace internal service error with a more specific
Expand All @@ -29,15 +27,12 @@ func (s *Service) fetchAndSaveParams(ctx context.Context) *types.Error {
fmt.Errorf("failed to get checkpoint params: %w", err),
)
}
log.Debug().Interface("checkpointParams", checkpointParams).Msg("Retrieved checkpoint params")

if err := s.db.SaveCheckpointParams(ctx, checkpointParams); err != nil {
log.Error().Err(err).Msg("Failed to save checkpoint params")
return types.NewInternalServiceError(
fmt.Errorf("failed to save checkpoint params: %w", err),
)
}
log.Info().Msg("Successfully saved checkpoint params")

allStakingParams, err := s.bbn.GetAllStakingParams(ctx)
if err != nil {
Expand All @@ -46,24 +41,19 @@ func (s *Service) fetchAndSaveParams(ctx context.Context) *types.Error {
fmt.Errorf("failed to get staking params: %w", err),
)
}
log.Debug().Interface("allStakingParams", allStakingParams).Msg("Retrieved all staking params")

for version, params := range allStakingParams {
if params == nil {
log.Error().Uint32("version", version).Msg("Nil staking params encountered")
return types.NewInternalServiceError(
fmt.Errorf("nil staking params for version %d", version),
)
}
if err := s.db.SaveStakingParams(ctx, version, params); err != nil {
log.Error().Err(err).Uint32("version", version).Msg("Failed to save staking params")
return types.NewInternalServiceError(
fmt.Errorf("failed to save staking params: %w", err),
)
}
log.Info().Uint32("version", version).Msg("Successfully saved staking params")
}

log.Info().Msg("Successfully fetched and saved all global parameters")
return nil
}
8 changes: 2 additions & 6 deletions internal/utils/poller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,20 @@ func NewPoller(interval time.Duration, pollMethod func(ctx context.Context) *typ

func (p *Poller) Start(ctx context.Context) {
ticker := time.NewTicker(p.interval)
defer ticker.Stop()

log.Info().Msgf("Starting poller with interval %s", p.interval)

for {
select {
case <-ticker.C:
log.Debug().Msg("Executing poll method")
if err := p.pollMethod(ctx); err != nil {
log.Error().Err(err).Msg("Error polling")
} else {
log.Debug().Msg("Poll method executed successfully")
}
case <-ctx.Done():
// Handle context cancellation.
log.Info().Msg("Poller stopped due to context cancellation")
return
case <-p.quit:
log.Info().Msg("Poller stopped")
ticker.Stop() // Stop the ticker
return
}
}
Expand Down

0 comments on commit 27a54a6

Please sign in to comment.