Skip to content

Commit

Permalink
chore: add additional logs to help debug
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwbabylonlab committed Aug 22, 2024
1 parent 1991173 commit 26a9c95
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions internal/poller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ func (p *Poller) Stop() {
}

func (p *Poller) poll(ctx context.Context) error {
log.Debug().Msg("Polling started")
if err := p.service.ProcessExpiredDelegations(ctx); err != nil {
log.Error().Err(err).Msg("Error processing expired delegations")
return err
}
log.Debug().Msg("Polling completed")
return nil
}
6 changes: 5 additions & 1 deletion internal/services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/babylonlabs-io/staking-expiry-checker/internal/db"
"github.com/babylonlabs-io/staking-expiry-checker/internal/queue"
queueclient "github.com/babylonlabs-io/staking-queue-client/client"
"github.com/rs/zerolog/log"
)

type Service struct {
Expand All @@ -27,12 +28,14 @@ func (s *Service) ProcessExpiredDelegations(ctx context.Context) error {
// TODO: Use cache with ttl to store the tip height.
btcTip, err := s.btc.GetBlockCount()
if err != nil {
log.Error().Err(err).Msg("Error getting BTC tip height")
return err
}

for {
expiredDelegations, err := s.db.FindExpiredDelegations(ctx, uint64(btcTip))
if err != nil {
log.Error().Err(err).Msg("Error finding expired delegations")
return err
}
if len(expiredDelegations) == 0 {
Expand All @@ -42,14 +45,15 @@ func (s *Service) ProcessExpiredDelegations(ctx context.Context) error {
for _, delegation := range expiredDelegations {
ev := queueclient.NewExpiredStakingEvent(delegation.StakingTxHashHex, delegation.TxType)
if err := s.queueManager.SendExpiredStakingEvent(ctx, ev); err != nil {
log.Error().Err(err).Msg("Error sending expired staking event")
return err
}
// After successfully sending the event, delete the entry from the database.
if err := s.db.DeleteExpiredDelegation(ctx, delegation.ID); err != nil {
log.Error().Err(err).Msg("Error deleting expired delegation")
return err
}
}

}

return nil
Expand Down

0 comments on commit 26a9c95

Please sign in to comment.