Skip to content

Commit

Permalink
fix: removing from metrics tracker (#184)
Browse files Browse the repository at this point in the history
We were returning nil, making the statement never true
  • Loading branch information
Lazar955 committed Jan 17, 2025
1 parent 616eb50 commit 5c2970f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Bug Fixes

* [#184](https://github.com/babylonlabs-io/vigilante/pull/184) fix: removing from metrics tracker

## v0.19.5

### Improvements
Expand Down
10 changes: 5 additions & 5 deletions btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ func (sew *StakingEventWatcher) fetchDelegations() {
delegationStartHeight: delegation.DelegationStartHeight,
unbondingOutput: delegation.UnbondingOutput,
}

if sew.pendingTracker.GetDelegation(delegation.StakingTx.TxHash()) == nil && !delegation.HasProof {
_, exists := sew.pendingTracker.GetDelegation(delegation.StakingTx.TxHash())
if !exists && !delegation.HasProof {
_, _ = sew.pendingTracker.AddDelegation(
del.stakingTx,
del.stakingOutputIdx,
Expand Down Expand Up @@ -617,7 +617,7 @@ func (sew *StakingEventWatcher) checkBtcForStakingTx() {
}

for del := range sew.pendingTracker.DelegationsIter(1000) {
if inProgDel := sew.inProgressTracker.GetDelegation(del.StakingTx.TxHash()); inProgDel != nil {
if inProgDel, _ := sew.inProgressTracker.GetDelegation(del.StakingTx.TxHash()); inProgDel != nil {
sew.logger.Debugf("skipping tx %s, already in progress", inProgDel.StakingTx.TxHash().String())

continue
Expand All @@ -639,7 +639,7 @@ func (sew *StakingEventWatcher) checkBtcForStakingTx() {
continue
}

if d := sew.verifiedNotInChainTracker.GetDelegation(txHash); d != nil {
if _, exists := sew.verifiedNotInChainTracker.GetDelegation(txHash); exists {
sew.verifiedNotInChainTracker.RemoveDelegation(txHash)
sew.metrics.NumberOfVerifiedNotInChainDelegations.Dec()
}
Expand Down Expand Up @@ -705,7 +705,7 @@ func (sew *StakingEventWatcher) activateBtcDelegation(
return
}

if d := sew.verifiedInsufficientConfTacker.GetDelegation(stakingTxHash); d != nil {
if _, exists := sew.verifiedInsufficientConfTacker.GetDelegation(stakingTxHash); exists {
sew.verifiedNotInChainTracker.RemoveDelegation(stakingTxHash)
sew.metrics.NumberOfVerifiedInsufficientConfDelegations.Dec()
}
Expand Down
6 changes: 3 additions & 3 deletions btcstaking-tracker/stakingeventwatcher/tracked_delegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ func NewTrackedDelegations() *TrackedDelegations {
}

// GetDelegation returns the tracked delegation for the given staking tx hash or nil if not found.
func (td *TrackedDelegations) GetDelegation(stakingTxHash chainhash.Hash) *TrackedDelegation {
func (td *TrackedDelegations) GetDelegation(stakingTxHash chainhash.Hash) (*TrackedDelegation, bool) {
td.mu.RLock()
defer td.mu.RUnlock()

del, ok := td.mapping[stakingTxHash]
if !ok {
return nil
return nil, false
}

return del
return del, true
}

// GetDelegations returns all tracked delegations as a slice.
Expand Down
4 changes: 4 additions & 0 deletions e2etest/unbondingwatcher_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ func TestActivatingDelegation(t *testing.T) {
return promtestutil.ToFloat64(stakingTrackerMetrics.FailedReportedActivateDelegations) == 0
}, eventuallyWaitTimeOut, eventuallyPollTime)

require.Eventually(t, func() bool {
return promtestutil.ToFloat64(stakingTrackerMetrics.NumberOfVerifiedNotInChainDelegations) == 0
}, eventuallyWaitTimeOut, eventuallyPollTime)

// created delegation lacks inclusion proof, once created it will be in
// pending status, once convenant signatures are added it will be in verified status,
// and once the stakingEventWatcher submits MsgAddBTCDelegationInclusionProof it will
Expand Down

0 comments on commit 5c2970f

Please sign in to comment.