From cfc6a1d3eeefb894ba2924d40ee83be52b4eb3b9 Mon Sep 17 00:00:00 2001 From: Charlie Chen Date: Mon, 29 Jan 2024 13:06:07 -0600 Subject: [PATCH] schedule bitcoin keysign with intervals to avoid keysign failures --- changelog.md | 4 +++- zetaclient/btc_signer.go | 11 ----------- zetaclient/zetacore_observer.go | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/changelog.md b/changelog.md index edf96c140d..af873e939c 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ ### Fixes * [1610](https://github.com/zeta-chain/node/issues/1610) - add pending outtx hash to tracker after monitoring for 10 minutes +* [1656](https://github.com/zeta-chain/node/issues/1656) - schedule bitcoin keysign with intervals to avoid keysign failures ## Version: v12.1.0 @@ -11,7 +12,8 @@ * [1577](https://github.com/zeta-chain/node/pull/1577) - add chain header tests in E2E tests and fix admin tests ### Features -* [1658](https://github.com/zeta-chain/node/pull/1658) - modify emission distribution to use fixed block rewards +* [1658](https://github.com/zeta-chain/node/pull/1658) - modify emission distribution to use fixed block rewards + ### Fixes * [1535](https://github.com/zeta-chain/node/issues/1535) - Avoid voting on wrong ballots due to false blockNumber in EVM tx receipt * [1588](https://github.com/zeta-chain/node/pull/1588) - fix chain params comparison logic diff --git a/zetaclient/btc_signer.go b/zetaclient/btc_signer.go index ba493a9fce..4cd57a5e0b 100644 --- a/zetaclient/btc_signer.go +++ b/zetaclient/btc_signer.go @@ -275,18 +275,7 @@ func (signer *BTCSigner) TryProcessOutTx( return } myid := zetaBridge.GetKeys().GetAddress() - // Early return if the send is already processed - // FIXME: handle revert case outboundTxTssNonce := params.OutboundTxTssNonce - included, confirmed, err := btcClient.IsSendOutTxProcessed(cctx.Index, outboundTxTssNonce, common.CoinType_Gas, logger) - if err != nil { - logger.Error().Err(err).Msgf("cannot check if send %s is processed", cctx.Index) - return - } - if included || confirmed { - logger.Info().Msgf("CCTX %s already processed; exit signer", outTxID) - return - } sizelimit := params.OutboundTxGasLimit gasprice, ok := new(big.Int).SetString(params.OutboundTxGasPrice, 10) diff --git a/zetaclient/zetacore_observer.go b/zetaclient/zetacore_observer.go index 333c6ce262..6fae898ece 100644 --- a/zetaclient/zetacore_observer.go +++ b/zetaclient/zetacore_observer.go @@ -257,7 +257,7 @@ func (co *CoreObserver) scheduleCctxEVM( // try confirming the outtx included, _, err := ob.IsSendOutTxProcessed(cctx.Index, params.OutboundTxTssNonce, params.CoinType, co.logger.ZetaChainWatcher) if err != nil { - co.logger.ZetaChainWatcher.Error().Err(err).Msgf("scheduleCctxEVM: IsSendOutTxProcessed faild for chain %d", chainID) + co.logger.ZetaChainWatcher.Error().Err(err).Msgf("scheduleCctxEVM: IsSendOutTxProcessed faild for chain %d nonce %d", chainID, nonce) continue } if included { @@ -320,6 +320,8 @@ func (co *CoreObserver) scheduleCctxBTC( co.logger.ZetaChainWatcher.Error().Msgf("scheduleCctxBTC: chain client is not a bitcoin client") return } + // #nosec G701 positive + interval := uint64(ob.GetChainParams().OutboundTxScheduleInterval) lookahead := ob.GetChainParams().OutboundTxScheduleLookahead // schedule at most one keysign per ticker @@ -332,6 +334,17 @@ func (co *CoreObserver) scheduleCctxBTC( co.logger.ZetaChainWatcher.Error().Msgf("scheduleCctxBTC: outtx %s chainid mismatch: want %d, got %d", outTxID, chainID, params.ReceiverChainId) continue } + // try confirming the outtx + included, confirmed, err := btcClient.IsSendOutTxProcessed(cctx.Index, nonce, params.CoinType, co.logger.ZetaChainWatcher) + if err != nil { + co.logger.ZetaChainWatcher.Error().Err(err).Msgf("scheduleCctxBTC: IsSendOutTxProcessed faild for chain %d nonce %d", chainID, nonce) + continue + } + if included || confirmed { + co.logger.ZetaChainWatcher.Info().Msgf("scheduleCctxBTC: outtx %s already included; do not schedule keysign", outTxID) + return + } + // stop if the nonce being processed is higher than the pending nonce if nonce > btcClient.GetPendingNonce() { break @@ -342,7 +355,7 @@ func (co *CoreObserver) scheduleCctxBTC( break } // try confirming the outtx or scheduling a keysign - if !outTxMan.IsOutTxActive(outTxID) { + if nonce%interval == zetaHeight%interval && !outTxMan.IsOutTxActive(outTxID) { outTxMan.StartTryProcess(outTxID) co.logger.ZetaChainWatcher.Debug().Msgf("scheduleCctxBTC: sign outtx %s with value %d\n", outTxID, params.Amount) go signer.TryProcessOutTx(cctx, outTxMan, outTxID, ob, co.bridge, zetaHeight)