Skip to content

Commit

Permalink
chore: Replace retriable error list with unrecoverable one (ethereum-…
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry authored Sep 13, 2023
1 parent 1b626ce commit d0de617
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
5 changes: 3 additions & 2 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{}
Expand Down Expand Up @@ -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")
Expand Down
26 changes: 17 additions & 9 deletions clientcontroller/retry_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion service/validator_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit d0de617

Please sign in to comment.