Skip to content

Commit

Permalink
skip keysign for pending-forever cctx and log print for monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Nov 10, 2023
1 parent fc03044 commit f95ffea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 14 additions & 3 deletions zetaclient/cctx_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
)

const (
RescanBatch uint64 = 10
RescanBatch uint64 = 10
LogPrintBlks int64 = 10
)

// CctxScanner scans missed pending cctx and updates their status
Expand Down Expand Up @@ -82,7 +83,7 @@ func (sc *CctxScanner) ScanMissedPendingCctx(bn int64, chainID int64, maxNonce u
}
}

func (sc *CctxScanner) EarliestPendingCctxByChain(chainID int64) *crosschaintypes.CrossChainTx {
func (sc *CctxScanner) EarliestPendingCctxByChain(bn int64, chainID int64) *crosschaintypes.CrossChainTx {
oldPendingCctxs := sc.AllMissedPendingCctxByChain(chainID)

// try removing finalized cctx
Expand All @@ -107,9 +108,19 @@ func (sc *CctxScanner) EarliestPendingCctxByChain(chainID int64) *crosschaintype

newPendingCctxs := sc.AllMissedPendingCctxByChain(chainID)
if len(newPendingCctxs) == 0 {
sc.logger.Info().Msgf("scanner: pending cctxs for chain %d is empty, next nonce to scan %d", chainID, sc.nextNonceToScan[chainID])
return nil
}
return newPendingCctxs[0]

// log print for monitoring
oldestCctx := newPendingCctxs[0]
latestCctx := newPendingCctxs[len(newPendingCctxs)-1]
if bn%LogPrintBlks == 0 {
sc.logger.Info().Msgf("scanner: pending cctxs for chain %d, oldest %d, latest %d, next nonce to scan %d",
chainID, oldestCctx.GetCurrentOutTxParam().OutboundTxTssNonce, latestCctx.GetCurrentOutTxParam().OutboundTxTssNonce, sc.nextNonceToScan[chainID])
}

return oldestCctx
}

// Note: deep clone is unnecessary as the cctx list is used in a single thread
Expand Down
6 changes: 5 additions & 1 deletion zetaclient/zetacore_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (co *CoreObserver) startSendScheduler() {
// Scan missed pending (forever) cctx in history and get the earliest
// #nosec G701 non negative value
co.scanner.ScanMissedPendingCctx(bn, c.ChainId, uint64(pendingNonces.NonceLow))
earliestCctx := co.scanner.EarliestPendingCctxByChain(c.ChainId)
earliestCctx := co.scanner.EarliestPendingCctxByChain(bn, c.ChainId)
if earliestCctx != nil { // append earliest missed pending cctx to head
cctxList = append([]*types.CrossChainTx{earliestCctx}, cctxList...)
}
Expand Down Expand Up @@ -223,6 +223,10 @@ func (co *CoreObserver) startSendScheduler() {
co.logger.ZetaChainWatcher.Error().Err(err).Msgf("IsSendOutTxProcessed fail, Chain ID: %s", c.ChainName)
continue
}
// skip keysign for missed pending (forever) cctx as outTx was already finalized
if co.scanner.IsMissedPendingCctx(c.ChainId, params.OutboundTxTssNonce) {
continue
}
if included {
co.logger.ZetaChainWatcher.Info().Msgf("send outTx already included; do not schedule")
continue
Expand Down

0 comments on commit f95ffea

Please sign in to comment.