From 04916f637c69ecb9bbc91e1dc425497543952fc8 Mon Sep 17 00:00:00 2001 From: skosito Date: Tue, 9 Apr 2024 22:46:46 +0200 Subject: [PATCH] PR comments --- changelog.md | 2 +- e2e/txserver/zeta_tx_server.go | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/changelog.md b/changelog.md index 340d81987a..6957804246 100644 --- a/changelog.md +++ b/changelog.md @@ -26,6 +26,7 @@ * [1936](https://github.com/zeta-chain/node/pull/1936) - refactor common package into subpackages and rename to pkg * [1966](https://github.com/zeta-chain/node/pull/1966) - move TSS vote message from crosschain to observer * [1853](https://github.com/zeta-chain/node/pull/1853) - refactor vote inbound tx and vote outbound tx +* [2001](https://github.com/zeta-chain/node/pull/2001) - replace broadcast mode block with sync ### Features @@ -59,7 +60,6 @@ * [1941](https://github.com/zeta-chain/node/pull/1941) - add unit tests for zetabridge package * [1985](https://github.com/zeta-chain/node/pull/1985) - improve fungible module coverage * [1992](https://github.com/zeta-chain/node/pull/1992) - remove setupKeeper from crosschain module -* [2001](https://github.com/zeta-chain/node/pull/2001) - replace broadcast mode block with sync ### Fixes diff --git a/e2e/txserver/zeta_tx_server.go b/e2e/txserver/zeta_tx_server.go index b2918aef1e..a06920a714 100644 --- a/e2e/txserver/zeta_tx_server.go +++ b/e2e/txserver/zeta_tx_server.go @@ -51,11 +51,12 @@ const EmissionsPoolAddress = "zeta1w43fn2ze2wyhu5hfmegr6vp52c3dgn0srdgymy" // ZetaTxServer is a ZetaChain tx server for E2E test type ZetaTxServer struct { - clientCtx client.Context - txFactory tx.Factory - name []string - mnemonic []string - address []string + clientCtx client.Context + txFactory tx.Factory + name []string + mnemonic []string + address []string + blockTimeout time.Duration } // NewZetaTxServer returns a new TxServer with provided account @@ -105,11 +106,12 @@ func NewZetaTxServer(rpcAddr string, names []string, mnemonics []string, chainID txf := newFactory(clientCtx) return ZetaTxServer{ - clientCtx: clientCtx, - txFactory: txf, - name: names, - mnemonic: mnemonics, - address: addresses, + clientCtx: clientCtx, + txFactory: txf, + name: names, + mnemonic: mnemonics, + address: addresses, + blockTimeout: 1 * time.Minute, }, nil } @@ -160,6 +162,7 @@ func (zts ZetaTxServer) GetAccountMnemonic(index int) string { } // BroadcastTx broadcasts a tx to ZetaChain with the provided msg from the account +// and waiting for blockTime for tx to be included in the block func (zts ZetaTxServer) BroadcastTx(account string, msg sdktypes.Msg) (*sdktypes.TxResponse, error) { // Find number and sequence and set it acc, err := zts.clientCtx.Keyring.Key(account) @@ -191,7 +194,10 @@ func (zts ZetaTxServer) BroadcastTx(account string, msg sdktypes.Msg) (*sdktypes return nil, err } - // Broadcast tx and wait 10 mins to be included in block + return broadcastWithBlockTimeout(zts, txBytes) +} + +func broadcastWithBlockTimeout(zts ZetaTxServer, txBytes []byte) (*sdktypes.TxResponse, error) { res, err := zts.clientCtx.BroadcastTx(txBytes) if err != nil { if res == nil { @@ -204,8 +210,7 @@ func (zts ZetaTxServer) BroadcastTx(account string, msg sdktypes.Msg) (*sdktypes }, err } - var blockTimeout time.Duration = 10 * time.Minute - exitAfter := time.After(blockTimeout) + exitAfter := time.After(zts.blockTimeout) hash, err := hex.DecodeString(res.TxHash) if err != nil { return nil, err @@ -213,7 +218,7 @@ func (zts ZetaTxServer) BroadcastTx(account string, msg sdktypes.Msg) (*sdktypes for { select { case <-exitAfter: - return nil, fmt.Errorf("timed out after waiting for tx to get included in the block: %d", blockTimeout) + return nil, fmt.Errorf("timed out after waiting for tx to get included in the block: %d", zts.blockTimeout) case <-time.After(time.Millisecond * 100): resTx, err := zts.clientCtx.Client.Tx(context.TODO(), hash, false) if err == nil {