Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add additional logs to help debug #6

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading