Skip to content

Commit f574d9c

Browse files
authored
refactor: replace broadcast mode block with sync and remove fungible params (#2001)
* Remove broadcast mode block wip * Fixes * Changelog * PR comments * Lint fix * refactor: remove fungible params (#2004) * Remove unused params from fungible module * Make generate * Changelog * Lint fix * Lint fix * Fix changelog * Revert proto indexes * make generate
1 parent 62ec009 commit f574d9c

36 files changed

+231
-1241
lines changed

app/app.go

-2
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ func New(
419419
appCodec,
420420
keys[fungibletypes.StoreKey],
421421
keys[fungibletypes.MemStoreKey],
422-
app.GetSubspace(fungibletypes.ModuleName),
423422
app.AccountKeeper,
424423
app.EvmKeeper,
425424
app.BankKeeper,
@@ -432,7 +431,6 @@ func New(
432431
keys[crosschaintypes.StoreKey],
433432
keys[crosschaintypes.MemStoreKey],
434433
&stakingKeeper,
435-
app.GetSubspace(crosschaintypes.ModuleName),
436434
app.AccountKeeper,
437435
app.BankKeeper,
438436
app.ObserverKeeper,

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* [1936](https://github.com/zeta-chain/node/pull/1936) - refactor common package into subpackages and rename to pkg
3030
* [1966](https://github.com/zeta-chain/node/pull/1966) - move TSS vote message from crosschain to observer
3131
* [1853](https://github.com/zeta-chain/node/pull/1853) - refactor vote inbound tx and vote outbound tx
32+
* [2001](https://github.com/zeta-chain/node/pull/2001) - replace broadcast mode block with sync and remove fungible params
3233
* [1989](https://github.com/zeta-chain/node/pull/1989) - simplify `IsSendOutTxProcessed` method and add unit tests
3334
* [2013](https://github.com/zeta-chain/node/pull/2013) - rename `GasPriceVoter` message to `VoteGasPrice`
3435

cmd/zetacored/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func NewRootCmd() (*cobra.Command, appparams.EncodingConfig) {
6464
WithLegacyAmino(encodingConfig.Amino).
6565
WithInput(os.Stdin).
6666
WithAccountRetriever(authtypes.AccountRetriever{}).
67-
WithBroadcastMode(flags.BroadcastBlock).
67+
WithBroadcastMode(flags.BroadcastSync).
6868
WithHomeDir(app.DefaultNodeHome).
6969
WithKeyringOptions(hd.EthSecp256k1Option()).
7070
WithViper(EnvPrefix)

docs/cli/zetacored/zetacored_query_fungible.md

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ zetacored query fungible [flags]
3030
* [zetacored query fungible gas-stability-pool-balance](zetacored_query_fungible_gas-stability-pool-balance.md) - query the balance of a gas stability pool for a chain
3131
* [zetacored query fungible gas-stability-pool-balances](zetacored_query_fungible_gas-stability-pool-balances.md) - query all gas stability pool balances
3232
* [zetacored query fungible list-foreign-coins](zetacored_query_fungible_list-foreign-coins.md) - list all ForeignCoins
33-
* [zetacored query fungible params](zetacored_query_fungible_params.md) - shows the parameters of the module
3433
* [zetacored query fungible show-foreign-coins](zetacored_query_fungible_show-foreign-coins.md) - shows a ForeignCoins
3534
* [zetacored query fungible system-contract](zetacored_query_fungible_system-contract.md) - query system contract
3635

docs/cli/zetacored/zetacored_query_fungible_params.md

-33
This file was deleted.

docs/openapi/openapi.swagger.yaml

-25
Original file line numberDiff line numberDiff line change
@@ -27401,21 +27401,6 @@ paths:
2740127401
format: int64
2740227402
tags:
2740327403
- Query
27404-
/zeta-chain/fungible/params:
27405-
get:
27406-
summary: Parameters queries the parameters of the module.
27407-
operationId: Query_Params
27408-
responses:
27409-
"200":
27410-
description: A successful response.
27411-
schema:
27412-
$ref: '#/definitions/zetacorefungibleQueryParamsResponse'
27413-
default:
27414-
description: An unexpected error response.
27415-
schema:
27416-
$ref: '#/definitions/googlerpcStatus'
27417-
tags:
27418-
- Query
2741927404
/zeta-chain/fungible/system_contract:
2742027405
get:
2742127406
summary: Queries SystemContract
@@ -54759,16 +54744,6 @@ definitions:
5475954744
$ref: '#/definitions/zetacoreemissionsParams'
5476054745
description: params holds all the parameters of this module.
5476154746
description: QueryParamsResponse is response type for the Query/Params RPC method.
54762-
zetacorefungibleParams:
54763-
type: object
54764-
description: Params defines the parameters for the module.
54765-
zetacorefungibleQueryParamsResponse:
54766-
type: object
54767-
properties:
54768-
params:
54769-
$ref: '#/definitions/zetacorefungibleParams'
54770-
description: params holds all the parameters of this module.
54771-
description: QueryParamsResponse is response type for the Query/Params RPC method.
5477254747
zetacoreobserverParams:
5477354748
type: object
5477454749
properties:

e2e/txserver/zeta_tx_server.go

+72-13
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package txserver
22

33
import (
44
"context"
5+
"encoding/hex"
56
"encoding/json"
67
"errors"
78
"fmt"
89
"math/big"
910
"os"
1011
"strings"
12+
"time"
1113

1214
"github.com/cosmos/cosmos-sdk/client"
1315
"github.com/cosmos/cosmos-sdk/client/flags"
@@ -33,6 +35,7 @@ import (
3335
etherminttypes "github.com/evmos/ethermint/types"
3436
evmtypes "github.com/evmos/ethermint/x/evm/types"
3537
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
38+
coretypes "github.com/tendermint/tendermint/rpc/core/types"
3639
"github.com/zeta-chain/zetacore/cmd/zetacored/config"
3740
"github.com/zeta-chain/zetacore/pkg/chains"
3841
"github.com/zeta-chain/zetacore/pkg/coin"
@@ -48,11 +51,12 @@ const EmissionsPoolAddress = "zeta1w43fn2ze2wyhu5hfmegr6vp52c3dgn0srdgymy"
4851

4952
// ZetaTxServer is a ZetaChain tx server for E2E test
5053
type ZetaTxServer struct {
51-
clientCtx client.Context
52-
txFactory tx.Factory
53-
name []string
54-
mnemonic []string
55-
address []string
54+
clientCtx client.Context
55+
txFactory tx.Factory
56+
name []string
57+
mnemonic []string
58+
address []string
59+
blockTimeout time.Duration
5660
}
5761

5862
// NewZetaTxServer returns a new TxServer with provided account
@@ -102,11 +106,12 @@ func NewZetaTxServer(rpcAddr string, names []string, mnemonics []string, chainID
102106
txf := newFactory(clientCtx)
103107

104108
return ZetaTxServer{
105-
clientCtx: clientCtx,
106-
txFactory: txf,
107-
name: names,
108-
mnemonic: mnemonics,
109-
address: addresses,
109+
clientCtx: clientCtx,
110+
txFactory: txf,
111+
name: names,
112+
mnemonic: mnemonics,
113+
address: addresses,
114+
blockTimeout: 1 * time.Minute,
110115
}, nil
111116
}
112117

@@ -157,6 +162,7 @@ func (zts ZetaTxServer) GetAccountMnemonic(index int) string {
157162
}
158163

159164
// BroadcastTx broadcasts a tx to ZetaChain with the provided msg from the account
165+
// and waiting for blockTime for tx to be included in the block
160166
func (zts ZetaTxServer) BroadcastTx(account string, msg sdktypes.Msg) (*sdktypes.TxResponse, error) {
161167
// Find number and sequence and set it
162168
acc, err := zts.clientCtx.Keyring.Key(account)
@@ -188,8 +194,61 @@ func (zts ZetaTxServer) BroadcastTx(account string, msg sdktypes.Msg) (*sdktypes
188194
return nil, err
189195
}
190196

191-
// Broadcast tx
192-
return zts.clientCtx.BroadcastTx(txBytes)
197+
return broadcastWithBlockTimeout(zts, txBytes)
198+
}
199+
200+
func broadcastWithBlockTimeout(zts ZetaTxServer, txBytes []byte) (*sdktypes.TxResponse, error) {
201+
res, err := zts.clientCtx.BroadcastTx(txBytes)
202+
if err != nil {
203+
if res == nil {
204+
return nil, err
205+
}
206+
return &sdktypes.TxResponse{
207+
Code: res.Code,
208+
Codespace: res.Codespace,
209+
TxHash: res.TxHash,
210+
}, err
211+
}
212+
213+
exitAfter := time.After(zts.blockTimeout)
214+
hash, err := hex.DecodeString(res.TxHash)
215+
if err != nil {
216+
return nil, err
217+
}
218+
for {
219+
select {
220+
case <-exitAfter:
221+
return nil, fmt.Errorf("timed out after waiting for tx to get included in the block: %d", zts.blockTimeout)
222+
case <-time.After(time.Millisecond * 100):
223+
resTx, err := zts.clientCtx.Client.Tx(context.TODO(), hash, false)
224+
if err == nil {
225+
txRes, err := mkTxResult(zts.clientCtx, resTx)
226+
if err == nil {
227+
return txRes, nil
228+
}
229+
}
230+
}
231+
}
232+
}
233+
234+
func mkTxResult(clientCtx client.Context, resTx *coretypes.ResultTx) (*sdktypes.TxResponse, error) {
235+
txb, err := clientCtx.TxConfig.TxDecoder()(resTx.Tx)
236+
if err != nil {
237+
return nil, err
238+
}
239+
p, ok := txb.(intoAny)
240+
if !ok {
241+
return nil, fmt.Errorf("expecting a type implementing intoAny, got: %T", txb)
242+
}
243+
resBlock, err := clientCtx.Client.Block(context.TODO(), &resTx.Height)
244+
if err != nil {
245+
return nil, err
246+
}
247+
return sdktypes.NewResponseResultTx(resTx, p.AsAny(), resBlock.Block.Time.Format(time.RFC3339)), nil
248+
}
249+
250+
type intoAny interface {
251+
AsAny() *codectypes.Any
193252
}
194253

195254
// DeploySystemContractsAndZRC20 deploys the system contracts and ZRC20 contracts
@@ -373,7 +432,7 @@ func newContext(
373432
WithLegacyAmino(codec.NewLegacyAmino()).
374433
WithInput(os.Stdin).
375434
WithOutput(os.Stdout).
376-
WithBroadcastMode(flags.BroadcastBlock).
435+
WithBroadcastMode(flags.BroadcastSync).
377436
WithClient(rpc).
378437
WithSkipConfirmation(true).
379438
WithFromName("creator").

proto/crosschain/genesis.proto

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ option go_package = "github.com/zeta-chain/zetacore/x/crosschain/types";
1313

1414
// GenesisState defines the metacore module's genesis state.
1515
message GenesisState {
16-
repeated OutTxTracker outTxTrackerList = 1 [(gogoproto.nullable) = false];
17-
repeated GasPrice gasPriceList = 2;
18-
repeated CrossChainTx CrossChainTxs = 3;
19-
repeated LastBlockHeight lastBlockHeightList = 4;
20-
repeated InTxHashToCctx inTxHashToCctxList = 5 [(gogoproto.nullable) = false];
21-
repeated InTxTracker in_tx_tracker_list = 6 [(gogoproto.nullable) = false];
22-
ZetaAccounting zeta_accounting = 7 [(gogoproto.nullable) = false];
23-
repeated string FinalizedInbounds = 8;
16+
repeated OutTxTracker outTxTrackerList = 2 [(gogoproto.nullable) = false];
17+
repeated GasPrice gasPriceList = 5;
18+
repeated CrossChainTx CrossChainTxs = 7;
19+
repeated LastBlockHeight lastBlockHeightList = 8;
20+
repeated InTxHashToCctx inTxHashToCctxList = 9 [(gogoproto.nullable) = false];
21+
repeated InTxTracker in_tx_tracker_list = 11 [(gogoproto.nullable) = false];
22+
ZetaAccounting zeta_accounting = 12 [(gogoproto.nullable) = false];
23+
repeated string FinalizedInbounds = 16;
2424
}

proto/fungible/genesis.proto

-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ syntax = "proto3";
22
package zetachain.zetacore.fungible;
33

44
import "fungible/foreign_coins.proto";
5-
import "fungible/params.proto";
65
import "fungible/system_contract.proto";
76
import "gogoproto/gogo.proto";
87

98
option go_package = "github.com/zeta-chain/zetacore/x/fungible/types";
109

1110
// GenesisState defines the fungible module's genesis state.
1211
message GenesisState {
13-
Params params = 1 [(gogoproto.nullable) = false];
1412
repeated ForeignCoins foreignCoinsList = 2 [(gogoproto.nullable) = false];
1513
SystemContract systemContract = 3;
1614
}

proto/fungible/params.proto

-11
This file was deleted.

proto/fungible/query.proto

-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package zetachain.zetacore.fungible;
33

44
import "cosmos/base/query/v1beta1/pagination.proto";
55
import "fungible/foreign_coins.proto";
6-
import "fungible/params.proto";
76
import "fungible/system_contract.proto";
87
import "gogoproto/gogo.proto";
98
import "google/api/annotations.proto";
@@ -12,11 +11,6 @@ option go_package = "github.com/zeta-chain/zetacore/x/fungible/types";
1211

1312
// Query defines the gRPC querier service.
1413
service Query {
15-
// Parameters queries the parameters of the module.
16-
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
17-
option (google.api.http).get = "/zeta-chain/fungible/params";
18-
}
19-
2014
// Queries a ForeignCoins by index.
2115
rpc ForeignCoins(QueryGetForeignCoinsRequest) returns (QueryGetForeignCoinsResponse) {
2216
option (google.api.http).get = "/zeta-chain/fungible/foreign_coins/{index}";
@@ -53,15 +47,6 @@ service Query {
5347
}
5448
}
5549

56-
// QueryParamsRequest is request type for the Query/Params RPC method.
57-
message QueryParamsRequest {}
58-
59-
// QueryParamsResponse is response type for the Query/Params RPC method.
60-
message QueryParamsResponse {
61-
// params holds all the parameters of this module.
62-
Params params = 1 [(gogoproto.nullable) = false];
63-
}
64-
6550
message QueryGetForeignCoinsRequest {
6651
string index = 1;
6752
}

testutil/keeper/crosschain.go

-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ func CrosschainKeeperWithMocks(
7575
cdc,
7676
db,
7777
stateStore,
78-
sdkKeepers.ParamsKeeper,
7978
sdkKeepers.AuthKeeper,
8079
sdkKeepers.BankKeeper,
8180
sdkKeepers.EvmKeeper,
@@ -134,7 +133,6 @@ func CrosschainKeeperWithMocks(
134133
storeKey,
135134
memStoreKey,
136135
stakingKeeper,
137-
sdkKeepers.ParamsKeeper.Subspace(types.ModuleName),
138136
authKeeper,
139137
bankKeeper,
140138
observerKeeper,

testutil/keeper/fungible.go

-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/cosmos/cosmos-sdk/store"
99
storetypes "github.com/cosmos/cosmos-sdk/store/types"
1010
sdk "github.com/cosmos/cosmos-sdk/types"
11-
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
1211
"github.com/evmos/ethermint/x/evm/statedb"
1312
evmtypes "github.com/evmos/ethermint/x/evm/types"
1413
"github.com/stretchr/testify/mock"
@@ -44,7 +43,6 @@ func initFungibleKeeper(
4443
cdc codec.Codec,
4544
db *tmdb.MemDB,
4645
ss store.CommitMultiStore,
47-
paramKeeper paramskeeper.Keeper,
4846
authKeeper types.AccountKeeper,
4947
bankKeepr types.BankKeeper,
5048
evmKeeper types.EVMKeeper,
@@ -60,7 +58,6 @@ func initFungibleKeeper(
6058
cdc,
6159
storeKey,
6260
memKey,
63-
paramKeeper.Subspace(types.ModuleName),
6461
authKeeper,
6562
evmKeeper,
6663
bankKeepr,
@@ -145,7 +142,6 @@ func FungibleKeeperWithMocks(t testing.TB, mockOptions FungibleMockOptions) (*ke
145142
cdc,
146143
storeKey,
147144
memStoreKey,
148-
sdkKeepers.ParamsKeeper.Subspace(types.ModuleName),
149145
authKeeper,
150146
evmKeeper,
151147
bankKeeper,

0 commit comments

Comments
 (0)