From 10308d1376be927170bd3bfcb505f9d6a104137f Mon Sep 17 00:00:00 2001 From: Charlie Chen <34498985+ws4charlie@users.noreply.github.com> Date: Fri, 17 Nov 2023 11:10:22 -0600 Subject: [PATCH] fix: speed up evm outtx inclusion and improve log prints (#1406) Co-authored-by: charliec --- changelog.md | 1 + zetaclient/evm_client.go | 33 +++++++++++++++------------------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/changelog.md b/changelog.md index 9ba982dbcc..bb313bed7a 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ * [1372](https://github.com/zeta-chain/node/pull/1372) - Include Event Index as part for inbound tx digest * [1367](https://github.com/zeta-chain/node/pull/1367) - fix minRelayTxFee issue and check misuse of bitcoin mainnet/testnet addresses * [1358](https://github.com/zeta-chain/node/pull/1358) - add a new thread to zetaclient which checks zeta supply in all connected chains in every block +* [1406](https://github.com/zeta-chain/node/pull/1406) - improve log prints and speed up evm outtx inclusion ### Refactoring diff --git a/zetaclient/evm_client.go b/zetaclient/evm_client.go index 785d81c35a..5188a2767e 100644 --- a/zetaclient/evm_client.go +++ b/zetaclient/evm_client.go @@ -324,7 +324,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co common.CoinType_Cmd, ) if err != nil { - logger.Error().Err(err).Msg("error posting confirmation to meta core") + logger.Error().Err(err).Msgf("error posting confirmation to meta core for cctx %s nonce %d", sendHash, nonce) } logger.Info().Msgf("Zeta tx hash: %s cctx %s nonce %d", zetaHash, sendHash, nonce) return true, true, nil @@ -345,7 +345,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co common.CoinType_Gas, ) if err != nil { - logger.Error().Err(err).Msg("error posting confirmation to meta core") + logger.Error().Err(err).Msgf("error posting confirmation to meta core for cctx %s nonce %d", sendHash, nonce) } logger.Info().Msgf("Zeta tx hash: %s cctx %s nonce %d", zetaHash, sendHash, nonce) return true, true, nil @@ -365,7 +365,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co common.CoinType_Gas, ) if err != nil { - logger.Error().Err(err).Msgf("PostReceiveConfirmation error in WatchTxHashWithTimeout; zeta tx hash %s", zetaTxHash) + logger.Error().Err(err).Msgf("PostReceiveConfirmation error in WatchTxHashWithTimeout; zeta tx hash %s cctx %s nonce %d", zetaTxHash, sendHash, nonce) } logger.Info().Msgf("Zeta tx hash: %s cctx %s nonce %d", zetaTxHash, sendHash, nonce) return true, true, nil @@ -410,7 +410,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co common.CoinType_Zeta, ) if err != nil { - logger.Error().Err(err).Msg("error posting confirmation to meta core") + logger.Error().Err(err).Msgf("error posting confirmation to meta core for cctx %s nonce %d", sendHash, nonce) continue } logger.Info().Msgf("Zeta tx hash: %s cctx %s nonce %d", zetaHash, sendHash, nonce) @@ -446,7 +446,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co common.CoinType_Zeta, ) if err != nil { - logger.Err(err).Msg("error posting confirmation to meta core") + logger.Err(err).Msgf("error posting confirmation to meta core for cctx %s nonce %d", sendHash, nonce) continue } logger.Info().Msgf("Zeta tx hash: %s cctx %s nonce %d", metaHash, sendHash, nonce) @@ -474,7 +474,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co common.CoinType_Zeta, ) if err != nil { - logger.Error().Err(err).Msgf("PostReceiveConfirmation error in WatchTxHashWithTimeout; zeta tx hash %s", zetaTxHash) + logger.Error().Err(err).Msgf("error posting confirmation to meta core for cctx %s nonce %d", sendHash, nonce) } logger.Info().Msgf("Zeta tx hash: %s cctx %s nonce %d", zetaTxHash, sendHash, nonce) return true, true, nil @@ -512,7 +512,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co common.CoinType_ERC20, ) if err != nil { - logger.Error().Err(err).Msg("error posting confirmation to meta core") + logger.Error().Err(err).Msgf("error posting confirmation to meta core for cctx %s nonce %d", sendHash, nonce) continue } logger.Info().Msgf("Zeta tx hash: %s cctx %s nonce %d", zetaHash, sendHash, nonce) @@ -588,21 +588,18 @@ func (ob *EVMChainClient) observeOutTx() { if nonceInt < lowestOutTxNonceToObserve[ob.chain.ChainId] { continue } - TXHASHLOOP: + ob.Mu.Lock() + _, found := ob.outTXConfirmedReceipts[ob.GetTxID(nonceInt)] + ob.Mu.Unlock() + if found { // Go to next tracker if this one has already been confirmed + continue + } for _, txHash := range tracker.HashList { - //inTimeout := time.After(3000 * time.Millisecond) select { case <-outTimeout: ob.logger.ObserveOutTx.Warn().Msgf("observeOutTx timeout on chain %d nonce %d", ob.chain.ChainId, nonceInt) break TRACKERLOOP default: - ob.Mu.Lock() - _, found := ob.outTXConfirmedReceipts[ob.GetTxID(nonceInt)] - ob.Mu.Unlock() - if found { - continue - } - receipt, transaction, err := ob.queryTxByHash(txHash.TxHash, nonceInt) time.Sleep(time.Duration(rpcRestTime) * time.Millisecond) if err == nil && receipt != nil { // confirmed @@ -610,13 +607,13 @@ func (ob *EVMChainClient) observeOutTx() { ob.outTXConfirmedReceipts[ob.GetTxID(nonceInt)] = receipt ob.outTXConfirmedTransaction[ob.GetTxID(nonceInt)] = transaction ob.Mu.Unlock() + ob.logger.ObserveOutTx.Info().Msgf("observeOutTx confirmed outTx %s for chain %d nonce %d", txHash.TxHash, ob.chain.ChainId, nonceInt) - break TXHASHLOOP + break } if err != nil { ob.logger.ObserveOutTx.Debug().Err(err).Msgf("error queryTxByHash: chain %s hash %s", ob.chain.String(), txHash.TxHash) } - //<-inTimeout } } }