Skip to content

Commit

Permalink
Merge pull request #2897 from zeta-chain/v20-0-2-backports
Browse files Browse the repository at this point in the history
chore: backport changes for v20.0.2
  • Loading branch information
gartnera authored Sep 18, 2024
2 parents 102b872 + 0fdbfff commit c05a91c
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/ticker/ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ package ticker
import (
"context"
"fmt"
"runtime/debug"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -78,7 +80,14 @@ func SecondsFromUint64(d uint64) time.Duration {
func (t *Ticker) Run(ctx context.Context) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic during ticker run: %v", r)
stack := string(debug.Stack())
lines := strings.Split(stack, "\n")
line := ""
// 8th line should be the actual line, see the unit tests
if len(lines) > 8 {
line = strings.TrimSpace(lines[8])
}
err = fmt.Errorf("panic during ticker run: %v at %s", r, line)
}
}()

Expand Down
27 changes: 27 additions & 0 deletions pkg/ticker/ticker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,33 @@ func TestTicker(t *testing.T) {

// ASSERT
assert.ErrorContains(t, err, "panic during ticker run: oops")
// assert that we get error with the correct line number
assert.ErrorContains(t, err, "ticker_test.go:142")
})

t.Run("Nil panic", func(t *testing.T) {
// ARRANGE
// Given a context
ctx := context.Background()

// And a ticker
ticker := New(durSmall, func(_ context.Context, _ *Ticker) error {
var a func()
a()
return nil
})

// ACT
err := ticker.Run(ctx)

// ASSERT
assert.ErrorContains(
t,
err,
"panic during ticker run: runtime error: invalid memory address or nil pointer dereference",
)
// assert that we get error with the correct line number
assert.ErrorContains(t, err, "ticker_test.go:162")
})

t.Run("Run as a single call", func(t *testing.T) {
Expand Down
9 changes: 9 additions & 0 deletions x/crosschain/keeper/grpc_query_cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (

// MaxLookbackNonce is the maximum number of nonces to look back to find missed pending cctxs
MaxLookbackNonce = 1000

DefaultPageSize = 100
)

func (k Keeper) ZetaAccounting(
Expand All @@ -46,6 +48,13 @@ func (k Keeper) CctxAll(c context.Context, req *types.QueryAllCctxRequest) (*typ
store := ctx.KVStore(k.storeKey)
sendStore := prefix.NewStore(store, types.KeyPrefix(types.CCTXKey))

if req.Pagination == nil {
req.Pagination = &query.PageRequest{}
}
if req.Pagination.Limit == 0 {
req.Pagination.Limit = DefaultPageSize
}

pageRes, err := query.Paginate(sendStore, req.Pagination, func(_ []byte, value []byte) error {
var send types.CrossChainTx
if err := k.cdc.Unmarshal(value, &send); err != nil {
Expand Down
38 changes: 38 additions & 0 deletions x/crosschain/keeper/grpc_query_cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/stretchr/testify/require"

keepertest "github.com/zeta-chain/zetacore/testutil/keeper"
Expand Down Expand Up @@ -288,3 +289,40 @@ func TestKeeper_CctxByNonce(t *testing.T) {
require.Equal(t, res.CrossChainTx.CctxStatus.LastUpdateTimestamp, ctx.BlockTime().Unix())
})
}

func TestKeeper_CctxAll(t *testing.T) {
t.Run("empty request", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
_, err := k.CctxAll(ctx, &types.QueryAllCctxRequest{})
require.NoError(t, err)
})

t.Run("default page size", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)
chainID := getValidEthChainID()
tss := sample.Tss()
zk.ObserverKeeper.SetTSS(ctx, tss)
_ = createCctxWithNonceRange(t, ctx, *k, 1000, 2000, chainID, tss, zk)

res, err := k.CctxAll(ctx, &types.QueryAllCctxRequest{})
require.NoError(t, err)
require.Len(t, res.CrossChainTx, keeper.DefaultPageSize)
})

t.Run("page size provided", func(t *testing.T) {
k, ctx, _, zk := keepertest.CrosschainKeeper(t)
chainID := getValidEthChainID()
tss := sample.Tss()
zk.ObserverKeeper.SetTSS(ctx, tss)
_ = createCctxWithNonceRange(t, ctx, *k, 1000, 2000, chainID, tss, zk)
testPageSize := 200

res, err := k.CctxAll(ctx, &types.QueryAllCctxRequest{
Pagination: &query.PageRequest{
Limit: uint64(testPageSize),
},
})
require.NoError(t, err)
require.Len(t, res.CrossChainTx, testPageSize)
})
}
3 changes: 3 additions & 0 deletions zetaclient/chains/evm/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ func (ob *Observer) BlockByNumber(blockNumber int) (*ethrpc.Block, error) {
if err != nil {
return nil, err
}
if block == nil {
return nil, fmt.Errorf("block not found: %d", blockNumber)
}
for i := range block.Transactions {
err := evm.ValidateEvmTransaction(&block.Transactions[i])
if err != nil {
Expand Down

0 comments on commit c05a91c

Please sign in to comment.