Skip to content

Commit

Permalink
Merge branch 'develop' into refactor-MsgUpdateZRC20
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD authored May 27, 2024
2 parents fa956b7 + 632b2b9 commit fa1d060
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ jobs:
build-test:
needs:
- check_branch
runs-on: buildjet-4vcpu-ubuntu-2004
runs-on: buildjet-4vcpu-ubuntu-2204
timeout-minutes: 15
concurrency:
group: "build-test"
Expand Down Expand Up @@ -411,7 +411,7 @@ jobs:
- e2e-admin-tests
- e2e-upgrade-test
- check_branch
runs-on: buildjet-4vcpu-ubuntu-2004
runs-on: ubuntu-20.04
timeout-minutes: 60
environment: release
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rc-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
echo "The major version found in 'releaseVersion' in app/setup_handlers.go matches this tagged release - Moving Forward!"
publish-release:
runs-on: buildjet-4vcpu-ubuntu-2004
runs-on: buildjet-4vcpu-ubuntu-2204
timeout-minutes: 60
needs:
- pre-release-checks
Expand Down
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
* [2222](https://github.com/zeta-chain/node/pull/2222) - removed `maxHeightDiff` to let observer scan from Bitcoin height where it left off
* [2233](https://github.com/zeta-chain/node/pull/2233) - fix `IsSupported` flag not properly updated in zetaclient's context
* [2243](https://github.com/zeta-chain/node/pull/2243) - fix incorrect bitcoin outbound height in the CCTX outbound parameter
* [2256](https://github.com/zeta-chain/node/pull/2256) - fix rate limiter falsely included reverted non-withdraw cctxs

### CI

* [2268](https://github.com/zeta-chain/node/pull/2268) - CI: updated the publish-release pipeline to utilize the Github Actions Ubuntu 20.04 Runners.
* [2070](https://github.com/zeta-chain/node/pull/2070) - Added commands to build binaries from the working branch as a live full node rpc to test non-governance changes.
* [2119](https://github.com/zeta-chain/node/pull/2119) - Updated the release pipeline to only run on hotfix/ and release/ branches. Added option to only run pre-checks and not cut release as well. Switched approval steps to use environments.
* [2189](https://github.com/zeta-chain/node/pull/2189) - Updated the docker tag when a release trigger runs to be the github event for the release name which should be the version. Removed mac specific build as the arm build should handle that.
Expand Down
8 changes: 5 additions & 3 deletions testutil/sample/crosschain.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ func CustomCctxsInBlockRange(
t *testing.T,
lowBlock uint64,
highBlock uint64,
chainID int64,
senderChainID int64,
receiverChainID int64,
coinType coin.CoinType,
asset string,
amount uint64,
Expand All @@ -233,12 +234,13 @@ func CustomCctxsInBlockRange(
// create 1 cctx per block
for i := lowBlock; i <= highBlock; i++ {
nonce := i - 1
cctx := CrossChainTx(t, fmt.Sprintf("%d-%d", chainID, nonce))
cctx := CrossChainTx(t, fmt.Sprintf("%d-%d", receiverChainID, nonce))
cctx.CctxStatus.Status = status
cctx.InboundParams.SenderChainId = senderChainID
cctx.InboundParams.CoinType = coinType
cctx.InboundParams.Asset = asset
cctx.InboundParams.ObservedExternalHeight = i
cctx.GetCurrentOutboundParam().ReceiverChainId = chainID
cctx.GetCurrentOutboundParam().ReceiverChainId = receiverChainID
cctx.GetCurrentOutboundParam().Amount = sdk.NewUint(amount)
cctx.GetCurrentOutboundParam().TssNonce = nonce
cctxs = append(cctxs, cctx)
Expand Down
44 changes: 30 additions & 14 deletions x/crosschain/keeper/grpc_query_cctx_rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)
Expand Down Expand Up @@ -55,11 +56,17 @@ func (k Keeper) RateLimiterInput(
}

// if a cctx falls within the rate limiter window
isCctxInWindow := func(cctx *types.CrossChainTx) bool {
isCCTXInWindow := func(cctx *types.CrossChainTx) bool {
// #nosec G701 checked positive
return cctx.InboundParams.ObservedExternalHeight >= uint64(leftWindowBoundary)
}

// if a cctx is an outgoing cctx that orginates from ZetaChain
// reverted incoming cctx has an external `SenderChainId` and should not be counted
isCCTXOutgoing := func(cctx *types.CrossChainTx) bool {
return chains.IsZetaChain(cctx.InboundParams.SenderChainId)
}

// it is a past cctx if its nonce < `nonceLow`,
isPastCctx := func(cctx *types.CrossChainTx, nonceLow int64) bool {
// #nosec G701 always positive
Expand Down Expand Up @@ -123,7 +130,8 @@ func (k Keeper) RateLimiterInput(
if err != nil {
return nil, err
}
inWindow := isCctxInWindow(cctx)
inWindow := isCCTXInWindow(cctx)
isOutgoing := isCCTXOutgoing(cctx)
isPast := isPastCctx(cctx, pendingNonces.NonceLow)

// we should at least go backwards by 1000 nonces to pick up missed pending cctxs
Expand All @@ -132,8 +140,8 @@ func (k Keeper) RateLimiterInput(
break
}

// sum up past cctxs' value within window
if inWindow && isPast {
// sum up the cctxs' value if the cctx is outgoing, within the window and in the past
if inWindow && isOutgoing && isPast {
pastCctxsValue = pastCctxsValue.Add(
types.ConvertCctxValueToAzeta(chain.ChainId, cctx, gasAssetRateMap, erc20AssetRateMap),
)
Expand Down Expand Up @@ -197,7 +205,7 @@ func (k Keeper) ListPendingCctxWithinRateLimit(
totalPending := uint64(0)
totalWithdrawInAzeta := sdkmath.NewInt(0)
cctxs := make([]*types.CrossChainTx, 0)
chains := k.zetaObserverKeeper.GetSupportedForeignChains(ctx)
foreignChains := k.zetaObserverKeeper.GetSupportedForeignChains(ctx)

// check rate limit flags to decide if we should apply rate limit
applyLimit := true
Expand All @@ -211,7 +219,7 @@ func (k Keeper) ListPendingCctxWithinRateLimit(

// fallback to non-rate-limited query if rate limiter is disabled
if !applyLimit {
for _, chain := range chains {
for _, chain := range foreignChains {
resp, err := k.ListPendingCctx(
ctx,
&types.QueryListPendingCctxRequest{ChainId: chain.ChainId, Limit: limit},
Expand Down Expand Up @@ -256,15 +264,21 @@ func (k Keeper) ListPendingCctxWithinRateLimit(
}

// if a cctx falls within the rate limiter window
isCctxInWindow := func(cctx *types.CrossChainTx) bool {
isCCTXInWindow := func(cctx *types.CrossChainTx) bool {
// #nosec G701 checked positive
return cctx.InboundParams.ObservedExternalHeight >= uint64(leftWindowBoundary)
}

// if a cctx is outgoing from ZetaChain
// reverted incoming cctx has an external `SenderChainId` and should not be counted
isCCTXOutgoing := func(cctx *types.CrossChainTx) bool {
return chains.IsZetaChain(cctx.InboundParams.SenderChainId)
}

// query pending nonces for each foreign chain and get the lowest height of the pending cctxs
lowestPendingCctxHeight := int64(0)
pendingNoncesMap := make(map[int64]observertypes.PendingNonces)
for _, chain := range chains {
for _, chain := range foreignChains {
pendingNonces, found := k.GetObserverKeeper().GetPendingNonces(ctx, tss.TssPubkey, chain.ChainId)
if !found {
return nil, status.Error(codes.Internal, "pending nonces not found")
Expand Down Expand Up @@ -300,7 +314,7 @@ func (k Keeper) ListPendingCctxWithinRateLimit(
}

// query backwards for potential missed pending cctxs for each foreign chain
for _, chain := range chains {
for _, chain := range foreignChains {
// we should at least query 1000 prior to find any pending cctx that we might have missed
// this logic is needed because a confirmation of higher nonce will automatically update the p.NonceLow
// therefore might mask some lower nonce cctx that is still pending.
Expand All @@ -317,16 +331,17 @@ func (k Keeper) ListPendingCctxWithinRateLimit(
if err != nil {
return nil, err
}
inWindow := isCctxInWindow(cctx)
inWindow := isCCTXInWindow(cctx)
isOutgoing := isCCTXOutgoing(cctx)

// we should at least go backwards by 1000 nonces to pick up missed pending cctxs
// we might go even further back if rate limiter is enabled and the endNonce hasn't hit the left window boundary yet
// stop at the left window boundary if the `endNonce` hasn't hit it yet
if nonce < endNonce && !inWindow {
break
}
// skip the cctx if rate limit is exceeded but still accumulate the total withdraw value
if inWindow &&
// sum up the cctxs' value if the cctx is outgoing and within the window
if inWindow && isOutgoing &&
types.RateLimitExceeded(
chain.ChainId,
cctx,
Expand All @@ -353,7 +368,7 @@ func (k Keeper) ListPendingCctxWithinRateLimit(
missedPending := len(cctxs)

// query forwards for pending cctxs for each foreign chain
for _, chain := range chains {
for _, chain := range foreignChains {
pendingNonces := pendingNoncesMap[chain.ChainId]

// #nosec G701 always in range
Expand All @@ -365,9 +380,10 @@ func (k Keeper) ListPendingCctxWithinRateLimit(
if err != nil {
return nil, err
}
isOutgoing := isCCTXOutgoing(cctx)

// skip the cctx if rate limit is exceeded but still accumulate the total withdraw value
if types.RateLimitExceeded(
if isOutgoing && types.RateLimitExceeded(
chain.ChainId,
cctx,
gasAssetRateMap,
Expand Down
Loading

0 comments on commit fa1d060

Please sign in to comment.