Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Oct 3, 2024
1 parent 56c134a commit 50f222b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Delegation struct {

type BabylonNodeAdapter interface {
BtcDelegations(offset uint64, limit uint64) ([]Delegation, error)
DelegationsByStatus(status btcstakingtypes.BTCDelegationStatus, offset uint64, limit uint64) ([]Delegation, error)
IsDelegationActive(stakingTxHash chainhash.Hash) (bool, error)
IsDelegationVerified(stakingTxHash chainhash.Hash) (bool, error)
ReportUnbonding(ctx context.Context, stakingTxHash chainhash.Hash, stakerUnbondingSig *schnorr.Signature) error
Expand Down Expand Up @@ -175,7 +176,7 @@ func (bca *BabylonClientAdapter) ActivateDelegation(
resp, err := bca.babylonClient.ReliablySendMsg(ctx, &msg, []*errors.Error{}, []*errors.Error{})

if err != nil && resp != nil {
return fmt.Errorf("msg MsgBTCUndelegate failed exeuction with code %d and error %w", resp.Code, err)
return fmt.Errorf("msg MsgAddBTCDelegationInclusionProof failed exeuction with code %d and error %w", resp.Code, err)
}

if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions btcstaking-tracker/stakingeventwatcher/mock_babylon_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (sew *StakingEventWatcher) Start() error {

sew.wg.Add(4)
go sew.handleNewBlocks(blockEventNotifier)
go sew.handleDelegations()
go sew.handleUnbondedDelegations()
go sew.fetchDelegations()
go sew.handlerVerifiedDelegations()

Expand Down Expand Up @@ -189,7 +189,8 @@ func (sew *StakingEventWatcher) checkBabylonDelegations() error {
}

// if we already have this delegation, skip it
if sew.unbondingTracker.GetDelegation(stakingTxHash) == nil && delegation.HasProof {
// we should track both verified and active status for unbonding
if sew.unbondingTracker.GetDelegation(stakingTxHash) == nil {
utils.PushOrQuit(sew.unbondingDelegationChan, del, sew.quit)
}

Expand Down Expand Up @@ -334,15 +335,18 @@ func (sew *StakingEventWatcher) reportUnbondingToBabylon(
return fmt.Errorf("error checking if delegation is active: %v", err)
}

if !active {
//
verified, err := sew.babylonNodeAdapter.IsDelegationVerified(stakingTxHash)

if err != nil {
return fmt.Errorf("error checking if delegation is verified: %v", err)
}

if !active && !verified {
sew.logger.Debugf("cannot report unbonding. delegation for staking tx %s is no longer active", stakingTxHash)
return nil
}

err = sew.babylonNodeAdapter.ReportUnbonding(ctx, stakingTxHash, unbondingSignature)

if err != nil {
if err = sew.babylonNodeAdapter.ReportUnbonding(ctx, stakingTxHash, unbondingSignature); err != nil {
sew.metrics.FailedReportedUnbondingTransactions.Inc()
return fmt.Errorf("error reporting unbonding tx %s to babylon: %v", stakingTxHash, err)
}
Expand Down Expand Up @@ -402,7 +406,7 @@ func (sew *StakingEventWatcher) watchForSpend(spendEvent *notifier.SpendEvent, t
)
}

func (sew *StakingEventWatcher) handleDelegations() {
func (sew *StakingEventWatcher) handleUnbondedDelegations() {
defer sew.wg.Done()
for {
select {
Expand Down

0 comments on commit 50f222b

Please sign in to comment.