From 454a56b8b905e6c62da4e80a6b3bc88db4abbd3c Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 Jul 2024 16:13:15 +0200 Subject: [PATCH] Fix gosec --- pkg/retry/retry.go | 1 + zetaclient/chains/bitcoin/observer/outbound.go | 17 +++++++++++++---- zetaclient/zetacore/client_monitor.go | 7 ++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pkg/retry/retry.go b/pkg/retry/retry.go index 3cf4a7e77f..fbb6f2e3d6 100644 --- a/pkg/retry/retry.go +++ b/pkg/retry/retry.go @@ -89,6 +89,7 @@ func DoTypedWithBackoff[T any](cb TypedCallback[T], bo Backoff) (T, error) { err error ) + // #nosec G703 error is propagated _ = DoWithBackoff(func() error { result, err = cb() return err diff --git a/zetaclient/chains/bitcoin/observer/outbound.go b/zetaclient/chains/bitcoin/observer/outbound.go index 25ffc17ad0..f8e0d6b80e 100644 --- a/zetaclient/chains/bitcoin/observer/outbound.go +++ b/zetaclient/chains/bitcoin/observer/outbound.go @@ -191,15 +191,24 @@ func (ob *Observer) IsOutboundProcessed( signer := ob.ZetacoreClient().GetKeys().GetOperatorAddress() + // not used with Bitcoin + const ( + gasUsed = 0 + gasPrice = 0 + gasLimit = 0 + ) + msg := crosschaintypes.NewMsgVoteOutbound( signer.String(), cctx.Index, res.TxID, - uint64(blockHeight), // #nosec G701 always positive - 0, // gas used not used with Bitcoin - math.NewInt(0), // gas price not used with Bitcoin - 0, // gas limit not used with Bitcoin + // #nosec G701 always positive + uint64(blockHeight), + + gasUsed, + math.NewInt(gasPrice), + gasLimit, math.NewUintFromBigInt(amountInSat), chains.ReceiveStatus_success, diff --git a/zetaclient/zetacore/client_monitor.go b/zetaclient/zetacore/client_monitor.go index b19629add5..673a7a343c 100644 --- a/zetaclient/zetacore/client_monitor.go +++ b/zetaclient/zetacore/client_monitor.go @@ -5,8 +5,8 @@ import ( "strings" "time" - "cosmossdk.io/errors" "github.com/cenkalti/backoff/v4" + "github.com/pkg/errors" "github.com/zeta-chain/zetacore/pkg/retry" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -165,11 +165,16 @@ func (c *Client) monitorVoteInboundResult( } func retryWithBackoff(call func() error, attempts int, minInternal, maxInterval time.Duration) error { + if attempts < 1 { + return errors.New("attempts must be positive") + } + bo := backoff.WithMaxRetries( backoff.NewExponentialBackOff( backoff.WithInitialInterval(minInternal), backoff.WithMaxInterval(maxInterval), ), + // #nosec G701 always positive uint64(attempts), )