From 85b7b92228e5a2c3672d0f5b1f9db42c7e5499eb Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 15 Aug 2024 11:33:53 -0400 Subject: [PATCH 01/10] refactor to using tss pubkey as a argument in SetCctxAndNonceToCctxAndInboundHashToCctx --- testutil/keeper/crosschain.go | 6 +- x/crosschain/genesis.go | 9 +- x/crosschain/keeper/cctx.go | 15 +- .../cctx_orchestrator_validate_inbound.go | 4 +- ...cctx_orchestrator_validate_inbound_test.go | 146 +++++++++--------- x/crosschain/keeper/cctx_test.go | 44 ++++-- .../grpc_query_inbound_hash_to_cctx_test.go | 11 +- .../msg_server_migrate_erc20_custody_funds.go | 5 +- .../keeper/msg_server_migrate_tss_funds.go | 4 +- .../keeper/msg_server_vote_outbound_tx.go | 38 +++-- .../msg_server_vote_outbound_tx_test.go | 104 ++++++++----- .../keeper/msg_server_whitelist_erc20.go | 5 +- 12 files changed, 226 insertions(+), 165 deletions(-) diff --git a/testutil/keeper/crosschain.go b/testutil/keeper/crosschain.go index d12e4e37f9..1351048a2d 100644 --- a/testutil/keeper/crosschain.go +++ b/testutil/keeper/crosschain.go @@ -386,10 +386,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, @@ -400,7 +396,7 @@ func MockSaveOutbound( m.On("RemoveFromPendingNonces", ctx, tss.TssPubkey, cctx.GetCurrentOutboundParam().ReceiverChainId, mock.Anything). Return().Times(expectedNumberOfOutboundParams) - m.On("GetTSS", ctx).Return(observertypes.TSS{}, true) + //m.On("GetTSS", ctx).Return(observertypes.TSS{}, true) } func MockSaveOutboundNewRevertCreated( diff --git a/x/crosschain/genesis.go b/x/crosschain/genesis.go index 6a1fe1ed58..715d01c44a 100644 --- a/x/crosschain/genesis.go +++ b/x/crosschain/genesis.go @@ -2,7 +2,6 @@ package crosschain import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/zeta-chain/zetacore/x/crosschain/keeper" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -45,7 +44,13 @@ 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) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, *elem, func(ctx sdk.Context) string { + tss, found := k.GetObserverKeeper().GetTSS(ctx) + if !found { + return "" + } + return tss.TssPubkey + }) } } for _, elem := range genState.FinalizedInbounds { diff --git a/x/crosschain/keeper/cctx.go b/x/crosschain/keeper/cctx.go index 306df6979b..60c1a56048 100644 --- a/x/crosschain/keeper/cctx.go +++ b/x/crosschain/keeper/cctx.go @@ -16,12 +16,13 @@ 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, tssFunc func(ctx sdk.Context) string) { + //tss, found := k.zetaObserverKeeper.GetTSS(ctx) + //if !found { + // return + //} // set mapping nonce => cctxIndex + tssPubkey := tssFunc(ctx) if cctx.CctxStatus.Status == types.CctxStatus_PendingOutbound || cctx.CctxStatus.Status == types.CctxStatus_PendingRevert { k.GetObserverKeeper().SetNonceToCctx(ctx, observerTypes.NonceToCctx{ @@ -29,7 +30,7 @@ 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, }) } @@ -37,7 +38,7 @@ func (k Keeper) SetCctxAndNonceToCctxAndInboundHashToCctx(ctx sdk.Context, 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 diff --git a/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go b/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go index 4cda69a5c3..dea6b9f6f9 100644 --- a/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go +++ b/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go @@ -51,7 +51,9 @@ func (k Keeper) ValidateInbound( if ok { cctx.InboundParams.ObservedHash = inCctxIndex } - k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, func(ctx sdk.Context) string { + return tss.TssPubkey + }) return &cctx, nil } diff --git a/x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go b/x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go index bbd4530484..d509b68b99 100644 --- a/x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go +++ b/x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go @@ -214,79 +214,79 @@ 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("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).Once() + // // 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, diff --git a/x/crosschain/keeper/cctx_test.go b/x/crosschain/keeper/cctx_test.go index 647016849e..ab3c9b374f 100644 --- a/x/crosschain/keeper/cctx_test.go +++ b/x/crosschain/keeper/cctx_test.go @@ -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 { @@ -38,13 +39,15 @@ func createNCctxWithStatus( items[i].InboundParams = &types.InboundParams{ObservedHash: fmt.Sprintf("%d", i), Amount: math.OneUint()} items[i].OutboundParams = []*types.OutboundParams{{Amount: math.ZeroUint()}} - keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, items[i]) + keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, items[i], func(ctx sdk.Context) string { + return 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" @@ -79,7 +82,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) - keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, items[i]) + keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, items[i], func(ctx sdk.Context) string { + return tssPubkey + }) } return items } @@ -122,21 +127,22 @@ 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)...) + createNCctxWithStatus(keeper, ctx, tt.PendingInbound, types.CctxStatus_PendingInbound, tss.TssPubkey)...) sends = append( sends, - createNCctxWithStatus(keeper, ctx, tt.PendingOutbound, types.CctxStatus_PendingOutbound)...) + createNCctxWithStatus(keeper, ctx, tt.PendingOutbound, types.CctxStatus_PendingOutbound, 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.PendingRevert, types.CctxStatus_PendingRevert, tss.TssPubkey)...) + sends = append(sends, createNCctxWithStatus(keeper, ctx, tt.Aborted, types.CctxStatus_Aborted, tss.TssPubkey)...) sends = append( sends, - createNCctxWithStatus(keeper, ctx, tt.OutboundMined, types.CctxStatus_OutboundMined)...) - sends = append(sends, createNCctxWithStatus(keeper, ctx, tt.Reverted, types.CctxStatus_Reverted)...) + createNCctxWithStatus(keeper, ctx, tt.OutboundMined, types.CctxStatus_OutboundMined, tss.TssPubkey)...) + sends = append(sends, createNCctxWithStatus(keeper, ctx, tt.Reverted, types.CctxStatus_Reverted, tss.TssPubkey)...) //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}))) @@ -153,8 +159,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 { @@ -167,9 +174,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 @@ -210,9 +218,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{ @@ -259,8 +268,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) diff --git a/x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go b/x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go index f1b2862520..a647bd3822 100644 --- a/x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go +++ b/x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go @@ -126,7 +126,7 @@ 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 { @@ -135,7 +135,9 @@ func createInTxHashToCctxWithCctxs(keeper *crosschainkeeper.Keeper, ctx sdk.Cont cctxs[i].ZetaFees = math.OneUint() cctxs[i].InboundParams = &types.InboundParams{ObservedHash: fmt.Sprintf("%d", i), Amount: math.OneUint()} cctxs[i].CctxStatus = &types.Status{Status: types.CctxStatus_PendingInbound} - keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctxs[i]) + keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctxs[i], func(ctx sdk.Context) string { + return tssPubkey + }) } var inboundHashToCctx types.InboundHashToCctx @@ -151,9 +153,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, } diff --git a/x/crosschain/keeper/msg_server_migrate_erc20_custody_funds.go b/x/crosschain/keeper/msg_server_migrate_erc20_custody_funds.go index 56bc0a5ea1..b4edc3b2f7 100644 --- a/x/crosschain/keeper/msg_server_migrate_erc20_custody_funds.go +++ b/x/crosschain/keeper/msg_server_migrate_erc20_custody_funds.go @@ -5,7 +5,6 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -83,7 +82,9 @@ func (k msgServer) MigrateERC20CustodyFunds( if err != nil { return nil, err } - k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, func(ctx sdk.Context) string { + return tss.TssPubkey + }) err = ctx.EventManager().EmitTypedEvent( &types.EventERC20CustodyFundsMigration{ diff --git a/x/crosschain/keeper/msg_server_migrate_tss_funds.go b/x/crosschain/keeper/msg_server_migrate_tss_funds.go index 7d48b48cdb..e442cb7b6b 100644 --- a/x/crosschain/keeper/msg_server_migrate_tss_funds.go +++ b/x/crosschain/keeper/msg_server_migrate_tss_funds.go @@ -128,7 +128,9 @@ func (k Keeper) initiateMigrateTSSFundsCCTX( } } - k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, func(ctx sdk.Context) string { + return currentTss.TssPubkey + }) k.zetaObserverKeeper.SetFundMigrator(ctx, observertypes.TssFundMigratorInfo{ ChainId: chainID, MigrationCctxIndex: cctx.Index, diff --git a/x/crosschain/keeper/msg_server_vote_outbound_tx.go b/x/crosschain/keeper/msg_server_vote_outbound_tx.go index 3da780ccc1..04181ecf09 100644 --- a/x/crosschain/keeper/msg_server_vote_outbound_tx.go +++ b/x/crosschain/keeper/msg_server_vote_outbound_tx.go @@ -63,6 +63,16 @@ func (k msgServer) VoteOutbound( ) (*types.MsgVoteOutboundResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + // Check TSS exists + // It is almost impossible to reach this point without a TSS, + // as the check for TSS was already done when creating the inbound, but we check anyway. + // We also expect the tss.Pubkey to be the same as the one in the outbound params, + // As we would have processed all CCTXs before migrating + tss, found := k.zetaObserverKeeper.GetTSS(ctx) + if !found { + return nil, cosmoserrors.Wrap(types.ErrCannotFindTSSKeys, voteOutboundID) + } + // Validate the message params to verify it against an existing CCTX. cctx, err := k.ValidateOutboundMessage(ctx, *msg) if err != nil { @@ -92,6 +102,7 @@ func (k msgServer) VoteOutbound( // Set the finalized ballot to the current outbound params. cctx.SetOutboundBallotIndex(ballotIndex) + // If ballot is successful, the value received should be the out tx amount. err = cctx.AddOutbound(ctx, *msg, ballot.BallotStatus) if err != nil { @@ -101,13 +112,13 @@ func (k msgServer) VoteOutbound( // Fund the gas stability pool with the remaining funds. k.FundStabilityPool(ctx, &cctx) + // We use the current TSS pubkey to finalize the outbound. err = k.ValidateOutboundObservers(ctx, &cctx, ballot.BallotStatus, msg.ValueReceived.String()) if err != nil { - k.SaveFailedOutbound(ctx, &cctx, err.Error()) + k.SaveFailedOutbound(ctx, &cctx, err.Error(), tss.TssPubkey) return &types.MsgVoteOutboundResponse{}, nil } - - k.SaveSuccessfulOutbound(ctx, &cctx) + k.SaveSuccessfulOutbound(ctx, &cctx, tss.TssPubkey) return &types.MsgVoteOutboundResponse{}, nil } @@ -173,17 +184,17 @@ SaveFailedOutbound saves a failed outbound transaction.It does the following thi 2. Save the outbound */ -func (k Keeper) SaveFailedOutbound(ctx sdk.Context, cctx *types.CrossChainTx, errMessage string) { +func (k Keeper) SaveFailedOutbound(ctx sdk.Context, cctx *types.CrossChainTx, errMessage string, tssPubkey string) { cctx.SetAbort(errMessage) ctx.Logger().Error(errMessage) - k.SaveOutbound(ctx, cctx) + k.SaveOutbound(ctx, cctx, tssPubkey) } // SaveSuccessfulOutbound saves a successful outbound transaction. // This function does not set the CCTX status, therefore all successful outbound transactions need // to have their status set during processing -func (k Keeper) SaveSuccessfulOutbound(ctx sdk.Context, cctx *types.CrossChainTx) { - k.SaveOutbound(ctx, cctx) +func (k Keeper) SaveSuccessfulOutbound(ctx sdk.Context, cctx *types.CrossChainTx, tssPubkey string) { + k.SaveOutbound(ctx, cctx, tssPubkey) } /* @@ -197,16 +208,17 @@ SaveOutbound saves the outbound transaction.It does the following things in one 4. Set the cctx and nonce to cctx and inboundHash to cctx */ -func (k Keeper) SaveOutbound(ctx sdk.Context, cctx *types.CrossChainTx) { +func (k Keeper) SaveOutbound(ctx sdk.Context, cctx *types.CrossChainTx, tssPubkey string) { // #nosec G115 always in range for _, outboundParams := range cctx.OutboundParams { k.GetObserverKeeper(). RemoveFromPendingNonces(ctx, outboundParams.TssPubkey, outboundParams.ReceiverChainId, int64(outboundParams.TssNonce)) k.RemoveOutboundTrackerFromStore(ctx, outboundParams.ReceiverChainId, outboundParams.TssNonce) } - // This should set nonce to cctx only if a new revert is created. - k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, *cctx) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, *cctx, func(ctx sdk.Context) string { + return tssPubkey + }) } func (k Keeper) ValidateOutboundMessage(ctx sdk.Context, msg types.MsgVoteOutbound) (types.CrossChainTx, error) { @@ -228,12 +240,6 @@ func (k Keeper) ValidateOutboundMessage(ctx sdk.Context, msg types.MsgVoteOutbou ) } - // Do not process an outbound vote if TSS is not found. - _, found = k.zetaObserverKeeper.GetTSS(ctx) - if !found { - return types.CrossChainTx{}, cosmoserrors.Wrap(types.ErrCannotFindTSSKeys, voteOutboundID) - } - if cctx.GetCurrentOutboundParam().ReceiverChainId != msg.OutboundChain { return types.CrossChainTx{}, cosmoserrors.Wrapf( sdkerrors.ErrInvalidRequest, diff --git a/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go b/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go index 0ac0d817ba..13ecdc672e 100644 --- a/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go +++ b/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go @@ -146,9 +146,6 @@ func TestKeeper_VoteOutbound(t *testing.T) { // Successfully mock VoteOnOutboundBallot keepertest.MockVoteOnOutboundSuccessBallot(observerMock, ctx, cctx, senderChain, observer) - // Successfully mock GetOutbound - keepertest.MockGetOutbound(observerMock, ctx) - // Successfully mock SaveSuccessfulOutbound expectedNumberOfOutboundParams := 1 keepertest.MockSaveOutbound(observerMock, ctx, cctx, tss, expectedNumberOfOutboundParams) @@ -176,6 +173,44 @@ func TestKeeper_VoteOutbound(t *testing.T) { require.Len(t, c.OutboundParams, expectedNumberOfOutboundParams) }) + t.Run("vote on outbound tx fails if tss is not found", func(t *testing.T) { + k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseObserverMock: true, + }) + + // Setup mock data + observerMock := keepertest.GetCrosschainObserverMock(t, k) + receiver := sample.EthAddress() + amount := big.NewInt(42) + senderChain := getValidEthChain() + asset := "" + observer := sample.AccAddress() + tss := sample.Tss() + zk.ObserverKeeper.SetObserverSet(ctx, observertypes.ObserverSet{ObserverList: []string{observer}}) + cctx := GetERC20Cctx(t, receiver, senderChain, asset, amount) + cctx.GetCurrentOutboundParam().TssPubkey = tss.TssPubkey + cctx.CctxStatus.Status = types.CctxStatus_PendingOutbound + k.SetCrossChainTx(ctx, *cctx) + observerMock.On("GetTSS", ctx).Return(observertypes.TSS{}, false).Once() + + msgServer := keeper.NewMsgServerImpl(*k) + msg := types.MsgVoteOutbound{ + CctxHash: cctx.Index, + OutboundTssNonce: cctx.GetCurrentOutboundParam().TssNonce, + OutboundChain: cctx.GetCurrentOutboundParam().ReceiverChainId, + Status: chains.ReceiveStatus_success, + Creator: observer, + ObservedOutboundHash: sample.Hash().String(), + ValueReceived: cctx.GetCurrentOutboundParam().Amount, + ObservedOutboundBlockHeight: 10, + ObservedOutboundEffectiveGasPrice: math.NewInt(21), + ObservedOutboundGasUsed: 21, + CoinType: cctx.InboundParams.CoinType, + } + _, err := msgServer.VoteOutbound(ctx, &msg) + require.ErrorIs(t, err, types.ErrCannotFindTSSKeys) + }) + t.Run("successfully vote on outbound tx, vote-type failed", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseObserverMock: true, @@ -201,9 +236,6 @@ func TestKeeper_VoteOutbound(t *testing.T) { // Successfully mock VoteOnOutboundBallot keepertest.MockVoteOnOutboundFailedBallot(observerMock, ctx, cctx, senderChain, observer) - // Successfully mock GetOutbound - keepertest.MockGetOutbound(observerMock, ctx) - // Successfully mock ProcessOutbound keepertest.MockGetRevertGasLimitForERC20(fungibleMock, asset, senderChain, 100) keepertest.MockPayGasAndUpdateCCTX(fungibleMock, observerMock, ctx, *k, senderChain, asset) @@ -264,9 +296,6 @@ func TestKeeper_VoteOutbound(t *testing.T) { // Successfully mock VoteOnOutboundBallot keepertest.MockVoteOnOutboundFailedBallot(observerMock, ctx, cctx, senderChain, observer) - // Successfully mock GetOutbound - keepertest.MockGetOutbound(observerMock, ctx) - // Mock Failed ProcessOutbound keepertest.MockGetRevertGasLimitForERC20(fungibleMock, asset, senderChain, 100) keepertest.MockPayGasAndUpdateCCTX(fungibleMock, observerMock, ctx, *k, senderChain, asset) @@ -334,9 +363,6 @@ func TestKeeper_VoteOutbound(t *testing.T) { // Successfully mock VoteOnOutboundBallot keepertest.MockVoteOnOutboundFailedBallot(observerMock, ctx, cctx, senderChain, observer) - // Successfully mock GetOutbound - keepertest.MockGetOutbound(observerMock, ctx) - // Fail ProcessOutbound so that changes are not committed to the state fungibleMock.On("GetForeignCoinFromAsset", mock.Anything, mock.Anything, mock.Anything). Return(fungibletypes.ForeignCoins{}, false) @@ -472,6 +498,7 @@ func TestKeeper_VoteOutbound(t *testing.T) { func TestKeeper_SaveFailedOutbound(t *testing.T) { t.Run("successfully save failed outbound", func(t *testing.T) { + //ARRANGE k, ctx, _, _ := keepertest.CrosschainKeeper(t) cctx := sample.CrossChainTx(t, "test") k.SetOutboundTracker(ctx, types.OutboundTracker{ @@ -481,7 +508,11 @@ func TestKeeper_SaveFailedOutbound(t *testing.T) { HashList: nil, }) cctx.CctxStatus.Status = types.CctxStatus_PendingOutbound - k.SaveFailedOutbound(ctx, cctx, sample.String()) + + //ACT + k.SaveFailedOutbound(ctx, cctx, sample.String(), sample.Tss().TssPubkey) + + //ASSERT require.Equal(t, cctx.CctxStatus.Status, types.CctxStatus_Aborted) _, found := k.GetOutboundTracker( ctx, @@ -492,6 +523,7 @@ func TestKeeper_SaveFailedOutbound(t *testing.T) { }) t.Run("successfully save failed outbound with multiple trackers", func(t *testing.T) { + //ARRANGE k, ctx, _, _ := keepertest.CrosschainKeeper(t) cctx := sample.CrossChainTx(t, "test") for _, outboundParams := range cctx.OutboundParams { @@ -503,9 +535,12 @@ func TestKeeper_SaveFailedOutbound(t *testing.T) { }) } cctx.CctxStatus.Status = types.CctxStatus_PendingOutbound - k.SaveFailedOutbound(ctx, cctx, sample.String()) - require.Equal(t, cctx.CctxStatus.Status, types.CctxStatus_Aborted) + //ACT + k.SaveFailedOutbound(ctx, cctx, sample.String(), sample.Tss().TssPubkey) + + //ASSERT + require.Equal(t, cctx.CctxStatus.Status, types.CctxStatus_Aborted) for _, outboundParams := range cctx.OutboundParams { _, found := k.GetOutboundTracker( ctx, @@ -514,12 +549,12 @@ func TestKeeper_SaveFailedOutbound(t *testing.T) { ) require.False(t, found) } - }) } func TestKeeper_SaveSuccessfulOutbound(t *testing.T) { t.Run("successfully save successful outbound", func(t *testing.T) { + //ARRANGE k, ctx, _, _ := keepertest.CrosschainKeeper(t) cctx := sample.CrossChainTx(t, "test") k.SetOutboundTracker(ctx, types.OutboundTracker{ @@ -529,8 +564,11 @@ func TestKeeper_SaveSuccessfulOutbound(t *testing.T) { HashList: nil, }) cctx.CctxStatus.Status = types.CctxStatus_PendingOutbound - k.SaveSuccessfulOutbound(ctx, cctx) + //ACT + k.SaveSuccessfulOutbound(ctx, cctx, sample.Tss().TssPubkey) + + //ASSERT _, found := k.GetOutboundTracker( ctx, cctx.GetCurrentOutboundParam().ReceiverChainId, @@ -540,6 +578,7 @@ func TestKeeper_SaveSuccessfulOutbound(t *testing.T) { }) t.Run("successfully save successful outbound with multiple trackers", func(t *testing.T) { + //ARRANGE k, ctx, _, _ := keepertest.CrosschainKeeper(t) cctx := sample.CrossChainTx(t, "test") for _, outboundParams := range cctx.OutboundParams { @@ -551,8 +590,11 @@ func TestKeeper_SaveSuccessfulOutbound(t *testing.T) { }) } cctx.CctxStatus.Status = types.CctxStatus_PendingOutbound - k.SaveSuccessfulOutbound(ctx, cctx) + //ACT + k.SaveSuccessfulOutbound(ctx, cctx, sample.Tss().TssPubkey) + + //ASSERT for _, outboundParams := range cctx.OutboundParams { _, found := k.GetOutboundTracker( ctx, @@ -566,8 +608,8 @@ func TestKeeper_SaveSuccessfulOutbound(t *testing.T) { func TestKeeper_SaveOutbound(t *testing.T) { t.Run("successfully save outbound", func(t *testing.T) { + //ARRANGE k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // setup state for crosschain and observer modules cctx := sample.CrossChainTx(t, "test") cctx.CctxStatus.Status = types.CctxStatus_PendingOutbound @@ -577,7 +619,6 @@ func TestKeeper_SaveOutbound(t *testing.T) { Nonce: cctx.GetCurrentOutboundParam().TssNonce, HashList: nil, }) - zk.ObserverKeeper.SetPendingNonces(ctx, observertypes.PendingNonces{ NonceLow: int64(cctx.GetCurrentOutboundParam().TssNonce) - 1, NonceHigh: int64(cctx.GetCurrentOutboundParam().TssNonce) + 1, @@ -588,8 +629,11 @@ func TestKeeper_SaveOutbound(t *testing.T) { TssPubkey: cctx.GetCurrentOutboundParam().TssPubkey, }) + //ACT // Save outbound and assert all values are successfully saved - k.SaveOutbound(ctx, cctx) + k.SaveOutbound(ctx, cctx, cctx.GetCurrentOutboundParam().TssPubkey) + + //ASSERT _, found := k.GetOutboundTracker( ctx, cctx.GetCurrentOutboundParam().ReceiverChainId, @@ -616,8 +660,8 @@ func TestKeeper_SaveOutbound(t *testing.T) { }) t.Run("successfully save outbound with multiple trackers", func(t *testing.T) { + //ARRANGE k, ctx, _, zk := keepertest.CrosschainKeeper(t) - // setup state for crosschain and observer modules cctx := sample.CrossChainTx(t, "test") for _, outboundParams := range cctx.OutboundParams { @@ -635,15 +679,16 @@ func TestKeeper_SaveOutbound(t *testing.T) { }) } cctx.CctxStatus.Status = types.CctxStatus_PendingRevert - tssPubkey := cctx.GetCurrentOutboundParam().TssPubkey zk.ObserverKeeper.SetTSS(ctx, observertypes.TSS{ TssPubkey: tssPubkey, }) + //ACT // Save outbound and assert all values are successfully saved - k.SaveOutbound(ctx, cctx) + k.SaveOutbound(ctx, cctx, cctx.GetCurrentOutboundParam().TssPubkey) + //ASSERT for _, outboundParams := range cctx.OutboundParams { _, found := k.GetOutboundTracker( ctx, @@ -717,17 +762,6 @@ func TestKeeper_ValidateOutboundMessage(t *testing.T) { ) }) - t.Run("failed to validate outbound message if tss not found", func(t *testing.T) { - k, ctx, _, _ := keepertest.CrosschainKeeper(t) - cctx := sample.CrossChainTx(t, "test") - k.SetCrossChainTx(ctx, *cctx) - _, err := k.ValidateOutboundMessage(ctx, types.MsgVoteOutbound{ - CctxHash: cctx.Index, - OutboundTssNonce: cctx.GetCurrentOutboundParam().TssNonce, - }) - require.ErrorIs(t, err, types.ErrCannotFindTSSKeys) - }) - t.Run("failed to validate outbound message if chain does not match", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) cctx := sample.CrossChainTx(t, "test") diff --git a/x/crosschain/keeper/msg_server_whitelist_erc20.go b/x/crosschain/keeper/msg_server_whitelist_erc20.go index 45cf836061..2a921f1dcf 100644 --- a/x/crosschain/keeper/msg_server_whitelist_erc20.go +++ b/x/crosschain/keeper/msg_server_whitelist_erc20.go @@ -8,7 +8,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/zeta-chain/zetacore/pkg/coin" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -154,7 +153,9 @@ func (k msgServer) WhitelistERC20( GasLimit: uint64(msg.GasLimit), } k.fungibleKeeper.SetForeignCoins(ctx, foreignCoin) - k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, func(ctx sdk.Context) string { + return tss.TssPubkey + }) commit() From 16254e96086a6ff3ea237585b6c80a3df49bbb80 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 15 Aug 2024 17:05:20 -0400 Subject: [PATCH 02/10] add changelog --- changelog.md | 4 +- testutil/keeper/crosschain.go | 1 - x/crosschain/genesis.go | 13 ++-- x/crosschain/keeper/cctx.go | 10 +-- ...cctx_orchestrator_validate_inbound_test.go | 74 ------------------- x/crosschain/keeper/cctx_test.go | 24 +++++- .../grpc_query_inbound_hash_to_cctx_test.go | 6 +- .../msg_server_migrate_erc20_custody_funds.go | 1 + .../keeper/msg_server_vote_outbound_tx.go | 2 +- .../keeper/msg_server_whitelist_erc20.go | 1 + 10 files changed, 42 insertions(+), 94 deletions(-) diff --git a/changelog.md b/changelog.md index f255139f81..8af7b278ba 100644 --- a/changelog.md +++ b/changelog.md @@ -10,15 +10,17 @@ * [2634](https://github.com/zeta-chain/node/pull/2634) - add support for EIP-1559 gas fees * [2597](https://github.com/zeta-chain/node/pull/2597) - Add generic rpc metrics to zetaclient * [2538](https://github.com/zeta-chain/node/pull/2538) - add background worker routines to shutdown zetaclientd when needed for tss migration -* [2644](https://github.com/zeta-chain/node/pull/2644) - add created_timestamp to cctx status + ### Refactor * [2615](https://github.com/zeta-chain/node/pull/2615) - Refactor cleanup of outbound trackers +* [2644](https://github.com/zeta-chain/node/pull/2644) - refactor SetCctxAndNonceToCctxAndInboundHashToCctx receive tsspubkey as an argument ### Fixes * [2654](https://github.com/zeta-chain/node/pull/2654) - add validation for authorization list in when validating genesis state for authorization module +* [2725](https://github.com/zeta-chain/node/pull/2725) - ## v19.0.0 diff --git a/testutil/keeper/crosschain.go b/testutil/keeper/crosschain.go index 1351048a2d..013d7aea21 100644 --- a/testutil/keeper/crosschain.go +++ b/testutil/keeper/crosschain.go @@ -396,7 +396,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( diff --git a/x/crosschain/genesis.go b/x/crosschain/genesis.go index 715d01c44a..608c53c71c 100644 --- a/x/crosschain/genesis.go +++ b/x/crosschain/genesis.go @@ -44,13 +44,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, func(ctx sdk.Context) string { - tss, found := k.GetObserverKeeper().GetTSS(ctx) - if !found { - return "" - } - return tss.TssPubkey - }) + tss, found := k.GetObserverKeeper().GetTSS(ctx) + if found { + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, *elem, func(ctx sdk.Context) string { + return tss.TssPubkey + }) + } } } for _, elem := range genState.FinalizedInbounds { diff --git a/x/crosschain/keeper/cctx.go b/x/crosschain/keeper/cctx.go index 60c1a56048..2ebe22e31f 100644 --- a/x/crosschain/keeper/cctx.go +++ b/x/crosschain/keeper/cctx.go @@ -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, tssFunc func(ctx sdk.Context) string) { - //tss, found := k.zetaObserverKeeper.GetTSS(ctx) - //if !found { - // return - //} +func (k Keeper) SetCctxAndNonceToCctxAndInboundHashToCctx( + ctx sdk.Context, + cctx types.CrossChainTx, + tssFunc func(ctx sdk.Context) string, +) { // set mapping nonce => cctxIndex tssPubkey := tssFunc(ctx) if cctx.CctxStatus.Status == types.CctxStatus_PendingOutbound || diff --git a/x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go b/x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go index d509b68b99..fd798998c0 100644 --- a/x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go +++ b/x/crosschain/keeper/cctx_orchestrator_validate_inbound_test.go @@ -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).Once() - // // 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{ diff --git a/x/crosschain/keeper/cctx_test.go b/x/crosschain/keeper/cctx_test.go index ab3c9b374f..0a99a1a674 100644 --- a/x/crosschain/keeper/cctx_test.go +++ b/x/crosschain/keeper/cctx_test.go @@ -131,18 +131,34 @@ func TestCCTXs(t *testing.T) { zk.ObserverKeeper.SetTSS(ctx, tss) sends = append( sends, - createNCctxWithStatus(keeper, ctx, tt.PendingInbound, types.CctxStatus_PendingInbound, tss.TssPubkey)...) + createNCctxWithStatus( + keeper, + ctx, + tt.PendingInbound, + types.CctxStatus_PendingInbound, + tss.TssPubkey, + )...) sends = append( sends, - createNCctxWithStatus(keeper, ctx, tt.PendingOutbound, types.CctxStatus_PendingOutbound, tss.TssPubkey)...) + createNCctxWithStatus( + keeper, + ctx, + tt.PendingOutbound, + types.CctxStatus_PendingOutbound, + tss.TssPubkey, + )...) sends = append( sends, createNCctxWithStatus(keeper, ctx, tt.PendingRevert, types.CctxStatus_PendingRevert, tss.TssPubkey)...) - sends = append(sends, createNCctxWithStatus(keeper, ctx, tt.Aborted, types.CctxStatus_Aborted, tss.TssPubkey)...) + sends = append( + sends, + createNCctxWithStatus(keeper, ctx, tt.Aborted, types.CctxStatus_Aborted, tss.TssPubkey)...) sends = append( sends, createNCctxWithStatus(keeper, ctx, tt.OutboundMined, types.CctxStatus_OutboundMined, tss.TssPubkey)...) - sends = append(sends, createNCctxWithStatus(keeper, ctx, tt.Reverted, types.CctxStatus_Reverted, tss.TssPubkey)...) + sends = append( + sends, + createNCctxWithStatus(keeper, ctx, tt.Reverted, types.CctxStatus_Reverted, tss.TssPubkey)...) //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}))) diff --git a/x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go b/x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go index a647bd3822..706072bd8a 100644 --- a/x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go +++ b/x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go @@ -126,7 +126,11 @@ func TestInTxHashToCctxQueryPaginated(t *testing.T) { }) } -func createInTxHashToCctxWithCctxs(ctx sdk.Context, keeper *crosschainkeeper.Keeper, tssPubkey string) ([]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 { diff --git a/x/crosschain/keeper/msg_server_migrate_erc20_custody_funds.go b/x/crosschain/keeper/msg_server_migrate_erc20_custody_funds.go index b4edc3b2f7..1195165fb1 100644 --- a/x/crosschain/keeper/msg_server_migrate_erc20_custody_funds.go +++ b/x/crosschain/keeper/msg_server_migrate_erc20_custody_funds.go @@ -5,6 +5,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" "github.com/zeta-chain/zetacore/x/crosschain/types" ) diff --git a/x/crosschain/keeper/msg_server_vote_outbound_tx.go b/x/crosschain/keeper/msg_server_vote_outbound_tx.go index 04181ecf09..4dff7338d9 100644 --- a/x/crosschain/keeper/msg_server_vote_outbound_tx.go +++ b/x/crosschain/keeper/msg_server_vote_outbound_tx.go @@ -63,7 +63,7 @@ func (k msgServer) VoteOutbound( ) (*types.MsgVoteOutboundResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // Check TSS exists + // Check if TSS exists // It is almost impossible to reach this point without a TSS, // as the check for TSS was already done when creating the inbound, but we check anyway. // We also expect the tss.Pubkey to be the same as the one in the outbound params, diff --git a/x/crosschain/keeper/msg_server_whitelist_erc20.go b/x/crosschain/keeper/msg_server_whitelist_erc20.go index 2a921f1dcf..d3f45ee080 100644 --- a/x/crosschain/keeper/msg_server_whitelist_erc20.go +++ b/x/crosschain/keeper/msg_server_whitelist_erc20.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ethcommon "github.com/ethereum/go-ethereum/common" + "github.com/zeta-chain/zetacore/pkg/coin" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" "github.com/zeta-chain/zetacore/x/crosschain/types" From 052453bc95aa1a462575c8a754d051ecf780ea03 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 15 Aug 2024 17:29:27 -0400 Subject: [PATCH 03/10] generate files --- changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 8af7b278ba..96fbb25c2a 100644 --- a/changelog.md +++ b/changelog.md @@ -10,17 +10,17 @@ * [2634](https://github.com/zeta-chain/node/pull/2634) - add support for EIP-1559 gas fees * [2597](https://github.com/zeta-chain/node/pull/2597) - Add generic rpc metrics to zetaclient * [2538](https://github.com/zeta-chain/node/pull/2538) - add background worker routines to shutdown zetaclientd when needed for tss migration +* [2644](https://github.com/zeta-chain/node/pull/2644) - add created_timestamp to cctx status ### Refactor * [2615](https://github.com/zeta-chain/node/pull/2615) - Refactor cleanup of outbound trackers -* [2644](https://github.com/zeta-chain/node/pull/2644) - refactor SetCctxAndNonceToCctxAndInboundHashToCctx receive tsspubkey as an argument +* [2725](https://github.com/zeta-chain/node/pull/2725) - refactor SetCctxAndNonceToCctxAndInboundHashToCctx receive tsspubkey as an argument ### Fixes * [2654](https://github.com/zeta-chain/node/pull/2654) - add validation for authorization list in when validating genesis state for authorization module -* [2725](https://github.com/zeta-chain/node/pull/2725) - ## v19.0.0 From 4bd18d25b8ae5438355d269a8ecec3164951f8d3 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 15 Aug 2024 17:29:50 -0400 Subject: [PATCH 04/10] generate files --- changelog.md | 1 - 1 file changed, 1 deletion(-) diff --git a/changelog.md b/changelog.md index 96fbb25c2a..8c1edf4065 100644 --- a/changelog.md +++ b/changelog.md @@ -12,7 +12,6 @@ * [2538](https://github.com/zeta-chain/node/pull/2538) - add background worker routines to shutdown zetaclientd when needed for tss migration * [2644](https://github.com/zeta-chain/node/pull/2644) - add created_timestamp to cctx status - ### Refactor * [2615](https://github.com/zeta-chain/node/pull/2615) - Refactor cleanup of outbound trackers From 8c6f3038a7ff96b182326c4ea13e401ec34cd50c Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 15 Aug 2024 17:31:56 -0400 Subject: [PATCH 05/10] remove commented code --- x/crosschain/keeper/cctx_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x/crosschain/keeper/cctx_test.go b/x/crosschain/keeper/cctx_test.go index 0a99a1a674..e27f10685d 100644 --- a/x/crosschain/keeper/cctx_test.go +++ b/x/crosschain/keeper/cctx_test.go @@ -159,9 +159,7 @@ func TestCCTXs(t *testing.T) { sends = append( sends, createNCctxWithStatus(keeper, ctx, tt.Reverted, types.CctxStatus_Reverted, tss.TssPubkey)...) - //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}))) + require.Equal(t, len(sends), len(keeper.GetAllCrossChainTx(ctx))) for _, s := range sends { send, found := keeper.GetCrossChainTx(ctx, s.Index) From d4d672b2e061a11e94efea9bbf80d9af2efbb242 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 15 Aug 2024 17:51:37 -0400 Subject: [PATCH 06/10] refactor genesis.go --- x/crosschain/genesis.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/crosschain/genesis.go b/x/crosschain/genesis.go index 608c53c71c..e660a433bc 100644 --- a/x/crosschain/genesis.go +++ b/x/crosschain/genesis.go @@ -42,10 +42,10 @@ 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 { - tss, found := k.GetObserverKeeper().GetTSS(ctx) - if found { + tss, found := k.GetObserverKeeper().GetTSS(ctx) + if found { + for _, elem := range genState.CrossChainTxs { + if elem != nil { k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, *elem, func(ctx sdk.Context) string { return tss.TssPubkey }) From a35599cf1f1afbc1086003788df405c5ed89626d Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 16 Aug 2024 11:59:33 -0400 Subject: [PATCH 07/10] generate files --- x/crosschain/genesis.go | 1 + .../keeper/msg_server_update_erc20_custody_pause_status.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/x/crosschain/genesis.go b/x/crosschain/genesis.go index e660a433bc..53fed8f94c 100644 --- a/x/crosschain/genesis.go +++ b/x/crosschain/genesis.go @@ -2,6 +2,7 @@ package crosschain import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/crosschain/keeper" "github.com/zeta-chain/zetacore/x/crosschain/types" ) diff --git a/x/crosschain/keeper/msg_server_update_erc20_custody_pause_status.go b/x/crosschain/keeper/msg_server_update_erc20_custody_pause_status.go index 4cda11f633..d699bc7cfb 100644 --- a/x/crosschain/keeper/msg_server_update_erc20_custody_pause_status.go +++ b/x/crosschain/keeper/msg_server_update_erc20_custody_pause_status.go @@ -81,7 +81,9 @@ func (k msgServer) UpdateERC20CustodyPauseStatus( if err != nil { return nil, err } - k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, func(ctx sdk.Context) string { + return tss.TssPubkey + }) err = ctx.EventManager().EmitTypedEvent( &types.EventERC20CustodyPausing{ From fe806a3eaea91cdacba2ce00aa1f2fc85983ace6 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Mon, 19 Aug 2024 15:33:56 -0400 Subject: [PATCH 08/10] generate files --- docs/cli/zetacored/cli.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cli/zetacored/cli.md b/docs/cli/zetacored/cli.md index bb8ac9f077..6e8555c166 100644 --- a/docs/cli/zetacored/cli.md +++ b/docs/cli/zetacored/cli.md @@ -9422,7 +9422,7 @@ zetacored tx crosschain vote-gas-price [chain] [price] [priorityFee] [blockNumbe Broadcast message to vote an inbound ``` -zetacored tx crosschain vote-inbound [sender] [senderChainID] [txOrigin] [receiver] [receiverChainID] [amount] [message] [inboundHash] [inBlockHeight] [coinType] [asset] [eventIndex] [flags] +zetacored tx crosschain vote-inbound [sender] [senderChainID] [txOrigin] [receiver] [receiverChainID] [amount] [message] [inboundHash] [inBlockHeight] [coinType] [asset] [eventIndex] [protocolContractVersion] [flags] ``` ### Options From f5431203e644135578553165b96b81bdb6c2920f Mon Sep 17 00:00:00 2001 From: Tanmay Date: Mon, 19 Aug 2024 18:06:19 -0400 Subject: [PATCH 09/10] fix lint --- x/crosschain/genesis.go | 4 +--- x/crosschain/keeper/cctx.go | 3 +-- x/crosschain/keeper/cctx_orchestrator_validate_inbound.go | 4 +--- x/crosschain/keeper/cctx_test.go | 8 ++------ .../keeper/grpc_query_inbound_hash_to_cctx_test.go | 4 +--- .../keeper/msg_server_migrate_erc20_custody_funds.go | 4 +--- x/crosschain/keeper/msg_server_migrate_tss_funds.go | 4 +--- .../msg_server_update_erc20_custody_pause_status.go | 4 +--- x/crosschain/keeper/msg_server_vote_outbound_tx.go | 4 +--- x/crosschain/keeper/msg_server_whitelist_erc20.go | 4 +--- 10 files changed, 11 insertions(+), 32 deletions(-) diff --git a/x/crosschain/genesis.go b/x/crosschain/genesis.go index 53fed8f94c..7d750bafa1 100644 --- a/x/crosschain/genesis.go +++ b/x/crosschain/genesis.go @@ -47,9 +47,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) if found { for _, elem := range genState.CrossChainTxs { if elem != nil { - k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, *elem, func(ctx sdk.Context) string { - return tss.TssPubkey - }) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, *elem, tss.TssPubkey) } } } diff --git a/x/crosschain/keeper/cctx.go b/x/crosschain/keeper/cctx.go index c4b3864c33..9a1e1781df 100644 --- a/x/crosschain/keeper/cctx.go +++ b/x/crosschain/keeper/cctx.go @@ -19,10 +19,9 @@ import ( func (k Keeper) SetCctxAndNonceToCctxAndInboundHashToCctx( ctx sdk.Context, cctx types.CrossChainTx, - tssFunc func(ctx sdk.Context) string, + tssPubkey string, ) { // set mapping nonce => cctxIndex - tssPubkey := tssFunc(ctx) if cctx.CctxStatus.Status == types.CctxStatus_PendingOutbound || cctx.CctxStatus.Status == types.CctxStatus_PendingRevert { k.GetObserverKeeper().SetNonceToCctx(ctx, observerTypes.NonceToCctx{ diff --git a/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go b/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go index dea6b9f6f9..f2f10e23b6 100644 --- a/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go +++ b/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go @@ -51,9 +51,7 @@ func (k Keeper) ValidateInbound( if ok { cctx.InboundParams.ObservedHash = inCctxIndex } - k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, func(ctx sdk.Context) string { - return tss.TssPubkey - }) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, tss.TssPubkey) return &cctx, nil } diff --git a/x/crosschain/keeper/cctx_test.go b/x/crosschain/keeper/cctx_test.go index 7c2652fe82..0c99f979c9 100644 --- a/x/crosschain/keeper/cctx_test.go +++ b/x/crosschain/keeper/cctx_test.go @@ -40,9 +40,7 @@ func createNCctxWithStatus( items[i].OutboundParams = []*types.OutboundParams{{Amount: math.ZeroUint()}} items[i].RevertOptions = types.NewEmptyRevertOptions() - keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, items[i], func(ctx sdk.Context) string { - return tssPubkey - }) + keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, items[i], tssPubkey) } return items } @@ -84,9 +82,7 @@ func createNCctx(keeper *keeper.Keeper, ctx sdk.Context, n int, tssPubkey string items[i].Index = fmt.Sprintf("%d", i) items[i].RevertOptions = types.NewEmptyRevertOptions() - keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, items[i], func(ctx sdk.Context) string { - return tssPubkey - }) + keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, items[i], tssPubkey) } return items } diff --git a/x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go b/x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go index ac476001e0..da91836fe4 100644 --- a/x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go +++ b/x/crosschain/keeper/grpc_query_inbound_hash_to_cctx_test.go @@ -140,9 +140,7 @@ func createInTxHashToCctxWithCctxs( 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], func(ctx sdk.Context) string { - return tssPubkey - }) + keeper.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctxs[i], tssPubkey) } var inboundHashToCctx types.InboundHashToCctx diff --git a/x/crosschain/keeper/msg_server_migrate_erc20_custody_funds.go b/x/crosschain/keeper/msg_server_migrate_erc20_custody_funds.go index 1195165fb1..da1cd23618 100644 --- a/x/crosschain/keeper/msg_server_migrate_erc20_custody_funds.go +++ b/x/crosschain/keeper/msg_server_migrate_erc20_custody_funds.go @@ -83,9 +83,7 @@ func (k msgServer) MigrateERC20CustodyFunds( if err != nil { return nil, err } - k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, func(ctx sdk.Context) string { - return tss.TssPubkey - }) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, tss.TssPubkey) err = ctx.EventManager().EmitTypedEvent( &types.EventERC20CustodyFundsMigration{ diff --git a/x/crosschain/keeper/msg_server_migrate_tss_funds.go b/x/crosschain/keeper/msg_server_migrate_tss_funds.go index e442cb7b6b..4a808a7842 100644 --- a/x/crosschain/keeper/msg_server_migrate_tss_funds.go +++ b/x/crosschain/keeper/msg_server_migrate_tss_funds.go @@ -128,9 +128,7 @@ func (k Keeper) initiateMigrateTSSFundsCCTX( } } - k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, func(ctx sdk.Context) string { - return currentTss.TssPubkey - }) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, currentTss.TssPubkey) k.zetaObserverKeeper.SetFundMigrator(ctx, observertypes.TssFundMigratorInfo{ ChainId: chainID, MigrationCctxIndex: cctx.Index, diff --git a/x/crosschain/keeper/msg_server_update_erc20_custody_pause_status.go b/x/crosschain/keeper/msg_server_update_erc20_custody_pause_status.go index d699bc7cfb..98e73566ed 100644 --- a/x/crosschain/keeper/msg_server_update_erc20_custody_pause_status.go +++ b/x/crosschain/keeper/msg_server_update_erc20_custody_pause_status.go @@ -81,9 +81,7 @@ func (k msgServer) UpdateERC20CustodyPauseStatus( if err != nil { return nil, err } - k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, func(ctx sdk.Context) string { - return tss.TssPubkey - }) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, tss.TssPubkey) err = ctx.EventManager().EmitTypedEvent( &types.EventERC20CustodyPausing{ diff --git a/x/crosschain/keeper/msg_server_vote_outbound_tx.go b/x/crosschain/keeper/msg_server_vote_outbound_tx.go index 4dff7338d9..d4505dd2f3 100644 --- a/x/crosschain/keeper/msg_server_vote_outbound_tx.go +++ b/x/crosschain/keeper/msg_server_vote_outbound_tx.go @@ -216,9 +216,7 @@ func (k Keeper) SaveOutbound(ctx sdk.Context, cctx *types.CrossChainTx, tssPubke k.RemoveOutboundTrackerFromStore(ctx, outboundParams.ReceiverChainId, outboundParams.TssNonce) } // This should set nonce to cctx only if a new revert is created. - k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, *cctx, func(ctx sdk.Context) string { - return tssPubkey - }) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, *cctx, tssPubkey) } func (k Keeper) ValidateOutboundMessage(ctx sdk.Context, msg types.MsgVoteOutbound) (types.CrossChainTx, error) { diff --git a/x/crosschain/keeper/msg_server_whitelist_erc20.go b/x/crosschain/keeper/msg_server_whitelist_erc20.go index d3f45ee080..62ce836643 100644 --- a/x/crosschain/keeper/msg_server_whitelist_erc20.go +++ b/x/crosschain/keeper/msg_server_whitelist_erc20.go @@ -154,9 +154,7 @@ func (k msgServer) WhitelistERC20( GasLimit: uint64(msg.GasLimit), } k.fungibleKeeper.SetForeignCoins(ctx, foreignCoin) - k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, func(ctx sdk.Context) string { - return tss.TssPubkey - }) + k.SetCctxAndNonceToCctxAndInboundHashToCctx(ctx, cctx, tss.TssPubkey) commit() From 23d26a71dca7f055aadd889fd3cab8cc68be815b Mon Sep 17 00:00:00 2001 From: Tanmay Date: Mon, 26 Aug 2024 12:00:04 -0400 Subject: [PATCH 10/10] Update changelog.md Co-authored-by: skosito --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index c8d9f21a6b..7a289f5ced 100644 --- a/changelog.md +++ b/changelog.md @@ -18,7 +18,7 @@ ### Refactor * [2615](https://github.com/zeta-chain/node/pull/2615) - Refactor cleanup of outbound trackers -* [2725](https://github.com/zeta-chain/node/pull/2725) - refactor SetCctxAndNonceToCctxAndInboundHashToCctx receive tsspubkey as an argument +* [2725](https://github.com/zeta-chain/node/pull/2725) - refactor SetCctxAndNonceToCctxAndInboundHashToCctx to receive tsspubkey as an argument ### Tests