From d0de617a725147b7481b84cab8117b9e6b7ea72c Mon Sep 17 00:00:00 2001 From: Cirrus Gai Date: Wed, 13 Sep 2023 12:31:26 +0800 Subject: [PATCH] chore: Replace retriable error list with unrecoverable one (#92) --- clientcontroller/babylon.go | 5 +++-- clientcontroller/retry_utils.go | 26 +++++++++++++++++--------- service/validator_instance.go | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/clientcontroller/babylon.go b/clientcontroller/babylon.go index bfa994411a7c8..c6b859e8e42b3 100644 --- a/clientcontroller/babylon.go +++ b/clientcontroller/babylon.go @@ -15,7 +15,6 @@ import ( btclctypes "github.com/babylonchain/babylon/x/btclightclient/types" btcstakingtypes "github.com/babylonchain/babylon/x/btcstaking/types" finalitytypes "github.com/babylonchain/babylon/x/finality/types" - "github.com/babylonchain/btc-validator/valcfg" "github.com/btcsuite/btcd/btcutil" ctypes "github.com/cometbft/cometbft/rpc/core/types" sdkclient "github.com/cosmos/cosmos-sdk/client" @@ -34,6 +33,8 @@ import ( "go.uber.org/zap" "go.uber.org/zap/zapcore" "golang.org/x/exp/maps" + + "github.com/babylonchain/btc-validator/valcfg" ) var _ ClientController = &BabylonController{} @@ -207,7 +208,7 @@ func (bc *BabylonController) reliablySendMsgs(msgs []sdk.Msg) (*provider.Relayer return retry.Unrecoverable(krErr) } if sendMsgErr != nil { - if !IsRetriable(sendMsgErr) { + if IsUnrecoverable(sendMsgErr) { bc.logger.WithFields(logrus.Fields{ "error": sendMsgErr, }).Error("unrecoverable err when submitting the tx, skip retrying") diff --git a/clientcontroller/retry_utils.go b/clientcontroller/retry_utils.go index 01518d1918b01..898ec236ed1da 100644 --- a/clientcontroller/retry_utils.go +++ b/clientcontroller/retry_utils.go @@ -6,8 +6,7 @@ import ( errorsmod "cosmossdk.io/errors" "github.com/avast/retry-go/v4" - "github.com/babylonchain/babylon/x/finality/types" - "github.com/cosmos/cosmos-sdk/types/errors" + ftypes "github.com/babylonchain/babylon/x/finality/types" ) // Variables used for retries @@ -18,14 +17,21 @@ var ( rtyErr = retry.LastErrorOnly(true) ) -var retriableErrors = []*errorsmod.Error{ - errors.ErrInsufficientFunds, - errors.ErrMempoolIsFull, +// these errors are considered unrecoverable because these indicate +// something critical in the validator program or the Babylon server +var unrecoverableErrors = []*errorsmod.Error{ + ftypes.ErrBlockNotFound, + ftypes.ErrInvalidFinalitySig, + ftypes.ErrHeightTooHigh, + ftypes.ErrInvalidPubRand, + ftypes.ErrNoPubRandYet, + ftypes.ErrPubRandNotFound, + ftypes.ErrTooFewPubRand, } -// IsRetriable returns true when the error is in the retriableErrors list -func IsRetriable(err error) bool { - for _, e := range retriableErrors { +// IsUnrecoverable returns true when the error is in the unrecoverableErrors list +func IsUnrecoverable(err error) bool { + for _, e := range unrecoverableErrors { if strings.Contains(err.Error(), e.Error()) { return true } @@ -35,7 +41,9 @@ func IsRetriable(err error) bool { } var expectedErrors = []*errorsmod.Error{ - types.ErrDuplicatedFinalitySig, + // if due to some low-level reason (e.g., network), we submit duplicated finality sig, + // we should just ignore the error + ftypes.ErrDuplicatedFinalitySig, } // IsExpected returns true when the error is in the expectedErrors list diff --git a/service/validator_instance.go b/service/validator_instance.go index c781b5135ed95..b8071b1b19cf7 100644 --- a/service/validator_instance.go +++ b/service/validator_instance.go @@ -510,7 +510,7 @@ func (v *ValidatorInstance) retrySubmitFinalitySignatureUntilBlockFinalized(targ // error will be returned if max retries have been reached res, err := v.SubmitFinalitySignature(targetBlock) if err != nil { - if !clientcontroller.IsRetriable(err) { + if clientcontroller.IsUnrecoverable(err) { return nil, err } v.logger.WithFields(logrus.Fields{