Skip to content

Commit

Permalink
schedule bitcoin keysign with intervals to avoid keysign failures (#1664
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ws4charlie authored Jan 30, 2024
1 parent 1c97d9f commit be1c040
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@

* [1642](https://github.com/zeta-chain/node/pull/1642) - Change WhitelistERC20 authorization from group1 to group2
* [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

### Tests
* [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
Expand Down
11 changes: 0 additions & 11 deletions zetaclient/btc_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 15 additions & 2 deletions zetaclient/zetacore_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit be1c040

Please sign in to comment.