Skip to content

Commit

Permalink
eliminate nil pending nonce issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Apr 26, 2024
1 parent 78ad7a3 commit 5827a06
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions x/crosschain/keeper/grpc_query_cctx_rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@ func (k Keeper) ListPendingCctxWithinRateLimit(c context.Context, req *types.Que
// query pending nonces for each foreign chain and get the lowest height of the pending cctxs
// Note: The pending nonces could change during the RPC call, so query them beforehand
lowestPendingCctxHeight := int64(0)
pendingNoncesMap := make(map[int64]*observertypes.PendingNonces)
pendingNoncesMap := make(map[int64]observertypes.PendingNonces)
for _, chain := range chains {
pendingNonces, found := k.GetObserverKeeper().GetPendingNonces(ctx, tss.TssPubkey, chain.ChainId)
if !found {
return nil, status.Error(codes.Internal, "pending nonces not found")
}
pendingNoncesMap[chain.ChainId] = pendingNonces

// insert pending nonces and update lowest height
if pendingNonces.NonceLow < pendingNonces.NonceHigh {
pendingNoncesMap[chain.ChainId] = &pendingNonces
cctx, err := getCctxByChainIDAndNonce(k, ctx, tss.TssPubkey, chain.ChainId, pendingNonces.NonceLow)
if err != nil {
return nil, err
Expand Down Expand Up @@ -149,11 +149,6 @@ func (k Keeper) ListPendingCctxWithinRateLimit(c context.Context, req *types.Que
// 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.
pendingNonces := pendingNoncesMap[chain.ChainId]

if pendingNonces == nil {
continue
}

startNonce := pendingNonces.NonceLow - 1
endNonce := pendingNonces.NonceLow - MaxLookbackNonce
if endNonce < 0 {
Expand Down Expand Up @@ -195,16 +190,12 @@ func (k Keeper) ListPendingCctxWithinRateLimit(c context.Context, req *types.Que

// query forwards for pending cctxs for each foreign chain
for _, chain := range chains {
// query the pending cctxs in range [NonceLow, NonceHigh)
pendingNonces := pendingNoncesMap[chain.ChainId]

if pendingNonces == nil {
continue
}

// #nosec G701 always in range
// #nosec G701 always in range
totalPending += uint64(pendingNonces.NonceHigh - pendingNonces.NonceLow)

// query the pending cctxs in range [NonceLow, NonceHigh)
for nonce := pendingNonces.NonceLow; nonce < pendingNonces.NonceHigh; nonce++ {
cctx, err := getCctxByChainIDAndNonce(k, ctx, tss.TssPubkey, chain.ChainId, nonce)
if err != nil {
Expand Down

0 comments on commit 5827a06

Please sign in to comment.