Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sequence in sign-batch (backport #13200) #13263

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
21 changes: 20 additions & 1 deletion x/auth/client/cli/tx_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down
37 changes: 36 additions & 1 deletion x/auth/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down