From 35b4812db0d5b320f5f41eb5ddcf4e5997121030 Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 25 Sep 2023 16:41:09 +0200 Subject: [PATCH] solve remaining --- zetaclient/bitcoin_client.go | 9 ++++++--- zetaclient/query.go | 9 ++++++--- zetaclient/zetacore_observer.go | 12 ++++++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/zetaclient/bitcoin_client.go b/zetaclient/bitcoin_client.go index a2e1f9252b..72bce508cb 100644 --- a/zetaclient/bitcoin_client.go +++ b/zetaclient/bitcoin_client.go @@ -662,9 +662,12 @@ func (ob *BitcoinChainClient) refreshPendingNonce() { pendingNonce := ob.pendingNonce ob.mu.Unlock() - if p.NonceLow > 0 && uint64(p.NonceLow) >= pendingNonce { + // #nosec G701 always positive + nonceLow := uint64(p.NonceLow) + + if nonceLow > 0 && nonceLow >= pendingNonce { // get the last included outTx hash - txid, err := ob.getOutTxidByNonce(uint64(p.NonceLow)-1, false) + txid, err := ob.getOutTxidByNonce(nonceLow-1, false) if err != nil { ob.logger.ChainLogger.Error().Err(err).Msg("refreshPendingNonce: error getting last outTx txid") } @@ -672,7 +675,7 @@ func (ob *BitcoinChainClient) refreshPendingNonce() { // set 'NonceLow' as the new pending nonce ob.mu.Lock() defer ob.mu.Unlock() - ob.pendingNonce = uint64(p.NonceLow) + ob.pendingNonce = nonceLow ob.logger.ChainLogger.Info().Msgf("refreshPendingNonce: increase pending nonce to %d with txid %s", ob.pendingNonce, txid) } } diff --git a/zetaclient/query.go b/zetaclient/query.go index d665e6d1bc..7b813600ce 100644 --- a/zetaclient/query.go +++ b/zetaclient/query.go @@ -122,8 +122,9 @@ func (b *ZetaCoreBridge) GetCctxByNonce(chainID int64, nonce uint64) (*types.Cro } func (b *ZetaCoreBridge) GetObserverList(chain common.Chain) ([]string, error) { + var err error + client := zetaObserverTypes.NewQueryClient(b.grpcConn) - err := error(nil) for i := 0; i <= DefaultRetryCount; i++ { resp, err := client.ObserversByChain(context.Background(), &zetaObserverTypes.QueryObserversByChainRequest{ObservationChain: chain.ChainName.String()}) if err == nil { @@ -164,8 +165,9 @@ func (b *ZetaCoreBridge) GetLatestZetaBlock() (*tmtypes.Block, error) { } func (b *ZetaCoreBridge) GetNodeInfo() (*tmservice.GetNodeInfoResponse, error) { + var err error + client := tmservice.NewServiceClient(b.grpcConn) - err := error(nil) for i := 0; i <= DefaultRetryCount; i++ { res, err := client.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{}) if err == nil { @@ -214,8 +216,9 @@ func (b *ZetaCoreBridge) GetAllNodeAccounts() ([]*zetaObserverTypes.NodeAccount, } func (b *ZetaCoreBridge) GetKeyGen() (*zetaObserverTypes.Keygen, error) { + var err error + client := zetaObserverTypes.NewQueryClient(b.grpcConn) - err := error(nil) for i := 0; i <= ExtendedRetryCount; i++ { resp, err := client.Keygen(context.Background(), &zetaObserverTypes.QueryGetKeygenRequest{}) if err == nil { diff --git a/zetaclient/zetacore_observer.go b/zetaclient/zetacore_observer.go index 4a193a37b1..343228004a 100644 --- a/zetaclient/zetacore_observer.go +++ b/zetaclient/zetacore_observer.go @@ -173,7 +173,8 @@ func (co *CoreObserver) startSendScheduler() { // Process Bitcoin OutTx if common.IsBitcoinChain(c.ChainId) && !outTxMan.IsOutTxActive(outTxID) { - if stop := co.processBitcoinOutTx(outTxMan, idx, cctx, signer, ob, currentHeight); stop { + // #nosec G701 positive + if stop := co.processBitcoinOutTx(outTxMan, uint64(idx), cctx, signer, ob, currentHeight); stop { break } continue @@ -190,6 +191,7 @@ func (co *CoreObserver) startSendScheduler() { continue } + // #nosec G701 positive interval := uint64(ob.GetCoreParams().OutboundTxScheduleInterval) lookahead := ob.GetCoreParams().OutboundTxScheduleLookahead @@ -221,6 +223,7 @@ func (co *CoreObserver) startSendScheduler() { go signer.TryProcessOutTx(cctx, outTxMan, outTxID, ob, co.bridge, currentHeight) } + // #nosec G701 always in range if int64(idx) >= lookahead-1 { // only look at 30 sends per chain break } @@ -242,10 +245,10 @@ func (co *CoreObserver) startSendScheduler() { // 3. stop processing when pendingNonce/lookahead is reached // // Returns whether to stop processing -func (co *CoreObserver) processBitcoinOutTx(outTxMan *OutTxProcessorManager, idx int, send *types.CrossChainTx, signer ChainSigner, ob ChainClient, currentHeight uint64) bool { +func (co *CoreObserver) processBitcoinOutTx(outTxMan *OutTxProcessorManager, idx uint64, send *types.CrossChainTx, signer ChainSigner, ob ChainClient, currentHeight uint64) bool { params := send.GetCurrentOutTxParam() nonce := params.OutboundTxTssNonce - lookahead := uint64(ob.GetCoreParams().OutboundTxScheduleLookahead) + lookahead := ob.GetCoreParams().OutboundTxScheduleLookahead outTxID := fmt.Sprintf("%s-%d-%d", send.Index, params.ReceiverChainId, nonce) // start go routine to process outtx @@ -264,7 +267,8 @@ func (co *CoreObserver) processBitcoinOutTx(outTxMan *OutTxProcessorManager, idx return true } // stop if lookahead is reached. 2 bitcoin confirmations span is 20 minutes on average. We look ahead up to 100 pending cctx to target TPM of 5. - if idx >= int(lookahead)-1 { + // #nosec G701 always in range + if int64(idx) >= lookahead-1 { return true } return false // otherwise, continue