Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replaced hard-coded MaxLookaheadNonce with a default lookback factor #2033

Merged
merged 8 commits into from
Apr 30, 2024
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,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
19 changes: 12 additions & 7 deletions zetaclient/zetacore_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@
)

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)
// NOTE: 1.0 means look back the same number of cctxs as we look ahead
EVMOutboundTxLookbackFactor = 1.0

Check failure on line 27 in zetaclient/zetacore_observer.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
)

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 +205,11 @@
for _, v := range res {
trackerMap[v.Nonce] = true
}
lookahead := ob.GetChainParams().OutboundTxScheduleLookahead

Check warning on line 208 in zetaclient/zetacore_observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/zetacore_observer.go#L208

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

Check warning on line 210 in zetaclient/zetacore_observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/zetacore_observer.go#L210

Added line #L210 was not covered by tests
ws4charlie marked this conversation as resolved.
Show resolved Hide resolved
// #nosec G701 positive
interval := uint64(ob.GetChainParams().OutboundTxScheduleInterval)

Check warning on line 212 in zetaclient/zetacore_observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/zetacore_observer.go#L212

Added line #L212 was not covered by tests
ws4charlie marked this conversation as resolved.
Show resolved Hide resolved

for idx, cctx := range cctxList {
params := cctx.GetCurrentOutTxParam()
Expand All @@ -211,7 +220,7 @@
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 223 in zetaclient/zetacore_observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/zetacore_observer.go#L223

Added line #L223 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 +237,6 @@
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
Loading