From 66416f17d8003dae9b642bd1ca4c28a391dabf3c Mon Sep 17 00:00:00 2001 From: atheesh Date: Thu, 8 Sep 2022 18:20:04 +0530 Subject: [PATCH 1/5] fix `sign-batch` --- x/auth/client/cli/tx_sign.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 45fd71fa083c..e8343a29e871 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -95,7 +95,22 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { scanner := authclient.NewBatchScanner(txCfg, infile) if !clientCtx.Offline { - txFactory = txFactory.WithAccountNumber(0).WithSequence(0) + from, err := cmd.Flags().GetString(flags.FlagFrom) + if err != nil { + return err + } + + addr, _, _, err := client.GetFromFields(clientCtx, txFactory.Keybase(), from) + if err != nil { + return err + } + + acc, err := txFactory.AccountRetriever().GetAccount(clientCtx, addr) + if err != nil { + return err + } + + txFactory = txFactory.WithAccountNumber(acc.GetAccountNumber()).WithSequence(acc.GetSequence()) } for sequence := txFactory.Sequence(); scanner.Scan(); sequence++ { From ae5b4b4735bea24746a4af935286765a1d7a387c Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 9 Sep 2022 12:00:44 +0530 Subject: [PATCH 2/5] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d96f9a5eec8a..83e63512d5d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -434,6 +434,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (types) [#12154](https://github.com/cosmos/cosmos-sdk/pull/12154) Add `baseAccountGetter` to avoid invalid account error when create vesting account. * (x/crisis) [#12208](https://github.com/cosmos/cosmos-sdk/pull/12208) Fix progress index of crisis invariant assertion logs. * (types) [#12229](https://github.com/cosmos/cosmos-sdk/pull/12229) Increase sdk.Dec maxApproxRootIterations to 300 +* (x/auth) [#13200](https://github.com/cosmos/cosmos-sdk/pull/13200) Fix wrong sequences in `sign-batch` ### State Machine Breaking From be0fd14a225ca9cd7e6ab90b8bd6f94bf6406299 Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 9 Sep 2022 16:04:59 +0530 Subject: [PATCH 3/5] fix tests --- x/auth/client/cli/tx_sign.go | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index e8343a29e871..287955507d31 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -95,22 +95,27 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { scanner := authclient.NewBatchScanner(txCfg, infile) if !clientCtx.Offline { - from, err := cmd.Flags().GetString(flags.FlagFrom) - if err != nil { - return err - } + if ms != "" { + txFactory = txFactory.WithAccountNumber(0).WithSequence(0) + } else { - addr, _, _, err := client.GetFromFields(clientCtx, txFactory.Keybase(), from) - if err != nil { - return err - } + from, err := cmd.Flags().GetString(flags.FlagFrom) + if err != nil { + return err + } - acc, err := txFactory.AccountRetriever().GetAccount(clientCtx, addr) - if err != nil { - return err - } + addr, _, _, err := client.GetFromFields(clientCtx, txFactory.Keybase(), from) + if err != nil { + return err + } - txFactory = txFactory.WithAccountNumber(acc.GetAccountNumber()).WithSequence(acc.GetSequence()) + acc, err := txFactory.AccountRetriever().GetAccount(clientCtx, addr) + if err != nil { + return err + } + + txFactory = txFactory.WithAccountNumber(acc.GetAccountNumber()).WithSequence(acc.GetSequence()) + } } for sequence := txFactory.Sequence(); scanner.Scan(); sequence++ { From b04d5ea6b9f3463884ed34e5be14a83e8acdf269 Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 9 Sep 2022 16:05:36 +0530 Subject: [PATCH 4/5] fix tests --- x/auth/client/cli/tx_sign.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 287955507d31..f6870c5eb3b4 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -95,10 +95,7 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { scanner := authclient.NewBatchScanner(txCfg, infile) if !clientCtx.Offline { - if ms != "" { - txFactory = txFactory.WithAccountNumber(0).WithSequence(0) - } else { - + if ms == "" { from, err := cmd.Flags().GetString(flags.FlagFrom) if err != nil { return err @@ -115,6 +112,8 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { } txFactory = txFactory.WithAccountNumber(acc.GetAccountNumber()).WithSequence(acc.GetSequence()) + } else { + txFactory = txFactory.WithAccountNumber(0).WithSequence(0) } } From 9ea19d12ba057a0557157558946753709dbe3c75 Mon Sep 17 00:00:00 2001 From: atheesh Date: Tue, 13 Sep 2022 11:55:24 +0530 Subject: [PATCH 5/5] add tests --- x/auth/client/testutil/suite.go | 37 ++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index 5e6e78d1580b..4e413378cdec 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -285,6 +285,40 @@ func (s *IntegrationTestSuite) TestCLISignBatch() { // Sign batch malformed tx file signature only. _, err = TxSignBatchExec(val.ClientCtx, val.Address, malformedFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--signature-only") s.Require().Error(err) + + // make a txn to increase the sequence of sender + _, seq, err := val.ClientCtx.AccountRetriever.GetAccountNumberSequence(val.ClientCtx, val.Address) + s.Require().NoError(err) + + account1, err := val.ClientCtx.Keyring.Key("newAccount1") + s.Require().NoError(err) + + addr, err := account1.GetAddress() + s.Require().NoError(err) + + // Send coins from validator to multisig. + _, err = s.createBankMsg( + val, + addr, + sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 1000)), + ) + s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + + // fetch the sequence after a tx, should be incremented. + _, seq1, err := val.ClientCtx.AccountRetriever.GetAccountNumberSequence(val.ClientCtx, val.Address) + s.Require().NoError(err) + s.Require().Equal(seq+1, seq1) + + // signing sign-batch should start from the last sequence. + signed, err := TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--signature-only") + s.Require().NoError(err) + signedTxs := strings.Split(strings.Trim(signed.String(), "\n"), "\n") + s.Require().GreaterOrEqual(len(signedTxs), 1) + + sigs, err := s.cfg.TxConfig.UnmarshalSignatureJSON([]byte(signedTxs[0])) + s.Require().NoError(err) + s.Require().Equal(sigs[0].Sequence, seq1) } func (s *IntegrationTestSuite) TestCliGetAccountAddressByID() { @@ -449,9 +483,10 @@ func (s *IntegrationTestSuite) TestCLIQueryTxCmdByHash() { sdk.NewCoins(sendTokens), ) s.Require().NoError(err) + s.Require().NoError(s.network.WaitForNextBlock()) + var txRes sdk.TxResponse s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &txRes)) - s.Require().NoError(s.network.WaitForNextBlock()) testCases := []struct { name string