From 81531dc19f3840e409e1554a39d6eac5f002902f Mon Sep 17 00:00:00 2001 From: Cirrus Gai Date: Thu, 21 Nov 2024 09:52:52 +0800 Subject: [PATCH] fix: Ignore voting power not updated error (#139) Closes #138 --- CHANGELOG.md | 4 ++++ clientcontroller/babylon.go | 7 +++++++ finality-provider/service/app.go | 11 +---------- finality-provider/service/app_test.go | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdcec56d..7554c0c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/clientcontroller/babylon.go b/clientcontroller/babylon.go index 12608b9b..2151845e 100644 --- a/clientcontroller/babylon.go +++ b/clientcontroller/babylon.go @@ -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) } diff --git a/finality-provider/service/app.go b/finality-provider/service/app.go index 99c9d43f..00a1a464 100644 --- a/finality-provider/service/app.go +++ b/finality-provider/service/app.go @@ -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" @@ -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() diff --git a/finality-provider/service/app_test.go b/finality-provider/service/app_test.go index 7d89dc34..2cafd504 100644 --- a/finality-provider/service/app_test.go +++ b/finality-provider/service/app_test.go @@ -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()