From 040346295092104f2a6dec0e9a2d5585705d482d Mon Sep 17 00:00:00 2001 From: Tanmay Date: Tue, 20 Aug 2024 13:11:28 -0400 Subject: [PATCH] refactor: fix lint errors from govet (#2749) * fix lint * fix lint * add changelog --- app/ante/authz.go | 2 +- changelog.md | 1 + cmd/zetaclientd/start.go | 2 +- cmd/zetaclientd/version.go | 2 +- .../test_message_passing_evm_to_zevm.go | 3 +-- e2e/e2etests/test_migrate_tss.go | 13 ++++++------- e2e/runner/accounting.go | 2 +- e2e/runner/logger.go | 14 +++++++------- e2e/runner/report.go | 2 +- pkg/chains/conversion.go | 3 ++- .../keeper/msg_server_add_inbound_tracker.go | 6 +++--- .../keeper/msg_server_add_outbound_tracker.go | 6 +++--- .../types/message_update_rate_limiter_flags.go | 2 +- x/emissions/keeper/msg_server_update_params.go | 2 +- x/fungible/keeper/evm.go | 18 +++++++++--------- x/fungible/keeper/gas_price.go | 6 +++--- .../types/message_update_chain_params.go | 2 +- x/observer/types/message_vote_block_header.go | 2 +- 18 files changed, 44 insertions(+), 44 deletions(-) diff --git a/app/ante/authz.go b/app/ante/authz.go index 5c8a58c534..d310943771 100644 --- a/app/ante/authz.go +++ b/app/ante/authz.go @@ -34,7 +34,7 @@ func (ald AuthzLimiterDecorator) AnteHandle( next sdk.AnteHandler, ) (newCtx sdk.Context, err error) { if err := ald.checkDisabledMsgs(tx.GetMsgs(), false, 1); err != nil { - return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, err.Error()) + return ctx, errorsmod.Wrap(errortypes.ErrUnauthorized, err.Error()) } return next(ctx, tx, simulate) } diff --git a/changelog.md b/changelog.md index d00252a146..d6791e1659 100644 --- a/changelog.md +++ b/changelog.md @@ -18,6 +18,7 @@ ### Refactor * [2615](https://github.com/zeta-chain/node/pull/2615) - Refactor cleanup of outbound trackers +* [2749](https://github.com/zeta-chain/node/pull/2749) - fix all lint errors from govet ### Tests diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index cf6a8e4d9e..0c0bbd6585 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -169,7 +169,7 @@ func start(_ *cobra.Command, _ []string) error { startLogger.Debug().Msgf("hotkeyPk %s", hotkeyPk.String()) if len(hotkeyPk.Bytes()) != 32 { errMsg := fmt.Sprintf("key bytes len %d != 32", len(hotkeyPk.Bytes())) - log.Error().Msgf(errMsg) + log.Error().Msg(errMsg) return errors.New(errMsg) } priKey := secp256k1.PrivKey(hotkeyPk.Bytes()[:32]) diff --git a/cmd/zetaclientd/version.go b/cmd/zetaclientd/version.go index 817d2752f7..15886d4b80 100644 --- a/cmd/zetaclientd/version.go +++ b/cmd/zetaclientd/version.go @@ -15,6 +15,6 @@ var VersionCmd = &cobra.Command{ } func Version(_ *cobra.Command, _ []string) error { - fmt.Printf(constant.Version) + fmt.Print(constant.Version) return nil } diff --git a/e2e/e2etests/test_message_passing_evm_to_zevm.go b/e2e/e2etests/test_message_passing_evm_to_zevm.go index 6dfb1b53c2..09dac29a73 100644 --- a/e2e/e2etests/test_message_passing_evm_to_zevm.go +++ b/e2e/e2etests/test_message_passing_evm_to_zevm.go @@ -1,7 +1,6 @@ package e2etests import ( - "fmt" "math/big" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -56,7 +55,7 @@ func TestMessagePassingEVMtoZEVM(r *runner.E2ERunner, args []string) { cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, receipt.TxHash.String(), r.CctxClient, r.Logger, r.CctxTimeout) utils.RequireCCTXStatus(r, cctx, cctxtypes.CctxStatus_OutboundMined) - r.Logger.Info(fmt.Sprintf("🔄 Cctx mined for contract call chain zevm %s", cctx.Index)) + r.Logger.Info("🔄 Cctx mined for contract call chain zevm %s", cctx.Index) // On finalization the Fungible module calls the onReceive function which in turn calls the onZetaMessage function on the destination contract receipt, err = r.ZEVMClient.TransactionReceipt(r.Ctx, ethcommon.HexToHash(cctx.GetCurrentOutboundParam().Hash)) diff --git a/e2e/e2etests/test_migrate_tss.go b/e2e/e2etests/test_migrate_tss.go index c72b876f0f..c1bb79c062 100644 --- a/e2e/e2etests/test_migrate_tss.go +++ b/e2e/e2etests/test_migrate_tss.go @@ -2,7 +2,6 @@ package e2etests import ( "context" - "fmt" "sort" "strconv" "time" @@ -146,9 +145,9 @@ func TestMigrateTSS(r *runner.E2ERunner, _ []string) { btcTSSBalanceNew += utxo.Amount } - r.Logger.Info(fmt.Sprintf("BTC Balance Old: %f", btcTSSBalanceOld*1e8)) - r.Logger.Info(fmt.Sprintf("BTC Balance New: %f", btcTSSBalanceNew*1e8)) - r.Logger.Info(fmt.Sprintf("Migrator amount : %s", cctxBTC.GetCurrentOutboundParam().Amount)) + r.Logger.Info("BTC Balance Old: %f", btcTSSBalanceOld*1e8) + r.Logger.Info("BTC Balance New: %f", btcTSSBalanceNew*1e8) + r.Logger.Info("Migrator amount : %s", cctxBTC.GetCurrentOutboundParam().Amount) // btcTSSBalanceNew should be less than btcTSSBalanceOld as there is some loss of funds during migration // #nosec G701 e2eTest - always in range @@ -165,9 +164,9 @@ func TestMigrateTSS(r *runner.E2ERunner, _ []string) { ethTSSBalanceNew, err := r.EVMClient.BalanceAt(context.Background(), r.TSSAddress, nil) require.NoError(r, err) - r.Logger.Info(fmt.Sprintf("TSS Balance Old: %s", ethTSSBalanceOld.String())) - r.Logger.Info(fmt.Sprintf("TSS Balance New: %s", ethTSSBalanceNew.String())) - r.Logger.Info(fmt.Sprintf("Migrator amount : %s", cctxETH.GetCurrentOutboundParam().Amount.String())) + r.Logger.Info("TSS Balance Old: %s", ethTSSBalanceOld.String()) + r.Logger.Info("TSS Balance New: %s", ethTSSBalanceNew.String()) + r.Logger.Info("Migrator amount : %s", cctxETH.GetCurrentOutboundParam().Amount.String()) // ethTSSBalanceNew should be less than ethTSSBalanceOld as there is some loss of funds during migration require.Equal(r, ethTSSBalanceNew.String(), cctxETH.GetCurrentOutboundParam().Amount.String()) diff --git a/e2e/runner/accounting.go b/e2e/runner/accounting.go index 7f357a69ab..7c9a0c5746 100644 --- a/e2e/runner/accounting.go +++ b/e2e/runner/accounting.go @@ -208,7 +208,7 @@ func (r *E2ERunner) checkZetaTSSBalance() error { } zetaSupply, _ := big.NewInt(0).SetString(result.Amount.Amount, 10) if zetaLocked.Cmp(zetaSupply) < 0 { - r.Logger.Info(fmt.Sprintf("ZETA: TSS balance (%d) < ZRC20 TotalSupply (%d)", zetaLocked, zetaSupply)) + r.Logger.Info("ZETA: TSS balance (%d) < ZRC20 TotalSupply (%d)", zetaLocked, zetaSupply) } else { r.Logger.Info("ZETA: TSS balance (%d) >= ZRC20 TotalSupply (%d)", zetaLocked, zetaSupply) } diff --git a/e2e/runner/logger.go b/e2e/runner/logger.go index 683154f056..0b970ab6f3 100644 --- a/e2e/runner/logger.go +++ b/e2e/runner/logger.go @@ -57,7 +57,7 @@ func (l *Logger) Print(message string, args ...interface{}) { text := fmt.Sprintf(message, args...) // #nosec G104 - we are not using user input - l.logger.Printf(l.getPrefixWithPadding() + loggerSeparator + text + "\n") + l.logger.Print(l.getPrefixWithPadding() + loggerSeparator + text + "\n") } // PrintNoPrefix prints a message to the logger without the prefix @@ -67,7 +67,7 @@ func (l *Logger) PrintNoPrefix(message string, args ...interface{}) { text := fmt.Sprintf(message, args...) // #nosec G104 - we are not using user input - l.logger.Printf(text + "\n") + _, _ = l.logger.Print(text + "\n") } // Info prints a message to the logger if verbose is true @@ -78,7 +78,7 @@ func (l *Logger) Info(message string, args ...interface{}) { if l.verbose { text := fmt.Sprintf(message, args...) // #nosec G104 - we are not using user input - l.logger.Printf(l.getPrefixWithPadding() + loggerSeparator + "[INFO]" + text + "\n") + _, _ = l.logger.Print(l.getPrefixWithPadding() + loggerSeparator + "[INFO]" + text + "\n") } } @@ -90,11 +90,11 @@ func (l *Logger) InfoLoud(message string, args ...interface{}) { if l.verbose { text := fmt.Sprintf(message, args...) // #nosec G104 - we are not using user input - l.logger.Printf(l.getPrefixWithPadding() + loggerSeparator + "[INFO] =======================================") + l.logger.Print(l.getPrefixWithPadding() + loggerSeparator + "[INFO] =======================================") // #nosec G104 - we are not using user input - l.logger.Printf(l.getPrefixWithPadding() + loggerSeparator + "[INFO]" + text + "\n") + l.logger.Print(l.getPrefixWithPadding() + loggerSeparator + "[INFO]" + text + "\n") // #nosec G104 - we are not using user input - l.logger.Printf(l.getPrefixWithPadding() + loggerSeparator + "[INFO] =======================================") + l.logger.Print(l.getPrefixWithPadding() + loggerSeparator + "[INFO] =======================================") } } @@ -105,7 +105,7 @@ func (l *Logger) Error(message string, args ...interface{}) { text := fmt.Sprintf(message, args...) // #nosec G104 - we are not using user input - l.logger.Printf(l.getPrefixWithPadding() + loggerSeparator + "[ERROR]" + text + "\n") + l.logger.Print(l.getPrefixWithPadding() + loggerSeparator + "[ERROR]" + text + "\n") } // CCTX prints a CCTX diff --git a/e2e/runner/report.go b/e2e/runner/report.go index d80024e0dd..31cd085fc6 100644 --- a/e2e/runner/report.go +++ b/e2e/runner/report.go @@ -59,7 +59,7 @@ func (r *E2ERunner) PrintTestReports(tr TestReports) { if err != nil { r.Logger.Print("Error rendering test report: %s", err) } - r.Logger.PrintNoPrefix(table) + r.Logger.PrintNoPrefix(table, "") } // NetworkReport is a struct that contains the report for the network used after running e2e tests diff --git a/pkg/chains/conversion.go b/pkg/chains/conversion.go index 949d39ebb7..3200b76693 100644 --- a/pkg/chains/conversion.go +++ b/pkg/chains/conversion.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "fmt" + "cosmossdk.io/errors" "github.com/btcsuite/btcd/chaincfg/chainhash" ethcommon "github.com/ethereum/go-ethereum/common" ) @@ -39,7 +40,7 @@ func ParseAddressAndData(message string) (ethcommon.Address, []byte, error) { data, err := hex.DecodeString(message) if err != nil { - return ethcommon.Address{}, nil, fmt.Errorf("message should be a hex encoded string: " + err.Error()) + return ethcommon.Address{}, nil, errors.Wrap(err, "message should be a hex encoded string") } if len(data) < 20 { diff --git a/x/crosschain/keeper/msg_server_add_inbound_tracker.go b/x/crosschain/keeper/msg_server_add_inbound_tracker.go index ae35036e88..13ad2bad1b 100644 --- a/x/crosschain/keeper/msg_server_add_inbound_tracker.go +++ b/x/crosschain/keeper/msg_server_add_inbound_tracker.go @@ -60,7 +60,7 @@ func (k msgServer) AddInboundTracker( func verifyProofAndInboundBody(ctx sdk.Context, k msgServer, msg *types.MsgAddInboundTracker) error { txBytes, err := k.GetLightclientKeeper().VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) if err != nil { - return types.ErrProofVerificationFail.Wrapf(err.Error()) + return types.ErrProofVerificationFail.Wrap(err.Error()) } // get chain params and tss addresses to verify the inTx body @@ -72,14 +72,14 @@ func verifyProofAndInboundBody(ctx sdk.Context, k msgServer, msg *types.MsgAddIn BitcoinChainId: msg.ChainId, }) if err != nil { - return observertypes.ErrTssNotFound.Wrapf(err.Error()) + return observertypes.ErrTssNotFound.Wrap(err.Error()) } if tss == nil { return observertypes.ErrTssNotFound.Wrapf("tss address nil") } if err := types.VerifyInboundBody(*msg, txBytes, *chainParams, *tss); err != nil { - return types.ErrTxBodyVerificationFail.Wrapf(err.Error()) + return types.ErrTxBodyVerificationFail.Wrap(err.Error()) } return nil diff --git a/x/crosschain/keeper/msg_server_add_outbound_tracker.go b/x/crosschain/keeper/msg_server_add_outbound_tracker.go index b82fba7f79..9fdf5ac48d 100644 --- a/x/crosschain/keeper/msg_server_add_outbound_tracker.go +++ b/x/crosschain/keeper/msg_server_add_outbound_tracker.go @@ -132,7 +132,7 @@ func (k msgServer) AddOutboundTracker( func verifyProofAndOutboundBody(ctx sdk.Context, k msgServer, msg *types.MsgAddOutboundTracker) error { txBytes, err := k.lightclientKeeper.VerifyProof(ctx, msg.Proof, msg.ChainId, msg.BlockHash, msg.TxIndex) if err != nil { - return types.ErrProofVerificationFail.Wrapf(err.Error()) + return types.ErrProofVerificationFail.Wrap(err.Error()) } // get tss address @@ -145,14 +145,14 @@ func verifyProofAndOutboundBody(ctx sdk.Context, k msgServer, msg *types.MsgAddO BitcoinChainId: bitcoinChainID, }) if err != nil { - return observertypes.ErrTssNotFound.Wrapf(err.Error()) + return observertypes.ErrTssNotFound.Wrap(err.Error()) } if tss == nil { return observertypes.ErrTssNotFound.Wrapf("tss address nil") } if err := types.VerifyOutboundBody(*msg, txBytes, *tss); err != nil { - return types.ErrTxBodyVerificationFail.Wrapf(err.Error()) + return types.ErrTxBodyVerificationFail.Wrap(err.Error()) } return nil diff --git a/x/crosschain/types/message_update_rate_limiter_flags.go b/x/crosschain/types/message_update_rate_limiter_flags.go index 85d3ccf7c4..f082ad4f58 100644 --- a/x/crosschain/types/message_update_rate_limiter_flags.go +++ b/x/crosschain/types/message_update_rate_limiter_flags.go @@ -43,7 +43,7 @@ func (msg *MsgUpdateRateLimiterFlags) ValidateBasic() error { return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } if err := msg.RateLimiterFlags.Validate(); err != nil { - return errorsmod.Wrapf(ErrInvalidRateLimiterFlags, err.Error()) + return errorsmod.Wrap(ErrInvalidRateLimiterFlags, err.Error()) } return nil } diff --git a/x/emissions/keeper/msg_server_update_params.go b/x/emissions/keeper/msg_server_update_params.go index 8652e4bb20..a91e1683be 100644 --- a/x/emissions/keeper/msg_server_update_params.go +++ b/x/emissions/keeper/msg_server_update_params.go @@ -28,7 +28,7 @@ func (k msgServer) UpdateParams( ctx := sdk.UnwrapSDKContext(goCtx) err := k.SetParams(ctx, msg.Params) if err != nil { - return nil, errors.Wrapf(types.ErrUnableToSetParams, err.Error()) + return nil, errors.Wrap(types.ErrUnableToSetParams, err.Error()) } return &types.MsgUpdateParamsResponse{}, nil diff --git a/x/fungible/keeper/evm.go b/x/fungible/keeper/evm.go index 7e426d4646..5f4c61bebf 100644 --- a/x/fungible/keeper/evm.go +++ b/x/fungible/keeper/evm.go @@ -573,7 +573,7 @@ func (k Keeper) BalanceOfZRC4( ) (*big.Int, error) { zrc4ABI, err := zrc20.ZRC20MetaData.GetAbi() if err != nil { - return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, err.Error()) + return nil, cosmoserrors.Wrap(types.ErrABIUnpack, err.Error()) } res, err := k.CallEVM(ctx, *zrc4ABI, types.ModuleAddressEVM, contract, BigIntZero, nil, false, false, "balanceOf", account) @@ -583,7 +583,7 @@ func (k Keeper) BalanceOfZRC4( unpacked, err := zrc4ABI.Unpack("balanceOf", res.Ret) if err != nil || len(unpacked) == 0 { - return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, err.Error()) + return nil, cosmoserrors.Wrap(types.ErrABIUnpack, err.Error()) } balance, ok := unpacked[0].(*big.Int) @@ -601,7 +601,7 @@ func (k Keeper) TotalSupplyZRC4( ) (*big.Int, error) { abi, err := zrc20.ZRC20MetaData.GetAbi() if err != nil { - return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, err.Error()) + return nil, cosmoserrors.Wrap(types.ErrABIUnpack, err.Error()) } res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, contract, BigIntZero, nil, false, false, "totalSupply") if err != nil { @@ -610,12 +610,12 @@ func (k Keeper) TotalSupplyZRC4( unpacked, err := abi.Unpack("totalSupply", res.Ret) if err != nil || len(unpacked) == 0 { - return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, err.Error()) + return nil, cosmoserrors.Wrap(types.ErrABIUnpack, err.Error()) } totalSupply, ok := unpacked[0].(*big.Int) if !ok { - return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, "failed to unpack total supply") + return nil, cosmoserrors.Wrap(types.ErrABIUnpack, "failed to unpack total supply") } return totalSupply, nil @@ -628,7 +628,7 @@ func (k Keeper) QueryChainIDFromContract( ) (*big.Int, error) { abi, err := zrc20.ZRC20MetaData.GetAbi() if err != nil { - return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, err.Error()) + return nil, cosmoserrors.Wrap(types.ErrABIUnpack, err.Error()) } res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, contract, BigIntZero, nil, false, false, "CHAIN_ID") if err != nil { @@ -637,12 +637,12 @@ func (k Keeper) QueryChainIDFromContract( unpacked, err := abi.Unpack("CHAIN_ID", res.Ret) if err != nil || len(unpacked) == 0 { - return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, err.Error()) + return nil, cosmoserrors.Wrap(types.ErrABIUnpack, err.Error()) } chainID, ok := unpacked[0].(*big.Int) if !ok { - return nil, cosmoserrors.Wrapf(types.ErrABIUnpack, "failed to unpack chain ID") + return nil, cosmoserrors.Wrap(types.ErrABIUnpack, "failed to unpack chain ID") } return chainID, nil @@ -684,7 +684,7 @@ func (k Keeper) CallEVM( if ok { errMes = fmt.Sprintf("%s, reason: %v", errMes, revertErr.ErrorData()) } - return resp, cosmoserrors.Wrapf(err, errMes) + return resp, cosmoserrors.Wrap(err, errMes) } return resp, nil } diff --git a/x/fungible/keeper/gas_price.go b/x/fungible/keeper/gas_price.go index 600e1171a2..88ff0d6704 100644 --- a/x/fungible/keeper/gas_price.go +++ b/x/fungible/keeper/gas_price.go @@ -42,7 +42,7 @@ func (k Keeper) SetGasPrice(ctx sdk.Context, chainid *big.Int, gasPrice *big.Int gasPrice, ) if err != nil { - return 0, cosmoserrors.Wrapf(types.ErrContractCall, err.Error()) + return 0, cosmoserrors.Wrap(types.ErrContractCall, err.Error()) } if res.Failed() { return res.GasUsed, cosmoserrors.Wrapf(types.ErrContractCall, "setGasPrice tx failed") @@ -78,7 +78,7 @@ func (k Keeper) SetGasCoin(ctx sdk.Context, chainid *big.Int, address ethcommon. address, ) if err != nil { - return cosmoserrors.Wrapf(types.ErrContractCall, err.Error()) + return cosmoserrors.Wrap(types.ErrContractCall, err.Error()) } if res.Failed() { return cosmoserrors.Wrapf(types.ErrContractCall, "setGasCoinZRC20 tx failed") @@ -114,7 +114,7 @@ func (k Keeper) SetGasZetaPool(ctx sdk.Context, chainid *big.Int, pool ethcommon pool, ) if err != nil { - return cosmoserrors.Wrapf(types.ErrContractCall, err.Error()) + return cosmoserrors.Wrap(types.ErrContractCall, err.Error()) } if res.Failed() { return cosmoserrors.Wrapf(types.ErrContractCall, "setGasZetaPool tx failed") diff --git a/x/observer/types/message_update_chain_params.go b/x/observer/types/message_update_chain_params.go index 52bd399f02..e9db71920b 100644 --- a/x/observer/types/message_update_chain_params.go +++ b/x/observer/types/message_update_chain_params.go @@ -45,7 +45,7 @@ func (msg *MsgUpdateChainParams) ValidateBasic() error { } if err := ValidateChainParams(msg.ChainParams); err != nil { - return cosmoserrors.Wrapf(ErrInvalidChainParams, err.Error()) + return cosmoserrors.Wrap(ErrInvalidChainParams, err.Error()) } return nil diff --git a/x/observer/types/message_vote_block_header.go b/x/observer/types/message_vote_block_header.go index ba52975251..383ed6464c 100644 --- a/x/observer/types/message_vote_block_header.go +++ b/x/observer/types/message_vote_block_header.go @@ -55,7 +55,7 @@ func (msg *MsgVoteBlockHeader) GetSignBytes() []byte { func (msg *MsgVoteBlockHeader) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, err.Error()) + return cosmoserrors.Wrap(sdkerrors.ErrInvalidAddress, err.Error()) } if len(msg.BlockHash) != 32 {