Skip to content

Commit

Permalink
fix: Ignore voting power not updated error (#139)
Browse files Browse the repository at this point in the history
Closes #138
  • Loading branch information
gitferry authored Nov 21, 2024
1 parent e052ab3 commit 81531dc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
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

* [139](https://github.com/babylonlabs-io/finality-provider/pull/139) Ignore voting power not updated error

### Improvements

* [#132](https://github.com/babylonlabs-io/finality-provider/pull/132) Replace fast sync with batch processing
Expand Down
7 changes: 7 additions & 0 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ func (bc *BabylonController) QueryFinalityProviderVotingPower(fpPk *btcec.Public
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(), finalitytypes.ErrVotingPowerTableNotUpdated.Error()) {
bc.logger.Info("the voting power table not updated yet")
return 0, nil
}

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

Expand Down
11 changes: 1 addition & 10 deletions finality-provider/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
sdkmath "cosmossdk.io/math"
bbntypes "github.com/babylonlabs-io/babylon/types"
bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
finalitytypes "github.com/babylonlabs-io/babylon/x/finality/types"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
Expand Down Expand Up @@ -249,15 +248,7 @@ func (app *FinalityProviderApp) SyncFinalityProviderStatus() (bool, error) {
for _, fp := range fps {
vp, err := app.cc.QueryFinalityProviderVotingPower(fp.BtcPk, latestBlock.Height)
if err != nil {
// if the 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",
latestBlock.Height, finalitytypes.ErrVotingPowerTableNotUpdated.Wrapf("height: %d", latestBlock.Height).Error())
if !strings.EqualFold(err.Error(), allowedErr) {
// if some other error occurred, then the finality-provider is not registered in the Babylon chain yet
continue
}
continue
}

bip340PubKey := fp.GetBIP340BTCPK()
Expand Down
2 changes: 1 addition & 1 deletion finality-provider/service/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func FuzzSyncFinalityProviderStatus(f *testing.F) {
if noVotingPowerTable {
allowedErr := fmt.Sprintf("failed to query Finality Voting Power at Height %d: rpc error: code = Unknown desc = %s: unknown request",
currentHeight, finalitytypes.ErrVotingPowerTableNotUpdated.Wrapf("height: %d", currentHeight).Error())
mockClientController.EXPECT().QueryFinalityProviderVotingPower(gomock.Any(), gomock.Any()).Return(uint64(0), errors.New(allowedErr)).AnyTimes()
mockClientController.EXPECT().QueryFinalityProviderVotingPower(gomock.Any(), gomock.Any()).Return(uint64(0), nil).AnyTimes()
mockClientController.EXPECT().QueryActivatedHeight().Return(uint64(0), errors.New(allowedErr)).AnyTimes()
} else {
mockClientController.EXPECT().QueryActivatedHeight().Return(currentHeight, nil).AnyTimes()
Expand Down

0 comments on commit 81531dc

Please sign in to comment.