Skip to content

Commit

Permalink
Merge branch 'develop' into v2-migration-test
Browse files Browse the repository at this point in the history
  • Loading branch information
swift1337 authored Aug 29, 2024
2 parents 93a7f83 + 26c4fb1 commit 1f7b29f
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 171 deletions.
2 changes: 1 addition & 1 deletion Dockerfile-localnet
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN --mount=type=cache,target="/root/.cache/go-build" make install
RUN --mount=type=cache,target="/root/.cache/go-build" make install-zetae2e

FROM ghcr.io/zeta-chain/golang:1.22.5-bookworm AS cosmovisor-build
RUN go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@v1.5.0
RUN go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@v1.6.0

FROM ghcr.io/zeta-chain/golang:1.22.5-bookworm AS base-runtime

Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

* [2615](https://github.com/zeta-chain/node/pull/2615) - Refactor cleanup of outbound trackers
* [2749](https://github.com/zeta-chain/node/pull/2749) - fix all lint errors from govet
* [2725](https://github.com/zeta-chain/node/pull/2725) - refactor SetCctxAndNonceToCctxAndInboundHashToCctx to receive tsspubkey as an argument

### Tests

Expand Down
5 changes: 0 additions & 5 deletions testutil/keeper/crosschain.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,6 @@ func MockVoteOnOutboundFailedBallot(
Once()
}

func MockGetOutbound(m *crosschainmocks.CrosschainObserverKeeper, ctx sdk.Context) {
m.On("GetTSS", ctx).Return(observertypes.TSS{}, true).Once()
}

func MockSaveOutbound(
m *crosschainmocks.CrosschainObserverKeeper,
ctx sdk.Context,
Expand All @@ -431,7 +427,6 @@ func MockSaveOutbound(
m.On("RemoveFromPendingNonces",
ctx, tss.TssPubkey, cctx.GetCurrentOutboundParam().ReceiverChainId, mock.Anything).
Return().Times(expectedNumberOfOutboundParams)
m.On("GetTSS", ctx).Return(observertypes.TSS{}, true)
}

func MockSaveOutboundNewRevertCreated(
Expand Down
9 changes: 6 additions & 3 deletions x/crosschain/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
}

// Set all the cross-chain txs
for _, elem := range genState.CrossChainTxs {
if elem != nil {
k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, *elem)
tss, found := k.GetObserverKeeper().GetTSS(ctx)
if found {
for _, elem := range genState.CrossChainTxs {
if elem != nil {
k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, *elem, tss.TssPubkey)
}
}
}
for _, elem := range genState.FinalizedInbounds {
Expand Down
14 changes: 7 additions & 7 deletions x/crosschain/keeper/cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
// 2. set the mapping inboundHash -> cctxIndex , one inboundHash can be connected to multiple cctxindex
// 3. set the mapping nonce => cctx
// 4. update the zeta accounting
func (k Keeper) SetCctxAndNonceToCctxAndInboundHashToCctx(ctx sdk.Context, cctx types.CrossChainTx) {
tss, found := k.zetaObserverKeeper.GetTSS(ctx)
if !found {
return
}
func (k Keeper) SetCctxAndNonceToCctxAndInboundHashToCctx(
ctx sdk.Context,
cctx types.CrossChainTx,
tssPubkey string,
) {
// set mapping nonce => cctxIndex
if cctx.CctxStatus.Status == types.CctxStatus_PendingOutbound ||
cctx.CctxStatus.Status == types.CctxStatus_PendingRevert {
Expand All @@ -29,15 +29,15 @@ func (k Keeper) SetCctxAndNonceToCctxAndInboundHashToCctx(ctx sdk.Context, cctx
// #nosec G115 always in range
Nonce: int64(cctx.GetCurrentOutboundParam().TssNonce),
CctxIndex: cctx.Index,
Tss: tss.TssPubkey,
Tss: tssPubkey,
})
}

k.SetCrossChainTx(ctx, cctx)
// set mapping inboundHash -> cctxIndex
in, _ := k.GetInboundHashToCctx(ctx, cctx.InboundParams.ObservedHash)
in.InboundHash = cctx.InboundParams.ObservedHash
found = false
found := false
for _, cctxIndex := range in.CctxIndex {
if cctxIndex == cctx.Index {
found = true
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/cctx_orchestrator_validate_inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (k Keeper) ValidateInbound(
if ok {
cctx.InboundParams.ObservedHash = inCctxIndex
}
k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx)
k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, tss.TssPubkey)

return &cctx, nil
}
Expand Down
74 changes: 0 additions & 74 deletions x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,80 +214,6 @@ func TestKeeper_ValidateInbound(t *testing.T) {
require.ErrorIs(t, err, types.ErrCannotFindReceiverNonce)
})

t.Run("does not set cctx if SetCctxAndNonceToCctxAndInboundHashToCctx fails", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t,
keepertest.CrosschainMockOptions{
UseObserverMock: true,
UseFungibleMock: true,
UseAuthorityMock: true,
})

// Setup mock data
observerMock := keepertest.GetCrosschainObserverMock(t, k)
authorityMock := keepertest.GetCrosschainAuthorityMock(t, k)
receiver := sample.EthAddress()
creator := sample.AccAddress()
amount := sdkmath.NewUint(42)
message := "test"
inboundBlockHeight := uint64(420)
inboundHash := sample.Hash()
gasLimit := uint64(100)
asset := "test-asset"
eventIndex := uint64(1)
cointType := coin.CoinType_ERC20
tss := sample.Tss()
receiverChain := chains.Goerli
senderChain := chains.Goerli
sender := sample.EthAddress()
tssList := sample.TssList(3)

// Set up mocks for CheckIfTSSMigrationTransfer
observerMock.On("GetAllTSS", ctx).Return(tssList)
observerMock.On("GetSupportedChainFromChainID", mock.Anything, senderChain.ChainId).Return(senderChain, true)
authorityMock.On("GetAdditionalChainList", ctx).Return([]chains.Chain{})
// setup Mocks for GetTSS
observerMock.On("GetTSS", mock.Anything).Return(tss, true).Twice()
// setup Mocks for IsInboundEnabled
observerMock.On("IsInboundEnabled", ctx).Return(true)
// setup mocks for Initiate Outbound
observerMock.On("GetChainNonces", mock.Anything, mock.Anything).
Return(observerTypes.ChainNonces{Nonce: 1}, true)
observerMock.On("GetPendingNonces", mock.Anything, mock.Anything, mock.Anything).
Return(observerTypes.PendingNonces{NonceHigh: 1}, true)
observerMock.On("SetChainNonces", mock.Anything, mock.Anything).Return(nil)
observerMock.On("SetPendingNonces", mock.Anything, mock.Anything).Return(nil)
// setup Mocks for SetCctxAndNonceToCctxAndInboundHashToCctx
observerMock.On("GetTSS", mock.Anything).Return(tss, false).Once()

k.SetGasPrice(ctx, types.GasPrice{
ChainId: senderChain.ChainId,
MedianIndex: 0,
Prices: []uint64{100},
})

// call InitiateOutbound
msg := types.MsgVoteInbound{
Creator: creator,
Sender: sender.String(),
SenderChainId: senderChain.ChainId,
Receiver: receiver.String(),
ReceiverChain: receiverChain.ChainId,
Amount: amount,
Message: message,
InboundHash: inboundHash.String(),
InboundBlockHeight: inboundBlockHeight,
GasLimit: gasLimit,
CoinType: cointType,
TxOrigin: sender.String(),
Asset: asset,
EventIndex: eventIndex,
}

_, err := k.ValidateInbound(ctx, &msg, false)
require.NoError(t, err)
require.Len(t, k.GetAllCrossChainTx(ctx), 0)
})

t.Run("fail if inbound is disabled", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t,
keepertest.CrosschainMockOptions{
Expand Down
61 changes: 40 additions & 21 deletions x/crosschain/keeper/cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func createNCctxWithStatus(
ctx sdk.Context,
n int,
status types.CctxStatus,
tssPubkey string,
) []types.CrossChainTx {
items := make([]types.CrossChainTx, n)
for i := range items {
Expand All @@ -39,13 +40,13 @@ func createNCctxWithStatus(
items[i].OutboundParams = []*types.OutboundParams{{Amount: math.ZeroUint()}}
items[i].RevertOptions = types.NewEmptyRevertOptions()

keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, items[i])
keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, items[i], tssPubkey)
}
return items
}

// Keeper Tests
func createNCctx(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.CrossChainTx {
func createNCctx(keeper *keeper.Keeper, ctx sdk.Context, n int, tssPubkey string) []types.CrossChainTx {
items := make([]types.CrossChainTx, n)
for i := range items {
items[i].Creator = "any"
Expand Down Expand Up @@ -79,10 +80,9 @@ func createNCctx(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.CrossCha

items[i].ZetaFees = math.OneUint()
items[i].Index = fmt.Sprintf("%d", i)

items[i].RevertOptions = types.NewEmptyRevertOptions()

keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, items[i])
keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, items[i], tssPubkey)
}
return items
}
Expand Down Expand Up @@ -125,24 +125,39 @@ func TestCCTXs(t *testing.T) {
keeper, ctx, _, zk := keepertest.CrosschainKeeper(t)
keeper.SetZetaAccounting(ctx, types.ZetaAccounting{AbortedZetaAmount: math.ZeroUint()})
var sends []types.CrossChainTx
zk.ObserverKeeper.SetTSS(ctx, sample.Tss())
tss := sample.Tss()
zk.ObserverKeeper.SetTSS(ctx, tss)
sends = append(
sends,
createNCctxWithStatus(
keeper,
ctx,
tt.PendingInbound,
types.CctxStatus_PendingInbound,
tss.TssPubkey,
)...)
sends = append(
sends,
createNCctxWithStatus(
keeper,
ctx,
tt.PendingOutbound,
types.CctxStatus_PendingOutbound,
tss.TssPubkey,
)...)
sends = append(
sends,
createNCctxWithStatus(keeper, ctx, tt.PendingInbound, types.CctxStatus_PendingInbound)...)
createNCctxWithStatus(keeper, ctx, tt.PendingRevert, types.CctxStatus_PendingRevert, tss.TssPubkey)...)
sends = append(
sends,
createNCctxWithStatus(keeper, ctx, tt.PendingOutbound, types.CctxStatus_PendingOutbound)...)
createNCctxWithStatus(keeper, ctx, tt.Aborted, types.CctxStatus_Aborted, tss.TssPubkey)...)
sends = append(
sends,
createNCctxWithStatus(keeper, ctx, tt.PendingRevert, types.CctxStatus_PendingRevert)...)
sends = append(sends, createNCctxWithStatus(keeper, ctx, tt.Aborted, types.CctxStatus_Aborted)...)
createNCctxWithStatus(keeper, ctx, tt.OutboundMined, types.CctxStatus_OutboundMined, tss.TssPubkey)...)
sends = append(
sends,
createNCctxWithStatus(keeper, ctx, tt.OutboundMined, types.CctxStatus_OutboundMined)...)
sends = append(sends, createNCctxWithStatus(keeper, ctx, tt.Reverted, types.CctxStatus_Reverted)...)
//require.Equal(t, tt.PendingOutbound, len(keeper.GetAllCctxByStatuses(ctx, []types.CctxStatus{types.CctxStatus_PendingOutbound})))
//require.Equal(t, tt.PendingInbound, len(keeper.GetAllCctxByStatuses(ctx, []types.CctxStatus{types.CctxStatus_PendingInbound})))
//require.Equal(t, tt.PendingOutbound+tt.PendingRevert, len(keeper.GetAllCctxByStatuses(ctx, []types.CctxStatus{types.CctxStatus_PendingOutbound, types.CctxStatus_PendingRevert})))
createNCctxWithStatus(keeper, ctx, tt.Reverted, types.CctxStatus_Reverted, tss.TssPubkey)...)

require.Equal(t, len(sends), len(keeper.GetAllCrossChainTx(ctx)))
for _, s := range sends {
send, found := keeper.GetCrossChainTx(ctx, s.Index)
Expand All @@ -156,8 +171,9 @@ func TestCCTXs(t *testing.T) {

func TestCCTXGetAll(t *testing.T) {
keeper, ctx, _, zk := keepertest.CrosschainKeeper(t)
zk.ObserverKeeper.SetTSS(ctx, sample.Tss())
items := createNCctx(keeper, ctx, 10)
tss := sample.Tss()
zk.ObserverKeeper.SetTSS(ctx, tss)
items := createNCctx(keeper, ctx, 10, tss.TssPubkey)
cctx := keeper.GetAllCrossChainTx(ctx)
c := make([]types.CrossChainTx, len(cctx))
for i, val := range cctx {
Expand All @@ -170,9 +186,10 @@ func TestCCTXGetAll(t *testing.T) {

func TestCCTXQuerySingle(t *testing.T) {
keeper, ctx, _, zk := keepertest.CrosschainKeeper(t)
zk.ObserverKeeper.SetTSS(ctx, sample.Tss())
tss := sample.Tss()
zk.ObserverKeeper.SetTSS(ctx, tss)
wctx := sdk.WrapSDKContext(ctx)
msgs := createNCctx(keeper, ctx, 2)
msgs := createNCctx(keeper, ctx, 2, tss.TssPubkey)
for _, tc := range []struct {
desc string
request *types.QueryGetCctxRequest
Expand Down Expand Up @@ -213,9 +230,10 @@ func TestCCTXQuerySingle(t *testing.T) {

func TestCCTXQueryPaginated(t *testing.T) {
keeper, ctx, _, zk := keepertest.CrosschainKeeper(t)
tss := sample.Tss()
zk.ObserverKeeper.SetTSS(ctx, sample.Tss())
wctx := sdk.WrapSDKContext(ctx)
msgs := createNCctx(keeper, ctx, 5)
msgs := createNCctx(keeper, ctx, 5, tss.TssPubkey)

request := func(next []byte, offset, limit uint64, total bool) *types.QueryAllCctxRequest {
return &types.QueryAllCctxRequest{
Expand Down Expand Up @@ -262,8 +280,9 @@ func TestCCTXQueryPaginated(t *testing.T) {

func TestKeeper_RemoveCrossChainTx(t *testing.T) {
keeper, ctx, _, zk := keepertest.CrosschainKeeper(t)
zk.ObserverKeeper.SetTSS(ctx, sample.Tss())
txs := createNCctx(keeper, ctx, 5)
tss := sample.Tss()
zk.ObserverKeeper.SetTSS(ctx, tss)
txs := createNCctx(keeper, ctx, 5, tss.TssPubkey)

keeper.RemoveCrossChainTx(ctx, txs[0].Index)
txs = keeper.GetAllCrossChainTx(ctx)
Expand Down
13 changes: 9 additions & 4 deletions x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ func TestInTxHashToCctxQueryPaginated(t *testing.T) {
})
}

func createInTxHashToCctxWithCctxs(keeper *crosschainkeeper.Keeper, ctx sdk.Context) ([]types.CrossChainTx,
func createInTxHashToCctxWithCctxs(
ctx sdk.Context,
keeper *crosschainkeeper.Keeper,
tssPubkey string,
) ([]types.CrossChainTx,
types.InboundHashToCctx) {
cctxs := make([]types.CrossChainTx, 5)
for i := range cctxs {
Expand All @@ -136,7 +140,7 @@ func createInTxHashToCctxWithCctxs(keeper *crosschainkeeper.Keeper, ctx sdk.Cont
cctxs[i].InboundParams = &types.InboundParams{ObservedHash: fmt.Sprintf("%d", i), Amount: math.OneUint()}
cctxs[i].CctxStatus = &types.Status{Status: types.CctxStatus_PendingInbound}
cctxs[i].RevertOptions = types.NewEmptyRevertOptions()
keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctxs[i])
keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctxs[i], tssPubkey)
}

var inboundHashToCctx types.InboundHashToCctx
Expand All @@ -152,9 +156,10 @@ func createInTxHashToCctxWithCctxs(keeper *crosschainkeeper.Keeper, ctx sdk.Cont
func TestKeeper_InTxHashToCctxDataQuery(t *testing.T) {
keeper, ctx, _, zk := keepertest.CrosschainKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
zk.ObserverKeeper.SetTSS(ctx, sample.Tss())
tss := sample.Tss()
zk.ObserverKeeper.SetTSS(ctx, tss)
t.Run("can query all cctxs data with in tx hash", func(t *testing.T) {
cctxs, inboundHashToCctx := createInTxHashToCctxWithCctxs(keeper, ctx)
cctxs, inboundHashToCctx := createInTxHashToCctxWithCctxs(ctx, keeper, tss.TssPubkey)
req := &types.QueryInboundHashToCctxDataRequest{
InboundHash: inboundHashToCctx.InboundHash,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (k msgServer) MigrateERC20CustodyFunds(
if err != nil {
return nil, err
}
k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx)
k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, tss.TssPubkey)

err = ctx.EventManager().EmitTypedEvent(
&types.EventERC20CustodyFundsMigration{
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/msg_server_migrate_tss_funds.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (k Keeper) initiateMigrateTSSFundsCCTX(
}
}

k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx)
k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, currentTss.TssPubkey)
k.zetaObserverKeeper.SetFundMigrator(ctx, observertypes.TssFundMigratorInfo{
ChainId: chainID,
MigrationCctxIndex: cctx.Index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (k msgServer) UpdateERC20CustodyPauseStatus(
if err != nil {
return nil, err
}
k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx)
k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, tss.TssPubkey)

err = ctx.EventManager().EmitTypedEvent(
&types.EventERC20CustodyPausing{
Expand Down
Loading

0 comments on commit 1f7b29f

Please sign in to comment.