Skip to content

Commit

Permalink
replaced hard-coded MaxLookaheadNonce with a default lookback factor
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Apr 15, 2024
1 parent 637c62e commit 4fea83e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@

* [1861](https://github.com/zeta-chain/node/pull/1861) - fix `ObserverSlashAmount` invalid read
* [1880](https://github.com/zeta-chain/node/issues/1880) - lower the gas price multiplier for EVM chains.
* [1883](https://github.com/zeta-chain/node/issues/1883) - zetaclient should check 'IsSupported' flag to pause/unpause a specific chain
* [1883](https://github.com/zeta-chain/node/issues/1883) - zetaclient should check `IsSupported` flag to pause/unpause a specific chain
* [1633](https://github.com/zeta-chain/node/issues/1633) - zetaclient should be able to pick up new connector and erc20Custody addresses
* [1944](https://github.com/zeta-chain/node/pull/1944) - fix evm signer unit tests
* [1888](https://github.com/zeta-chain/node/issues/1888) - zetaclient should stop inbound/outbound txs according to cross-chain flags
* [1970](https://github.com/zeta-chain/node/issues/1970) - remove the timeout in the evm outtx tracker processing thread
* [1484](https://github.com/zeta-chain/node/issues/1484) - replaced hard-coded `MaxLookaheadNonce` with a default lookback factor

### Chores

Expand Down
18 changes: 11 additions & 7 deletions zetaclient/zetacore_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ import (
)

const (
MaxLookaheadNonce = 120
// EVMOutboundTxLookbackFactor is the factor to determine how many nonces to look back for pending cctxs
// For example, give OutboundTxScheduleLookahead of 120, pending NonceLow of 1000 and factor of 1.0,
// the scheduler need to be able to pick up and schedule any pending cctx with nonce < 880 (1000 - 120 * 1.0)
EVMOutboundTxLookbackFactor = 1.0 // 1.0 means look back the same number of cctxs as we look ahead
)

type ZetaCoreLog struct {
ChainLogger zerolog.Logger
ZetaChainWatcher zerolog.Logger
}

// CoreObserver wraps the zetabridge bridge and adds the client and signer maps to it . This is the high level object used for CCTX interactions
// CoreObserver wraps the zetabridge, chain clients and signers. This is the high level object used for CCTX scheduling
type CoreObserver struct {
bridge interfaces.ZetaCoreBridger
signerMap map[int64]interfaces.ChainSigner
Expand Down Expand Up @@ -201,6 +204,11 @@ func (co *CoreObserver) scheduleCctxEVM(
for _, v := range res {
trackerMap[v.Nonce] = true
}
lookahead := ob.GetChainParams().OutboundTxScheduleLookahead

Check warning on line 207 in zetaclient/zetacore_observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/zetacore_observer.go#L207

Added line #L207 was not covered by tests
// #nosec G701 always in range
lookback := uint64(float64(lookahead) * EVMOutboundTxLookbackFactor)

Check warning on line 209 in zetaclient/zetacore_observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/zetacore_observer.go#L209

Added line #L209 was not covered by tests
// #nosec G701 positive
interval := uint64(ob.GetChainParams().OutboundTxScheduleInterval)

Check warning on line 211 in zetaclient/zetacore_observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/zetacore_observer.go#L211

Added line #L211 was not covered by tests

for idx, cctx := range cctxList {
params := cctx.GetCurrentOutTxParam()
Expand All @@ -211,7 +219,7 @@ func (co *CoreObserver) scheduleCctxEVM(
co.logger.ZetaChainWatcher.Error().Msgf("scheduleCctxEVM: outtx %s chainid mismatch: want %d, got %d", outTxID, chainID, params.ReceiverChainId)
continue
}
if params.OutboundTxTssNonce > cctxList[0].GetCurrentOutTxParam().OutboundTxTssNonce+MaxLookaheadNonce {
if params.OutboundTxTssNonce > cctxList[0].GetCurrentOutTxParam().OutboundTxTssNonce+lookback {

Check warning on line 222 in zetaclient/zetacore_observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/zetacore_observer.go#L222

Added line #L222 was not covered by tests
co.logger.ZetaChainWatcher.Error().Msgf("scheduleCctxEVM: nonce too high: signing %d, earliest pending %d, chain %d",
params.OutboundTxTssNonce, cctxList[0].GetCurrentOutTxParam().OutboundTxTssNonce, chainID)
break
Expand All @@ -228,10 +236,6 @@ func (co *CoreObserver) scheduleCctxEVM(
continue
}

// #nosec G701 positive
interval := uint64(ob.GetChainParams().OutboundTxScheduleInterval)
lookahead := ob.GetChainParams().OutboundTxScheduleLookahead

// determining critical outtx; if it satisfies following criteria
// 1. it's the first pending outtx for this chain
// 2. the following 5 nonces have been in tracker
Expand Down

0 comments on commit 4fea83e

Please sign in to comment.