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

fix: removing from metrics tracker #184

Merged
merged 4 commits into from
Jan 17, 2025
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
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
Loading