From d72dc111560c1848514eb7a2ea3c6378e3cad5b5 Mon Sep 17 00:00:00 2001 From: dudong2 Date: Tue, 25 Oct 2022 18:20:34 +0900 Subject: [PATCH 1/2] fix: get seq number for non-multisig signing --- CHANGELOG.md | 1 + x/auth/client/cli/tx_sign.go | 23 +++++++++++++++++++++ x/auth/client/testutil/suite.go | 36 +++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43b86a943c..bb3fe1ca1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -118,6 +118,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/foundation) [\#730](https://github.com/line/lbm-sdk/pull/730) prune stale x/foundation proposals at voting period end * (cli) [\#734](https://github.com/line/lbm-sdk/pull/734) add restrictions on the number of args in the CLIs * (client) [\#737](https://github.com/line/lbm-sdk/pull/737) check multisig key list to prevent unexpected key deletion +* (x/auth) [#754](https://github.com/line/lbm-sdk/pull/754) Fix wrong sequences in `sign-batch` ### Breaking Changes * (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 266ce32ca2..69197a1e4e 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -90,6 +90,29 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { } scanner := authclient.NewBatchScanner(txCfg, infile) + if !clientCtx.Offline { + if ms == "" { + from, err := cmd.Flags().GetString(flags.FlagFrom) + if err != nil { + return err + } + + addr, _, _, err := client.GetFromFields(txFactory.Keybase(), from, clientCtx.GenerateOnly) + 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++ { unsignedStdTx := scanner.Tx() txFactory = txFactory.WithSequence(sequence) diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index 6c7f6017e8..ba451263b2 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -144,6 +144,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 := 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) TestCLISignAminoJSON() { @@ -259,6 +293,8 @@ 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()) From 562ff8b3c514d2e01ee1b81196be7402f193dc80 Mon Sep 17 00:00:00 2001 From: dudong2 Date: Wed, 26 Oct 2022 15:45:06 +0900 Subject: [PATCH 2/2] chore: apply pr review --- CHANGELOG.md | 2 +- x/auth/client/testutil/suite.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5be228feb7..493c5e026e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -122,7 +122,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (cli) [\#734](https://github.com/line/lbm-sdk/pull/734) add restrictions on the number of args in the CLIs * (client) [\#737](https://github.com/line/lbm-sdk/pull/737) check multisig key list to prevent unexpected key deletion * (simapp) [\#752](https://github.com/line/lbm-sdk/pull/752) add x/distribution's module account into blockedAddr -* (x/auth) [#754](https://github.com/line/lbm-sdk/pull/754) Fix wrong sequences in `sign-batch` +* (x/auth) [\#754](https://github.com/line/lbm-sdk/pull/754) Fix wrong sequences in `sign-batch` ### Breaking Changes * (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index ba451263b2..f8c267743e 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -293,7 +293,6 @@ 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))