diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index 62e43e61aa..825046c04b 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -232,6 +232,10 @@ func start(_ *cobra.Command, _ []string) error { hotkeyPass, server, ) + if err != nil { + startLogger.Error().Err(err).Msg("NewTSS error") + return err + } if cfg.TestTssKeysign { err = TestTSS(tss.CurrentPubkey, *tss.Server, masterLogger) if err != nil { diff --git a/cmd/zetae2e/config/localnet.yml b/cmd/zetae2e/config/localnet.yml index abb780db39..21239e5d87 100644 --- a/cmd/zetae2e/config/localnet.yml +++ b/cmd/zetae2e/config/localnet.yml @@ -36,6 +36,10 @@ additional_accounts: bech32_address: "zeta1svzuz982w09vf2y08xsh8qplj36phyz466krj3" evm_address: "0x8305C114Ea73cAc4A88f39A173803F94741b9055" private_key: "d88d09a7d6849c15a36eb6931f9dd616091a63e9849a2cc86f309ba11fb8fec5" + user_migration_admin: + bech32_address: "zeta1pvtxa708yvdmszn687nne6nl8qn704daf420xz" + evm_address: "0x0B166ef9e7231Bb80A7A3FA73CEA7F3827E7D5BD" + private_key: "0BCC2FA28B526F90E1D54648D612DB901E860BF68248555593F91EA801C6B482" rpcs: zevm: "http://zetacore0:8545" evm: "http://eth:8545" diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 85753a74fe..fe45d1aa44 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -8,6 +8,7 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" + "github.com/stretchr/testify/require" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/e2etests" @@ -67,7 +68,7 @@ func NewLocalCmd() *cobra.Command { cmd.Flags().Bool(flagSkipSetup, false, "set to true to skip setup") cmd.Flags().Bool(flagSkipBitcoinSetup, false, "set to true to skip bitcoin wallet setup") cmd.Flags().Bool(flagSkipHeaderProof, false, "set to true to skip header proof tests") - cmd.Flags().Bool(flagTestMigration, false, "set to true to skip migration tests") + cmd.Flags().Bool(flagTestMigration, false, "set to true to include a migration test at the end") return cmd } @@ -326,30 +327,30 @@ func localE2ETest(cmd *cobra.Command, _ []string) { if testMigration { migrationCtx, cancel := context.WithCancel(context.Background()) deployerRunner.CtxCancel = cancel - migrationStartTime := time.Now() + migrationStartTime := time.Now() logger.Print("🏁 starting tss migration") + response, err := deployerRunner.CctxClient.LastZetaHeight(migrationCtx, &crosschaintypes.QueryLastZetaHeightRequest{}) - if err != nil { - logger.Error("cctxClient.LastZetaHeight error: %s", err) - panic(err) - } + require.NoError(deployerRunner, err) err = zetaTxServer.UpdateKeygen(response.Height) - if err != nil { - panic(err) - } + require.NoError(deployerRunner, err) + + // Generate new TSS waitKeygenHeight(migrationCtx, deployerRunner.CctxClient, deployerRunner.ObserverClient, logger, 0) + // migration test is a blocking thread, we cannot run other tests in parallel - eg.Go(migrationTestRoutine(conf, deployerRunner, verbose, e2etests.TestMigrateTssEthName)) + // The migration test migrates funds to a new TSS and then updates the TSS address on zetacore. + // The necessary restarts are done by the zetaclient supervisor + fn := migrationTestRoutine(conf, deployerRunner, verbose, e2etests.TestMigrateTssEthName) - if err := eg.Wait(); err != nil { - deployerRunner.CtxCancel() + if err := fn(); err != nil { logger.Print("❌ %v", err) logger.Print("❌ tss migration failed") os.Exit(1) } - logger.Print("✅ migration tests completed in %s sleeping for 30 secs ", time.Since(migrationStartTime).String()) + logger.Print("✅ migration completed in %s ", time.Since(migrationStartTime).String()) logger.Print("🏁 starting post migration tests") tests := []string{ @@ -364,8 +365,6 @@ func localE2ETest(cmd *cobra.Command, _ []string) { logger.Print("❌ post migration tests failed") os.Exit(1) } - - logger.Print("✅ migration tests completed in %s", time.Since(migrationStartTime).String()) } // print and validate report diff --git a/cmd/zetae2e/local/migration.go b/cmd/zetae2e/local/migration.go index 830d3213a4..0699894799 100644 --- a/cmd/zetae2e/local/migration.go +++ b/cmd/zetae2e/local/migration.go @@ -12,7 +12,7 @@ import ( "github.com/zeta-chain/zetacore/e2e/runner" ) -// adminTestRoutine runs admin functions tests +// migrationTestRoutine runs migration related e2e tests func migrationTestRoutine( conf config.Config, deployerRunner *runner.E2ERunner, @@ -28,8 +28,8 @@ func migrationTestRoutine( err = fmt.Errorf("admin panic: %v, stack trace %s", r, stack[:n]) } }() - account := conf.AdditionalAccounts.UserBitcoin - // initialize runner for erc20 advanced test + account := conf.AdditionalAccounts.UserMigration + // initialize runner for migration test migrationTestRunner, err := initTestRunner( "migration", conf, @@ -49,7 +49,7 @@ func migrationTestRoutine( migrationTestRunner.Logger.Print("🍾 migration tests completed in %s", time.Since(startTime).String()) return nil } - // run erc20 advanced test + // run migration test testsToRun, err := migrationTestRunner.GetE2ETestsToRunByName( e2etests.AllE2ETests, testNames..., @@ -61,7 +61,6 @@ func migrationTestRoutine( if err := migrationTestRunner.RunE2ETests(testsToRun); err != nil { return fmt.Errorf("migration tests failed: %v", err) } - if err := migrationTestRunner.CheckBtcTSSBalance(); err != nil { migrationTestRunner.Logger.Print("🍾 BTC check error") } @@ -70,5 +69,4 @@ func migrationTestRoutine( return err } - } diff --git a/cmd/zetae2e/local/post_migration.go b/cmd/zetae2e/local/post_migration.go index b73cd10612..d4fc7ab459 100644 --- a/cmd/zetae2e/local/post_migration.go +++ b/cmd/zetae2e/local/post_migration.go @@ -11,7 +11,7 @@ import ( "github.com/zeta-chain/zetacore/e2e/runner" ) -// postMigrationTestRoutine runs Bitcoin related e2e tests +// postMigrationTestRoutine runs post migration tests func postMigrationTestRoutine( conf config.Config, deployerRunner *runner.E2ERunner, @@ -19,8 +19,8 @@ func postMigrationTestRoutine( testNames ...string, ) func() error { return func() (err error) { - account := conf.AdditionalAccounts.UserBitcoin - // initialize runner for bitcoin test + account := conf.AdditionalAccounts.UserMigration + // initialize runner for post migration test postMigrationRunner, err := initTestRunner( "postMigration", conf, @@ -35,25 +35,6 @@ func postMigrationTestRoutine( postMigrationRunner.Logger.Print("🏃 starting postMigration tests") startTime := time.Now() - // funding the account - //txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 1000) - //postMigrationRunner.WaitForTxReceiptOnEvm(txERC20Send) - // - //// depositing the necessary tokens on ZetaChain - //txEtherDeposit := postMigrationRunner.DepositEther(false) - //txERC20Deposit := postMigrationRunner.DepositERC20() - // - //postMigrationRunner.WaitForMinedCCTX(txEtherDeposit) - //postMigrationRunner.WaitForMinedCCTX(txERC20Deposit) - // - //postMigrationRunner.Name = "bitcoin" - //postMigrationRunner.SetupBitcoinAccount(initBitcoinNetwork) - //postMigrationRunner.Name = "postMigration" - //postMigrationRunner.DepositBTC(testHeader) - - // run bitcoin test - // Note: due to the extensive block generation in Bitcoin localnet, block header test is run first - // to make it faster to catch up with the latest block header testsToRun, err := postMigrationRunner.GetE2ETestsToRunByName( e2etests.AllE2ETests, testNames..., diff --git a/contrib/localnet/scripts/start-zetacored.sh b/contrib/localnet/scripts/start-zetacored.sh index 64779d2a39..1605afad5a 100755 --- a/contrib/localnet/scripts/start-zetacored.sh +++ b/contrib/localnet/scripts/start-zetacored.sh @@ -242,6 +242,9 @@ then # ethers tester address=$(yq -r '.additional_accounts.user_ether.bech32_address' /root/config.yml) zetacored add-genesis-account "$address" 100000000000000000000000000azeta +# migration tester + address=$(yq -r '.additional_accounts.user_migration.bech32_address' /root/config.yml) + zetacored add-genesis-account "$address" 100000000000000000000000000azeta # 3. Copy the genesis.json to all the nodes .And use it to create a gentx for every node zetacored gentx operator 1000000000000000000000azeta --chain-id=$CHAINID --keyring-backend=$KEYRING --gas-prices 20000000000azeta diff --git a/e2e/config/config.go b/e2e/config/config.go index 66409ee339..84e952086a 100644 --- a/e2e/config/config.go +++ b/e2e/config/config.go @@ -65,6 +65,7 @@ type AdditionalAccounts struct { UserMisc Account `yaml:"user_misc"` UserAdmin Account `yaml:"user_admin"` UserFungibleAdmin Account `yaml:"user_fungible_admin"` + UserMigration Account `yaml:"user_migration"` } // RPCs contains the configuration for the RPC endpoints @@ -193,6 +194,7 @@ func (a AdditionalAccounts) AsSlice() []Account { a.UserMisc, a.UserAdmin, a.UserFungibleAdmin, + a.UserMigration, } } @@ -261,6 +263,10 @@ func (c *Config) GenerateKeys() error { if err != nil { return err } + c.AdditionalAccounts.UserMigration, err = generateAccount() + if err != nil { + return err + } return nil } diff --git a/e2e/e2etests/test_migrate_tss.go b/e2e/e2etests/test_migrate_tss.go index ea1e2ddadf..7ffb2fa832 100644 --- a/e2e/e2etests/test_migrate_tss.go +++ b/e2e/e2etests/test_migrate_tss.go @@ -18,8 +18,7 @@ import ( observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) -func TestMigrateTss(r *runner.E2ERunner, args []string) { - +func TestMigrateTss(r *runner.E2ERunner, _ []string) { r.SetBtcAddress(r.Name, false) stop := r.MineBlocksIfLocalBitcoin() defer stop() diff --git a/e2e/runner/accounting.go b/e2e/runner/accounting.go index 6a2c2504b6..d5f0ed2ae5 100644 --- a/e2e/runner/accounting.go +++ b/e2e/runner/accounting.go @@ -33,9 +33,9 @@ func (r *E2ERunner) CheckZRC20ReserveAndSupply() error { return r.checkZetaTSSBalance() } -func (runner *E2ERunner) checkEthTSSBalance() error { +func (r *E2ERunner) checkEthTSSBalance() error { - allTssAddress, err := runner.ObserverClient.TssHistory(runner.Ctx, &observertypes.QueryTssHistoryRequest{}) + allTssAddress, err := r.ObserverClient.TssHistory(r.Ctx, &observertypes.QueryTssHistoryRequest{}) if err != nil { return err } @@ -43,33 +43,32 @@ func (runner *E2ERunner) checkEthTSSBalance() error { tssTotalBalance := big.NewInt(0) for _, tssAddress := range allTssAddress.TssList { - evmAddress, err := runner.ObserverClient.GetTssAddressByFinalizedHeight(runner.Ctx, &observertypes.QueryGetTssAddressByFinalizedHeightRequest{ + evmAddress, err := r.ObserverClient.GetTssAddressByFinalizedHeight(r.Ctx, &observertypes.QueryGetTssAddressByFinalizedHeightRequest{ FinalizedZetaHeight: tssAddress.FinalizedZetaHeight, }) if err != nil { continue } - tssBal, err := runner.EVMClient.BalanceAt(runner.Ctx, common.HexToAddress(evmAddress.Eth), nil) + tssBal, err := r.EVMClient.BalanceAt(r.Ctx, common.HexToAddress(evmAddress.Eth), nil) if err != nil { continue } tssTotalBalance.Add(tssTotalBalance, tssBal) } - zrc20Supply, err := runner.ETHZRC20.TotalSupply(&bind.CallOpts{}) + zrc20Supply, err := r.ETHZRC20.TotalSupply(&bind.CallOpts{}) if err != nil { return err } if tssTotalBalance.Cmp(zrc20Supply) < 0 { return fmt.Errorf("ETH: TSS balance (%d) < ZRC20 TotalSupply (%d) ", tssTotalBalance, zrc20Supply) } - runner.Logger.Info("ETH: TSS balance (%d) >= ZRC20 TotalSupply (%d)", tssTotalBalance, zrc20Supply) + r.Logger.Info("ETH: TSS balance (%d) >= ZRC20 TotalSupply (%d)", tssTotalBalance, zrc20Supply) return nil } func (r *E2ERunner) CheckBtcTSSBalance() error { - allTssAddress, err := r.ObserverClient.TssHistory(r.Ctx, &observertypes.QueryTssHistoryRequest{}) if err != nil { return err @@ -91,20 +90,8 @@ func (r *E2ERunner) CheckBtcTSSBalance() error { tssTotalBalance += utxo.Amount } } - } - //utxos, err := r.BtcRPCClient.ListUnspent() - //if err != nil { - // return err - //} - //var btcBalance float64 - //for _, utxo := range utxos { - // if utxo.Address == r.BTCTSSAddress.EncodeAddress() { - // btcBalance += utxo.Amount - // } - //} - zrc20Supply, err := r.BTCZRC20.TotalSupply(&bind.CallOpts{}) if err != nil { return err diff --git a/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go b/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go index 0c56bbdf21..7f28672f2f 100644 --- a/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go +++ b/x/crosschain/keeper/cctx_orchestrator_validate_inbound.go @@ -16,7 +16,6 @@ func (k Keeper) ValidateInbound( msg *types.MsgVoteInbound, shouldPayGas bool, ) (*types.CrossChainTx, error) { - err := k.CheckMigration(ctx, msg) if err != nil { return nil, err diff --git a/zetaclient/chains/bitcoin/observer/outbound.go b/zetaclient/chains/bitcoin/observer/outbound.go index 504b960d47..bdc082d6b7 100644 --- a/zetaclient/chains/bitcoin/observer/outbound.go +++ b/zetaclient/chains/bitcoin/observer/outbound.go @@ -433,13 +433,7 @@ func (ob *Observer) setIncludedTx(nonce uint64, getTxResult *btcjson.GetTransact ob.Mu().Lock() defer ob.Mu().Unlock() res, found := ob.includedTxResults[outboundID] - - fmt.Printf("latest confirmations %d", getTxResult.Confirmations) - if !found { // not found. - - fmt.Printf("setIncludedTx: included new bitcoin outbound %s outboundID %s pending nonce %d", txHash, outboundID, ob.pendingNonce) - ob.includedTxHashes[txHash] = true ob.includedTxResults[outboundID] = getTxResult // include new outbound and enforce rigid 1-to-1 mapping: nonce <===> txHash if nonce >= ob.pendingNonce { // try increasing pending nonce on every newly included outbound @@ -447,16 +441,12 @@ func (ob *Observer) setIncludedTx(nonce uint64, getTxResult *btcjson.GetTransact } ob.logger.Outbound.Info(). Msgf("setIncludedTx: included new bitcoin outbound %s outboundID %s pending nonce %d", txHash, outboundID, ob.pendingNonce) - } else if txHash == res.TxID { // found same hash. - - fmt.Printf("setIncludedTx: update bitcoin outbound %s got confirmations %d", txHash, getTxResult.Confirmations) + } else if txHash == res.TxID { // found same hash ob.includedTxResults[outboundID] = getTxResult // update tx result as confirmations may increase if getTxResult.Confirmations > res.Confirmations { ob.logger.Outbound.Info().Msgf("setIncludedTx: bitcoin outbound %s got confirmations %d", txHash, getTxResult.Confirmations) } } else { // found other hash. - - fmt.Printf("setIncludedTx: duplicate payment by bitcoin outbound %s outboundID %s, prior outbound %s", txHash, outboundID, res.TxID) // be alert for duplicate payment!!! As we got a new hash paying same cctx (for whatever reason). delete(ob.includedTxResults, outboundID) // we can't tell which txHash is true, so we remove all to be safe ob.logger.Outbound.Error().Msgf("setIncludedTx: duplicate payment by bitcoin outbound %s outboundID %s, prior outbound %s", txHash, outboundID, res.TxID) diff --git a/zetaclient/tss/tss_signer.go b/zetaclient/tss/tss_signer.go index 59ece1070c..eb418cb08b 100644 --- a/zetaclient/tss/tss_signer.go +++ b/zetaclient/tss/tss_signer.go @@ -438,7 +438,7 @@ func (tss *TSS) EVMAddress() ethcommon.Address { } func (tss *TSS) EVMAddressList() []ethcommon.Address { - var addresses []ethcommon.Address + addresses := make([]ethcommon.Address, 0) for _, key := range tss.Keys { addr, err := GetTssAddrEVM(key.PubkeyInBech32) if err != nil {