From 3175343fbef5cf17ec0f7a3bcf2b9bd91fa5b33c Mon Sep 17 00:00:00 2001 From: atheeshp <59333759+atheeshp@users.noreply.github.com> Date: Tue, 13 Sep 2022 19:05:51 +0530 Subject: [PATCH 1/2] fix: sequence in `sign-batch` (#13200) ## Description Closes: #13199 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) (cherry picked from commit 04858ea2ea285b3079b2cf8e887308e6511553f9) --- CHANGELOG.md | 1 + x/auth/client/cli/tx_sign.go | 21 ++++++++++++++++++- x/auth/client/testutil/suite.go | 37 ++++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f428aaa84aa..33760a24ddf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -353,6 +353,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 diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 39626e5ed1a..a8bda05cb85 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -95,7 +95,26 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { scanner := authclient.NewBatchScanner(txCfg, infile) if !clientCtx.Offline { - txFactory = txFactory.WithAccountNumber(0).WithSequence(0) + if ms == "" { + 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()) + } else { + txFactory = txFactory.WithAccountNumber(0).WithSequence(0) + } } for sequence := txFactory.Sequence(); scanner.Scan(); sequence++ { diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index 7de8c50085b..8e9ddf26190 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -279,6 +279,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() { @@ -443,9 +477,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 From be590179931ebea7889b05e42d60ccb3d7c48fc7 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 13 Sep 2022 21:15:14 +0200 Subject: [PATCH 2/2] fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33760a24ddf..35ec2007669 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (x/auth) [#13200](https://github.com/cosmos/cosmos-sdk/pull/13200) Fix wrong sequences in `sign-batch`. * (export) [#13029](https://github.com/cosmos/cosmos-sdk/pull/13029) Fix exporting the blockParams regression. * [#13046](https://github.com/cosmos/cosmos-sdk/pull/13046) Fix missing return statement in BaseApp.Query. @@ -353,7 +354,6 @@ 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