From b2826b7d31cd6a15d89f32f7390943bdd9a9a1cb Mon Sep 17 00:00:00 2001 From: Tanmay Date: Tue, 23 Jan 2024 13:34:24 -0500 Subject: [PATCH 1/4] chore: increment hanlder to v12.1.0 (#1615) * increment hanlder to v12.1.0 * fix upgrade test * add changelog entry --------- Co-authored-by: lumtis --- Dockerfile-versioned-source | 2 +- Makefile | 2 +- app/setup_handlers.go | 6 +----- changelog.md | 5 +++++ 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Dockerfile-versioned-source b/Dockerfile-versioned-source index f6b90d5126..67c4ac4273 100644 --- a/Dockerfile-versioned-source +++ b/Dockerfile-versioned-source @@ -17,7 +17,7 @@ WORKDIR /go/delivery/zeta-node RUN mkdir -p $GOPATH/bin/old RUN mkdir -p $GOPATH/bin/new -ENV NEW_VERSION=v12.0.0 +ENV NEW_VERSION=v12.1.0 # Build new release from the current source COPY go.mod /go/delivery/zeta-node/ diff --git a/Makefile b/Makefile index 34862f40e3..2fe0da31cd 100644 --- a/Makefile +++ b/Makefile @@ -240,7 +240,7 @@ stateful-upgrade: stateful-upgrade-source: @echo "--> Starting stateful smoketest" - $(DOCKER) build --build-arg old_version=v11.0.0-patch-core-params -t zetanode -f ./Dockerfile-versioned-source . + $(DOCKER) build --build-arg old_version=v12.0.0 -t zetanode -f ./Dockerfile-versioned-source . $(DOCKER) build -t orchestrator -f contrib/localnet/orchestrator/Dockerfile-upgrade.fastbuild . cd contrib/localnet/ && $(DOCKER) compose -f docker-compose-stateful.yml up -d diff --git a/app/setup_handlers.go b/app/setup_handlers.go index 533679f243..8619fa046f 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -5,11 +5,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/upgrade/types" - crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) -const releaseVersion = "v12.0.0" +const releaseVersion = "v12.1.0" func SetupHandlers(app *App) { app.UpgradeKeeper.SetUpgradeHandler(releaseVersion, func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { @@ -18,8 +16,6 @@ func SetupHandlers(app *App) { for m, mb := range app.mm.Modules { vm[m] = mb.ConsensusVersion() } - vm[crosschaintypes.ModuleName] = 3 - vm[observertypes.ModuleName] = 4 return app.mm.RunMigrations(ctx, app.configurator, vm) }) diff --git a/changelog.md b/changelog.md index c6396ae86f..037accc506 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,9 @@ ## Unreleased + +## Version: v12.1.0 + ### Tests * [1577](https://github.com/zeta-chain/node/pull/1577) - add chain header tests in E2E tests and fix admin tests @@ -21,6 +24,8 @@ ### Chores * [1585](https://github.com/zeta-chain/node/pull/1585) - Updated release instructions +* [1615](https://github.com/zeta-chain/node/pull/1615) - Add upgrade handler for version v12.1.0 + ## Version: v12.0.0 From d940b9445413a8563115d537407218a65066435d Mon Sep 17 00:00:00 2001 From: Lucas Bertrand Date: Thu, 25 Jan 2024 09:03:05 -0800 Subject: [PATCH 2/4] fix: cherry-pick ZetaClient fixes from `12.0.4` (#1631) * refactor(`hotfix`): support retrying sending inbound vote with higher gas limit (#1601) * chore: v12.0.0 changelog (#1578) * fix: skip unsupported chain parameters (#1581) Co-authored-by: Lucas Bertrand * remove debug zetaclient1 * remove comments * tx resend * complete renaming * change log level and create constants * increase retry value * test change gas limit for outbound * refactor vote inbound outbound into separate files * add monitoring capability for outbound txs * changelog --------- Co-authored-by: Charlie Chen <34498985+ws4charlie@users.noreply.github.com> * fix: some necessary code refactor for banned address and bug fix during refactor (#1603) * cherry picked: fixed ChainParams equality check and added changelog entry * respect isSupported in zetaclient observation * add some RPC diagnosis log * guard against multiple deposits * make cosmos go sec linter happy * update e2e tests * Update zetaclient/bitcoin_client.go Co-authored-by: Charlie Chen <34498985+ws4charlie@users.noreply.github.com> --------- Co-authored-by: Charlie Chen <34498985+ws4charlie@users.noreply.github.com> Co-authored-by: Charlie Chen Co-authored-by: brewmaster012 <88689859+brewmaster012@users.noreply.github.com> --- changelog.md | 15 +- cmd/zetae2e/local/erc20.go | 1 - .../scripts/start-zetaclientd-genesis.sh | 2 +- contrib/localnet/scripts/start-zetaclientd.sh | 2 +- zetaclient/bitcoin_client.go | 55 ++++- zetaclient/broadcast.go | 8 +- zetaclient/btc_signer.go | 4 +- zetaclient/evm_client.go | 135 ++++++++---- zetaclient/inbound_tracker.go | 81 ++++--- zetaclient/interfaces.go | 4 +- zetaclient/telemetry.go | 1 + zetaclient/tx.go | 202 ++---------------- zetaclient/tx_vote_inbound.go | 153 +++++++++++++ zetaclient/tx_vote_outbound.go | 154 +++++++++++++ zetaclient/utils.go | 87 ++++---- zetaclient/voter_test.go | 12 +- zetaclient/zetacore_observer_test.go | 8 +- 17 files changed, 593 insertions(+), 331 deletions(-) create mode 100644 zetaclient/tx_vote_inbound.go create mode 100644 zetaclient/tx_vote_outbound.go diff --git a/changelog.md b/changelog.md index 037accc506..01cee846e4 100644 --- a/changelog.md +++ b/changelog.md @@ -2,7 +2,6 @@ ## Unreleased - ## Version: v12.1.0 ### Tests @@ -16,6 +15,8 @@ * [1535](https://github.com/zeta-chain/node/issues/1535) - Avoid voting on wrong ballots due to false blockNumber in EVM tx receipt * [1588](https://github.com/zeta-chain/node/pull/1588) - fix chain params comparison logic * [1650](https://github.com/zeta-chain/node/pull/1605) - exempt (discounted) *system txs* from min gas price check and gas fee deduction +* [1576](https://github.com/zeta-chain/node/pull/1576) - Fix zetaclient crash due to out of bound integer conversion and log prints. +* [1575](https://github.com/zeta-chain/node/issues/1575) - Skip unsupported chain parameters by IsSupported flag ### CI @@ -26,6 +27,10 @@ * [1585](https://github.com/zeta-chain/node/pull/1585) - Updated release instructions * [1615](https://github.com/zeta-chain/node/pull/1615) - Add upgrade handler for version v12.1.0 +### Features + +* [1591](https://github.com/zeta-chain/node/pull/1591) - support lower gas limit for voting on inbound and outbound transactions +* [1592](https://github.com/zeta-chain/node/issues/1592) - check inbound tracker tx hash against Tss address and some refactor on inTx observation ## Version: v12.0.0 @@ -49,8 +54,6 @@ Getting the correct TSS address for Bitcoin now requires proviidng the Bitcoin c * `GetTssAddress` : Changed from `/zeta-chain/observer/get_tss_address/` to `/zeta-chain/observer/getTssAddress/{bitcoin_chain_id}` . Optional bitcoin chain id can now be passed as a parameter to fetch the correct tss for required BTC chain. This parameter only affects the BTC tss address in the response. ### Features - -* [1549](https://github.com/zeta-chain/node/pull/1549) - add monitoring for vote tx results in ZetaClient * [1498](https://github.com/zeta-chain/node/pull/1498) - Add monitoring(grafana, prometheus, ethbalance) for localnet testing * [1395](https://github.com/zeta-chain/node/pull/1395) - Add state variable to track aborted zeta amount * [1410](https://github.com/zeta-chain/node/pull/1410) - `snapshots` commands @@ -60,8 +63,6 @@ Getting the correct TSS address for Bitcoin now requires proviidng the Bitcoin c ### Fixes -* [1576](https://github.com/zeta-chain/node/pull/1576) - Fix zetaclient crash due to out of bound integer conversion and log prints. -* [1575](https://github.com/zeta-chain/node/issues/1575) - Skip unsupported chain parameters by IsSupported flag * [1554](https://github.com/zeta-chain/node/pull/1554) - Screen out unconfirmed UTXOs that are not created by TSS itself * [1560](https://github.com/zeta-chain/node/issues/1560) - Zetaclient post evm-chain outtx hashes only when receipt is available * [1516](https://github.com/zeta-chain/node/issues/1516) - Unprivileged outtx tracker removal @@ -80,7 +81,6 @@ Getting the correct TSS address for Bitcoin now requires proviidng the Bitcoin c * [1525](https://github.com/zeta-chain/node/pull/1525) - relax EVM chain block header length check 1024->4096 * [1522](https://github.com/zeta-chain/node/pull/1522/files) - block `distribution` module account from receiving zeta * [1528](https://github.com/zeta-chain/node/pull/1528) - fix panic caused on decoding malformed BTC addresses -* [1557](https://github.com/zeta-chain/node/pull/1557) - remove decreaseAllowance and increaseAllowance checks * [1536](https://github.com/zeta-chain/node/pull/1536) - add index to check previously finalized inbounds * [1556](https://github.com/zeta-chain/node/pull/1556) - add emptiness check for topic array in event parsing * [1546](https://github.com/zeta-chain/node/pull/1546) - fix reset of pending nonces on genesis import @@ -109,7 +109,6 @@ Getting the correct TSS address for Bitcoin now requires proviidng the Bitcoin c * Update --ledger flag hint ### Chores - * [1446](https://github.com/zeta-chain/node/pull/1446) - renamed file `zetaclientd/aux.go` to `zetaclientd/utils.go` to avoid complaints from go package resolver. * [1499](https://github.com/zeta-chain/node/pull/1499) - Add scripts to localnet to help test gov proposals * [1442](https://github.com/zeta-chain/node/pull/1442) - remove build types in `.goreleaser.yaml` @@ -121,9 +120,7 @@ Getting the correct TSS address for Bitcoin now requires proviidng the Bitcoin c * [1538](https://github.com/zeta-chain/node/pull/1538) - improve stateful e2e testing ### CI - * Removed private runners and unused GitHub Action -* Adding typescript publishing pipeline. ## Version: v11.0.0 diff --git a/cmd/zetae2e/local/erc20.go b/cmd/zetae2e/local/erc20.go index 8e5a286fa8..66703121e8 100644 --- a/cmd/zetae2e/local/erc20.go +++ b/cmd/zetae2e/local/erc20.go @@ -62,7 +62,6 @@ func erc20TestRoutine( // run erc20 test if err := erc20Runner.RunSmokeTestsFromNames( smoketests.AllSmokeTests, - smoketests.TestMultipleERC20DepositName, smoketests.TestWithdrawERC20Name, smoketests.TestMultipleWithdrawsName, smoketests.TestERC20DepositAndCallRefundName, diff --git a/contrib/localnet/scripts/start-zetaclientd-genesis.sh b/contrib/localnet/scripts/start-zetaclientd-genesis.sh index 7c23cd0673..5f2cadceab 100755 --- a/contrib/localnet/scripts/start-zetaclientd-genesis.sh +++ b/contrib/localnet/scripts/start-zetaclientd-genesis.sh @@ -36,6 +36,6 @@ else SEED=$(curl --retry 10 --retry-delay 5 --retry-connrefused -s zetaclient0:8123/p2p) done rm ~/.tss/* - zetaclientd init --peer /ip4/172.20.0.21/tcp/6668/p2p/"$SEED" --zetacore-url "$node" --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --log-level 0 --keyring-backend "$BACKEND" + zetaclientd init --peer /ip4/172.20.0.21/tcp/6668/p2p/"$SEED" --zetacore-url "$node" --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --log-level 1 --keyring-backend "$BACKEND" zetaclientd start fi diff --git a/contrib/localnet/scripts/start-zetaclientd.sh b/contrib/localnet/scripts/start-zetaclientd.sh index 14de0fada6..eecb8b8e5d 100644 --- a/contrib/localnet/scripts/start-zetaclientd.sh +++ b/contrib/localnet/scripts/start-zetaclientd.sh @@ -23,6 +23,6 @@ else zetaclientd init \ --peer /ip4/172.20.0.21/tcp/6668/p2p/$SEED \ --pre-params ~/preParams.json --zetacore-url $node \ - --chain-id athens_101-1 --operator zeta1lz2fqwzjnk6qy48fgj753h48444fxtt7hekp52 --log-level 0 --hotkey=val_grantee_observer + --chain-id athens_101-1 --operator zeta1lz2fqwzjnk6qy48fgj753h48444fxtt7hekp52 --log-level 1 --hotkey=val_grantee_observer zetaclientd start fi diff --git a/zetaclient/bitcoin_client.go b/zetaclient/bitcoin_client.go index a82e3a44cb..d802d2b953 100644 --- a/zetaclient/bitcoin_client.go +++ b/zetaclient/bitcoin_client.go @@ -11,6 +11,7 @@ import ( "strconv" "sync" "sync/atomic" + "time" cosmosmath "cosmossdk.io/math" "github.com/btcsuite/btcd/btcjson" @@ -199,6 +200,54 @@ func (ob *BitcoinChainClient) Start() { go ob.WatchUTXOS() go ob.WatchGasPrice() go ob.ExternalChainWatcherForNewInboundTrackerSuggestions() + go ob.RPCStatus() +} + +func (ob *BitcoinChainClient) RPCStatus() { + ob.logger.ChainLogger.Info().Msgf("RPCStatus is starting") + ticker := time.NewTicker(60 * time.Second) + + for { + select { + case <-ticker.C: + //ob.logger.ChainLogger.Info().Msgf("RPCStatus is running") + bn, err := ob.rpcClient.GetBlockCount() + if err != nil { + ob.logger.ChainLogger.Error().Err(err).Msg("RPC status check: RPC down? ") + continue + } + hash, err := ob.rpcClient.GetBlockHash(bn) + if err != nil { + ob.logger.ChainLogger.Error().Err(err).Msg("RPC status check: RPC down? ") + continue + } + header, err := ob.rpcClient.GetBlockHeader(hash) + if err != nil { + ob.logger.ChainLogger.Error().Err(err).Msg("RPC status check: RPC down? ") + continue + } + blockTime := header.Timestamp + elapsedSeconds := time.Since(blockTime).Seconds() + if elapsedSeconds > 1200 { + ob.logger.ChainLogger.Error().Err(err).Msg("RPC status check: RPC down? ") + continue + } + tssAddr := ob.Tss.BTCAddressWitnessPubkeyHash() + res, err := ob.rpcClient.ListUnspentMinMaxAddresses(0, 1000000, []btcutil.Address{tssAddr}) + if err != nil { + ob.logger.ChainLogger.Error().Err(err).Msg("RPC status check: can't list utxos of TSS address; wallet or loaded? TSS address is not imported? ") + continue + } + if len(res) == 0 { + ob.logger.ChainLogger.Error().Err(err).Msg("RPC status check: TSS address has no utxos; TSS address is not imported? ") + continue + } + ob.logger.ChainLogger.Info().Msgf("[OK] RPC status check: latest block number %d, timestamp %s (%.fs ago), tss addr %s, #utxos: %d", bn, blockTime, elapsedSeconds, tssAddr, len(res)) + + case <-ob.stop: + return + } + } } func (ob *BitcoinChainClient) Stop() { @@ -385,12 +434,12 @@ func (ob *BitcoinChainClient) observeInTx() error { // post inbound vote message to zetacore for _, inTx := range inTxs { msg := ob.GetInboundVoteMessageFromBtcEvent(inTx) - zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendEVMGasLimit, msg) + zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundExecutionGasLimit, msg) if err != nil { ob.logger.WatchInTx.Error().Err(err).Msgf("observeInTxBTC: error posting to zeta core for tx %s", inTx.TxHash) return err // we have to re-scan this block next time } else if zetaHash != "" { - ob.logger.WatchInTx.Info().Msgf("observeInTxBTC: BTC deposit detected and reported: PostSend zeta tx: %s ballot %s", zetaHash, ballot) + ob.logger.WatchInTx.Info().Msgf("observeInTxBTC: BTC deposit detected and reported: PostVoteInbound zeta tx: %s ballot %s", zetaHash, ballot) } } @@ -470,7 +519,7 @@ func (ob *BitcoinChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64 } logger.Debug().Msgf("Bitcoin outTx confirmed: txid %s, amount %s\n", res.TxID, amountInSat.String()) - zetaHash, ballot, err := ob.zetaClient.PostReceiveConfirmation( + zetaHash, ballot, err := ob.zetaClient.PostVoteOutbound( sendHash, res.TxID, // #nosec G701 always positive diff --git a/zetaclient/broadcast.go b/zetaclient/broadcast.go index 8c1a86e70d..97870d3791 100644 --- a/zetaclient/broadcast.go +++ b/zetaclient/broadcast.go @@ -57,7 +57,6 @@ func (b *ZetaCoreBridge) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg b.seqNumber[authzSigner.KeyType] = seqNumber } } - //b.logger.Info().Uint64("account_number", b.accountNumber).Uint64("sequence_number", b.seqNumber).Msg("account info") flags := flag.NewFlagSet("zetacore", 0) @@ -73,12 +72,13 @@ func (b *ZetaCoreBridge) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg if err != nil { return "", err } + builder.SetGasLimit(gaslimit) + // #nosec G701 always in range fee := sdktypes.NewCoins(sdktypes.NewCoin(config.BaseDenom, cosmos.NewInt(int64(gaslimit)).Mul(adjustedBaseGasPrice.Ceil().RoundInt()))) builder.SetFeeAmount(fee) - //fmt.Printf("signing from name: %s\n", ctx.GetFromName()) err = b.SignTx(factory, ctx.GetFromName(), builder, true, ctx.TxConfig) if err != nil { return "", err @@ -94,6 +94,7 @@ func (b *ZetaCoreBridge) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg b.logger.Error().Err(err).Msgf("fail to broadcast tx %s", err.Error()) return "", err } + // Code will be the tendermint ABICode , it start at 1 , so if it is an error , code will not be zero if commit.Code > 0 { if commit.Code == 32 { @@ -118,11 +119,8 @@ func (b *ZetaCoreBridge) Broadcast(gaslimit uint64, authzWrappedMsg sdktypes.Msg } return commit.TxHash, fmt.Errorf("fail to broadcast to zetachain,code:%d, log:%s", commit.Code, commit.RawLog) } - //b.logger.Debug().Msgf("Received a TxHash of %v from the metachain, Code %d, log %s", commit.TxHash, commit.Code, commit.Logs) // increment seqNum - //seq := b.seqNumber[authzSigner.KeyType] - //atomic.AddUint64(&seq, 1) b.seqNumber[authzSigner.KeyType] = b.seqNumber[authzSigner.KeyType] + 1 return commit.TxHash, nil diff --git a/zetaclient/btc_signer.go b/zetaclient/btc_signer.go index d175c9af71..ba493a9fce 100644 --- a/zetaclient/btc_signer.go +++ b/zetaclient/btc_signer.go @@ -119,11 +119,11 @@ func (signer *BTCSigner) SignWithdrawTx( signer.logger.Info().Msgf("sizeLimit %d is less than txSize %d for nonce %d", sizeLimit, txSize, nonce) } if txSize < outTxBytesMin { // outbound shouldn't be blocked a low sizeLimit - signer.logger.Warn().Msgf("sizeLimit %d is less than outTxBytesMin %d; use outTxBytesMin", sizeLimit, outTxBytesMin) + signer.logger.Warn().Msgf("txSize %d is less than outTxBytesMin %d; use outTxBytesMin", txSize, outTxBytesMin) txSize = outTxBytesMin } if txSize > outTxBytesMax { // in case of accident - signer.logger.Warn().Msgf("sizeLimit %d is greater than outTxBytesMax %d; use outTxBytesMax", sizeLimit, outTxBytesMax) + signer.logger.Warn().Msgf("txSize %d is greater than outTxBytesMax %d; use outTxBytesMax", txSize, outTxBytesMax) txSize = outTxBytesMax } diff --git a/zetaclient/evm_client.go b/zetaclient/evm_client.go index d88ee980f9..36d5ee0570 100644 --- a/zetaclient/evm_client.go +++ b/zetaclient/evm_client.go @@ -1,7 +1,6 @@ package zetaclient import ( - "bytes" "context" "fmt" "math" @@ -283,6 +282,42 @@ func (ob *EVMChainClient) Start() { go ob.ExternalChainWatcher() // Observes external Chains for incoming trasnactions go ob.WatchGasPrice() // Observes external Chains for Gas prices and posts to core go ob.observeOutTx() // Populates receipts and confirmed outbound transactions + go ob.ExternalChainRPCStatus() +} + +func (ob *EVMChainClient) ExternalChainRPCStatus() { + ob.logger.ChainLogger.Info().Msgf("Starting RPC status check for chain %s", ob.chain.String()) + ticker := time.NewTicker(60 * time.Second) + for { + select { + case <-ticker.C: + bn, err := ob.evmClient.BlockNumber(context.Background()) + if err != nil { + ob.logger.ChainLogger.Error().Err(err).Msg("RPC Status Check error: RPC down?") + continue + } + gasPrice, err := ob.evmClient.SuggestGasPrice(context.Background()) + if err != nil { + ob.logger.ChainLogger.Error().Err(err).Msg("RPC Status Check error: RPC down?") + continue + } + header, err := ob.evmClient.HeaderByNumber(context.Background(), new(big.Int).SetUint64(bn)) + if err != nil { + ob.logger.ChainLogger.Error().Err(err).Msg("RPC Status Check error: RPC down?") + continue + } + // #nosec G701 always in range + blockTime := time.Unix(int64(header.Time), 0).UTC() + elapsedSeconds := time.Since(blockTime).Seconds() + if elapsedSeconds > 100 { + ob.logger.ChainLogger.Warn().Msgf("RPC Status Check warning: RPC stale or chain stuck (check explorer)? Latest block %d timestamp is %.0fs ago", bn, elapsedSeconds) + continue + } + ob.logger.ChainLogger.Info().Msgf("[OK] RPC status: latest block num %d, timestamp %s ( %.0fs ago), suggested gas price %d", header.Number, blockTime.String(), elapsedSeconds, gasPrice.Uint64()) + case <-ob.stop: + return + } + } } func (ob *EVMChainClient) Stop() { @@ -318,7 +353,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co if receipt.Status == 1 { recvStatus = common.ReceiveStatus_Success } - zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation( + zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound( sendHash, receipt.TxHash.Hex(), receipt.BlockNumber.Uint64(), @@ -340,7 +375,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co } else if cointype == common.CoinType_Gas { // the outbound is a regular Ether/BNB/Matic transfer; no need to check events if receipt.Status == 1 { - zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation( + zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound( sendHash, receipt.TxHash.Hex(), receipt.BlockNumber.Uint64(), @@ -361,7 +396,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co return true, true, nil } else if receipt.Status == 0 { // the same as below events flow logger.Info().Msgf("Found (failed tx) sendHash %s on chain %s txhash %s", sendHash, ob.chain.String(), receipt.TxHash.Hex()) - zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation( + zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound( sendHash, receipt.TxHash.Hex(), receipt.BlockNumber.Uint64(), @@ -375,7 +410,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co common.CoinType_Gas, ) if err != nil { - logger.Error().Err(err).Msgf("PostReceiveConfirmation error in WatchTxHashWithTimeout; zeta tx hash %s cctx %s nonce %d", zetaTxHash, sendHash, nonce) + logger.Error().Err(err).Msgf("PostVoteOutbound error in WatchTxHashWithTimeout; zeta tx hash %s cctx %s nonce %d", zetaTxHash, sendHash, nonce) } else if zetaTxHash != "" { logger.Info().Msgf("Zeta tx hash: %s cctx %s nonce %d ballot %s", zetaTxHash, sendHash, nonce, ballot) } @@ -405,7 +440,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co sendhash := vLog.Topics[3].Hex() //var rxAddress string = ethcommon.HexToAddress(vLog.Topics[1].Hex()).Hex() mMint := receivedLog.ZetaValue - zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation( + zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound( sendhash, vLog.TxHash.Hex(), vLog.BlockNumber, @@ -442,7 +477,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co } sendhash := vLog.Topics[2].Hex() mMint := revertedLog.RemainingZetaValue - zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation( + zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound( sendhash, vLog.TxHash.Hex(), vLog.BlockNumber, @@ -470,7 +505,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co } else if receipt.Status == 0 { //FIXME: check nonce here by getTransaction RPC logger.Info().Msgf("Found (failed tx) sendHash %s on chain %s txhash %s", sendHash, ob.chain.String(), receipt.TxHash.Hex()) - zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation( + zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound( sendHash, receipt.TxHash.Hex(), receipt.BlockNumber.Uint64(), @@ -510,7 +545,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co } if confHeight <= ob.GetLastBlockHeight() { logger.Info().Msg("Confirmed! Sending PostConfirmation to zetacore...") - zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation( + zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound( sendHash, vLog.TxHash.Hex(), vLog.BlockNumber, @@ -537,7 +572,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co } } else { logger.Info().Msgf("Found (failed tx) sendHash %s on chain %s txhash %s", sendHash, ob.chain.String(), receipt.TxHash.Hex()) - zetaTxHash, ballot, err := ob.zetaClient.PostReceiveConfirmation( + zetaTxHash, ballot, err := ob.zetaClient.PostVoteOutbound( sendHash, receipt.TxHash.Hex(), receipt.BlockNumber.Uint64(), @@ -551,7 +586,7 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce uint64, co common.CoinType_ERC20, ) if err != nil { - logger.Error().Err(err).Msgf("PostReceiveConfirmation error in WatchTxHashWithTimeout; zeta tx hash %s", zetaTxHash) + logger.Error().Err(err).Msgf("PostVoteOutbound error in WatchTxHashWithTimeout; zeta tx hash %s", zetaTxHash) } else if zetaTxHash != "" { logger.Info().Msgf("Zeta tx hash: %s cctx %s nonce %d ballot %s", zetaTxHash, sendHash, nonce, ballot) } @@ -980,13 +1015,11 @@ func (ob *EVMChainClient) observeZetaSent(startBlock, toBlock uint64) uint64 { if event.Raw.BlockNumber > beingScanned { beingScanned = event.Raw.BlockNumber } - msg, err := ob.GetInboundVoteMsgForZetaSentEvent(event) - if err != nil { - ob.logger.ExternalChainWatcher.Error().Err(err).Msgf( - "observeZetaSent: error getting inbound vote msg for tx %s chain %d", event.Raw.TxHash.Hex(), ob.chain.ChainId) + msg := ob.GetInboundVoteMsgForZetaSentEvent(event) + if msg == nil { continue } - zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendNonEVMGasLimit, &msg) + zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundMessagePassingExecutionGasLimit, msg) if err != nil { ob.logger.ExternalChainWatcher.Error().Err(err).Msgf( "observeZetaSent: error posting event to zeta core for tx %s at height %d for chain %d", @@ -994,7 +1027,7 @@ func (ob *EVMChainClient) observeZetaSent(startBlock, toBlock uint64) uint64 { return beingScanned - 1 // we have to re-scan from this block next time } else if zetaHash != "" { ob.logger.ExternalChainWatcher.Info().Msgf( - "observeZetaSent: event detected in tx %s at height %d for chain %d, PostSend zeta tx: %s ballot %s", + "observeZetaSent: event detected in tx %s at height %d for chain %d, PostVoteInbound zeta tx: %s ballot %s", event.Raw.TxHash.Hex(), event.Raw.BlockNumber, ob.chain.ChainId, zetaHash, ballot) } } @@ -1053,19 +1086,35 @@ func (ob *EVMChainClient) observeERC20Deposited(startBlock, toBlock uint64) uint } // post to zetacore + guard := make(map[string]bool) // guard against multiple events in the same tx beingScanned := uint64(0) for _, event := range events { // remember which block we are scanning (there could be multiple events in the same block) if event.Raw.BlockNumber > beingScanned { beingScanned = event.Raw.BlockNumber } - msg, err := ob.GetInboundVoteMsgForDepositedEvent(event) + tx, _, err := ob.evmClient.TransactionByHash(context.Background(), event.Raw.TxHash) if err != nil { - ob.logger.ExternalChainWatcher.Error().Err(err).Msgf( - "observeERC20Deposited: error getting inbound vote msg for tx %s chain %d", event.Raw.TxHash.Hex(), ob.chain.ChainId) + ob.logger.ExternalChainWatcher.Err(err).Msgf( + "observeERC20Deposited: TransactionByHash error for tx %s chain %d", tx.Hash().Hex(), ob.chain.ChainId) + return beingScanned - 1 // we have to re-scan from this block next time + } + sender, err := ob.GetTransactionSender(tx, event.Raw.BlockHash, event.Raw.TxIndex) + if err != nil { + ob.logger.ExternalChainWatcher.Err(err).Msgf( + "observeERC20Deposited: GetTransactionSender error for tx %s chain %d", tx.Hash().Hex(), ob.chain.ChainId) + return beingScanned - 1 // we have to re-scan from this block next time + } + if guard[event.Raw.TxHash.Hex()] { + ob.logger.ExternalChainWatcher.Warn().Msgf("more than one remote call event in a single tx %s; skip the rest", event.Raw.TxHash.Hex()) + continue + } + + msg := ob.GetInboundVoteMsgForDepositedEvent(event, sender) + if msg == nil { continue } - zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendEVMGasLimit, &msg) + zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundExecutionGasLimit, msg) if err != nil { ob.logger.ExternalChainWatcher.Error().Err(err).Msgf( "observeERC20Deposited: error posting event to zeta core for tx %s at height %d for chain %d", @@ -1073,9 +1122,10 @@ func (ob *EVMChainClient) observeERC20Deposited(startBlock, toBlock uint64) uint return beingScanned - 1 // we have to re-scan from this block next time } else if zetaHash != "" { ob.logger.ExternalChainWatcher.Info().Msgf( - "observeERC20Deposited: event detected in tx %s at height %d for chain %d, PostSend zeta tx: %s ballot %s", + "observeERC20Deposited: event detected in tx %s at height %d for chain %d, PostVoteInbound zeta tx: %s ballot %s", event.Raw.TxHash.Hex(), event.Raw.BlockNumber, ob.chain.ChainId, zetaHash, ballot) } + guard[event.Raw.TxHash.Hex()] = true } // successful processed all events in [startBlock, toBlock] return toBlock @@ -1084,6 +1134,10 @@ func (ob *EVMChainClient) observeERC20Deposited(startBlock, toBlock uint64) uint // observeTssRecvd queries the incoming gas asset to TSS address and posts to zetacore // returns the last block successfully scanned func (ob *EVMChainClient) observeTssRecvd(startBlock, toBlock uint64, flags observertypes.CrosschainFlags) uint64 { + if !ob.GetChainParams().IsSupported { + //ob.logger.ExternalChainWatcher.Warn().Msgf("observeTssRecvd: chain %d is not supported", ob.chain.ChainId) + return startBlock - 1 // lastScanned + } // check TSS address (after keygen, ob.Tss.pubkey will be updated) tssAddress := ob.Tss.EVMAddress() if tssAddress == (ethcommon.Address{}) { @@ -1108,54 +1162,44 @@ func (ob *EVMChainClient) observeTssRecvd(startBlock, toBlock uint64, flags obse block, err := ob.GetBlockByNumberCached(bn) if err != nil { ob.logger.ExternalChainWatcher.Error().Err(err).Msgf("observeTssRecvd: error getting block %d for chain %d", bn, ob.chain.ChainId) - return startBlock - 1 // we have to re-scan from this block next time + return bn - 1 // we have to re-scan from this block next time } for _, tx := range block.Transactions() { if tx.To() == nil { continue } - if bytes.Equal(tx.Data(), []byte(DonationMessage)) { - ob.logger.ExternalChainWatcher.Info().Msgf( - "observeTssRecvd: thank you rich folk for your donation!: %s chain %d", tx.Hash().Hex(), ob.chain.ChainId) - continue - } if *tx.To() == tssAddress { receipt, err := ob.evmClient.TransactionReceipt(context.Background(), tx.Hash()) if err != nil { ob.logger.ExternalChainWatcher.Err(err).Msgf( "observeTssRecvd: TransactionReceipt error for tx %s chain %d", tx.Hash().Hex(), ob.chain.ChainId) - return startBlock - 1 // we have to re-scan this block next time + return bn - 1 // we have to re-scan this block next time } if receipt.Status != 1 { // 1: successful, 0: failed ob.logger.ExternalChainWatcher.Info().Msgf("observeTssRecvd: tx %s chain %d failed; don't act", tx.Hash().Hex(), ob.chain.ChainId) continue } - from, err := ob.evmClient.TransactionSender(context.Background(), tx, block.Hash(), receipt.TransactionIndex) + sender, err := ob.GetTransactionSender(tx, block.Hash(), receipt.TransactionIndex) if err != nil { - ob.logger.ExternalChainWatcher.Err(err).Msgf("observeTssRecvd: TransactionSender error for tx %s", tx.Hash().Hex()) - // trying local recovery (assuming LondonSigner dynamic fee tx type) of sender address - signer := ethtypes.NewLondonSigner(big.NewInt(ob.chain.ChainId)) - from, err = signer.Sender(tx) - if err != nil { - ob.logger.ExternalChainWatcher.Err(err).Msgf( - "observeTssRecvd: local recovery of sender address failed for tx %s chain %d", tx.Hash().Hex(), ob.chain.ChainId) - continue - } + ob.logger.ExternalChainWatcher.Err(err).Msgf( + "observeTssRecvd: GetTransactionSender error for tx %s chain %d", tx.Hash().Hex(), ob.chain.ChainId) + return bn - 1 // we have to re-scan this block next time } - msg := ob.GetInboundVoteMsgForTokenSentToTSS(tx.Hash(), tx.Value(), receipt, from, tx.Data()) + + msg := ob.GetInboundVoteMsgForTokenSentToTSS(tx, sender, receipt.BlockNumber.Uint64()) if msg == nil { continue } - zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendEVMGasLimit, msg) + zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundExecutionGasLimit, msg) if err != nil { ob.logger.ExternalChainWatcher.Error().Err(err).Msgf( "observeTssRecvd: error posting to zeta core for tx %s at height %d for chain %d", tx.Hash().Hex(), bn, ob.chain.ChainId) - return startBlock - 1 // we have to re-scan this block next time + return bn - 1 // we have to re-scan this block next time } else if zetaHash != "" { ob.logger.ExternalChainWatcher.Info().Msgf( - "observeTssRecvd: gas asset deposit detected in tx %s at height %d for chain %d, PostSend zeta tx: %s ballot %s", + "observeTssRecvd: gas asset deposit detected in tx %s at height %d for chain %d, PostVoteInbound zeta tx: %s ballot %s", tx.Hash().Hex(), bn, ob.chain.ChainId, zetaHash, ballot) } } @@ -1166,7 +1210,7 @@ func (ob *EVMChainClient) observeTssRecvd(startBlock, toBlock uint64, flags obse } func (ob *EVMChainClient) WatchGasPrice() { - + ob.logger.WatchGasPrice.Info().Msg("WatchGasPrice starting...") err := ob.PostGasPrice() if err != nil { height, err := ob.zetaClient.GetBlockHeight() @@ -1182,6 +1226,7 @@ func (ob *EVMChainClient) WatchGasPrice() { ob.logger.WatchGasPrice.Error().Err(err).Msg("NewDynamicTicker error") return } + ob.logger.WatchGasPrice.Info().Msgf("WatchGasPrice started with interval %d", ob.GetChainParams().GasPriceTicker) defer ticker.Stop() for { @@ -1205,6 +1250,7 @@ func (ob *EVMChainClient) WatchGasPrice() { } func (ob *EVMChainClient) PostGasPrice() error { + // GAS PRICE gasPrice, err := ob.evmClient.SuggestGasPrice(context.TODO()) if err != nil { @@ -1226,7 +1272,6 @@ func (ob *EVMChainClient) PostGasPrice() error { return err } _ = zetaHash - //ob.logger.WatchGasPrice.Debug().Msgf("PostGasPrice zeta tx: %s", zetaHash) return nil } diff --git a/zetaclient/inbound_tracker.go b/zetaclient/inbound_tracker.go index 8a7ebd1147..31ea30f06e 100644 --- a/zetaclient/inbound_tracker.go +++ b/zetaclient/inbound_tracker.go @@ -3,11 +3,9 @@ package zetaclient import ( "errors" "fmt" - "math/big" "github.com/btcsuite/btcd/chaincfg/chainhash" ethcommon "github.com/ethereum/go-ethereum/common" - ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/x/crosschain/types" "golang.org/x/net/context" @@ -114,12 +112,12 @@ func (ob *BitcoinChainClient) CheckReceiptForBtcTxHash(txHash string, vote bool) if !vote { return msg.Digest(), nil } - zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendEVMGasLimit, msg) + zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundExecutionGasLimit, msg) if err != nil { ob.logger.WatchInTx.Error().Err(err).Msg("error posting to zeta core") return "", err } else if ballot == "" { - ob.logger.WatchInTx.Info().Msgf("BTC deposit detected and reported: PostSend zeta tx: %s ballot %s", zetaHash, ballot) + ob.logger.WatchInTx.Info().Msgf("BTC deposit detected and reported: PostVoteInbound zeta tx: %s ballot %s", zetaHash, ballot) } return msg.Digest(), nil } @@ -172,15 +170,15 @@ func (ob *EVMChainClient) CheckReceiptForCoinTypeZeta(txHash string, vote bool) return "", fmt.Errorf("txHash %s has not been confirmed yet: receipt block %d current block %d", txHash, receipt.BlockNumber, lastHeight) } - var msg types.MsgVoteOnObservedInboundTx + var msg *types.MsgVoteOnObservedInboundTx for _, log := range receipt.Logs { event, err := connector.ParseZetaSent(*log) if err == nil && event != nil { // sanity check tx event err = ob.CheckEvmTxLog(&event.Raw, addrConnector, txHash, TopicsZetaSent) if err == nil { - msg, err = ob.GetInboundVoteMsgForZetaSentEvent(event) - if err == nil { + msg = ob.GetInboundVoteMsgForZetaSentEvent(event) + if msg != nil { break } } else { @@ -188,16 +186,19 @@ func (ob *EVMChainClient) CheckReceiptForCoinTypeZeta(txHash string, vote bool) } } } + if msg == nil { + return "", errors.New("no ZetaSent event found") + } if !vote { return msg.Digest(), nil } - zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendNonEVMGasLimit, &msg) + zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundMessagePassingExecutionGasLimit, msg) if err != nil { ob.logger.ExternalChainWatcher.Error().Err(err).Msg("error posting to zeta core") return "", err } else if zetaHash != "" { - ob.logger.ExternalChainWatcher.Info().Msgf("ZetaSent event detected and reported: PostSend zeta tx: %s ballot %s", zetaHash, ballot) + ob.logger.ExternalChainWatcher.Info().Msgf("ZetaSent event detected and reported: PostVoteInbound zeta tx: %s ballot %s", zetaHash, ballot) } return msg.Digest(), nil @@ -208,11 +209,20 @@ func (ob *EVMChainClient) CheckReceiptForCoinTypeERC20(txHash string, vote bool) if err != nil { return "", err } + // get transaction, receipt and sender hash := ethcommon.HexToHash(txHash) + tx, _, err := ob.evmClient.TransactionByHash(context.Background(), hash) + if err != nil { + return "", err + } receipt, err := ob.evmClient.TransactionReceipt(context.Background(), hash) if err != nil { return "", err } + sender, err := ob.evmClient.TransactionSender(context.Background(), tx, receipt.BlockHash, receipt.TransactionIndex) + if err != nil { + return "", err + } // check if the tx is confirmed lastHeight := ob.GetLastBlockHeight() @@ -220,38 +230,48 @@ func (ob *EVMChainClient) CheckReceiptForCoinTypeERC20(txHash string, vote bool) return "", fmt.Errorf("txHash %s has not been confirmed yet: receipt block %d current block %d", txHash, receipt.BlockNumber, lastHeight) } - var msg types.MsgVoteOnObservedInboundTx + var msg *types.MsgVoteOnObservedInboundTx for _, log := range receipt.Logs { zetaDeposited, err := custody.ParseDeposited(*log) if err == nil && zetaDeposited != nil { // sanity check tx event err = ob.CheckEvmTxLog(&zetaDeposited.Raw, addrCustory, txHash, TopicsDeposited) if err == nil { - msg, err = ob.GetInboundVoteMsgForDepositedEvent(zetaDeposited) + msg = ob.GetInboundVoteMsgForDepositedEvent(zetaDeposited, sender) if err == nil { break } } else { - ob.logger.ExternalChainWatcher.Error().Err(err).Msg("CheckEvmTxLog error on Deposited event") + ob.logger.ExternalChainWatcher.Error().Err(err).Msg("CheckEvmTxLog error on ERC20CustodyDeposited event") } } } + if msg == nil { + return "", errors.New("no ERC20CustodyDeposited event found") + } if !vote { return msg.Digest(), nil } - zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendEVMGasLimit, &msg) + zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundExecutionGasLimit, msg) if err != nil { ob.logger.ExternalChainWatcher.Error().Err(err).Msg("error posting to zeta core") return "", err } else if zetaHash != "" { - ob.logger.ExternalChainWatcher.Info().Msgf("ERC20 Deposit event detected and reported: PostSend zeta tx: %s ballot %s", zetaHash, ballot) + ob.logger.ExternalChainWatcher.Info().Msgf("ERC20 Deposit event detected and reported: PostVoteInbound zeta tx: %s ballot %s", zetaHash, ballot) } return msg.Digest(), nil } func (ob *EVMChainClient) CheckReceiptForCoinTypeGas(txHash string, vote bool) (string, error) { + // TSS address should be set + tssAddress := ob.Tss.EVMAddress() + if tssAddress == (ethcommon.Address{}) { + return "", errors.New("TSS address not set") + } + + // check transaction and receipt hash := ethcommon.HexToHash(txHash) tx, isPending, err := ob.evmClient.TransactionByHash(context.Background(), hash) if err != nil { @@ -260,6 +280,12 @@ func (ob *EVMChainClient) CheckReceiptForCoinTypeGas(txHash string, vote bool) ( if isPending { return "", errors.New("tx is still pending") } + if tx.To() == nil { + return "", errors.New("tx.To() is nil") + } + if *tx.To() != tssAddress { + return "", fmt.Errorf("tx.To() %s is not TSS address", tssAddress.Hex()) + } receipt, err := ob.evmClient.TransactionReceipt(context.Background(), hash) if err != nil { @@ -270,39 +296,30 @@ func (ob *EVMChainClient) CheckReceiptForCoinTypeGas(txHash string, vote bool) ( ob.logger.ExternalChainWatcher.Info().Msgf("tx %s failed; don't act", tx.Hash().Hex()) return "", errors.New("tx not successful yet") } + sender, err := ob.evmClient.TransactionSender(context.Background(), tx, receipt.BlockHash, receipt.TransactionIndex) + if err != nil { + return "", err + } // check if the tx is confirmed lastHeight := ob.GetLastBlockHeight() if !ob.HasEnoughConfirmations(receipt, lastHeight) { return "", fmt.Errorf("txHash %s has not been confirmed yet: receipt block %d current block %d", txHash, receipt.BlockNumber, lastHeight) } - - block, err := ob.evmClient.BlockByNumber(context.Background(), receipt.BlockNumber) - if err != nil { - ob.logger.ExternalChainWatcher.Err(err).Msg("BlockByNumber error") - return "", err - } - from, err := ob.evmClient.TransactionSender(context.Background(), tx, block.Hash(), receipt.TransactionIndex) - if err != nil { - ob.logger.ExternalChainWatcher.Err(err).Msg("TransactionSender error; trying local recovery (assuming LondonSigner dynamic fee tx type) of sender address") - signer := ethtypes.NewLondonSigner(big.NewInt(ob.chain.ChainId)) - from, err = signer.Sender(tx) - if err != nil { - ob.logger.ExternalChainWatcher.Err(err).Msg("local recovery of sender address failed") - return "", err - } + msg := ob.GetInboundVoteMsgForTokenSentToTSS(tx, sender, receipt.BlockNumber.Uint64()) + if msg == nil { + return "", errors.New("no message built for token sent to TSS") } - msg := ob.GetInboundVoteMsgForTokenSentToTSS(tx.Hash(), tx.Value(), receipt, from, tx.Data()) if !vote { return msg.Digest(), nil } - zetaHash, ballot, err := ob.zetaClient.PostSend(PostSendEVMGasLimit, msg) + zetaHash, ballot, err := ob.zetaClient.PostVoteInbound(PostVoteInboundGasLimit, PostVoteInboundExecutionGasLimit, msg) if err != nil { ob.logger.ExternalChainWatcher.Error().Err(err).Msg("error posting to zeta core") return "", err } else if zetaHash != "" { - ob.logger.ExternalChainWatcher.Info().Msgf("Gas deposit detected and reported: PostSend zeta tx: %s ballot %s", zetaHash, ballot) + ob.logger.ExternalChainWatcher.Info().Msgf("Gas deposit detected and reported: PostVoteInbound zeta tx: %s ballot %s", zetaHash, ballot) } return msg.Digest(), nil diff --git a/zetaclient/interfaces.go b/zetaclient/interfaces.go index fe2d0824c1..6ca41f59fd 100644 --- a/zetaclient/interfaces.go +++ b/zetaclient/interfaces.go @@ -48,8 +48,8 @@ type ChainSigner interface { // ZetaCoreBridger is the interface to interact with ZetaCore type ZetaCoreBridger interface { - PostSend(zetaGasLimit uint64, msg *crosschaintypes.MsgVoteOnObservedInboundTx) (string, string, error) - PostReceiveConfirmation( + PostVoteInbound(gasLimit, retryGasLimit uint64, msg *crosschaintypes.MsgVoteOnObservedInboundTx) (string, string, error) + PostVoteOutbound( sendHash string, outTxHash string, outBlockHeight uint64, diff --git a/zetaclient/telemetry.go b/zetaclient/telemetry.go index 9255b54247..e43b0e6d99 100644 --- a/zetaclient/telemetry.go +++ b/zetaclient/telemetry.go @@ -133,6 +133,7 @@ func (t *TelemetryServer) Handlers() http.Handler { router.Handle("/status", http.HandlerFunc(t.statusHandler)).Methods(http.MethodGet) router.Handle("/ip", http.HandlerFunc(t.ipHandler)).Methods(http.MethodGet) router.Handle("/hotkeyburnrate", http.HandlerFunc(t.hotKeyFeeBurnRate)).Methods(http.MethodGet) + // router.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine")) // router.Handle("/debug/pprof/heap", pprof.Handler("heap")) // router.HandleFunc("/debug/pprof/", pprof.Index) diff --git a/zetaclient/tx.go b/zetaclient/tx.go index 38a02052ed..15847c3f80 100644 --- a/zetaclient/tx.go +++ b/zetaclient/tx.go @@ -2,15 +2,10 @@ package zetaclient import ( "fmt" - "math/big" - "strings" "time" - "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/authz" - "github.com/pkg/errors" - "github.com/zeta-chain/go-tss/blame" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -19,55 +14,27 @@ import ( ) const ( - PostGasPriceGasLimit = 1_500_000 + // DefaultGasLimit is the default gas limit used for broadcasting txs + DefaultGasLimit = 200_000 + + // PostGasPriceGasLimit is the gas limit for voting new gas price + PostGasPriceGasLimit = 1_500_000 + + // AddTxHashToOutTxTrackerGasLimit is the gas limit for adding tx hash to out tx tracker AddTxHashToOutTxTrackerGasLimit = 200_000 - PostNonceGasLimit = 200_000 - PostSendEVMGasLimit = 4_000_000 // likely emit a lot of logs, so costly - PostSendNonEVMGasLimit = 1_000_000 - PostReceiveConfirmationGasLimit = 400_000 - PostBlameDataGasLimit = 200_000 - DefaultGasLimit = 200_000 - PostProveOutboundTxGasLimit = 400_000 - DefaultRetryCount = 5 - ExtendedRetryCount = 15 - DefaultRetryInterval = 5 -) -// GetInBoundVoteMessage returns a new MsgVoteOnObservedInboundTx -func GetInBoundVoteMessage( - sender string, - senderChain int64, - txOrigin string, - receiver string, - receiverChain int64, - amount math.Uint, - message string, - inTxHash string, - inBlockHeight uint64, - gasLimit uint64, - coinType common.CoinType, - asset string, - signerAddress string, - eventIndex uint, -) *types.MsgVoteOnObservedInboundTx { - msg := types.NewMsgVoteOnObservedInboundTx( - signerAddress, - sender, - senderChain, - txOrigin, - receiver, - receiverChain, - amount, - message, - inTxHash, - inBlockHeight, - gasLimit, - coinType, - asset, - eventIndex, - ) - return msg -} + // PostBlameDataGasLimit is the gas limit for voting on blames + PostBlameDataGasLimit = 200_000 + + // DefaultRetryCount is the number of retries for broadcasting a tx + DefaultRetryCount = 5 + + // ExtendedRetryCount is an extended number of retries for broadcasting a tx, used in keygen operations + ExtendedRetryCount = 15 + + // DefaultRetryInterval is the interval between retries in seconds + DefaultRetryInterval = 5 +) func (b *ZetaCoreBridge) WrapMessageWithAuthz(msg sdk.Msg) (sdk.Msg, AuthZSigner, error) { msgURL := sdk.MsgTypeURL(msg) @@ -126,100 +93,6 @@ func (b *ZetaCoreBridge) AddTxHashToOutTxTracker( return zetaTxHash, nil } -func (b *ZetaCoreBridge) PostSend(zetaGasLimit uint64, msg *types.MsgVoteOnObservedInboundTx) (string, string, error) { - authzMsg, authzSigner, err := b.WrapMessageWithAuthz(msg) - if err != nil { - return "", "", err - } - - // don't post send if has already voted before - ballotIndex := msg.Digest() - hasVoted, err := b.HasVoted(ballotIndex, msg.Creator) - if err != nil { - return "", ballotIndex, errors.Wrapf(err, "PostSend: unable to check if already voted for ballot %s voter %s", ballotIndex, msg.Creator) - } - if hasVoted { - return "", ballotIndex, nil - } - - for i := 0; i < DefaultRetryCount; i++ { - zetaTxHash, err := b.Broadcast(zetaGasLimit, authzMsg, authzSigner) - if err == nil { - // monitor the result of the transaction - go b.MonitorTxResult(zetaTxHash, true) - - return zetaTxHash, ballotIndex, nil - } - b.logger.Debug().Err(err).Msgf("PostSend broadcast fail | Retry count : %d", i+1) - time.Sleep(DefaultRetryInterval * time.Second) - } - return "", ballotIndex, fmt.Errorf("post send failed after %d retries", DefaultRetryInterval) -} - -func (b *ZetaCoreBridge) PostReceiveConfirmation( - sendHash string, - outTxHash string, - outBlockHeight uint64, - outTxGasUsed uint64, - outTxEffectiveGasPrice *big.Int, - outTxEffectiveGasLimit uint64, - amount *big.Int, - status common.ReceiveStatus, - chain common.Chain, - nonce uint64, - coinType common.CoinType, -) (string, string, error) { - signerAddress := b.keys.GetOperatorAddress().String() - msg := types.NewMsgVoteOnObservedOutboundTx( - signerAddress, - sendHash, - outTxHash, - outBlockHeight, - outTxGasUsed, - math.NewIntFromBigInt(outTxEffectiveGasPrice), - outTxEffectiveGasLimit, - math.NewUintFromBigInt(amount), - status, - chain.ChainId, - nonce, - coinType, - ) - - authzMsg, authzSigner, err := b.WrapMessageWithAuthz(msg) - if err != nil { - return "", "", err - } - - // don't post confirmation if has already voted before - ballotIndex := msg.Digest() - hasVoted, err := b.HasVoted(ballotIndex, msg.Creator) - if err != nil { - return "", ballotIndex, errors.Wrapf(err, "PostReceiveConfirmation: unable to check if already voted for ballot %s voter %s", ballotIndex, msg.Creator) - } - if hasVoted { - return "", ballotIndex, nil - } - - // FIXME: remove this gas limit stuff; in the special ante handler with no gas limit, add - // NewMsgReceiveConfirmation to it. - var gasLimit uint64 = PostReceiveConfirmationGasLimit - if status == common.ReceiveStatus_Failed { - gasLimit = PostSendEVMGasLimit - } - for i := 0; i < DefaultRetryCount; i++ { - zetaTxHash, err := b.Broadcast(gasLimit, authzMsg, authzSigner) - if err == nil { - // monitor the result of the transaction - go b.MonitorTxResult(zetaTxHash, true) - - return zetaTxHash, ballotIndex, nil - } - b.logger.Debug().Err(err).Msgf("PostReceive broadcast fail | Retry count : %d", i+1) - time.Sleep(DefaultRetryInterval * time.Second) - } - return "", ballotIndex, fmt.Errorf("post receive failed after %d retries", DefaultRetryCount) -} - func (b *ZetaCoreBridge) SetTSS(tssPubkey string, keyGenZetaHeight int64, status common.ReceiveStatus) (string, error) { signerAddress := b.keys.GetOperatorAddress().String() msg := types.NewMsgCreateTSSVoter(signerAddress, tssPubkey, keyGenZetaHeight, status) @@ -308,40 +181,3 @@ func (b *ZetaCoreBridge) PostAddBlockHeader(chainID int64, blockHash []byte, hei } return "", fmt.Errorf("post add block header failed after %d retries", DefaultRetryCount) } - -// MonitorTxResult monitors the result of a tx (used for inbound and outbound vote txs) -func (b *ZetaCoreBridge) MonitorTxResult(zetaTxHash string, isInbound bool) { - var lastErr error - ticker := 5 * time.Second - retry := 10 - prefix := "MonitorOutboundTxResult" - if isInbound { - prefix = "MonitorInboundTxResult" - } - - for i := 0; i < retry; i++ { - time.Sleep(ticker) - txResult, err := b.QueryTxResult(zetaTxHash) - if err == nil { - // the inbound vote tx shouldn't fail to execute - if strings.Contains(txResult.RawLog, "failed to execute message") { - b.logger.Error().Msgf( - "%s: failed to execute vote, txHash: %s, txResult %s", - prefix, - zetaTxHash, - txResult.String(), - ) - } - return - } - lastErr = err - } - - b.logger.Error().Err(lastErr).Msgf( - "%s: unable to query tx result for txHash %s, err %s", - prefix, - zetaTxHash, - lastErr.Error(), - ) - return -} diff --git a/zetaclient/tx_vote_inbound.go b/zetaclient/tx_vote_inbound.go new file mode 100644 index 0000000000..1e5807474f --- /dev/null +++ b/zetaclient/tx_vote_inbound.go @@ -0,0 +1,153 @@ +package zetaclient + +import ( + "fmt" + "strings" + "time" + + "cosmossdk.io/math" + "github.com/zeta-chain/zetacore/common" + + "github.com/pkg/errors" + + "github.com/zeta-chain/zetacore/x/crosschain/types" +) + +const ( + // PostVoteInboundGasLimit is the gas limit for voting on observed inbound tx + PostVoteInboundGasLimit = 400_000 + + // PostVoteInboundExecutionGasLimit is the gas limit for voting on observed inbound tx and executing it + PostVoteInboundExecutionGasLimit = 4_000_000 + + // PostVoteInboundMessagePassingExecutionGasLimit is the gas limit for voting on, and executing ,observed inbound tx related to message passing (coin_type == zeta) + PostVoteInboundMessagePassingExecutionGasLimit = 1_000_000 + + // MonitorVoteInboundTxResultInterval is the interval between retries for monitoring tx result in seconds + MonitorVoteInboundTxResultInterval = 5 + + // MonitorVoteInboundTxResultRetryCount is the number of retries to fetch monitoring tx result + MonitorVoteInboundTxResultRetryCount = 20 +) + +// GetInBoundVoteMessage returns a new MsgVoteOnObservedInboundTx +func GetInBoundVoteMessage( + sender string, + senderChain int64, + txOrigin string, + receiver string, + receiverChain int64, + amount math.Uint, + message string, + inTxHash string, + inBlockHeight uint64, + gasLimit uint64, + coinType common.CoinType, + asset string, + signerAddress string, + eventIndex uint, +) *types.MsgVoteOnObservedInboundTx { + msg := types.NewMsgVoteOnObservedInboundTx( + signerAddress, + sender, + senderChain, + txOrigin, + receiver, + receiverChain, + amount, + message, + inTxHash, + inBlockHeight, + gasLimit, + coinType, + asset, + eventIndex, + ) + return msg +} + +// PostVoteInbound posts a vote on an observed inbound tx +// retryGasLimit is the gas limit used to resend the tx if it fails because of insufficient gas +// it is used when the ballot is finalized and the inbound tx needs to be processed +func (b *ZetaCoreBridge) PostVoteInbound(gasLimit, retryGasLimit uint64, msg *types.MsgVoteOnObservedInboundTx) (string, string, error) { + authzMsg, authzSigner, err := b.WrapMessageWithAuthz(msg) + if err != nil { + return "", "", err + } + + // don't post send if has already voted before + ballotIndex := msg.Digest() + hasVoted, err := b.HasVoted(ballotIndex, msg.Creator) + if err != nil { + return "", ballotIndex, errors.Wrapf(err, "PostVoteInbound: unable to check if already voted for ballot %s voter %s", ballotIndex, msg.Creator) + } + if hasVoted { + return "", ballotIndex, nil + } + + for i := 0; i < DefaultRetryCount; i++ { + zetaTxHash, err := b.Broadcast(gasLimit, authzMsg, authzSigner) + if err == nil { + // monitor the result of the transaction and resend if necessary + go b.MonitorVoteInboundTxResult(zetaTxHash, retryGasLimit, msg) + + return zetaTxHash, ballotIndex, nil + } + b.logger.Debug().Err(err).Msgf("PostVoteInbound broadcast fail | Retry count : %d", i+1) + time.Sleep(DefaultRetryInterval * time.Second) + } + return "", ballotIndex, fmt.Errorf("post send failed after %d retries", DefaultRetryInterval) +} + +// MonitorVoteInboundTxResult monitors the result of a vote inbound tx +// retryGasLimit is the gas limit used to resend the tx if it fails because of insufficient gas +// if retryGasLimit is 0, the tx is not resent +func (b *ZetaCoreBridge) MonitorVoteInboundTxResult(zetaTxHash string, retryGasLimit uint64, msg *types.MsgVoteOnObservedInboundTx) { + var lastErr error + + for i := 0; i < MonitorVoteInboundTxResultRetryCount; i++ { + time.Sleep(MonitorVoteInboundTxResultInterval * time.Second) + + // query tx result from ZetaChain + txResult, err := b.QueryTxResult(zetaTxHash) + + if err == nil { + if strings.Contains(txResult.RawLog, "failed to execute message") { + // the inbound vote tx shouldn't fail to execute + // this shouldn't happen + b.logger.Error().Msgf( + "MonitorInboundTxResult: failed to execute vote, txHash: %s, log %s", zetaTxHash, txResult.RawLog, + ) + } else if strings.Contains(txResult.RawLog, "out of gas") { + // if the tx fails with an out of gas error, resend the tx with more gas if retryGasLimit > 0 + b.logger.Debug().Msgf( + "MonitorInboundTxResult: out of gas, txHash: %s, log %s", zetaTxHash, txResult.RawLog, + ) + if retryGasLimit > 0 { + // new retryGasLimit set to 0 to prevent reentering this function + _, _, err := b.PostVoteInbound(retryGasLimit, 0, msg) + if err != nil { + b.logger.Error().Err(err).Msgf( + "MonitorInboundTxResult: failed to resend tx, txHash: %s, log %s", zetaTxHash, txResult.RawLog, + ) + } else { + b.logger.Info().Msgf( + "MonitorInboundTxResult: successfully resent tx, txHash: %s, log %s", zetaTxHash, txResult.RawLog, + ) + } + } + } else { + b.logger.Debug().Msgf( + "MonitorInboundTxResult: successful txHash %s, log %s", zetaTxHash, txResult.RawLog, + ) + } + return + } + lastErr = err + } + + b.logger.Error().Err(lastErr).Msgf( + "MonitorInboundTxResult: unable to query tx result for txHash %s, err %s", zetaTxHash, lastErr.Error(), + ) + return +} diff --git a/zetaclient/tx_vote_outbound.go b/zetaclient/tx_vote_outbound.go new file mode 100644 index 0000000000..bcf79c69f6 --- /dev/null +++ b/zetaclient/tx_vote_outbound.go @@ -0,0 +1,154 @@ +package zetaclient + +import ( + "fmt" + "math/big" + "strings" + "time" + + "cosmossdk.io/math" + "github.com/pkg/errors" + "github.com/zeta-chain/zetacore/common" + "github.com/zeta-chain/zetacore/x/crosschain/types" +) + +const ( + // PostVoteOutboundGasLimit is the gas limit for voting on observed outbound tx + PostVoteOutboundGasLimit = 400_000 + + // PostVoteOutboundRevertGasLimit is the gas limit for voting on observed outbound tx for revert (when outbound fails) + // The value needs to be higher because reverting implies interacting with the EVM to perform swaps for the gas token + PostVoteOutboundRevertGasLimit = 1_500_000 + + // MonitorVoteOutboundTxResultInterval is the interval between retries for monitoring tx result in seconds + MonitorVoteOutboundTxResultInterval = 5 + + // MonitorVoteOutboundTxResultRetryCount is the number of retries to fetch monitoring tx result + MonitorVoteOutboundTxResultRetryCount = 20 +) + +// PostVoteOutbound posts a vote on an observed outbound tx +func (b *ZetaCoreBridge) PostVoteOutbound( + sendHash string, + outTxHash string, + outBlockHeight uint64, + outTxGasUsed uint64, + outTxEffectiveGasPrice *big.Int, + outTxEffectiveGasLimit uint64, + amount *big.Int, + status common.ReceiveStatus, + chain common.Chain, + nonce uint64, + coinType common.CoinType, +) (string, string, error) { + signerAddress := b.keys.GetOperatorAddress().String() + msg := types.NewMsgVoteOnObservedOutboundTx( + signerAddress, + sendHash, + outTxHash, + outBlockHeight, + outTxGasUsed, + math.NewIntFromBigInt(outTxEffectiveGasPrice), + outTxEffectiveGasLimit, + math.NewUintFromBigInt(amount), + status, + chain.ChainId, + nonce, + coinType, + ) + + // when an outbound fails and a revert is required, the gas limit needs to be higher + // this is because the revert tx needs to interact with the EVM to perform swaps for the gas token + // the higher gas limit is only necessary when the vote is finalized and the outbound is processed + // therefore we use a retryGasLimit with a higher value to resend the tx if it fails (when the vote is finalized) + retryGasLimit := uint64(0) + if msg.Status == common.ReceiveStatus_Failed { + retryGasLimit = PostVoteOutboundRevertGasLimit + } + + return b.PostVoteOutboundFromMsg(PostVoteOutboundGasLimit, retryGasLimit, msg) +} + +// PostVoteOutboundFromMsg posts a vote on an observed outbound tx from a MsgVoteOnObservedOutboundTx +func (b *ZetaCoreBridge) PostVoteOutboundFromMsg(gasLimit, retryGasLimit uint64, msg *types.MsgVoteOnObservedOutboundTx) (string, string, error) { + authzMsg, authzSigner, err := b.WrapMessageWithAuthz(msg) + if err != nil { + return "", "", err + } + + // don't post confirmation if has already voted before + ballotIndex := msg.Digest() + hasVoted, err := b.HasVoted(ballotIndex, msg.Creator) + if err != nil { + return "", ballotIndex, errors.Wrapf(err, "PostVoteOutbound: unable to check if already voted for ballot %s voter %s", ballotIndex, msg.Creator) + } + if hasVoted { + return "", ballotIndex, nil + } + for i := 0; i < DefaultRetryCount; i++ { + zetaTxHash, err := b.Broadcast(gasLimit, authzMsg, authzSigner) + if err == nil { + // monitor the result of the transaction and resend if necessary + go b.MonitorVoteOutboundTxResult(zetaTxHash, retryGasLimit, msg) + + return zetaTxHash, ballotIndex, nil + } + b.logger.Debug().Err(err).Msgf("PostVoteOutbound broadcast fail | Retry count : %d", i+1) + time.Sleep(DefaultRetryInterval * time.Second) + } + return "", ballotIndex, fmt.Errorf("post receive failed after %d retries", DefaultRetryCount) +} + +// MonitorVoteOutboundTxResult monitors the result of a vote outbound tx +// retryGasLimit is the gas limit used to resend the tx if it fails because of insufficient gas +// if retryGasLimit is 0, the tx is not resent +func (b *ZetaCoreBridge) MonitorVoteOutboundTxResult(zetaTxHash string, retryGasLimit uint64, msg *types.MsgVoteOnObservedOutboundTx) { + var lastErr error + + for i := 0; i < MonitorVoteOutboundTxResultRetryCount; i++ { + time.Sleep(MonitorVoteOutboundTxResultInterval * time.Second) + + // query tx result from ZetaChain + txResult, err := b.QueryTxResult(zetaTxHash) + + if err == nil { + if strings.Contains(txResult.RawLog, "failed to execute message") { + // the inbound vote tx shouldn't fail to execute + // this shouldn't happen + b.logger.Error().Msgf( + "MonitorVoteOutboundTxResult: failed to execute vote, txHash: %s, log %s", zetaTxHash, txResult.RawLog, + ) + } else if strings.Contains(txResult.RawLog, "out of gas") { + // if the tx fails with an out of gas error, resend the tx with more gas if retryGasLimit > 0 + b.logger.Debug().Msgf( + "MonitorVoteOutboundTxResult: out of gas, txHash: %s, log %s", zetaTxHash, txResult.RawLog, + ) + if retryGasLimit > 0 { + // new retryGasLimit set to 0 to prevent reentering this function + _, _, err := b.PostVoteOutboundFromMsg(retryGasLimit, 0, msg) + + if err != nil { + b.logger.Error().Err(err).Msgf( + "MonitorVoteOutboundTxResult: failed to resend tx, txHash: %s, log %s", zetaTxHash, txResult.RawLog, + ) + } else { + b.logger.Info().Msgf( + "MonitorVoteOutboundTxResult: successfully resent tx, txHash: %s, log %s", zetaTxHash, txResult.RawLog, + ) + } + } + } else { + b.logger.Debug().Msgf( + "MonitorVoteOutboundTxResult: successful txHash %s, log %s", zetaTxHash, txResult.RawLog, + ) + } + return + } + lastErr = err + } + + b.logger.Error().Err(lastErr).Msgf( + "MonitorVoteOutboundTxResult: unable to query tx result for txHash %s, err %s", zetaTxHash, lastErr.Error(), + ) + return +} diff --git a/zetaclient/utils.go b/zetaclient/utils.go index 0dfa5cb973..5a0fcd9ab2 100644 --- a/zetaclient/utils.go +++ b/zetaclient/utils.go @@ -196,26 +196,31 @@ func (ob *EVMChainClient) HasEnoughConfirmations(receipt *ethtypes.Receipt, last return lastHeight >= confHeight } -func (ob *EVMChainClient) GetInboundVoteMsgForDepositedEvent(event *erc20custody.ERC20CustodyDeposited) (types.MsgVoteOnObservedInboundTx, error) { - ob.logger.ExternalChainWatcher.Info().Msgf("TxBlockNumber %d Transaction Hash: %s Message : %s", event.Raw.BlockNumber, event.Raw.TxHash, event.Message) - if bytes.Equal(event.Message, []byte(DonationMessage)) { - ob.logger.ExternalChainWatcher.Info().Msgf("thank you rich folk for your donation!: %s", event.Raw.TxHash.Hex()) - return types.MsgVoteOnObservedInboundTx{}, fmt.Errorf("thank you rich folk for your donation!: %s", event.Raw.TxHash.Hex()) - } - // get the sender of the event's transaction - tx, _, err := ob.evmClient.TransactionByHash(context.Background(), event.Raw.TxHash) +// GetTransactionSender returns the sender of the given transaction +func (ob *EVMChainClient) GetTransactionSender(tx *ethtypes.Transaction, blockHash ethcommon.Hash, txIndex uint) (ethcommon.Address, error) { + sender, err := ob.evmClient.TransactionSender(context.Background(), tx, blockHash, txIndex) if err != nil { - ob.logger.ExternalChainWatcher.Error().Err(err).Msg(fmt.Sprintf("failed to get transaction by hash: %s", event.Raw.TxHash.Hex())) - return types.MsgVoteOnObservedInboundTx{}, errors.Wrap(err, fmt.Sprintf("failed to get transaction by hash: %s", event.Raw.TxHash.Hex())) + // trying local recovery (assuming LondonSigner dynamic fee tx type) of sender address + signer := ethtypes.NewLondonSigner(big.NewInt(ob.chain.ChainId)) + sender, err = signer.Sender(tx) + if err != nil { + ob.logger.ExternalChainWatcher.Err(err).Msgf("can't recover the sender from tx hash %s chain %d", tx.Hash().Hex(), ob.chain.ChainId) + return ethcommon.Address{}, err + } } - signer := ethtypes.NewLondonSigner(big.NewInt(ob.chain.ChainId)) - sender, err := signer.Sender(tx) - if err != nil { - ob.logger.ExternalChainWatcher.Error().Err(err).Msg(fmt.Sprintf("can't recover the sender from the tx hash: %s", event.Raw.TxHash.Hex())) - return types.MsgVoteOnObservedInboundTx{}, errors.Wrap(err, fmt.Sprintf("can't recover the sender from the tx hash: %s", event.Raw.TxHash.Hex())) + return sender, nil +} +func (ob *EVMChainClient) GetInboundVoteMsgForDepositedEvent(event *erc20custody.ERC20CustodyDeposited, sender ethcommon.Address) *types.MsgVoteOnObservedInboundTx { + if bytes.Equal(event.Message, []byte(DonationMessage)) { + ob.logger.ExternalChainWatcher.Info().Msgf("thank you rich folk for your donation! tx %s chain %d", event.Raw.TxHash.Hex(), ob.chain.ChainId) + return nil } - return *GetInBoundVoteMessage( + message := hex.EncodeToString(event.Message) + ob.logger.ExternalChainWatcher.Info().Msgf("ERC20CustodyDeposited inTx detected on chain %d tx %s block %d from %s value %s message %s", + ob.chain.ChainId, event.Raw.TxHash.Hex(), event.Raw.BlockNumber, sender.Hex(), event.Amount.String(), message) + + return GetInBoundVoteMessage( sender.Hex(), ob.chain.ChainId, "", @@ -230,35 +235,39 @@ func (ob *EVMChainClient) GetInboundVoteMsgForDepositedEvent(event *erc20custody event.Asset.String(), ob.zetaClient.GetKeys().GetOperatorAddress().String(), event.Raw.Index, - ), nil + ) } -func (ob *EVMChainClient) GetInboundVoteMsgForZetaSentEvent(event *zetaconnector.ZetaConnectorNonEthZetaSent) (types.MsgVoteOnObservedInboundTx, error) { - ob.logger.ExternalChainWatcher.Info().Msgf("TxBlockNumber %d Transaction Hash: %s Message : %s", event.Raw.BlockNumber, event.Raw.TxHash, event.Message) +func (ob *EVMChainClient) GetInboundVoteMsgForZetaSentEvent(event *zetaconnector.ZetaConnectorNonEthZetaSent) *types.MsgVoteOnObservedInboundTx { destChain := common.GetChainFromChainID(event.DestinationChainId.Int64()) if destChain == nil { ob.logger.ExternalChainWatcher.Warn().Msgf("chain id not supported %d", event.DestinationChainId.Int64()) - return types.MsgVoteOnObservedInboundTx{}, fmt.Errorf("chain id not supported %d", event.DestinationChainId.Int64()) + return nil } destAddr := clienttypes.BytesToEthHex(event.DestinationAddress) if !destChain.IsZetaChain() { cfgDest, found := ob.cfg.GetEVMConfig(destChain.ChainId) if !found { - return types.MsgVoteOnObservedInboundTx{}, fmt.Errorf("chain id not present in EVMChainConfigs %d", event.DestinationChainId.Int64()) + ob.logger.ExternalChainWatcher.Warn().Msgf("chain id not present in EVMChainConfigs %d", event.DestinationChainId.Int64()) + return nil } if strings.EqualFold(destAddr, cfgDest.ZetaTokenContractAddress) { ob.logger.ExternalChainWatcher.Warn().Msgf("potential attack attempt: %s destination address is ZETA token contract address %s", destChain, destAddr) - return types.MsgVoteOnObservedInboundTx{}, fmt.Errorf("potential attack attempt: %s destination address is ZETA token contract address %s", destChain, destAddr) + return nil } } - return *GetInBoundVoteMessage( + message := base64.StdEncoding.EncodeToString(event.Message) + ob.logger.ExternalChainWatcher.Info().Msgf("ZetaSent inTx detected on chain %d tx %s block %d from %s value %s message %s", + ob.chain.ChainId, event.Raw.TxHash.Hex(), event.Raw.BlockNumber, event.ZetaTxSenderAddress.Hex(), event.ZetaValueAndGas.String(), message) + + return GetInBoundVoteMessage( event.ZetaTxSenderAddress.Hex(), ob.chain.ChainId, event.SourceTxOriginAddress.Hex(), clienttypes.BytesToEthHex(event.DestinationAddress), destChain.ChainId, sdkmath.NewUintFromBigInt(event.ZetaValueAndGas), - base64.StdEncoding.EncodeToString(event.Message), + message, event.Raw.TxHash.Hex(), event.Raw.BlockNumber, event.DestinationGasLimit.Uint64(), @@ -266,27 +275,31 @@ func (ob *EVMChainClient) GetInboundVoteMsgForZetaSentEvent(event *zetaconnector "", ob.zetaClient.GetKeys().GetOperatorAddress().String(), event.Raw.Index, - ), nil + ) } -func (ob *EVMChainClient) GetInboundVoteMsgForTokenSentToTSS(txhash ethcommon.Hash, value *big.Int, receipt *ethtypes.Receipt, from ethcommon.Address, data []byte) *types.MsgVoteOnObservedInboundTx { - ob.logger.ExternalChainWatcher.Info().Msgf("TSS inTx detected: %s, blocknum %d", txhash.Hex(), receipt.BlockNumber) - ob.logger.ExternalChainWatcher.Info().Msgf("TSS inTx value: %s", value.String()) - ob.logger.ExternalChainWatcher.Info().Msgf("TSS inTx from: %s", from.Hex()) +func (ob *EVMChainClient) GetInboundVoteMsgForTokenSentToTSS(tx *ethtypes.Transaction, sender ethcommon.Address, blockNumber uint64) *types.MsgVoteOnObservedInboundTx { + if bytes.Equal(tx.Data(), []byte(DonationMessage)) { + ob.logger.ExternalChainWatcher.Info().Msgf("thank you rich folk for your donation! tx %s chain %d", tx.Hash().Hex(), ob.chain.ChainId) + return nil + } message := "" - if len(data) != 0 { - message = hex.EncodeToString(data) + if len(tx.Data()) != 0 { + message = hex.EncodeToString(tx.Data()) } + ob.logger.ExternalChainWatcher.Info().Msgf("TSS inTx detected on chain %d tx %s block %d from %s value %s message %s", + ob.chain.ChainId, tx.Hash().Hex(), blockNumber, sender.Hex(), tx.Value().String(), hex.EncodeToString(tx.Data())) + return GetInBoundVoteMessage( - from.Hex(), + sender.Hex(), ob.chain.ChainId, - from.Hex(), - from.Hex(), + sender.Hex(), + sender.Hex(), ob.zetaClient.ZetaChain().ChainId, - sdkmath.NewUintFromBigInt(value), + sdkmath.NewUintFromBigInt(tx.Value()), message, - txhash.Hex(), - receipt.BlockNumber.Uint64(), + tx.Hash().Hex(), + blockNumber, 90_000, common.CoinType_Gas, "", diff --git a/zetaclient/voter_test.go b/zetaclient/voter_test.go index 5df01de806..853c17eea9 100644 --- a/zetaclient/voter_test.go +++ b/zetaclient/voter_test.go @@ -85,20 +85,20 @@ func (s *VoterSuite) SetUpTest(c *C) { func (s *VoterSuite) TestSendVoter(c *C) { b1 := s.bridge1 b2 := s.bridge2 - metaHash, err := b1.PostSend("0xfrom", "Ethereum", "0xfrom", "0xto", "BSC", "123456", "23245", "little message", + metaHash, err := b1.PostVoteInbound("0xfrom", "Ethereum", "0xfrom", "0xto", "BSC", "123456", "23245", "little message", "0xtxhash", 123123, "0xtoken") c.Assert(err, IsNil) - log.Info().Msgf("PostSend metaHash %s", metaHash) + log.Info().Msgf("PostVoteInbound metaHash %s", metaHash) // wait for the next block timer1 := time.NewTimer(2 * time.Second) <-timer1.C - metaHash, err = b2.PostSend("0xfrom", "Ethereum", "0xfrom", "0xto", "BSC", "123456", "23245", "little message", + metaHash, err = b2.PostVoteInbound("0xfrom", "Ethereum", "0xfrom", "0xto", "BSC", "123456", "23245", "little message", "0xtxhash", 123123, "0xtoken") c.Assert(err, IsNil) - log.Info().Msgf("Second PostSend metaHash %s", metaHash) + log.Info().Msgf("Second PostVoteInbound metaHash %s", metaHash) // wait for the next block timer2 := time.NewTimer(2 * time.Second) @@ -111,13 +111,13 @@ func (s *VoterSuite) TestSendVoter(c *C) { send := sends[0] - metaHash, err = b1.PostReceiveConfirmation(send.Index, "0xoutHash", 2123, "23245") + metaHash, err = b1.PostVoteOutbound(send.Index, "0xoutHash", 2123, "23245") c.Assert(err, IsNil) timer3 := time.NewTimer(2 * time.Second) <-timer3.C - metaHash, err = b2.PostReceiveConfirmation(send.Index, "0xoutHash", 2123, "23245") + metaHash, err = b2.PostVoteOutbound(send.Index, "0xoutHash", 2123, "23245") c.Assert(err, IsNil) receives, err := b2.GetAllReceive() diff --git a/zetaclient/zetacore_observer_test.go b/zetaclient/zetacore_observer_test.go index afa8114764..919450d1cb 100644 --- a/zetaclient/zetacore_observer_test.go +++ b/zetaclient/zetacore_observer_test.go @@ -117,18 +117,18 @@ func (s *COSuite) SetUpTest(c *C) { func (s *COSuite) TestSendFlow(c *C) { b1 := s.bridge1 b2 := s.bridge2 - metaHash, err := b1.PostSend(TEST_SENDER, "Ethereum", TEST_SENDER, TEST_RECEIVER, "BSC", "1337", "0", "treat or trick", + metaHash, err := b1.PostVoteInbound(TEST_SENDER, "Ethereum", TEST_SENDER, TEST_RECEIVER, "BSC", "1337", "0", "treat or trick", "0xtxhash", 123123, "0xtoken") c.Assert(err, IsNil) - c.Logf("PostSend metaHash %s", metaHash) + c.Logf("PostVoteInbound metaHash %s", metaHash) timer1 := time.NewTimer(2 * time.Second) <-timer1.C - metaHash, err = b2.PostSend(TEST_SENDER, "Ethereum", TEST_SENDER, TEST_RECEIVER, "BSC", "1337", "0", "treat or trick", + metaHash, err = b2.PostVoteInbound(TEST_SENDER, "Ethereum", TEST_SENDER, TEST_RECEIVER, "BSC", "1337", "0", "treat or trick", "0xtxhash", 123123, "0xtoken") c.Assert(err, IsNil) - c.Logf("Second PostSend metaHash %s", metaHash) + c.Logf("Second PostVoteInbound metaHash %s", metaHash) timer2 := time.NewTimer(2 * time.Second) <-timer2.C From 174a0cf6c0777b51dba55c56af06187013f3ed3c Mon Sep 17 00:00:00 2001 From: Lucas Bertrand Date: Thu, 25 Jan 2024 09:29:22 -0800 Subject: [PATCH 3/4] feat(`crosschain`): `MsgAbortStuckCCTX` message (#1635) * proto * implement message * tests * cli commands * generate doc * Update x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go Co-authored-by: Tanmay --------- Co-authored-by: Tanmay --- docs/cli/zetacored/zetacored_tx_crosschain.md | 1 + ...etacored_tx_crosschain_abort-stuck-cctx.md | 52 ++ docs/openapi/openapi.swagger.yaml | 2 + docs/spec/crosschain/messages.md | 12 + proto/crosschain/tx.proto | 9 + typescript/crosschain/tx_pb.d.ts | 48 ++ x/crosschain/client/cli/cli_cctx.go | 22 + x/crosschain/client/cli/tx.go | 1 + .../keeper/msg_server_abort_stuck_cctx.go | 51 ++ .../msg_server_abort_stuck_cctx_test.go | 151 +++++ x/crosschain/types/codec.go | 2 + .../types/message_abort_stuck_cctx.go | 47 ++ .../types/message_abort_stuck_cctx_test.go | 45 ++ x/crosschain/types/tx.pb.go | 557 +++++++++++++++--- 14 files changed, 911 insertions(+), 89 deletions(-) create mode 100644 docs/cli/zetacored/zetacored_tx_crosschain_abort-stuck-cctx.md create mode 100644 x/crosschain/keeper/msg_server_abort_stuck_cctx.go create mode 100644 x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go create mode 100644 x/crosschain/types/message_abort_stuck_cctx.go create mode 100644 x/crosschain/types/message_abort_stuck_cctx_test.go diff --git a/docs/cli/zetacored/zetacored_tx_crosschain.md b/docs/cli/zetacored/zetacored_tx_crosschain.md index a7e2465ab1..bb8a200308 100644 --- a/docs/cli/zetacored/zetacored_tx_crosschain.md +++ b/docs/cli/zetacored/zetacored_tx_crosschain.md @@ -25,6 +25,7 @@ zetacored tx crosschain [flags] ### SEE ALSO * [zetacored tx](zetacored_tx.md) - Transactions subcommands +* [zetacored tx crosschain abort-stuck-cctx](zetacored_tx_crosschain_abort-stuck-cctx.md) - abort a stuck CCTX * [zetacored tx crosschain add-to-in-tx-tracker](zetacored_tx_crosschain_add-to-in-tx-tracker.md) - Add a in-tx-tracker Use 0:Zeta,1:Gas,2:ERC20 * [zetacored tx crosschain add-to-out-tx-tracker](zetacored_tx_crosschain_add-to-out-tx-tracker.md) - Add a out-tx-tracker diff --git a/docs/cli/zetacored/zetacored_tx_crosschain_abort-stuck-cctx.md b/docs/cli/zetacored/zetacored_tx_crosschain_abort-stuck-cctx.md new file mode 100644 index 0000000000..206cda6442 --- /dev/null +++ b/docs/cli/zetacored/zetacored_tx_crosschain_abort-stuck-cctx.md @@ -0,0 +1,52 @@ +# tx crosschain abort-stuck-cctx + +abort a stuck CCTX + +``` +zetacored tx crosschain abort-stuck-cctx [index] [flags] +``` + +### Options + +``` + -a, --account-number uint The account number of the signing account (offline mode only) + --aux Generate aux signer data instead of sending a tx + -b, --broadcast-mode string Transaction broadcasting mode (sync|async|block) + --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible) + --fee-granter string Fee granter grants fees for the transaction + --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer + --fees string Fees to pay along with transaction; eg: 10uatom + --from string Name or address of private key with which to sign + --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) + --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) + --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) + --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) + -h, --help help for abort-stuck-cctx + --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) + --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used + --ledger Use a connected Ledger device + --node string [host]:[port] to tendermint rpc interface for this chain + --note string Note to add a description to the transaction (previously --memo) + --offline Offline mode (does not allow any online functionality) + -o, --output string Output format (text|json) + -s, --sequence uint The sequence number of the signing account (offline mode only) + --sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature + --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height + --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator + -y, --yes Skip tx broadcasting prompt confirmation +``` + +### Options inherited from parent commands + +``` + --chain-id string The network chain ID + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored tx crosschain](zetacored_tx_crosschain.md) - crosschain transactions subcommands + diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index 2e2b7c54c3..1ba9d75fcb 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -50830,6 +50830,8 @@ definitions: lastReceiveHeight: type: string format: uint64 + crosschainMsgAbortStuckCCTXResponse: + type: object crosschainMsgAddToInTxTrackerResponse: type: object crosschainMsgAddToOutTxTrackerResponse: diff --git a/docs/spec/crosschain/messages.md b/docs/spec/crosschain/messages.md index c74e063ffd..1659a95bf0 100644 --- a/docs/spec/crosschain/messages.md +++ b/docs/spec/crosschain/messages.md @@ -258,3 +258,15 @@ message MsgCreateTSSVoter { } ``` +## MsgAbortStuckCCTX + +AbortStuckCCTX aborts a stuck CCTX +Authorized: admin policy group 2 + +```proto +message MsgAbortStuckCCTX { + string creator = 1; + string cctx_index = 2; +} +``` + diff --git a/proto/crosschain/tx.proto b/proto/crosschain/tx.proto index b660c38968..3ccfba1911 100644 --- a/proto/crosschain/tx.proto +++ b/proto/crosschain/tx.proto @@ -19,6 +19,8 @@ service Msg { rpc UpdateTssAddress(MsgUpdateTssAddress) returns (MsgUpdateTssAddressResponse); rpc MigrateTssFunds(MsgMigrateTssFunds) returns (MsgMigrateTssFundsResponse); rpc CreateTSSVoter(MsgCreateTSSVoter) returns (MsgCreateTSSVoterResponse); + + rpc AbortStuckCCTX(MsgAbortStuckCCTX) returns (MsgAbortStuckCCTXResponse); } message MsgCreateTSSVoter { @@ -153,3 +155,10 @@ message MsgVoteOnObservedInboundTx { } message MsgVoteOnObservedInboundTxResponse {} + +message MsgAbortStuckCCTX { + string creator = 1; + string cctx_index = 2; +} + +message MsgAbortStuckCCTXResponse {} diff --git a/typescript/crosschain/tx_pb.d.ts b/typescript/crosschain/tx_pb.d.ts index 6c425e3990..b96408964c 100644 --- a/typescript/crosschain/tx_pb.d.ts +++ b/typescript/crosschain/tx_pb.d.ts @@ -730,3 +730,51 @@ export declare class MsgVoteOnObservedInboundTxResponse extends Message | undefined, b: MsgVoteOnObservedInboundTxResponse | PlainMessage | undefined): boolean; } +/** + * @generated from message zetachain.zetacore.crosschain.MsgAbortStuckCCTX + */ +export declare class MsgAbortStuckCCTX extends Message { + /** + * @generated from field: string creator = 1; + */ + creator: string; + + /** + * @generated from field: string cctx_index = 2; + */ + cctxIndex: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.crosschain.MsgAbortStuckCCTX"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgAbortStuckCCTX; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgAbortStuckCCTX; + + static fromJsonString(jsonString: string, options?: Partial): MsgAbortStuckCCTX; + + static equals(a: MsgAbortStuckCCTX | PlainMessage | undefined, b: MsgAbortStuckCCTX | PlainMessage | undefined): boolean; +} + +/** + * @generated from message zetachain.zetacore.crosschain.MsgAbortStuckCCTXResponse + */ +export declare class MsgAbortStuckCCTXResponse extends Message { + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.crosschain.MsgAbortStuckCCTXResponse"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): MsgAbortStuckCCTXResponse; + + static fromJson(jsonValue: JsonValue, options?: Partial): MsgAbortStuckCCTXResponse; + + static fromJsonString(jsonString: string, options?: Partial): MsgAbortStuckCCTXResponse; + + static equals(a: MsgAbortStuckCCTXResponse | PlainMessage | undefined, b: MsgAbortStuckCCTXResponse | PlainMessage | undefined): boolean; +} + diff --git a/x/crosschain/client/cli/cli_cctx.go b/x/crosschain/client/cli/cli_cctx.go index 8f38c4ebe1..e85712f50e 100644 --- a/x/crosschain/client/cli/cli_cctx.go +++ b/x/crosschain/client/cli/cli_cctx.go @@ -277,3 +277,25 @@ func CmdCCTXOutboundVoter() *cobra.Command { return cmd } + +func CmdAbortStuckCCTX() *cobra.Command { + cmd := &cobra.Command{ + Use: "abort-stuck-cctx [index]", + Short: "abort a stuck CCTX", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + msg := &types.MsgAbortStuckCCTX{ + Creator: clientCtx.GetFromAddress().String(), + CctxIndex: args[0], + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/crosschain/client/cli/tx.go b/x/crosschain/client/cli/tx.go index 0fc5e3c302..d8e6b3bc0e 100644 --- a/x/crosschain/client/cli/tx.go +++ b/x/crosschain/client/cli/tx.go @@ -30,6 +30,7 @@ func GetTxCmd() *cobra.Command { CmdUpdateTss(), CmdMigrateTssFunds(), CmdAddToInTxTracker(), + CmdAbortStuckCCTX(), ) return cmd diff --git a/x/crosschain/keeper/msg_server_abort_stuck_cctx.go b/x/crosschain/keeper/msg_server_abort_stuck_cctx.go new file mode 100644 index 0000000000..32c4bdf55f --- /dev/null +++ b/x/crosschain/keeper/msg_server_abort_stuck_cctx.go @@ -0,0 +1,51 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/crosschain/types" + observertypes "github.com/zeta-chain/zetacore/x/observer/types" +) + +const ( + // AbortMessage is the message to abort a stuck CCTX + AbortMessage = "CCTX aborted with admin cmd" +) + +// AbortStuckCCTX aborts a stuck CCTX +// Authorized: admin policy group 2 +func (k msgServer) AbortStuckCCTX( + goCtx context.Context, + msg *types.MsgAbortStuckCCTX, +) (*types.MsgAbortStuckCCTXResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // check if authorized + if msg.Creator != k.zetaObserverKeeper.GetParams(ctx).GetAdminPolicyAccount(observertypes.Policy_Type_group2) { + return nil, observertypes.ErrNotAuthorized + } + + // check if the cctx exists + cctx, found := k.GetCrossChainTx(ctx, msg.CctxIndex) + if !found { + return nil, types.ErrCannotFindCctx + } + + // check if the cctx is pending + isPending := cctx.CctxStatus.Status == types.CctxStatus_PendingOutbound || + cctx.CctxStatus.Status == types.CctxStatus_PendingInbound || + cctx.CctxStatus.Status == types.CctxStatus_PendingRevert + if !isPending { + return nil, types.ErrStatusNotPending + } + + cctx.CctxStatus = &types.Status{ + Status: types.CctxStatus_Aborted, + StatusMessage: AbortMessage, + } + + k.SetCrossChainTx(ctx, cctx) + + return &types.MsgAbortStuckCCTXResponse{}, nil +} diff --git a/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go b/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go new file mode 100644 index 0000000000..f9b7c380e0 --- /dev/null +++ b/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go @@ -0,0 +1,151 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + crosschainkeeper "github.com/zeta-chain/zetacore/x/crosschain/keeper" + crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" + observertypes "github.com/zeta-chain/zetacore/x/observer/types" +) + +func TestMsgServer_AbortStuckCCTX(t *testing.T) { + t.Run("can abort a cctx in pending inbound", func(t *testing.T) { + k, ctx, _, zk := keepertest.CrosschainKeeper(t) + msgServer := crosschainkeeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + setAdminPolicies(ctx, zk, admin) + + // create a cctx + cctx := sample.CrossChainTx(t, "cctx_index") + cctx.CctxStatus = &crosschaintypes.Status{ + Status: crosschaintypes.CctxStatus_PendingInbound, + StatusMessage: "pending inbound", + } + k.SetCrossChainTx(ctx, *cctx) + + // abort the cctx + _, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{ + Creator: admin, + CctxIndex: "cctx_index", + }) + + require.NoError(t, err) + cctxFound, found := k.GetCrossChainTx(ctx, "cctx_index") + require.True(t, found) + require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) + require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) + }) + + t.Run("can abort a cctx in pending outbound", func(t *testing.T) { + k, ctx, _, zk := keepertest.CrosschainKeeper(t) + msgServer := crosschainkeeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + setAdminPolicies(ctx, zk, admin) + + // create a cctx + cctx := sample.CrossChainTx(t, "cctx_index") + cctx.CctxStatus = &crosschaintypes.Status{ + Status: crosschaintypes.CctxStatus_PendingOutbound, + StatusMessage: "pending outbound", + } + k.SetCrossChainTx(ctx, *cctx) + + // abort the cctx + _, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{ + Creator: admin, + CctxIndex: "cctx_index", + }) + + require.NoError(t, err) + cctxFound, found := k.GetCrossChainTx(ctx, "cctx_index") + require.True(t, found) + require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) + require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) + }) + + t.Run("can abort a cctx in pending revert", func(t *testing.T) { + k, ctx, _, zk := keepertest.CrosschainKeeper(t) + msgServer := crosschainkeeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + setAdminPolicies(ctx, zk, admin) + + // create a cctx + cctx := sample.CrossChainTx(t, "cctx_index") + cctx.CctxStatus = &crosschaintypes.Status{ + Status: crosschaintypes.CctxStatus_PendingRevert, + StatusMessage: "pending revert", + } + k.SetCrossChainTx(ctx, *cctx) + + // abort the cctx + _, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{ + Creator: admin, + CctxIndex: "cctx_index", + }) + + require.NoError(t, err) + cctxFound, found := k.GetCrossChainTx(ctx, "cctx_index") + require.True(t, found) + require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) + require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) + }) + + t.Run("cannot abort a cctx in pending outbound if not admin", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeper(t) + msgServer := crosschainkeeper.NewMsgServerImpl(*k) + + // create a cctx + cctx := sample.CrossChainTx(t, "cctx_index") + cctx.CctxStatus = &crosschaintypes.Status{ + Status: crosschaintypes.CctxStatus_PendingOutbound, + StatusMessage: "pending outbound", + } + k.SetCrossChainTx(ctx, *cctx) + + // abort the cctx + _, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{ + Creator: sample.AccAddress(), + CctxIndex: "cctx_index", + }) + require.ErrorIs(t, err, observertypes.ErrNotAuthorized) + }) + + t.Run("cannot abort a cctx if doesn't exist", func(t *testing.T) { + k, ctx, _, zk := keepertest.CrosschainKeeper(t) + msgServer := crosschainkeeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + setAdminPolicies(ctx, zk, admin) + + // abort the cctx + _, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{ + Creator: admin, + CctxIndex: "cctx_index", + }) + require.ErrorIs(t, err, crosschaintypes.ErrCannotFindCctx) + }) + + t.Run("cannot abort a cctx if not pending", func(t *testing.T) { + k, ctx, _, zk := keepertest.CrosschainKeeper(t) + msgServer := crosschainkeeper.NewMsgServerImpl(*k) + admin := sample.AccAddress() + setAdminPolicies(ctx, zk, admin) + + // create a cctx + cctx := sample.CrossChainTx(t, "cctx_index") + cctx.CctxStatus = &crosschaintypes.Status{ + Status: crosschaintypes.CctxStatus_OutboundMined, + StatusMessage: "outbound mined", + } + k.SetCrossChainTx(ctx, *cctx) + + // abort the cctx + _, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{ + Creator: admin, + CctxIndex: "cctx_index", + }) + require.ErrorIs(t, err, crosschaintypes.ErrStatusNotPending) + }) +} diff --git a/x/crosschain/types/codec.go b/x/crosschain/types/codec.go index c85eb7f8ea..fb3d51db0a 100644 --- a/x/crosschain/types/codec.go +++ b/x/crosschain/types/codec.go @@ -18,6 +18,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgWhitelistERC20{}, "crosschain/WhitelistERC20", nil) cdc.RegisterConcrete(&MsgMigrateTssFunds{}, "crosschain/MigrateTssFunds", nil) cdc.RegisterConcrete(&MsgUpdateTssAddress{}, "crosschain/UpdateTssAddress", nil) + cdc.RegisterConcrete(&MsgAbortStuckCCTX{}, "crosschain/AbortStuckCCTX", nil) } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { @@ -32,6 +33,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &MsgWhitelistERC20{}, &MsgMigrateTssFunds{}, &MsgUpdateTssAddress{}, + &MsgAbortStuckCCTX{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/crosschain/types/message_abort_stuck_cctx.go b/x/crosschain/types/message_abort_stuck_cctx.go new file mode 100644 index 0000000000..102290ab9b --- /dev/null +++ b/x/crosschain/types/message_abort_stuck_cctx.go @@ -0,0 +1,47 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeMsgAbortStuckCCTX = "AbortStuckCCTX" + +var _ sdk.Msg = &MsgAbortStuckCCTX{} + +func NewMsgAbortStuckCCTX(creator string, cctxIndex string) *MsgAbortStuckCCTX { + return &MsgAbortStuckCCTX{ + Creator: creator, + CctxIndex: cctxIndex, + } +} + +func (msg *MsgAbortStuckCCTX) Route() string { + return RouterKey +} + +func (msg *MsgAbortStuckCCTX) Type() string { + return TypeMsgAbortStuckCCTX +} + +func (msg *MsgAbortStuckCCTX) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgAbortStuckCCTX) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgAbortStuckCCTX) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + return nil +} diff --git a/x/crosschain/types/message_abort_stuck_cctx_test.go b/x/crosschain/types/message_abort_stuck_cctx_test.go new file mode 100644 index 0000000000..40bdcf4794 --- /dev/null +++ b/x/crosschain/types/message_abort_stuck_cctx_test.go @@ -0,0 +1,45 @@ +package types_test + +import ( + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/crosschain/types" +) + +func TestMsgAbortStuckCCTX_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg types.MsgAbortStuckCCTX + err error + }{ + { + name: "invalid address", + msg: types.MsgAbortStuckCCTX{ + Creator: "invalid_address", + CctxIndex: "cctx_index", + }, + err: sdkerrors.ErrInvalidAddress, + }, + { + name: "valid", + msg: types.MsgAbortStuckCCTX{ + Creator: sample.AccAddress(), + CctxIndex: "cctx_index", + }, + err: nil, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/crosschain/types/tx.pb.go b/x/crosschain/types/tx.pb.go index 6745107685..c784912394 100644 --- a/x/crosschain/types/tx.pb.go +++ b/x/crosschain/types/tx.pb.go @@ -1262,6 +1262,94 @@ func (m *MsgVoteOnObservedInboundTxResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgVoteOnObservedInboundTxResponse proto.InternalMessageInfo +type MsgAbortStuckCCTX struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + CctxIndex string `protobuf:"bytes,2,opt,name=cctx_index,json=cctxIndex,proto3" json:"cctx_index,omitempty"` +} + +func (m *MsgAbortStuckCCTX) Reset() { *m = MsgAbortStuckCCTX{} } +func (m *MsgAbortStuckCCTX) String() string { return proto.CompactTextString(m) } +func (*MsgAbortStuckCCTX) ProtoMessage() {} +func (*MsgAbortStuckCCTX) Descriptor() ([]byte, []int) { + return fileDescriptor_81d6d611190b7635, []int{20} +} +func (m *MsgAbortStuckCCTX) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAbortStuckCCTX) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAbortStuckCCTX.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAbortStuckCCTX) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAbortStuckCCTX.Merge(m, src) +} +func (m *MsgAbortStuckCCTX) XXX_Size() int { + return m.Size() +} +func (m *MsgAbortStuckCCTX) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAbortStuckCCTX.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAbortStuckCCTX proto.InternalMessageInfo + +func (m *MsgAbortStuckCCTX) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgAbortStuckCCTX) GetCctxIndex() string { + if m != nil { + return m.CctxIndex + } + return "" +} + +type MsgAbortStuckCCTXResponse struct { +} + +func (m *MsgAbortStuckCCTXResponse) Reset() { *m = MsgAbortStuckCCTXResponse{} } +func (m *MsgAbortStuckCCTXResponse) String() string { return proto.CompactTextString(m) } +func (*MsgAbortStuckCCTXResponse) ProtoMessage() {} +func (*MsgAbortStuckCCTXResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_81d6d611190b7635, []int{21} +} +func (m *MsgAbortStuckCCTXResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAbortStuckCCTXResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAbortStuckCCTXResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAbortStuckCCTXResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAbortStuckCCTXResponse.Merge(m, src) +} +func (m *MsgAbortStuckCCTXResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgAbortStuckCCTXResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAbortStuckCCTXResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAbortStuckCCTXResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgCreateTSSVoter)(nil), "zetachain.zetacore.crosschain.MsgCreateTSSVoter") proto.RegisterType((*MsgCreateTSSVoterResponse)(nil), "zetachain.zetacore.crosschain.MsgCreateTSSVoterResponse") @@ -1283,100 +1371,105 @@ func init() { proto.RegisterType((*MsgVoteOnObservedOutboundTxResponse)(nil), "zetachain.zetacore.crosschain.MsgVoteOnObservedOutboundTxResponse") proto.RegisterType((*MsgVoteOnObservedInboundTx)(nil), "zetachain.zetacore.crosschain.MsgVoteOnObservedInboundTx") proto.RegisterType((*MsgVoteOnObservedInboundTxResponse)(nil), "zetachain.zetacore.crosschain.MsgVoteOnObservedInboundTxResponse") + proto.RegisterType((*MsgAbortStuckCCTX)(nil), "zetachain.zetacore.crosschain.MsgAbortStuckCCTX") + proto.RegisterType((*MsgAbortStuckCCTXResponse)(nil), "zetachain.zetacore.crosschain.MsgAbortStuckCCTXResponse") } func init() { proto.RegisterFile("crosschain/tx.proto", fileDescriptor_81d6d611190b7635) } var fileDescriptor_81d6d611190b7635 = []byte{ - // 1407 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x58, 0x6d, 0x4f, 0x1b, 0xc7, - 0x13, 0xe7, 0xfe, 0x80, 0xb1, 0x07, 0x0c, 0xe4, 0x20, 0x89, 0x73, 0x04, 0x43, 0x8e, 0x7f, 0x52, - 0x54, 0x09, 0x3b, 0x21, 0xaa, 0x9a, 0xa4, 0xad, 0xd4, 0x80, 0x12, 0x42, 0x5b, 0x42, 0x74, 0x71, - 0x5a, 0x29, 0x6f, 0x4e, 0xe7, 0xbb, 0xe5, 0x7c, 0xc2, 0xb7, 0x6b, 0xdd, 0xae, 0x91, 0x8d, 0x2a, - 0x55, 0x8a, 0xd4, 0xf7, 0x55, 0x55, 0xa9, 0x55, 0xbf, 0x40, 0xbf, 0x4a, 0x5e, 0x46, 0x7d, 0xd5, - 0x54, 0x6a, 0x54, 0x85, 0x4f, 0xd0, 0x7e, 0x82, 0x6a, 0x1f, 0xee, 0xf0, 0x19, 0xfc, 0x00, 0x51, - 0x5e, 0xdd, 0xce, 0xec, 0xce, 0xec, 0xcc, 0x6f, 0x66, 0x76, 0xf6, 0x16, 0xe6, 0xdc, 0x88, 0x50, - 0xea, 0xd6, 0x9c, 0x00, 0x97, 0x59, 0xab, 0xd4, 0x88, 0x08, 0x23, 0xfa, 0xe2, 0x21, 0x62, 0x8e, - 0xe0, 0x95, 0xc4, 0x88, 0x44, 0xa8, 0x74, 0xbc, 0xce, 0x98, 0x73, 0x49, 0x18, 0x12, 0x5c, 0x96, - 0x1f, 0x29, 0x63, 0xcc, 0xfb, 0xc4, 0x27, 0x62, 0x58, 0xe6, 0x23, 0xc9, 0x35, 0x7f, 0xd3, 0xe0, - 0xc2, 0x0e, 0xf5, 0x37, 0x23, 0xe4, 0x30, 0x54, 0x79, 0xfa, 0xf4, 0x6b, 0xc2, 0x50, 0xa4, 0x17, - 0x60, 0xc2, 0xe5, 0x1c, 0x12, 0x15, 0xb4, 0x65, 0x6d, 0x35, 0x67, 0xc5, 0xa4, 0xbe, 0x08, 0xc0, - 0x28, 0xb5, 0x1b, 0xcd, 0xea, 0x3e, 0x6a, 0x17, 0xfe, 0x27, 0x26, 0x73, 0x8c, 0xd2, 0x27, 0x82, - 0xa1, 0x7f, 0x08, 0xb3, 0xfb, 0xa8, 0xbd, 0x85, 0xf0, 0x73, 0xc4, 0x9c, 0x47, 0x28, 0xf0, 0x6b, - 0xac, 0x30, 0xba, 0xac, 0xad, 0x8e, 0x5a, 0x27, 0xf8, 0xfa, 0x1a, 0x64, 0x28, 0x73, 0x58, 0x93, - 0x16, 0xc6, 0x96, 0xb5, 0xd5, 0xe9, 0xf5, 0x8b, 0x25, 0x65, 0xaf, 0x85, 0x5c, 0x14, 0x1c, 0xa0, - 0xa7, 0x62, 0xd2, 0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33, 0xce, - 0x91, 0xa0, 0xbe, 0xd6, 0x60, 0x3e, 0x46, 0x75, 0xb7, 0xc9, 0xde, 0x31, 0x93, 0xe6, 0x61, 0x1c, - 0x13, 0xec, 0x22, 0x81, 0xd5, 0x98, 0x25, 0x89, 0xce, 0xfc, 0x1a, 0x4b, 0xe5, 0xd7, 0x7b, 0x4e, - 0x98, 0xcf, 0xe0, 0xea, 0x69, 0xae, 0x25, 0xf8, 0x2d, 0x02, 0x04, 0xd4, 0x8e, 0x50, 0x48, 0x0e, - 0x90, 0x27, 0xbc, 0xcc, 0x5a, 0xb9, 0x80, 0x5a, 0x92, 0x61, 0xee, 0x09, 0xec, 0x25, 0xf5, 0x30, - 0x22, 0xe1, 0x7b, 0x82, 0xc7, 0x5c, 0x81, 0x6b, 0x3d, 0xf7, 0x49, 0xb2, 0xfb, 0x17, 0x0d, 0x66, - 0x77, 0xa8, 0xbf, 0xe5, 0xd0, 0x27, 0x51, 0xe0, 0xa2, 0x41, 0x07, 0x7b, 0x7f, 0x23, 0x1a, 0x5c, - 0x45, 0x6c, 0x84, 0x20, 0xf4, 0x6b, 0x30, 0x25, 0x51, 0xc6, 0xcd, 0xb0, 0x8a, 0x22, 0x11, 0xa8, - 0x31, 0x6b, 0x52, 0xf0, 0x1e, 0x0b, 0x96, 0x48, 0xee, 0x66, 0xa3, 0x51, 0x6f, 0x27, 0xc9, 0x2d, - 0x28, 0xd3, 0x80, 0x42, 0xb7, 0x65, 0x89, 0xd9, 0xaf, 0xc7, 0x45, 0xd1, 0x72, 0xe6, 0x2e, 0xde, - 0xad, 0x52, 0x14, 0x1d, 0x20, 0x6f, 0xb7, 0xc9, 0xaa, 0xa4, 0x89, 0xbd, 0x4a, 0xab, 0x8f, 0x07, - 0x0b, 0x20, 0xb2, 0x54, 0x46, 0x5d, 0xa6, 0x6d, 0x96, 0x33, 0x44, 0xd0, 0x4b, 0x30, 0x47, 0x94, - 0x32, 0x9b, 0x70, 0xb8, 0x3a, 0x4f, 0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6, 0xa8, 0xfd, 0x70, 0x54, 0x1c, 0x79, - 0x75, 0x54, 0x1c, 0xf9, 0xe3, 0xa8, 0x38, 0xf2, 0xfc, 0x56, 0x47, 0x43, 0xe3, 0x3a, 0xd7, 0xe4, - 0x13, 0x4d, 0xac, 0xbe, 0xdc, 0x2a, 0x77, 0x3e, 0xdc, 0xf0, 0xfe, 0x56, 0xcd, 0x88, 0x27, 0x97, - 0xdb, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x47, 0x0c, 0x03, 0xae, 0xd3, 0x11, 0x00, 0x00, + // 1449 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x58, 0x6d, 0x4f, 0xdb, 0xd6, + 0x17, 0xc7, 0x7f, 0x20, 0x24, 0x07, 0x02, 0xd4, 0xd0, 0x36, 0x35, 0x25, 0x50, 0xf3, 0x6f, 0x87, + 0x26, 0x91, 0xb4, 0x54, 0xd3, 0xda, 0x6e, 0x93, 0x06, 0x51, 0x4b, 0xd9, 0x4a, 0xa9, 0x4c, 0xba, + 0x4d, 0x7d, 0x63, 0x39, 0xf6, 0xc5, 0xb1, 0x88, 0x7d, 0x23, 0xdf, 0x6b, 0x94, 0xa0, 0x49, 0x93, + 0x2a, 0xed, 0xfd, 0x34, 0x4d, 0xda, 0xb4, 0x2f, 0xb0, 0xaf, 0xd2, 0x97, 0xd5, 0x5e, 0xad, 0x9b, + 0x54, 0x4d, 0xed, 0x27, 0xd8, 0x3e, 0xc1, 0x74, 0x1f, 0x6c, 0xe2, 0x40, 0x1e, 0xa0, 0xea, 0xab, + 0xdc, 0x73, 0xee, 0x3d, 0x4f, 0xbf, 0x73, 0xce, 0x3d, 0x37, 0x86, 0x39, 0x3b, 0xc4, 0x84, 0xd8, + 0x75, 0xcb, 0x0b, 0xca, 0xb4, 0x55, 0x6a, 0x86, 0x98, 0x62, 0x75, 0xf1, 0x08, 0x51, 0x8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 0xda, 0xda, 0x66, 0xa4, + 0x84, 0xa4, 0x3b, 0xe4, 0x04, 0x92, 0xdf, 0x45, 0xed, 0x7f, 0x5d, 0xf7, 0x28, 0x6a, 0x78, 0x84, + 0xde, 0x37, 0x2a, 0xeb, 0x37, 0xfb, 0x00, 0xb2, 0x02, 0x79, 0x14, 0xda, 0xeb, 0x37, 0x4d, 0x4b, + 0x60, 0x2b, 0x73, 0x30, 0xc5, 0x99, 0x71, 0xfe, 0x3a, 0x51, 0x1b, 0x4d, 0xa3, 0xa6, 0xc2, 0x58, + 0x60, 0xf9, 0x02, 0x97, 0x9c, 0xc1, 0xd7, 0xea, 0x25, 0xc8, 0x90, 0xb6, 0x5f, 0xc3, 0x0d, 0x0e, + 0x41, 0xce, 0x90, 0x94, 0xaa, 0x41, 0xd6, 0x41, 0xb6, 0xe7, 0x5b, 0x0d, 0xc2, 0x43, 0xce, 0x1b, + 0x09, 0xad, 0x2e, 0x40, 0xce, 0xb5, 0x88, 0xd9, 0xf0, 0x7c, 0x8f, 0xca, 0x90, 0xb3, 0xae, 0x45, + 0x1e, 0x31, 0x5a, 0x37, 0x79, 0x9b, 0xa4, 0x63, 0x8a, 0x23, 0x66, 0x11, 0x1c, 0xa5, 0x22, 0x10, + 0x11, 0x4e, 0x1d, 0x75, 0x46, 0xb0, 0x08, 0x60, 0xdb, 0x09, 0xa4, 0xb2, 0xce, 0x18, 0x47, 0x80, + 0xfa, 0x4a, 0x81, 0xf9, 0x18, 0xd5, 0xdd, 0x88, 0xbe, 0x63, 0x25, 0xcd, 0xc3, 0x78, 0x80, 0x03, + 0x1b, 0x71, 0xac, 0xc6, 0x0c, 0x41, 0x74, 0xd6, 0xd7, 0x58, 0xaa, 0xbe, 0xde, 0x73, 0xc1, 0x7c, + 0x06, 0x57, 0x4f, 0x0b, 0x2d, 0xc1, 0x6f, 0x11, 0xc0, 0x23, 0x66, 0x88, 0x7c, 0x7c, 0x88, 0x1c, + 0x1e, 0x65, 0xd6, 0xc8, 0x79, 0xc4, 0x10, 0x0c, 0x7d, 0x9f, 0x63, 0x2f, 0xa8, 0x07, 0x21, 0xf6, + 0xdf, 0x13, 0x3c, 0xfa, 0x0a, 0x5c, 0xeb, 0x69, 0x27, 0xa9, 0xee, 0x5f, 0x14, 0x98, 0xdd, 0x21, + 0xee, 0x96, 0x45, 0x9e, 0x84, 0x9e, 0x8d, 0x06, 0x5d, 0xec, 0xfd, 0x9d, 0x68, 0x32, 0x15, 0xb1, + 0x13, 0x9c, 0x50, 0xaf, 0xc1, 0x94, 0x40, 0x39, 0x88, 0xfc, 0x1a, 0x0a, 0x79, 0xa2, 0xc6, 0x8c, + 0x49, 0xce, 0x7b, 0xcc, 0x59, 0xbc, 0xb8, 0xa3, 0x66, 0xb3, 0xd1, 0x4e, 0x8a, 0x9b, 0x53, 0xba, + 0x06, 0x85, 0x6e, 0xcf, 0x12, 0xb7, 0x5f, 0x8d, 0xf3, 0xa6, 0x65, 0xcc, 0xdd, 0x60, 0xb7, 0x46, + 0x50, 0x78, 0x88, 0x9c, 0xdd, 0x88, 0xd6, 0x70, 0x14, 0x38, 0xd5, 0x56, 0x9f, 0x08, 0x16, 0x80, + 0x57, 0xa9, 0xc8, 0xba, 0x28, 0xdb, 0x2c, 0x63, 0xf0, 0xa4, 0x97, 0x60, 0x0e, 0x4b, 0x65, 0x26, + 0x66, 0x70, 0x75, 0xde, 0x5e, 0x17, 0xf0, 0xb1, 0x9d, 0xaa, 0x38, 0xff, 0x29, 0x68, 0x5d, 0xe7, + 0x45, 0x01, 0x89, 0x91, 0x26, 0x62, 0x2d, 0xa4, 0xc4, 0x36, 0x8f, 0xf7, 0xd5, 0x8f, 0xe0, 0x72, + 0x97, 0x34, 0x6b, 0xd8, 0x88, 0x20, 0xa7, 0x00, 0x5c, 0x74, 0x3e, 0x25, 0xba, 0x65, 0x91, 0xa7, + 0x04, 0x39, 0xea, 0x11, 0xe8, 0x5d, 0x62, 0x68, 0x7f, 0x1f, 0xd9, 0xd4, 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xdb, 0xe2, 0xc8, 0x1f, 0x6f, 0x8b, + 0x23, 0xcf, 0x6e, 0x75, 0x4c, 0x6e, 0xa6, 0x73, 0x4d, 0x7c, 0x8b, 0x8a, 0xd5, 0x97, 0x5b, 0xe5, + 0xce, 0x2f, 0x54, 0x6c, 0x90, 0xd7, 0x32, 0xfc, 0xdb, 0xd2, 0xed, 0xff, 0x02, 0x00, 0x00, 0xff, + 0xff, 0x1e, 0x53, 0x7a, 0xa6, 0xbc, 0x12, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1401,6 +1494,7 @@ type MsgClient interface { UpdateTssAddress(ctx context.Context, in *MsgUpdateTssAddress, opts ...grpc.CallOption) (*MsgUpdateTssAddressResponse, error) MigrateTssFunds(ctx context.Context, in *MsgMigrateTssFunds, opts ...grpc.CallOption) (*MsgMigrateTssFundsResponse, error) CreateTSSVoter(ctx context.Context, in *MsgCreateTSSVoter, opts ...grpc.CallOption) (*MsgCreateTSSVoterResponse, error) + AbortStuckCCTX(ctx context.Context, in *MsgAbortStuckCCTX, opts ...grpc.CallOption) (*MsgAbortStuckCCTXResponse, error) } type msgClient struct { @@ -1501,6 +1595,15 @@ func (c *msgClient) CreateTSSVoter(ctx context.Context, in *MsgCreateTSSVoter, o return out, nil } +func (c *msgClient) AbortStuckCCTX(ctx context.Context, in *MsgAbortStuckCCTX, opts ...grpc.CallOption) (*MsgAbortStuckCCTXResponse, error) { + out := new(MsgAbortStuckCCTXResponse) + err := c.cc.Invoke(ctx, "/zetachain.zetacore.crosschain.Msg/AbortStuckCCTX", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { AddToOutTxTracker(context.Context, *MsgAddToOutTxTracker) (*MsgAddToOutTxTrackerResponse, error) @@ -1513,6 +1616,7 @@ type MsgServer interface { UpdateTssAddress(context.Context, *MsgUpdateTssAddress) (*MsgUpdateTssAddressResponse, error) MigrateTssFunds(context.Context, *MsgMigrateTssFunds) (*MsgMigrateTssFundsResponse, error) CreateTSSVoter(context.Context, *MsgCreateTSSVoter) (*MsgCreateTSSVoterResponse, error) + AbortStuckCCTX(context.Context, *MsgAbortStuckCCTX) (*MsgAbortStuckCCTXResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -1549,6 +1653,9 @@ func (*UnimplementedMsgServer) MigrateTssFunds(ctx context.Context, req *MsgMigr func (*UnimplementedMsgServer) CreateTSSVoter(ctx context.Context, req *MsgCreateTSSVoter) (*MsgCreateTSSVoterResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method CreateTSSVoter not implemented") } +func (*UnimplementedMsgServer) AbortStuckCCTX(ctx context.Context, req *MsgAbortStuckCCTX) (*MsgAbortStuckCCTXResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AbortStuckCCTX not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -1734,6 +1841,24 @@ func _Msg_CreateTSSVoter_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } +func _Msg_AbortStuckCCTX_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgAbortStuckCCTX) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).AbortStuckCCTX(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/zetachain.zetacore.crosschain.Msg/AbortStuckCCTX", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).AbortStuckCCTX(ctx, req.(*MsgAbortStuckCCTX)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "zetachain.zetacore.crosschain.Msg", HandlerType: (*MsgServer)(nil), @@ -1778,6 +1903,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "CreateTSSVoter", Handler: _Msg_CreateTSSVoter_Handler, }, + { + MethodName: "AbortStuckCCTX", + Handler: _Msg_AbortStuckCCTX_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "crosschain/tx.proto", @@ -2677,6 +2806,66 @@ func (m *MsgVoteOnObservedInboundTxResponse) MarshalToSizedBuffer(dAtA []byte) ( return len(dAtA) - i, nil } +func (m *MsgAbortStuckCCTX) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgAbortStuckCCTX) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAbortStuckCCTX) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CctxIndex) > 0 { + i -= len(m.CctxIndex) + copy(dAtA[i:], m.CctxIndex) + i = encodeVarintTx(dAtA, i, uint64(len(m.CctxIndex))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgAbortStuckCCTXResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgAbortStuckCCTXResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAbortStuckCCTXResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -3097,6 +3286,32 @@ func (m *MsgVoteOnObservedInboundTxResponse) Size() (n int) { return n } +func (m *MsgAbortStuckCCTX) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.CctxIndex) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgAbortStuckCCTXResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -5861,6 +6076,170 @@ func (m *MsgVoteOnObservedInboundTxResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgAbortStuckCCTX) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAbortStuckCCTX: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAbortStuckCCTX: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CctxIndex", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CctxIndex = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgAbortStuckCCTXResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAbortStuckCCTXResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAbortStuckCCTXResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From d1236ba8e6660492b131e224c66c100490401c43 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 25 Jan 2024 14:18:03 -0500 Subject: [PATCH 4/4] feat: Keygen migration script (#1632) * add migration script * add debug logs * remove debug logs * add changelog entry * remove commented code --------- Co-authored-by: Lucas Bertrand --- app/setup_handlers.go | 12 ++++ changelog.md | 3 +- x/observer/keeper/migrator.go | 5 ++ x/observer/migrations/v6/migrate.go | 39 +++++++++++ x/observer/migrations/v6/migrate_test.go | 87 ++++++++++++++++++++++++ x/observer/module.go | 5 +- x/observer/types/errors.go | 1 + 7 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 x/observer/migrations/v6/migrate.go create mode 100644 x/observer/migrations/v6/migrate_test.go diff --git a/app/setup_handlers.go b/app/setup_handlers.go index 8619fa046f..bdb18a0aa8 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/upgrade/types" + observerTypes "github.com/zeta-chain/zetacore/x/observer/types" ) const releaseVersion = "v12.1.0" @@ -16,6 +17,8 @@ func SetupHandlers(app *App) { for m, mb := range app.mm.Modules { vm[m] = mb.ConsensusVersion() } + vm = VersionMigrator{vm}.TriggerMigration(observerTypes.ModuleName) + return app.mm.RunMigrations(ctx, app.configurator, vm) }) @@ -34,3 +37,12 @@ func SetupHandlers(app *App) { app.SetStoreLoader(types.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) } } + +type VersionMigrator struct { + v module.VersionMap +} + +func (v VersionMigrator) TriggerMigration(moduleName string) module.VersionMap { + v.v[moduleName] = v.v[moduleName] - 1 + return v.v +} diff --git a/changelog.md b/changelog.md index 01cee846e4..1adfa29044 100644 --- a/changelog.md +++ b/changelog.md @@ -5,16 +5,15 @@ ## Version: v12.1.0 ### Tests - * [1577](https://github.com/zeta-chain/node/pull/1577) - add chain header tests in E2E tests and fix admin tests ### Features ### Fixes - * [1535](https://github.com/zeta-chain/node/issues/1535) - Avoid voting on wrong ballots due to false blockNumber in EVM tx receipt * [1588](https://github.com/zeta-chain/node/pull/1588) - fix chain params comparison logic * [1650](https://github.com/zeta-chain/node/pull/1605) - exempt (discounted) *system txs* from min gas price check and gas fee deduction +* [1632](https://github.com/zeta-chain/node/pull/1632) - set keygen to `KeygenStatus_KeyGenSuccess` if its in `KeygenStatus_PendingKeygen`. * [1576](https://github.com/zeta-chain/node/pull/1576) - Fix zetaclient crash due to out of bound integer conversion and log prints. * [1575](https://github.com/zeta-chain/node/issues/1575) - Skip unsupported chain parameters by IsSupported flag diff --git a/x/observer/keeper/migrator.go b/x/observer/keeper/migrator.go index 47b8ecfcc7..0cee0ed183 100644 --- a/x/observer/keeper/migrator.go +++ b/x/observer/keeper/migrator.go @@ -6,6 +6,7 @@ import ( v3 "github.com/zeta-chain/zetacore/x/observer/migrations/v3" v4 "github.com/zeta-chain/zetacore/x/observer/migrations/v4" v5 "github.com/zeta-chain/zetacore/x/observer/migrations/v5" + v6 "github.com/zeta-chain/zetacore/x/observer/migrations/v6" ) // Migrator is a struct for handling in-place store migrations. @@ -37,3 +38,7 @@ func (m Migrator) Migrate3to4(ctx sdk.Context) error { func (m Migrator) Migrate4to5(ctx sdk.Context) error { return v5.MigrateStore(ctx, m.observerKeeper) } + +func (m Migrator) Migrate5to6(ctx sdk.Context) error { + return v6.MigrateStore(ctx, m.observerKeeper) +} diff --git a/x/observer/migrations/v6/migrate.go b/x/observer/migrations/v6/migrate.go new file mode 100644 index 0000000000..a678c8a54d --- /dev/null +++ b/x/observer/migrations/v6/migrate.go @@ -0,0 +1,39 @@ +package v6 + +import ( + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/zeta-chain/zetacore/x/observer/types" +) + +// observerKeeper prevents circular dependency +type observerKeeper interface { + SetKeygen(ctx sdk.Context, keygen types.Keygen) + GetKeygen(ctx sdk.Context) (val types.Keygen, found bool) + GetTSS(ctx sdk.Context) (val types.TSS, found bool) + StoreKey() storetypes.StoreKey + Codec() codec.BinaryCodec +} + +func MigrateStore(ctx sdk.Context, observerKeeper observerKeeper) error { + return SetKeyGenStatus(ctx, observerKeeper) +} + +func SetKeyGenStatus(ctx sdk.Context, keeper observerKeeper) error { + keygen, found := keeper.GetKeygen(ctx) + if !found { + return types.ErrKeygenNotFound + } + if keygen.Status == types.KeygenStatus_PendingKeygen { + tss, foundTss := keeper.GetTSS(ctx) + if !foundTss { + return types.ErrTssNotFound + } + keygen.Status = types.KeygenStatus_KeyGenSuccess + keygen.BlockNumber = tss.KeyGenZetaHeight + keygen.GranteePubkeys = tss.TssParticipantList + keeper.SetKeygen(ctx, keygen) + } + return nil +} diff --git a/x/observer/migrations/v6/migrate_test.go b/x/observer/migrations/v6/migrate_test.go new file mode 100644 index 0000000000..574ece4be4 --- /dev/null +++ b/x/observer/migrations/v6/migrate_test.go @@ -0,0 +1,87 @@ +package v6_test + +import ( + "math" + "testing" + + "github.com/stretchr/testify/assert" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + v6 "github.com/zeta-chain/zetacore/x/observer/migrations/v6" + "github.com/zeta-chain/zetacore/x/observer/types" +) + +func TestMigrateObserverParams(t *testing.T) { + t.Run("Migrate when keygen is Pending", func(t *testing.T) { + k, ctx := keepertest.ObserverKeeper(t) + k.SetKeygen(ctx, types.Keygen{ + Status: types.KeygenStatus_PendingKeygen, + BlockNumber: math.MaxInt64, + }) + participantList := []string{ + "zetapub1addwnpepqglunjrgl3qg08duxq9pf28jmvrer3crwnnfzp6m0u0yh9jk9mnn5p76utc", + "zetapub1addwnpepqwwpjwwnes7cywfkr0afme7ymk8rf5jzhn8pfr6qqvfm9v342486qsrh4f5", + "zetapub1addwnpepq07xj82w5e6vr85qj3r7htmzh2mp3vkvfraapcv6ynhdwankseayk5yh80t", + "zetapub1addwnpepq0lxqx92m3fhae3usn8jffqvtx6cuzl06xh9r345c2qcqq8zyfs4cdpqcum", + "zetapub1addwnpepqvzlntzltvpm22ved5gjtn9nzqfz5fun38el4r64njc979rwanxlgq4u3p8", + "zetapub1addwnpepqg40psrhwwgy257p4xv50xp0asmtwjup66z8vk829289zxge5lyl7sycga8", + "zetapub1addwnpepqgpr5ffquqchra93r8l6d35q62cv4nsc9d4k2q7kten4sljxg5rluwx29gh", + "zetapub1addwnpepqdjf3vt8etgdddkghrvxfmmmeatky6m7hx7wjuv86udfghqpty8h5h4r78w", + "zetapub1addwnpepqtfcfmsdkzdgv03t8392gsh7kzrstp9g864w2ltz9k0xzz33q60dq6mnkex", + } + operatorList := []string{ + "zeta19jr7nl82lrktge35f52x9g5y5prmvchmk40zhg", + "zeta1cxj07f3ju484ry2cnnhxl5tryyex7gev0yzxtj", + "zeta1hjct6q7npsspsg3dgvzk3sdf89spmlpf7rqmnw", + "zeta1k6vh9y7ctn06pu5jngznv5dyy0rltl2qp0j30g", + "zeta1l07weaxkmn6z69qm55t53v4rfr43eys4cjz54h", + "zeta1p0uwsq4naus5r4l7l744upy0k8ezzj84mn40nf", + "zeta1rhj4pkp7eygw8lu9wacpepeh0fnzdxrqr27g6m", + "zeta1t0uj2z93jd2g3w94zl3jhfrn2ek6dnuk3v93j9", + "zeta1t5pgk2fucx3drkynzew9zln5z9r7s3wqqyy0pe", + } + keygenHeight := int64(1440460) + finalizedZetaHeight := int64(1440680) + k.SetTSS(ctx, types.TSS{ + KeyGenZetaHeight: keygenHeight, + TssParticipantList: participantList, + TssPubkey: "zetapub1addwnpepqtadxdyt037h86z60nl98t6zk56mw5zpnm79tsmvspln3hgt5phdc79kvfc", + OperatorAddressList: operatorList, + FinalizedZetaHeight: finalizedZetaHeight, + }) + err := v6.MigrateStore(ctx, k) + assert.NoError(t, err) + keygen, found := k.GetKeygen(ctx) + assert.True(t, found) + assert.Equal(t, types.KeygenStatus_KeyGenSuccess, keygen.Status) + assert.Equal(t, keygenHeight, keygenHeight) + assert.Equal(t, participantList, participantList) + }) + t.Run("Migrate when keygen is not Pending", func(t *testing.T) { + k, ctx := keepertest.ObserverKeeper(t) + participantList := []string{ + "zetapub1addwnpepqglunjrgl3qg08duxq9pf28jmvrer3crwnnfzp6m0u0yh9jk9mnn5p76utc", + "zetapub1addwnpepqwwpjwwnes7cywfkr0afme7ymk8rf5jzhn8pfr6qqvfm9v342486qsrh4f5", + "zetapub1addwnpepq07xj82w5e6vr85qj3r7htmzh2mp3vkvfraapcv6ynhdwankseayk5yh80t", + "zetapub1addwnpepq0lxqx92m3fhae3usn8jffqvtx6cuzl06xh9r345c2qcqq8zyfs4cdpqcum", + "zetapub1addwnpepqvzlntzltvpm22ved5gjtn9nzqfz5fun38el4r64njc979rwanxlgq4u3p8", + "zetapub1addwnpepqg40psrhwwgy257p4xv50xp0asmtwjup66z8vk829289zxge5lyl7sycga8", + "zetapub1addwnpepqgpr5ffquqchra93r8l6d35q62cv4nsc9d4k2q7kten4sljxg5rluwx29gh", + "zetapub1addwnpepqdjf3vt8etgdddkghrvxfmmmeatky6m7hx7wjuv86udfghqpty8h5h4r78w", + "zetapub1addwnpepqtfcfmsdkzdgv03t8392gsh7kzrstp9g864w2ltz9k0xzz33q60dq6mnkex", + } + keygenHeight := int64(1440460) + k.SetKeygen(ctx, types.Keygen{ + Status: types.KeygenStatus_KeyGenSuccess, + BlockNumber: keygenHeight, + GranteePubkeys: participantList, + }) + err := v6.MigrateStore(ctx, k) + assert.NoError(t, err) + keygen, found := k.GetKeygen(ctx) + assert.True(t, found) + assert.Equal(t, types.KeygenStatus_KeyGenSuccess, keygen.Status) + assert.Equal(t, keygen.BlockNumber, keygenHeight) + assert.Equal(t, keygen.GranteePubkeys, participantList) + }) + +} diff --git a/x/observer/module.go b/x/observer/module.go index 563b5188ea..8e4e750608 100644 --- a/x/observer/module.go +++ b/x/observer/module.go @@ -156,6 +156,9 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { if err := cfg.RegisterMigration(types.ModuleName, 4, m.Migrate4to5); err != nil { panic(err) } + if err := cfg.RegisterMigration(types.ModuleName, 5, m.Migrate5to6); err != nil { + panic(err) + } } // RegisterInvariants registers the observer module's invariants. @@ -180,7 +183,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 5 } +func (AppModule) ConsensusVersion() uint64 { return 6 } // BeginBlock executes all ABCI BeginBlock logic respective to the observer module. func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { diff --git a/x/observer/types/errors.go b/x/observer/types/errors.go index 8918b08e7f..fd61f4ea4d 100644 --- a/x/observer/types/errors.go +++ b/x/observer/types/errors.go @@ -36,4 +36,5 @@ var ( ErrParamsMinObserverDelegation = errorsmod.Register(ModuleName, 1128, "min observer delegation cannot be nil") ErrMinDelegationNotFound = errorsmod.Register(ModuleName, 1129, "min delegation not found") ErrObserverSetNotFound = errorsmod.Register(ModuleName, 1130, "observer set not found") + ErrTssNotFound = errorsmod.Register(ModuleName, 1131, "tss not found") )