Skip to content

Commit

Permalink
Replace .Str() with .Stringer() in log for types that implement fmt.S…
Browse files Browse the repository at this point in the history
…tringer (#121)
  • Loading branch information
kirugan authored Jan 16, 2025
1 parent f1a55b8 commit ab2f9da
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
10 changes: 5 additions & 5 deletions internal/services/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (s *Service) processCovenantQuorumReachedEvent(
log.Debug().
Str("staking_tx", covenantQuorumReachedEvent.StakingTxHash).
Str("staking_start_height", strconv.FormatUint(uint64(delegation.StartHeight), 10)).
Str("event_type", EventCovenantQuorumReached.String()).
Stringer("event_type", EventCovenantQuorumReached).
Msg("handling active state")

err = s.emitActiveDelegationEvent(
Expand Down Expand Up @@ -233,7 +233,7 @@ func (s *Service) processBTCDelegationInclusionProofReceivedEvent(
log.Debug().
Str("staking_tx", inclusionProofEvent.StakingTxHash).
Str("staking_start_height", inclusionProofEvent.StartHeight).
Str("event_type", EventBTCDelegationInclusionProofReceived.String()).
Stringer("event_type", EventBTCDelegationInclusionProofReceived).
Msg("handling active state")

err = s.emitActiveDelegationEvent(
Expand Down Expand Up @@ -336,12 +336,12 @@ func (s *Service) processBTCDelegationUnbondedEarlyEvent(

log.Debug().
Str("staking_tx", unbondedEarlyEvent.StakingTxHash).
Str("new_state", types.StateUnbonding.String()).
Stringer("new_state", types.StateUnbonding).
Str("early_unbonding_start_height", unbondedEarlyEvent.StartHeight).
Str("unbonding_time", strconv.FormatUint(uint64(delegation.UnbondingTime), 10)).
Str("unbonding_expire_height", strconv.FormatUint(uint64(unbondingExpireHeight), 10)).
Str("sub_state", subState.String()).
Str("event_type", EventBTCDelgationUnbondedEarly.String()).
Stringer("sub_state", subState).
Stringer("event_type", EventBTCDelgationUnbondedEarly).
Msg("updating delegation state")

// Update delegation state
Expand Down
2 changes: 1 addition & 1 deletion internal/services/delegation_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *Service) registerUnbondingSpendNotification(

log.Debug().
Str("staking_tx", delegation.StakingTxHashHex).
Str("unbonding_tx", unbondingTx.TxHash().String()).
Stringer("unbonding_tx", unbondingTx.TxHash()).
Msg("registering early unbonding spend notification")

unbondingOutpoint := wire.OutPoint{
Expand Down
14 changes: 7 additions & 7 deletions internal/services/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (s *Service) validateCovenantQuorumReachedEvent(ctx context.Context, event
if !utils.Contains(qualifiedStates, delegation.State) {
log.Debug().
Str("stakingTxHashHex", event.StakingTxHash).
Str("currentState", delegation.State.String()).
Stringer("currentState", delegation.State).
Str("newState", event.NewState).
Msg("Ignoring EventCovenantQuorumReached because current state is not qualified for transition")
return false, nil // Ignore the event silently
Expand All @@ -224,7 +224,7 @@ func (s *Service) validateCovenantQuorumReachedEvent(ctx context.Context, event
if delegation.HasInclusionProof() {
log.Debug().
Str("stakingTxHashHex", event.StakingTxHash).
Str("currentState", delegation.State.String()).
Stringer("currentState", delegation.State).
Str("newState", event.NewState).
Msg("Ignoring EventCovenantQuorumReached because inclusion proof already received")
return false, nil
Expand All @@ -236,7 +236,7 @@ func (s *Service) validateCovenantQuorumReachedEvent(ctx context.Context, event
if !delegation.HasInclusionProof() {
log.Debug().
Str("stakingTxHashHex", event.StakingTxHash).
Str("currentState", delegation.State.String()).
Stringer("currentState", delegation.State).
Str("newState", event.NewState).
Msg("Ignoring EventCovenantQuorumReached because inclusion proof not received")
return false, nil
Expand Down Expand Up @@ -278,7 +278,7 @@ func (s *Service) validateBTCDelegationInclusionProofReceivedEvent(ctx context.C
if !utils.Contains(qualifiedStates, delegation.State) {
log.Debug().
Str("stakingTxHashHex", event.StakingTxHash).
Str("currentState", delegation.State.String()).
Stringer("currentState", delegation.State).
Str("newState", event.NewState).
Msg("Ignoring EventBTCDelegationInclusionProofReceived because current state is not qualified for transition")
return false, nil
Expand All @@ -289,7 +289,7 @@ func (s *Service) validateBTCDelegationInclusionProofReceivedEvent(ctx context.C
if delegation.HasInclusionProof() {
log.Debug().
Str("stakingTxHashHex", event.StakingTxHash).
Str("currentState", delegation.State.String()).
Stringer("currentState", delegation.State).
Str("newState", event.NewState).
Msg("Ignoring EventBTCDelegationInclusionProofReceived because inclusion proof already received")
return false, nil
Expand Down Expand Up @@ -329,7 +329,7 @@ func (s *Service) validateBTCDelegationUnbondedEarlyEvent(ctx context.Context, e
if !utils.Contains(types.QualifiedStatesForUnbondedEarly(), delegation.State) {
log.Debug().
Str("stakingTxHashHex", event.StakingTxHash).
Str("currentState", delegation.State.String()).
Stringer("currentState", delegation.State).
Msg("Ignoring EventBTCDelgationUnbondedEarly because current state is not qualified for transition")
return false, nil
}
Expand Down Expand Up @@ -368,7 +368,7 @@ func (s *Service) validateBTCDelegationExpiredEvent(ctx context.Context, event *
if !utils.Contains(types.QualifiedStatesForExpired(), delegation.State) {
log.Debug().
Str("stakingTxHashHex", event.StakingTxHash).
Str("currentState", delegation.State.String()).
Stringer("currentState", delegation.State).
Msg("Ignoring EventBTCDelegationExpired because current state is not qualified for transition")
return false, nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/services/expiry_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (s *Service) checkExpiry(ctx context.Context) *types.Error {

log.Debug().
Str("staking_tx", delegation.StakingTxHashHex).
Str("current_state", delegation.State.String()).
Str("new_sub_state", tlDoc.DelegationSubState.String()).
Stringer("current_state", delegation.State).
Stringer("new_sub_state", tlDoc.DelegationSubState).
Str("expire_height", strconv.FormatUint(uint64(tlDoc.ExpireHeight), 10)).
Msg("checking if delegation is expired")

Expand Down
2 changes: 1 addition & 1 deletion internal/services/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *Service) ResubscribeToMissedBtcNotifications(ctx context.Context) {

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

// Register spend notification
Expand Down
30 changes: 15 additions & 15 deletions internal/services/watch_btc_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *Service) watchForSpendStakingTx(
case spendDetail := <-spendEvent.Spend:
log.Debug().
Str("staking_tx", stakingTxHashHex).
Str("spending_tx", spendDetail.SpendingTx.TxHash().String()).
Stringer("spending_tx", spendDetail.SpendingTx.TxHash()).
Msg("staking tx has been spent")
if err := s.handleSpendingStakingTransaction(
quitCtx,
Expand All @@ -45,7 +45,7 @@ func (s *Service) watchForSpendStakingTx(
log.Error().
Err(err).
Str("staking_tx", stakingTxHashHex).
Str("spending_tx", spendDetail.SpendingTx.TxHash().String()).
Stringer("spending_tx", spendDetail.SpendingTx.TxHash()).
Msg("failed to handle spending staking transaction")
return
}
Expand All @@ -71,7 +71,7 @@ func (s *Service) watchForSpendUnbondingTx(
case spendDetail := <-spendEvent.Spend:
log.Debug().
Str("staking_tx", delegation.StakingTxHashHex).
Str("unbonding_tx", spendDetail.SpendingTx.TxHash().String()).
Stringer("unbonding_tx", spendDetail.SpendingTx.TxHash()).
Msg("unbonding tx has been spent")
if err := s.handleSpendingUnbondingTransaction(
quitCtx,
Expand All @@ -83,7 +83,7 @@ func (s *Service) watchForSpendUnbondingTx(
log.Error().
Err(err).
Str("staking_tx", delegation.StakingTxHashHex).
Str("unbonding_tx", spendDetail.SpendingTx.TxHash().String()).
Stringer("unbonding_tx", spendDetail.SpendingTx.TxHash()).
Msg("failed to handle spending unbonding transaction")
return
}
Expand All @@ -108,7 +108,7 @@ func (s *Service) watchForSpendSlashingChange(
case spendDetail := <-spendEvent.Spend:
log.Debug().
Str("staking_tx", delegation.StakingTxHashHex).
Str("spending_tx", spendDetail.SpendingTx.TxHash().String()).
Stringer("spending_tx", spendDetail.SpendingTx.TxHash()).
Msg("slashing change output has been spent")
delegationState, err := s.db.GetBTCDelegationState(quitCtx, delegation.StakingTxHashHex)
if err != nil {
Expand All @@ -123,7 +123,7 @@ func (s *Service) watchForSpendSlashingChange(
if qualifiedStates == nil || !utils.Contains(qualifiedStates, *delegationState) {
log.Error().
Str("staking_tx", delegation.StakingTxHashHex).
Str("state", delegationState.String()).
Stringer("state", delegationState).
Msg("current state is not qualified for slashed withdrawn")
return
}
Expand All @@ -141,8 +141,8 @@ func (s *Service) watchForSpendSlashingChange(
log.Error().
Err(err).
Str("staking_tx", delegation.StakingTxHashHex).
Str("state", types.StateWithdrawn.String()).
Str("sub_state", delegationSubState.String()).
Stringer("state", types.StateWithdrawn).
Stringer("sub_state", delegationSubState).
Msg("failed to update delegation state to withdrawn")
return
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func (s *Service) handleSpendingStakingTransaction(
if isUnbonding {
log.Debug().
Str("staking_tx", delegation.StakingTxHashHex).
Str("unbonding_tx", spendingTx.TxHash().String()).
Stringer("unbonding_tx", spendingTx.TxHash()).
Msg("staking tx has been spent through unbonding path")

// Register unbonding spend notification
Expand All @@ -192,7 +192,7 @@ func (s *Service) handleSpendingStakingTransaction(
// It's a valid withdrawal, process it
log.Debug().
Str("staking_tx", delegation.StakingTxHashHex).
Str("withdrawal_tx", spendingTx.TxHash().String()).
Stringer("withdrawal_tx", spendingTx.TxHash()).
Msg("staking tx has been spent through withdrawal path")
return s.handleWithdrawal(ctx, delegation, types.SubStateTimelock, spendingHeight)
}
Expand Down Expand Up @@ -254,7 +254,7 @@ func (s *Service) handleSpendingUnbondingTransaction(
// It's a valid withdrawal, process it
log.Debug().
Str("staking_tx", delegation.StakingTxHashHex).
Str("unbonding_tx", spendingTx.TxHash().String()).
Stringer("unbonding_tx", spendingTx.TxHash()).
Msg("unbonding tx has been spent through withdrawal path")
return s.handleWithdrawal(ctx, delegation, types.SubStateEarlyUnbonding, spendingHeight)
}
Expand Down Expand Up @@ -312,16 +312,16 @@ func (s *Service) handleWithdrawal(
if qualifiedStates == nil || !utils.Contains(qualifiedStates, *delegationState) {
log.Error().
Str("staking_tx", delegation.StakingTxHashHex).
Str("current_state", delegationState.String()).
Stringer("current_state", delegationState).
Msg("current state is not qualified for withdrawal")
return fmt.Errorf("current state %s is not qualified for withdrawal", *delegationState)
}

// Update to withdrawn state
log.Debug().
Str("staking_tx", delegation.StakingTxHashHex).
Str("state", types.StateWithdrawn.String()).
Str("sub_state", subState.String()).
Stringer("state", types.StateWithdrawn).
Stringer("sub_state", subState).
Msg("updating delegation state to withdrawn")

return s.db.UpdateBTCDelegationState(
Expand All @@ -343,7 +343,7 @@ func (s *Service) startWatchingSlashingChange(
) error {
log.Debug().
Str("staking_tx", delegation.StakingTxHashHex).
Str("slashing_tx", slashingTx.TxHash().String()).
Stringer("slashing_tx", slashingTx.TxHash()).
Msg("watching for slashing change output")

// Create outpoint for the change output (index 1)
Expand Down
2 changes: 1 addition & 1 deletion internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func GetBTCParams(net string) (*chaincfg.Params, error) {
return &chaincfg.SigNetParams, nil
}
return nil, fmt.Errorf("BTC network with name %s does not exist. should be one of {%s, %s, %s, %s, %s}",
net, BtcMainnet.String(), BtcTestnet.String(), BtcSimnet.String(), BtcRegtest.String(), BtcSignet.String())
net, BtcMainnet, BtcTestnet, BtcSimnet, BtcRegtest, BtcSignet)
}

func GetValidNetParams() map[string]bool {
Expand Down

0 comments on commit ab2f9da

Please sign in to comment.