diff --git a/changelog.md b/changelog.md index 7b679fb678..789515b900 100644 --- a/changelog.md +++ b/changelog.md @@ -76,6 +76,7 @@ * [2349](https://github.com/zeta-chain/node/pull/2349) - add TestBitcoinDepositRefund and WithdrawBitcoinMultipleTimes E2E tests * [2368](https://github.com/zeta-chain/node/pull/2368) - eliminate panic usage across testing suite * [2369](https://github.com/zeta-chain/node/pull/2369) - fix random cross-chain swap failure caused by using tiny UTXO +* [2440](https://github.com/zeta-chain/node/pull/2440) - Add e2e test for Tss migration ### Fixes diff --git a/cmd/zetaclientd-supervisor/lib.go b/cmd/zetaclientd-supervisor/lib.go index 7b8cfbb4dd..4c495dcf1d 100644 --- a/cmd/zetaclientd-supervisor/lib.go +++ b/cmd/zetaclientd-supervisor/lib.go @@ -19,9 +19,9 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/hashicorp/go-getter" "github.com/rs/zerolog" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" "google.golang.org/grpc" + observertypes "github.com/zeta-chain/zetacore/x/observer/types" "github.com/zeta-chain/zetacore/zetaclient/config" ) @@ -207,7 +207,8 @@ func (s *zetaclientdSupervisor) handleTssUpdate(ctx context.Context) { } tss = tssNew - s.logger.Warn().Msg(fmt.Sprintf("tss address is updated from %s to %s", tss.TSS.TssPubkey, tssNew.TSS.TssPubkey)) + s.logger.Warn(). + Msg(fmt.Sprintf("tss address is updated from %s to %s", tss.TSS.TssPubkey, tssNew.TSS.TssPubkey)) time.Sleep(6 * time.Second) s.logger.Info().Msg("restarting zetaclientd to update tss address") s.restartChan <- syscall.SIGHUP diff --git a/cmd/zetaclientd/keygen_tss.go b/cmd/zetaclientd/keygen_tss.go index 74c45841fe..49c1407028 100644 --- a/cmd/zetaclientd/keygen_tss.go +++ b/cmd/zetaclientd/keygen_tss.go @@ -11,11 +11,11 @@ import ( tsscommon "github.com/zeta-chain/go-tss/common" "github.com/zeta-chain/go-tss/keygen" "github.com/zeta-chain/go-tss/tss" - "github.com/zeta-chain/zetacore/zetaclient/chains/interfaces" "golang.org/x/crypto/sha3" "github.com/zeta-chain/zetacore/pkg/chains" observertypes "github.com/zeta-chain/zetacore/x/observer/types" + "github.com/zeta-chain/zetacore/zetaclient/chains/interfaces" "github.com/zeta-chain/zetacore/zetaclient/context" "github.com/zeta-chain/zetacore/zetaclient/metrics" mc "github.com/zeta-chain/zetacore/zetaclient/tss" @@ -120,7 +120,12 @@ func GenerateTss( // keygenTss generates a new TSS using the keygen request and the TSS server. // If the keygen is successful, the function returns the new TSS pubkey. // If the keygen is unsuccessful, the function posts blame and returns an error. -func keygenTss(keyGen observertypes.Keygen, tssServer tss.TssServer, zetacoreClient interfaces.ZetacoreClient, keygenLogger zerolog.Logger) (string, error) { +func keygenTss( + keyGen observertypes.Keygen, + tssServer tss.TssServer, + zetacoreClient interfaces.ZetacoreClient, + keygenLogger zerolog.Logger, +) (string, error) { keygenLogger.Info().Msgf("Keygen at blocknum %d , TSS signers %s ", keyGen.BlockNumber, keyGen.GranteePubkeys) var req keygen.Request req = keygen.NewRequest(keyGen.GranteePubkeys, keyGen.BlockNumber, "0.14.0") diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index 825046c04b..e2b3dae4e7 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -20,10 +20,9 @@ import ( "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/zeta-chain/go-tss/p2p" - "github.com/zeta-chain/zetacore/pkg/chains" - mc "github.com/zeta-chain/zetacore/zetaclient/tss" "github.com/zeta-chain/zetacore/pkg/authz" + "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/constant" observerTypes "github.com/zeta-chain/zetacore/x/observer/types" "github.com/zeta-chain/zetacore/zetaclient/chains/base" @@ -31,6 +30,7 @@ import ( "github.com/zeta-chain/zetacore/zetaclient/context" "github.com/zeta-chain/zetacore/zetaclient/metrics" "github.com/zeta-chain/zetacore/zetaclient/orchestrator" + mc "github.com/zeta-chain/zetacore/zetaclient/tss" ) type Multiaddr = core.Multiaddr diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index fe45d1aa44..829569cefd 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -9,6 +9,8 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" "github.com/stretchr/testify/require" + "golang.org/x/sync/errgroup" + zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/e2etests" @@ -19,7 +21,6 @@ import ( "github.com/zeta-chain/zetacore/testutil" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" - "golang.org/x/sync/errgroup" ) const ( @@ -331,7 +332,10 @@ func localE2ETest(cmd *cobra.Command, _ []string) { migrationStartTime := time.Now() logger.Print("🏁 starting tss migration") - response, err := deployerRunner.CctxClient.LastZetaHeight(migrationCtx, &crosschaintypes.QueryLastZetaHeightRequest{}) + response, err := deployerRunner.CctxClient.LastZetaHeight( + migrationCtx, + &crosschaintypes.QueryLastZetaHeightRequest{}, + ) require.NoError(deployerRunner, err) err = zetaTxServer.UpdateKeygen(response.Height) require.NoError(deployerRunner, err) diff --git a/cmd/zetae2e/local/migration.go b/cmd/zetae2e/local/migration.go index 0699894799..9a28a9d7a7 100644 --- a/cmd/zetae2e/local/migration.go +++ b/cmd/zetae2e/local/migration.go @@ -6,9 +6,9 @@ import ( "time" "github.com/fatih/color" - "github.com/zeta-chain/zetacore/e2e/e2etests" "github.com/zeta-chain/zetacore/e2e/config" + "github.com/zeta-chain/zetacore/e2e/e2etests" "github.com/zeta-chain/zetacore/e2e/runner" ) diff --git a/e2e/e2etests/test_migrate_tss.go b/e2e/e2etests/test_migrate_tss.go index 7ffb2fa832..9c85ece8c1 100644 --- a/e2e/e2etests/test_migrate_tss.go +++ b/e2e/e2etests/test_migrate_tss.go @@ -11,6 +11,7 @@ import ( "github.com/btcsuite/btcutil" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" zetacrypto "github.com/zeta-chain/zetacore/pkg/crypto" @@ -87,7 +88,10 @@ func TestMigrateTss(r *runner.E2ERunner, _ []string) { require.NoError(r, err) // Fetch migrator cctx for eth migration - migrator, err = r.ObserverClient.TssFundsMigratorInfo(r.Ctx, &observertypes.QueryTssFundsMigratorInfoRequest{ChainId: evmChainID.Int64()}) + migrator, err = r.ObserverClient.TssFundsMigratorInfo( + r.Ctx, + &observertypes.QueryTssFundsMigratorInfoRequest{ChainId: evmChainID.Int64()}, + ) require.NoError(r, err) cctxETHMigration := migrator.TssFundsMigrator.MigrationCctxIndex @@ -149,7 +153,11 @@ func TestMigrateTss(r *runner.E2ERunner, _ []string) { r.Logger.Info(fmt.Sprintf("Migrator amount : %s", cctxBTC.GetCurrentOutboundParam().Amount)) // btcTSSBalanceNew should be less than btcTSSBalanceOld as there is some loss of funds during migration - require.Equal(r, strconv.FormatInt(int64(btcTSSBalanceNew*1e8), 10), cctxBTC.GetCurrentOutboundParam().Amount.String()) + require.Equal( + r, + strconv.FormatInt(int64(btcTSSBalanceNew*1e8), 10), + cctxBTC.GetCurrentOutboundParam().Amount.String(), + ) require.LessOrEqual(r, btcTSSBalanceNew*1e8, btcTSSBalanceOld*1e8) // ETH diff --git a/e2e/runner/accounting.go b/e2e/runner/accounting.go index e2cc51313e..cdcc269066 100644 --- a/e2e/runner/accounting.go +++ b/e2e/runner/accounting.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + zetacrypto "github.com/zeta-chain/zetacore/pkg/crypto" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -42,9 +43,12 @@ func (r *E2ERunner) checkEthTSSBalance() error { tssTotalBalance := big.NewInt(0) for _, tssAddress := range allTssAddress.TssList { - evmAddress, err := r.ObserverClient.GetTssAddressByFinalizedHeight(r.Ctx, &observertypes.QueryGetTssAddressByFinalizedHeightRequest{ - FinalizedZetaHeight: tssAddress.FinalizedZetaHeight, - }) + evmAddress, err := r.ObserverClient.GetTssAddressByFinalizedHeight( + r.Ctx, + &observertypes.QueryGetTssAddressByFinalizedHeightRequest{ + FinalizedZetaHeight: tssAddress.FinalizedZetaHeight, + }, + ) if err != nil { continue } diff --git a/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go b/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go index 7f28672f2f..a51c3fa927 100644 --- a/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go +++ b/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go @@ -3,6 +3,7 @@ package keeper import ( "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/crypto" "github.com/zeta-chain/zetacore/x/crosschain/types" diff --git a/x/crosschain/keeper/msg_server_migrate_tss_funds.go b/x/crosschain/keeper/msg_server_migrate_tss_funds.go index 73598b3e22..8656cf2e80 100644 --- a/x/crosschain/keeper/msg_server_migrate_tss_funds.go +++ b/x/crosschain/keeper/msg_server_migrate_tss_funds.go @@ -182,7 +182,9 @@ func (k Keeper) MigrateTSSFundsForChain( ) } - cctx.GetCurrentOutboundParam().Amount = amount.Sub(evmFee.Add(sdkmath.NewUintFromString(types.TSSMigrationBufferAmountEVM))) + cctx.GetCurrentOutboundParam().Amount = amount.Sub( + evmFee.Add(sdkmath.NewUintFromString(types.TSSMigrationBufferAmountEVM)), + ) } // Set the sender and receiver addresses for Bitcoin chain if chains.IsBitcoinChain(chainID, additionalChains) { diff --git a/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go b/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go index 0fe5a5c28a..7e86307fc0 100644 --- a/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go +++ b/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go @@ -385,7 +385,8 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { cctx, found := k.GetCrossChainTx(ctx, index) require.True(t, found) feeCalculated := sdk.NewUint(cctx.GetCurrentOutboundParam().GasLimit). - Mul(sdkmath.NewUintFromString(cctx.GetCurrentOutboundParam().GasPrice)).Add(sdkmath.NewUintFromString(crosschaintypes.TSSMigrationBufferAmountEVM)) + Mul(sdkmath.NewUintFromString(cctx.GetCurrentOutboundParam().GasPrice)). + Add(sdkmath.NewUintFromString(crosschaintypes.TSSMigrationBufferAmountEVM)) require.Equal(t, cctx.GetCurrentOutboundParam().Amount.String(), amount.Sub(feeCalculated).String()) }) diff --git a/x/crosschain/keeper/msg_server_remove_outbound_tracker.go b/x/crosschain/keeper/msg_server_remove_outbound_tracker.go index 00b7be6e29..ef20dfc6f7 100644 --- a/x/crosschain/keeper/msg_server_remove_outbound_tracker.go +++ b/x/crosschain/keeper/msg_server_remove_outbound_tracker.go @@ -5,8 +5,8 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - authoritytypes "github.com/zeta-chain/zetacore/x/authority/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_update_tss_test.go b/x/crosschain/keeper/msg_server_update_tss_test.go index c071406aea..761ff617c8 100644 --- a/x/crosschain/keeper/msg_server_update_tss_test.go +++ b/x/crosschain/keeper/msg_server_update_tss_test.go @@ -224,7 +224,11 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { } keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.UpdateTssAddress(ctx, &msg) - require.ErrorContains(t, err, "cannot update tss address incorrect number of migrations have been created and completed: unable to update TSS address") + require.ErrorContains( + t, + err, + "cannot update tss address incorrect number of migrations have been created and completed: unable to update TSS address", + ) require.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) tss, found := k.GetObserverKeeper().GetTSS(ctx) require.True(t, found) diff --git a/zetaclient/chains/bitcoin/observer/outbound.go b/zetaclient/chains/bitcoin/observer/outbound.go index bdc082d6b7..efbc109dcb 100644 --- a/zetaclient/chains/bitcoin/observer/outbound.go +++ b/zetaclient/chains/bitcoin/observer/outbound.go @@ -138,7 +138,6 @@ func (ob *Observer) IsOutboundProcessed(cctx *crosschaintypes.CrossChainTx, logg // prevents double spending of same UTXO. However, for nonce 0, we don't have a prior nonce (e.g., -1) // for the signer to check against when making the payment. Signer treats nonce 0 as a special case in downstream code. if nonce == 0 { - fmt.Println("IsOutboundProcessed: nonce is zero") return true, false, nil } @@ -167,7 +166,11 @@ func (ob *Observer) IsOutboundProcessed(cctx *crosschaintypes.CrossChainTx, logg // It's safe to use cctx's amount to post confirmation because it has already been verified in observeOutbound() amountInSat := params.Amount.BigInt() if res.Confirmations < ob.ConfirmationsThreshold(amountInSat) { - fmt.Printf("IsOutboundProcessed: outbound not confirmed yet %d: %d", res.Confirmations, ob.ConfirmationsThreshold(amountInSat)) + fmt.Printf( + "IsOutboundProcessed: outbound not confirmed yet %d: %d", + res.Confirmations, + ob.ConfirmationsThreshold(amountInSat), + ) return true, false, nil } diff --git a/zetaclient/chains/evm/observer/outbound.go b/zetaclient/chains/evm/observer/outbound.go index 7015ce33d7..5952d1fa4e 100644 --- a/zetaclient/chains/evm/observer/outbound.go +++ b/zetaclient/chains/evm/observer/outbound.go @@ -376,8 +376,9 @@ func (ob *Observer) checkConfirmedTx(txHash string, nonce uint64) (*ethtypes.Rec } } if !isOldTssAddress { - log.Error().Msgf("confirmTxByHash: sender %s for outbound %s chain %d is not current or old TSS address. Current TSS %s", - from.Hex(), transaction.Hash().Hex(), ob.Chain().ChainId, ob.TSS().EVMAddress().Hex()) + log.Error(). + Msgf("confirmTxByHash: sender %s for outbound %s chain %d is not current or old TSS address. Current TSS %s", + from.Hex(), transaction.Hash().Hex(), ob.Chain().ChainId, ob.TSS().EVMAddress().Hex()) return nil, nil, false } } @@ -407,7 +408,9 @@ func (ob *Observer) checkConfirmedTx(txHash string, nonce uint64) (*ethtypes.Rec // check confirmations lastHeight, err := ob.evmClient.BlockNumber(context.Background()) if err != nil { - log.Error().Err(err).Msgf("confirmTxByHash: error getting block number for chain %d", ob.GetChainParams().ChainId) + log.Error(). + Err(err). + Msgf("confirmTxByHash: error getting block number for chain %d", ob.GetChainParams().ChainId) return nil, nil, false } if !ob.HasEnoughConfirmations(receipt, lastHeight) {