Skip to content

Commit

Permalink
fix resubscription logic (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
gusin13 authored Jan 7, 2025
1 parent 4834c1e commit a54dce1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/services/expiry_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *Service) checkExpiry(ctx context.Context) *types.Error {
if db.IsNotFoundError(stateUpdateErr) {
log.Debug().
Str("staking_tx", delegation.StakingTxHashHex).
Msg("Skip updating BTC delegation state to withdrawable as the it's outdated")
Msg("skip updating BTC delegation state to withdrawable as the state is not qualified")
} else {
log.Error().
Str("staking_tx", delegation.StakingTxHashHex).
Expand Down
28 changes: 24 additions & 4 deletions internal/services/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,33 @@ func (s *Service) SubscribeToBbnEvents(ctx context.Context) {
// Resubscribe to missed BTC notifications
func (s *Service) ResubscribeToMissedBtcNotifications(ctx context.Context) {
go func() {
log.Info().Msg("Resubscribing to missed BTC notifications")
delegations, err := s.db.GetBTCDelegationsByStates(ctx, []types.DelegationState{types.StateUnbonding, types.StateSlashed})
log.Info().Msg("resubscribing to missed BTC notifications")
delegations, err := s.db.GetBTCDelegationsByStates(ctx,
[]types.DelegationState{
types.StateActive,
types.StateUnbonding,
types.StateWithdrawable,
types.StateSlashed,
},
)
if err != nil {
log.Fatal().Msgf("Failed to get BTC delegations: %v", err)
log.Fatal().Msgf("failed to get BTC delegations: %v", err)
}

for _, delegation := range delegations {
if !delegation.HasInclusionProof() {
log.Debug().
Str("staking_tx", delegation.StakingTxHashHex).
Str("reason", "missing_inclusion_proof").
Msg("skip resubscribing to missed BTC notification")
continue
}

log.Debug().
Str("staking_tx", delegation.StakingTxHashHex).
Str("current_state", delegation.State.String()).
Msg("resubscribing to missed BTC notification")

// Register spend notification
if err := s.registerStakingSpendNotification(
ctx,
Expand All @@ -69,7 +89,7 @@ func (s *Service) ResubscribeToMissedBtcNotifications(ctx context.Context) {
delegation.StakingOutputIdx,
delegation.StartHeight,
); err != nil {
log.Fatal().Msgf("Failed to register spend notification: %v", err)
log.Fatal().Msgf("failed to register spend notification: %v", err)
}
}
}()
Expand Down

0 comments on commit a54dce1

Please sign in to comment.