Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace broadcast mode block with sync and remove fungible params #2001

Merged
merged 11 commits into from
Apr 18, 2024
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
* [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
skosito marked this conversation as resolved.
Show resolved Hide resolved

### Fixes

Expand Down
2 changes: 1 addition & 1 deletion cmd/zetacored/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewRootCmd() (*cobra.Command, appparams.EncodingConfig) {
WithLegacyAmino(encodingConfig.Amino).
WithInput(os.Stdin).
WithAccountRetriever(authtypes.AccountRetriever{}).
WithBroadcastMode(flags.BroadcastBlock).
WithBroadcastMode(flags.BroadcastSync).
WithHomeDir(app.DefaultNodeHome).
WithKeyringOptions(hd.EthSecp256k1Option()).
WithViper(EnvPrefix)
Expand Down
61 changes: 58 additions & 3 deletions e2e/txserver/zeta_tx_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math/big"
"os"
"strings"
"time"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -33,6 +35,7 @@
etherminttypes "github.com/evmos/ethermint/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/zeta-chain/zetacore/cmd/zetacored/config"
"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/pkg/coin"
Expand Down Expand Up @@ -188,8 +191,60 @@
return nil, err
}

// Broadcast tx
return zts.clientCtx.BroadcastTx(txBytes)
// Broadcast tx and wait 10 mins to be included in block
res, err := zts.clientCtx.BroadcastTx(txBytes)
if err != nil {
if res == nil {
return nil, err
}
return &sdktypes.TxResponse{
Code: res.Code,
Codespace: res.Codespace,
TxHash: res.TxHash,
}, err
}

var blockTimeout time.Duration = 10 * time.Minute

Check warning on line 207 in e2e/txserver/zeta_tx_server.go

View workflow job for this annotation

GitHub Actions / lint

var-declaration: should omit type time.Duration from declaration of var blockTimeout; it will be inferred from the right-hand side (revive)
skosito marked this conversation as resolved.
Show resolved Hide resolved
exitAfter := time.After(blockTimeout)
hash, err := hex.DecodeString(res.TxHash)
if err != nil {
return nil, err
}
for {
select {
case <-exitAfter:
return nil, fmt.Errorf("timed out after waiting for tx to get included in the block: %d", blockTimeout)
case <-time.After(time.Millisecond * 100):
resTx, err := zts.clientCtx.Client.Tx(context.TODO(), hash, false)
if err == nil {
txRes, err := mkTxResult(zts.clientCtx, resTx)
if err == nil {
return txRes, nil
}
}
}
}
skosito marked this conversation as resolved.
Show resolved Hide resolved
}

func mkTxResult(clientCtx client.Context, resTx *coretypes.ResultTx) (*sdktypes.TxResponse, error) {
skosito marked this conversation as resolved.
Show resolved Hide resolved
txb, err := clientCtx.TxConfig.TxDecoder()(resTx.Tx)
if err != nil {
return nil, err
}
p, ok := txb.(intoAny)
if !ok {
return nil, fmt.Errorf("expecting a type implementing intoAny, got: %T", txb)
}
any := p.AsAny()

Check warning on line 238 in e2e/txserver/zeta_tx_server.go

View workflow job for this annotation

GitHub Actions / lint

redefines-builtin-id: redefinition of the built-in type any (revive)
resBlock, err := clientCtx.Client.Block(context.TODO(), &resTx.Height)
if err != nil {
return nil, err
}
return sdktypes.NewResponseResultTx(resTx, any, resBlock.Block.Time.Format(time.RFC3339)), nil
}

type intoAny interface {
AsAny() *codectypes.Any
}

// DeploySystemContractsAndZRC20 deploys the system contracts and ZRC20 contracts
Expand Down Expand Up @@ -373,7 +428,7 @@
WithLegacyAmino(codec.NewLegacyAmino()).
WithInput(os.Stdin).
WithOutput(os.Stdout).
WithBroadcastMode(flags.BroadcastBlock).
WithBroadcastMode(flags.BroadcastSync).
WithClient(rpc).
WithSkipConfirmation(true).
WithFromName("creator").
Expand Down
Loading