Skip to content

Commit

Permalink
backport: Fix voting power not updated error handler (#139) (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry authored Nov 21, 2024
1 parent 7d341b5 commit 74cb82e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
8 changes: 8 additions & 0 deletions clientcontroller/babylon/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package babylon
import (
"context"
"fmt"
"strings"

sdkErr "cosmossdk.io/errors"
"cosmossdk.io/math"
Expand Down Expand Up @@ -161,6 +162,13 @@ func (bc *BabylonController) QueryFinalityProviderHasPower(fpPk *btcec.PublicKey
blockHeight,
)
if err != nil {
// voting power table not updated indicates that no fp has voting power
// therefore, it should be treated as the fp having 0 voting power
if strings.Contains(err.Error(), btcstakingtypes.ErrVotingPowerTableNotUpdated.Error()) {
bc.logger.Info("the voting power table not updated yet")
return true, nil
}

return false, fmt.Errorf("failed to query Finality Voting Power at Height %d: %w", blockHeight, err)
}

Expand Down
9 changes: 1 addition & 8 deletions finality-provider/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,7 @@ func (app *FinalityProviderApp) SyncFinalityProviderStatus() (fpInstanceRunning
for _, fp := range fps {
hasPower, err := app.consumerCon.QueryFinalityProviderHasPower(fp.BtcPk, latestBlockHeight)
if err != nil {
// if ther error is that there is nothing in the voting power table
// it should continue and consider the voting power
// as zero to start the finality provider and send public randomness
allowedErr := fmt.Sprintf("failed to query Finality Voting Power at Height %d: rpc error: code = Unknown desc = %s: unknown request", latestBlockHeight, bstypes.ErrVotingPowerTableNotUpdated.Wrapf("height: %d", latestBlockHeight).Error())
if !strings.EqualFold(err.Error(), allowedErr) {
// if some other error occured then the finality-provider is not registered in the Babylon chain yet
continue
}
continue
}

bip340PubKey := fp.GetBIP340BTCPK()
Expand Down
5 changes: 3 additions & 2 deletions finality-provider/service/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ func FuzzSyncFinalityProviderStatus(f *testing.F) {

noVotingPowerTable := r.Int31n(10) > 5
if noVotingPowerTable {
allowedErr := fmt.Sprintf("failed to query Finality Voting Power at Height %d: rpc error: code = Unknown desc = %s: unknown request", currentHeight, bstypes.ErrVotingPowerTableNotUpdated.Wrapf("height: %d", currentHeight).Error())
mockConsumerController.EXPECT().QueryFinalityProviderHasPower(gomock.Any(), gomock.Any()).Return(false, errors.New(allowedErr)).AnyTimes()
allowedErr := fmt.Sprintf("failed to query Finality Voting Power at Height %d: rpc error: code = Unknown desc = %s: unknown request",
currentHeight, bstypes.ErrVotingPowerTableNotUpdated.Wrapf("height: %d", currentHeight).Error())
mockConsumerController.EXPECT().QueryFinalityProviderHasPower(gomock.Any(), gomock.Any()).Return(false, nil).AnyTimes()
mockConsumerController.EXPECT().QueryActivatedHeight().Return(uint64(0), errors.New(allowedErr)).AnyTimes()
} else {
mockConsumerController.EXPECT().QueryFinalityProviderHasPower(gomock.Any(), gomock.Any()).Return(true, nil).AnyTimes()
Expand Down

0 comments on commit 74cb82e

Please sign in to comment.