From 62e1bfd8a60fa93a8e3801fdfcbee20ac79afae3 Mon Sep 17 00:00:00 2001 From: fx0x55 <80245546+fx0x55@users.noreply.github.com> Date: Sat, 27 Jan 2024 01:53:01 +0800 Subject: [PATCH] refactor: optimize some returns (#1628) * refactor: Optimize return delete redundant judgments * changelog --- changelog.md | 4 ++++ common/chain.go | 5 +---- rpc/namespaces/ethereum/debug/utils.go | 6 +----- x/crosschain/keeper/cctx_utils.go | 5 +---- x/crosschain/keeper/msg_server_tss_voter.go | 5 +---- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/changelog.md b/changelog.md index 1adfa29044..18632d0202 100644 --- a/changelog.md +++ b/changelog.md @@ -31,6 +31,10 @@ * [1591](https://github.com/zeta-chain/node/pull/1591) - support lower gas limit for voting on inbound and outbound transactions * [1592](https://github.com/zeta-chain/node/issues/1592) - check inbound tracker tx hash against Tss address and some refactor on inTx observation +### Refactoring + +* [1628](https://github.com/zeta-chain/node/pull/1628) optimize return and simplify code + ## Version: v12.0.0 ### Breaking Changes diff --git a/common/chain.go b/common/chain.go index d6762c1a91..cc3dde3722 100644 --- a/common/chain.go +++ b/common/chain.go @@ -23,10 +23,7 @@ type Chains []Chain // IsEqual compare two chain to see whether they represent the same chain func (chain Chain) IsEqual(c Chain) bool { - if chain.ChainId == c.ChainId { - return true - } - return false + return chain.ChainId == c.ChainId } func (chain Chain) IsZetaChain() bool { diff --git a/rpc/namespaces/ethereum/debug/utils.go b/rpc/namespaces/ethereum/debug/utils.go index a65134977d..bfd8ced432 100644 --- a/rpc/namespaces/ethereum/debug/utils.go +++ b/rpc/namespaces/ethereum/debug/utils.go @@ -30,11 +30,7 @@ import ( func isCPUProfileConfigurationActivated(ctx *server.Context) bool { // TODO: use same constants as server/start.go // constant declared in start.go cannot be imported (cyclical dependency) - const flagCPUProfile = "cpu-profile" - if cpuProfile := ctx.Viper.GetString(flagCPUProfile); cpuProfile != "" { - return true - } - return false + return ctx.Viper.GetString("cpu-profile") != "" } // ExpandHome expands home directory in file paths. diff --git a/x/crosschain/keeper/cctx_utils.go b/x/crosschain/keeper/cctx_utils.go index 528139af69..7b43123cbe 100644 --- a/x/crosschain/keeper/cctx_utils.go +++ b/x/crosschain/keeper/cctx_utils.go @@ -124,8 +124,5 @@ func (k Keeper) GetRevertGasLimit(ctx sdk.Context, cctx types.CrossChainTx) (uin func IsPending(cctx types.CrossChainTx) bool { // pending inbound is not considered a "pending" state because it has not reached consensus yet - if cctx.CctxStatus.Status == types.CctxStatus_PendingOutbound || cctx.CctxStatus.Status == types.CctxStatus_PendingRevert { - return true - } - return false + return cctx.CctxStatus.Status == types.CctxStatus_PendingOutbound || cctx.CctxStatus.Status == types.CctxStatus_PendingRevert } diff --git a/x/crosschain/keeper/msg_server_tss_voter.go b/x/crosschain/keeper/msg_server_tss_voter.go index 13a97e58ae..29672a1a6d 100644 --- a/x/crosschain/keeper/msg_server_tss_voter.go +++ b/x/crosschain/keeper/msg_server_tss_voter.go @@ -116,8 +116,5 @@ func (k msgServer) CreateTSSVoter(goCtx context.Context, msg *types.MsgCreateTSS // IsAuthorizedNodeAccount 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 func (k Keeper) IsAuthorizedNodeAccount(ctx sdk.Context, address string) bool { _, found := k.zetaObserverKeeper.GetNodeAccount(ctx, address) - if found { - return true - } - return false + return found }