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

chore: do not wait forever for required depth #145

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* [#136](https://github.com/babylonlabs-io/vigilante/pull/136) rate limit activations
* [#141](https://github.com/babylonlabs-io/vigilante/pull/141) decrement tracked delegations in atomic slasher
* [#143](https://github.com/babylonlabs-io/vigilante/pull/143) adds nlreturn linter rule
* [#145](https://github.com/babylonlabs-io/vigilante/pull/145) do not wait forever

## v0.18.0

Expand Down
28 changes: 22 additions & 6 deletions btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,11 @@ func (sew *StakingEventWatcher) checkBtcForStakingTx() {

go func() {
defer sew.activationLimiter.Release(1)
sew.activateBtcDelegation(txHash, proof, details.Block.BlockHash(), params.ConfirmationTimeBlocks)
done := make(chan struct{})

go sew.activateBtcDelegation(txHash, proof, details.Block.BlockHash(), params.ConfirmationTimeBlocks, done)

<-done
}()
}
}
Expand All @@ -667,7 +671,10 @@ func (sew *StakingEventWatcher) activateBtcDelegation(
proof *btcctypes.BTCSpvProof,
inclusionBlockHash chainhash.Hash,
requiredDepth uint32,
done chan struct{},
) {
var once sync.Once
defer once.Do(func() { close(done) })
sew.metrics.NumberOfActivationInProgress.Inc()
defer sew.metrics.NumberOfActivationInProgress.Dec()

Expand All @@ -677,7 +684,11 @@ func (sew *StakingEventWatcher) activateBtcDelegation(
defer sew.latency("activateBtcDelegation")()
defer sew.inProgressTracker.RemoveDelegation(stakingTxHash)

sew.waitForRequiredDepth(ctx, stakingTxHash, &inclusionBlockHash, requiredDepth)
if err := sew.waitForRequiredDepth(ctx, stakingTxHash, &inclusionBlockHash, requiredDepth); err != nil {
sew.logger.Warnf("exceeded waiting for required depth, will try later: err %v", err)

return
}

defer sew.latency("activateDelegationRPC")()

Expand All @@ -701,9 +712,13 @@ func (sew *StakingEventWatcher) activateBtcDelegation(

sew.metrics.ReportedActivateDelegationsCounter.Inc()

sew.pendingTracker.RemoveDelegation(stakingTxHash)
once.Do(func() {
close(done)
})

sew.pendingTracker.RemoveDelegation(stakingTxHash)
sew.metrics.NumberOfVerifiedDelegations.Dec()

sew.logger.Debugf("staking tx activated %s", stakingTxHash.String())

return nil
Expand All @@ -724,11 +739,12 @@ func (sew *StakingEventWatcher) waitForRequiredDepth(
stakingTxHash chainhash.Hash,
inclusionBlockHash *chainhash.Hash,
requiredDepth uint32,
) {
) error {
defer sew.latency("waitForRequiredDepth")()

var depth uint32
_ = retry.Do(func() error {

return retry.Do(func() error {
var err error
depth, err = sew.babylonNodeAdapter.QueryHeaderDepth(inclusionBlockHash)
if err != nil {
Expand All @@ -749,7 +765,7 @@ func (sew *StakingEventWatcher) waitForRequiredDepth(
return nil
},
retry.Context(ctx),
retryForever,
retry.Attempts(10),
fixedDelyTypeWithJitter,
retry.MaxDelay(sew.cfg.RetrySubmitUnbondingTxInterval),
retry.MaxJitter(sew.cfg.RetryJitter),
Expand Down
Loading