From c657669b0240d3e8a26a62af4f8128603e99e4cf Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 12 Jan 2024 10:55:45 -0500 Subject: [PATCH] fix: pending nonces genesis import (#1546) --- changelog.md | 1 + testutil/network/genesis_state.go | 10 ++++++ .../client/integrationtests/cli_helpers.go | 2 +- .../integrationtests/inbound_voter_test.go | 20 +++++------- x/crosschain/keeper/msg_server_tss_voter.go | 1 - .../cli/tx_update_update_system_contract.go | 3 -- x/observer/genesis.go | 31 +++++++++++-------- x/observer/keeper/pending_nonces.go | 1 - 8 files changed, 37 insertions(+), 32 deletions(-) diff --git a/changelog.md b/changelog.md index db702f1fba..40b38a4322 100644 --- a/changelog.md +++ b/changelog.md @@ -41,6 +41,7 @@ * [1528](https://github.com/zeta-chain/node/pull/1528) - fix panic caused on decoding malformed BTC addresses * [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 * [1555](https://github.com/zeta-chain/node/pull/1555) - Reduce websocket message limit to 10MB * [1567](https://github.com/zeta-chain/node/pull/1567) - add bitcoin chain id to fetch the tss address rpc endpoint diff --git a/testutil/network/genesis_state.go b/testutil/network/genesis_state.go index a88018e8f7..d74b5c4c8f 100644 --- a/testutil/network/genesis_state.go +++ b/testutil/network/genesis_state.go @@ -127,8 +127,18 @@ func AddObserverData(t *testing.T, n int, genesisState map[string]json.RawMessag FinalizedZetaHeight: 1, KeyGenZetaHeight: 1, } + pendingNonces := make([]observertypes.PendingNonces, len(common.DefaultChainsList())) + for i, chain := range common.DefaultChainsList() { + pendingNonces[i] = observertypes.PendingNonces{ + ChainId: chain.ChainId, + NonceLow: 0, + NonceHigh: 0, + Tss: tss.TssPubkey, + } + } state.Tss = &tss state.TssHistory = []observertypes.TSS{tss} + state.PendingNonces = pendingNonces // set crosschain flags crosschainFlags := &observertypes.CrosschainFlags{ diff --git a/x/crosschain/client/integrationtests/cli_helpers.go b/x/crosschain/client/integrationtests/cli_helpers.go index 03f565fc97..626706a627 100644 --- a/x/crosschain/client/integrationtests/cli_helpers.go +++ b/x/crosschain/client/integrationtests/cli_helpers.go @@ -181,7 +181,7 @@ func BuildSignedTssVote(t testing.TB, val *network.Validator, denom string, acco cmd := cli.CmdCreateTSSVoter() inboundVoterArgs := []string{ "tsspubkey", - strconv.FormatInt(common.GoerliLocalnetChain().ChainId, 10), + "1", "0", } txArgs := []string{ diff --git a/x/crosschain/client/integrationtests/inbound_voter_test.go b/x/crosschain/client/integrationtests/inbound_voter_test.go index ce0a0043e8..424a7e68eb 100644 --- a/x/crosschain/client/integrationtests/inbound_voter_test.go +++ b/x/crosschain/client/integrationtests/inbound_voter_test.go @@ -237,20 +237,14 @@ func (s *IntegrationTestSuite) TestCCTXInboundVoter() { _, err = clitestutil.ExecTestCLICmd(broadcaster.ClientCtx, authcli.GetBroadcastCommand(), []string{signedTx.Name(), "--broadcast-mode", "sync"}) s.Require().NoError(err) } - s.Require().NoError(s.network.WaitForNBlocks(2)) - - // Vote the tss - for _, val := range s.network.Validators { - out, err := clitestutil.ExecTestCLICmd(broadcaster.ClientCtx, authcli.GetAccountCmd(), []string{val.Address.String(), "--output", "json"}) - s.Require().NoError(err) - var account authtypes.AccountI - s.NoError(val.ClientCtx.Codec.UnmarshalInterfaceJSON(out.Bytes(), &account)) - signedTx := BuildSignedTssVote(s.T(), val, s.cfg.BondDenom, account) - out, err = clitestutil.ExecTestCLICmd(broadcaster.ClientCtx, authcli.GetBroadcastCommand(), []string{signedTx.Name(), "--broadcast-mode", "sync"}) - s.Require().NoError(err) - } s.Require().NoError(s.network.WaitForNBlocks(2)) + out, err := clitestutil.ExecTestCLICmd(broadcaster.ClientCtx, observercli.CmdListPendingNonces(), []string{"--output", "json"}) + s.Require().NoError(err) + fmt.Println(out.String()) + out, err = clitestutil.ExecTestCLICmd(broadcaster.ClientCtx, observercli.CmdGetSupportedChains(), []string{"--output", "json"}) + s.Require().NoError(err) + fmt.Println(out.String()) // Vote the inbound tx for _, val := range s.network.Validators { @@ -274,7 +268,7 @@ func (s *IntegrationTestSuite) TestCCTXInboundVoter() { // Get the ballot ballotIdentifier := GetBallotIdentifier(test.name, i) - out, err := clitestutil.ExecTestCLICmd(broadcaster.ClientCtx, observercli.CmdBallotByIdentifier(), []string{ballotIdentifier, "--output", "json"}) + out, err = clitestutil.ExecTestCLICmd(broadcaster.ClientCtx, observercli.CmdBallotByIdentifier(), []string{ballotIdentifier, "--output", "json"}) s.Require().NoError(err) ballot := observerTypes.QueryBallotByIdentifierResponse{} s.NoError(broadcaster.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &ballot)) diff --git a/x/crosschain/keeper/msg_server_tss_voter.go b/x/crosschain/keeper/msg_server_tss_voter.go index b15dfcabc9..13a97e58ae 100644 --- a/x/crosschain/keeper/msg_server_tss_voter.go +++ b/x/crosschain/keeper/msg_server_tss_voter.go @@ -97,7 +97,6 @@ func (k msgServer) CreateTSSVoter(goCtx context.Context, msg *types.MsgCreateTSS } // Set TSS history only, current TSS is updated via admin transaction // In Case this is the first TSS address update both current and history - tssList := k.zetaObserverKeeper.GetAllTSS(ctx) if len(tssList) == 0 { k.GetObserverKeeper().SetTssAndUpdateNonce(ctx, tss) diff --git a/x/fungible/client/cli/tx_update_update_system_contract.go b/x/fungible/client/cli/tx_update_update_system_contract.go index 2f30a528e9..63f367c402 100644 --- a/x/fungible/client/cli/tx_update_update_system_contract.go +++ b/x/fungible/client/cli/tx_update_update_system_contract.go @@ -1,8 +1,6 @@ package cli import ( - "fmt" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" @@ -20,7 +18,6 @@ func CmdUpdateSystemContract() *cobra.Command { if err != nil { return err } - fmt.Printf("CLI address: %s\n", clientCtx.GetFromAddress().String()) msg := types.NewMsgUpdateSystemContract(clientCtx.GetFromAddress().String(), args[0]) if err := msg.ValidateBasic(); err != nil { return err diff --git a/x/observer/genesis.go b/x/observer/genesis.go index 1f22e4208f..8098394f65 100644 --- a/x/observer/genesis.go +++ b/x/observer/genesis.go @@ -94,21 +94,30 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) k.SetLastObserverCount(ctx, &types.LastObserverCount{LastChangeHeight: 0, Count: observerCount}) } + tss := types.TSS{} if genState.Tss != nil { - tss := *genState.Tss + tss = *genState.Tss k.SetTSS(ctx, tss) + } + + // Set all the pending nonces + if genState.PendingNonces != nil { + for _, pendingNonce := range genState.PendingNonces { + k.SetPendingNonces(ctx, pendingNonce) + } + } else { for _, chain := range common.DefaultChainsList() { - k.SetPendingNonces(ctx, types.PendingNonces{ - NonceLow: 0, - NonceHigh: 0, - ChainId: chain.ChainId, - Tss: tss.TssPubkey, - }) + if genState.Tss != nil { + k.SetPendingNonces(ctx, types.PendingNonces{ + NonceLow: 0, + NonceHigh: 0, + ChainId: chain.ChainId, + Tss: tss.TssPubkey, + }) + } } } - // Get all chain nonces - for _, elem := range genState.TssHistory { k.SetTSSHistory(ctx, elem) } @@ -121,10 +130,6 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) k.SetBlame(ctx, elem) } - // Set all the pending nonces - for _, pendingNonce := range genState.PendingNonces { - k.SetPendingNonces(ctx, pendingNonce) - } for _, chainNonce := range genState.ChainNonces { k.SetChainNonces(ctx, chainNonce) } diff --git a/x/observer/keeper/pending_nonces.go b/x/observer/keeper/pending_nonces.go index eb140ee4bd..198a1219b5 100644 --- a/x/observer/keeper/pending_nonces.go +++ b/x/observer/keeper/pending_nonces.go @@ -91,7 +91,6 @@ func (k Keeper) SetTssAndUpdateNonce(ctx sdk.Context, tss types.TSS) { FinalizedHeight: uint64(ctx.BlockHeight()), } k.SetChainNonces(ctx, chainNonce) - p := types.PendingNonces{ NonceLow: 0, NonceHigh: 0,