diff --git a/x/observer/keeper/msg_server_update_observer.go b/x/observer/keeper/msg_server_update_observer.go index a1e4c134d1..f7686c4782 100644 --- a/x/observer/keeper/msg_server_update_observer.go +++ b/x/observer/keeper/msg_server_update_observer.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "fmt" errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -25,18 +24,16 @@ func (k msgServer) UpdateObserver( return nil, errorsmod.Wrap(types.ErrUpdateObserver, err.Error()) } if !ok { - return nil, errorsmod.Wrap( + return nil, errorsmod.Wrapf( types.ErrUpdateObserver, - fmt.Sprintf("Unable to update observer with update reason : %s", msg.UpdateReason), - ) + "Unable to update observer with update reason : %s", msg.UpdateReason) } // We do not use IsNonTombstonedObserver here because we want to allow tombstoned observers to be updated if !k.IsAddressPartOfObserverSet(ctx, msg.OldObserverAddress) { - return nil, errorsmod.Wrap( + return nil, errorsmod.Wrapf( types.ErrNotObserver, - fmt.Sprintf("Observer address is not authorized : %s", msg.OldObserverAddress), - ) + "Observer address is not authorized : %s", msg.OldObserverAddress) } err = k.IsValidator(ctx, msg.NewObserverAddress) @@ -53,10 +50,9 @@ func (k msgServer) UpdateObserver( // Update the node account with the new operator address nodeAccount, found := k.GetNodeAccount(ctx, msg.OldObserverAddress) if !found { - return nil, errorsmod.Wrap( + return nil, errorsmod.Wrapf( types.ErrNodeAccountNotFound, - fmt.Sprintf("Observer node account not found : %s", msg.OldObserverAddress), - ) + "Observer node account not found : %s", msg.OldObserverAddress) } newNodeAccount := nodeAccount newNodeAccount.Operator = msg.NewObserverAddress @@ -68,15 +64,15 @@ func (k msgServer) UpdateObserver( // Check LastBlockObserver count just to be safe observerSet, found := k.GetObserverSet(ctx) if !found { - return nil, errorsmod.Wrap(types.ErrObserverSetNotFound, fmt.Sprintf("Observer set not found")) + return nil, errorsmod.Wrap(types.ErrObserverSetNotFound, "Observer set not found") } totalObserverCountCurrentBlock := observerSet.LenUint() lastBlockCount, found := k.GetLastObserverCount(ctx) if !found { - return nil, errorsmod.Wrap(types.ErrLastObserverCountNotFound, fmt.Sprintf("Observer count not found")) + return nil, errorsmod.Wrap(types.ErrLastObserverCountNotFound, "Observer count not found") } if lastBlockCount.Count != totalObserverCountCurrentBlock { - return nil, errorsmod.Wrap(types.ErrUpdateObserver, fmt.Sprintf("Observer count mismatch")) + return nil, errorsmod.Wrap(types.ErrUpdateObserver, "Observer count mismatch") } return &types.MsgUpdateObserverResponse{}, nil } @@ -88,9 +84,7 @@ func (k Keeper) CheckUpdateReason(ctx sdk.Context, msg *types.MsgUpdateObserver) if msg.Creator != msg.OldObserverAddress { return false, errorsmod.Wrap( types.ErrUpdateObserver, - fmt.Sprintf( - "Creator address and old observer address need to be same for updating tombstoned observer", - ), + "Creator address and old observer address need to be same for updating tombstoned observer", ) } return k.IsOperatorTombstoned(ctx, msg.Creator) diff --git a/x/observer/keeper/msg_server_vote_blame.go b/x/observer/keeper/msg_server_vote_blame.go index d2bc179c59..8e8e9dbf74 100644 --- a/x/observer/keeper/msg_server_vote_blame.go +++ b/x/observer/keeper/msg_server_vote_blame.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "fmt" sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -20,10 +19,9 @@ func (k msgServer) VoteBlame( // GetChainFromChainID makes sure we are getting only supported chains , if a chain support has been turned on using gov proposal, this function returns nil observationChain, found := k.GetSupportedChainFromChainID(ctx, msg.ChainId) if !found { - return nil, sdkerrors.Wrap( + return nil, sdkerrors.Wrapf( crosschainTypes.ErrUnsupportedChain, - fmt.Sprintf("ChainID %d, Blame vote", msg.ChainId), - ) + "ChainID %d, Blame vote", msg.ChainId) } if ok := k.IsNonTombstonedObserver(ctx, msg.Creator); !ok { @@ -39,7 +37,7 @@ func (k msgServer) VoteBlame( types.VoteType_SuccessObservation, ) if err != nil { - return nil, sdkerrors.Wrap(err, "failed to vote on ballot") + return nil, sdkerrors.Wrap(err, errVoteOnBallot) } if isNew { diff --git a/x/observer/keeper/msg_server_vote_block_header.go b/x/observer/keeper/msg_server_vote_block_header.go index c355ab4290..1193260baf 100644 --- a/x/observer/keeper/msg_server_vote_block_header.go +++ b/x/observer/keeper/msg_server_vote_block_header.go @@ -43,7 +43,7 @@ func (k msgServer) VoteBlockHeader( types.VoteType_SuccessObservation, ) if err != nil { - return nil, sdkerrors.Wrap(err, "failed to vote on ballot") + return nil, sdkerrors.Wrap(err, errVoteOnBallot) } if !isFinalized { diff --git a/x/observer/keeper/msg_server_vote_tss.go b/x/observer/keeper/msg_server_vote_tss.go index 0bc5fc7ae4..402fbd2a6a 100644 --- a/x/observer/keeper/msg_server_vote_tss.go +++ b/x/observer/keeper/msg_server_vote_tss.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "fmt" errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -29,10 +28,9 @@ func (k msgServer) VoteTSS(goCtx context.Context, msg *types.MsgVoteTSS) (*types // checks whether a signer is authorized to sign , by checking their address against the observer mapper which contains the observer list for the chain and type _, found := k.GetNodeAccount(ctx, msg.Creator) if !found { - return nil, errorsmod.Wrap( + return nil, errorsmod.Wrapf( sdkerrors.ErrorInvalidSigner, - fmt.Sprintf("signer %s does not have a node account set", msg.Creator), - ) + "signer %s does not have a node account set", msg.Creator) } // no need to create a ballot if keygen does not exist keygen, found := k.GetKeygen(ctx) diff --git a/x/observer/keeper/vote_inbound.go b/x/observer/keeper/vote_inbound.go index 5c2b2b1550..20b38b7df7 100644 --- a/x/observer/keeper/vote_inbound.go +++ b/x/observer/keeper/vote_inbound.go @@ -1,8 +1,6 @@ package keeper import ( - "fmt" - sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -31,11 +29,10 @@ func (k Keeper) VoteOnInboundBallot( // this function returns nil senderChain, found := k.GetSupportedChainFromChainID(ctx, senderChainID) if !found { - return false, false, sdkerrors.Wrap(types.ErrSupportedChains, fmt.Sprintf( + return false, false, sdkerrors.Wrapf(types.ErrSupportedChains, "ChainID %d, Observation %s", senderChainID, - types.ObservationType_InboundTx.String()), - ) + types.ObservationType_InboundTx.String()) } // checks the voter is authorized to vote on the observation chain @@ -46,11 +43,10 @@ func (k Keeper) VoteOnInboundBallot( // makes sure we are getting only supported chains receiverChain, found := k.GetSupportedChainFromChainID(ctx, receiverChainID) if !found { - return false, false, sdkerrors.Wrap(types.ErrSupportedChains, fmt.Sprintf( + return false, false, sdkerrors.Wrapf(types.ErrSupportedChains, "ChainID %d, Observation %s", receiverChainID, - types.ObservationType_InboundTx.String()), - ) + types.ObservationType_InboundTx.String()) } // check if we want to send ZETA to external chain, but there is no ZETA token. @@ -73,7 +69,7 @@ func (k Keeper) VoteOnInboundBallot( types.VoteType_SuccessObservation, ) if err != nil { - return false, false, sdkerrors.Wrap(err, "failed to vote on ballot") + return false, false, sdkerrors.Wrap(err, errVoteOnBallot) } if isNew { diff --git a/x/observer/keeper/vote_outbound.go b/x/observer/keeper/vote_outbound.go index 1f1295cbe9..fc9094fc4c 100644 --- a/x/observer/keeper/vote_outbound.go +++ b/x/observer/keeper/vote_outbound.go @@ -46,7 +46,7 @@ func (k Keeper) VoteOnOutboundBallot( observertypes.ConvertReceiveStatusToVoteType(receiveStatus), ) if err != nil { - return false, false, ballot, "", sdkerrors.Wrap(err, "failed to vote on ballot") + return false, false, ballot, "", sdkerrors.Wrap(err, errVoteOnBallot) } return isFinalized, isNew, ballot, observationChain.String(), nil diff --git a/x/observer/keeper/voting.go b/x/observer/keeper/voting.go index dbda230398..756f1fe9ed 100644 --- a/x/observer/keeper/voting.go +++ b/x/observer/keeper/voting.go @@ -9,6 +9,10 @@ import ( "github.com/zeta-chain/zetacore/x/observer/types" ) +const ( + errVoteOnBallot = "error while voting on ballot" +) + func (k Keeper) AddVoteToBallot( ctx sdk.Context, ballot types.Ballot,