diff --git a/CHANGELOG.md b/CHANGELOG.md index aa4032e..80a5d10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## Unreleased +### Bug Fixes + +* [#84](https://github.com/babylonlabs-io/vigilante/pull/84) fix spawning more go routines than needed when activating +delegations, add more logging + + ## v0.13.0 ### Improvements diff --git a/btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go b/btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go index 331ff72..85b709d 100644 --- a/btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go +++ b/btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go @@ -177,7 +177,7 @@ func (sew *StakingEventWatcher) checkBabylonDelegations(status btcstakingtypes.B return fmt.Errorf("error fetching active delegations from babylon: %v", err) } - sew.logger.Debugf("fetched %d delegations from babylon", len(delegations)) + sew.logger.Debugf("fetched %d delegations from babylon by status %s", len(delegations), status) for _, delegation := range delegations { addDel(delegation) @@ -484,7 +484,7 @@ func (sew *StakingEventWatcher) handleUnbondedDelegations() { spendEv, err := sew.btcNotifier.RegisterSpendNtfn( &stakingOutpoint, activeDel.stakingTx.TxOut[activeDel.stakingOutputIdx].PkScript, - uint32(activeDel.delegationStartHeight), + activeDel.delegationStartHeight, ) if err != nil { @@ -539,6 +539,10 @@ func (sew *StakingEventWatcher) checkBtcForStakingTx() error { } for _, del := range delegations { + if del.ActivationInProgress { + continue + } + txHash := del.StakingTx.TxHash() details, status, err := sew.btcClient.TxDetails(&txHash, del.StakingTx.TxOut[del.StakingOutputIdx].PkScript) if err != nil { @@ -571,6 +575,10 @@ func (sew *StakingEventWatcher) activateBtcDelegation( ctx, cancel := sew.quitContext() defer cancel() + if err := sew.pendingTracker.UpdateActivation(stakingTxHash, true); err != nil { + sew.logger.Debugf("skipping tx %s is not in pending tracker, err: %v", stakingTxHash, err) + } + _ = retry.Do(func() error { verified, err := sew.babylonNodeAdapter.IsDelegationVerified(stakingTxHash) if err != nil { @@ -590,6 +598,7 @@ func (sew *StakingEventWatcher) activateBtcDelegation( sew.metrics.ReportedActivateDelegationsCounter.Inc() sew.pendingTracker.RemoveDelegation(stakingTxHash) + sew.logger.Debugf("staking tx activated %s", stakingTxHash.String()) return nil }, diff --git a/btcstaking-tracker/stakingeventwatcher/tracked_delegations.go b/btcstaking-tracker/stakingeventwatcher/tracked_delegations.go index d5ec235..7bbcecf 100644 --- a/btcstaking-tracker/stakingeventwatcher/tracked_delegations.go +++ b/btcstaking-tracker/stakingeventwatcher/tracked_delegations.go @@ -13,6 +13,7 @@ type TrackedDelegation struct { StakingOutputIdx uint32 UnbondingOutput *wire.TxOut DelegationStartHeight uint32 + ActivationInProgress bool } type TrackedDelegations struct { @@ -118,3 +119,18 @@ func (td *TrackedDelegations) HasDelegationChanged( // The delegation exists but hasn't changed return false, true } + +func (td *TrackedDelegations) UpdateActivation(tx chainhash.Hash, inProgress bool) error { + td.mu.Lock() + defer td.mu.Unlock() + + delegation, ok := td.mapping[tx] + + if !ok { + return fmt.Errorf("delegation with tx hash %s not found", tx.String()) + } + + delegation.ActivationInProgress = inProgress + + return nil +}