From 525b2d5bbc2f12761c5b608957cae7d5e624fce9 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 8 Jul 2021 14:54:42 +0530 Subject: [PATCH 01/12] return MaxUint64 for Limit on InfiniteGasMeter and add a func to return GasLeft on GasMeter --- store/types/gas.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/store/types/gas.go b/store/types/gas.go index bf44e717d095..53121bb06f1c 100644 --- a/store/types/gas.go +++ b/store/types/gas.go @@ -41,6 +41,7 @@ type ErrorGasOverflow struct { type GasMeter interface { GasConsumed() Gas GasConsumedToLimit() Gas + GasLeft() Gas Limit() Gas ConsumeGas(amount Gas, descriptor string) RefundGas(amount Gas, descriptor string) @@ -66,6 +67,10 @@ func (g *basicGasMeter) GasConsumed() Gas { return g.consumed } +func (g *basicGasMeter) GasLeft() Gas { + return g.limit - g.consumed +} + func (g *basicGasMeter) Limit() Gas { return g.limit } @@ -145,8 +150,12 @@ func (g *infiniteGasMeter) GasConsumedToLimit() Gas { return g.consumed } +func (g *infiniteGasMeter) GasLeft() Gas { + return math.MaxUint64 +} + func (g *infiniteGasMeter) Limit() Gas { - return 0 + return math.MaxUint64 } func (g *infiniteGasMeter) ConsumeGas(amount Gas, descriptor string) { From dcdab0cf4ad4e02cecdea066d5a284d4d6aa11a4 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 5 Aug 2021 14:43:17 +0530 Subject: [PATCH 02/12] overwrite sequence and account-number flag's values with default values when provided with offline != true --- x/auth/client/cli/tx_sign.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 34483f9c935b..453d3ff4fabc 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -62,6 +62,7 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { if err != nil { return err } + var seq_value uint64 txFactory := tx.NewFactoryCLI(clientCtx, cmd.Flags()) txCfg := clientCtx.TxConfig printSignatureOnly, _ := cmd.Flags().GetBool(flagSigOnly) @@ -88,8 +89,14 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { } } scanner := authclient.NewBatchScanner(txCfg, infile) + if clientCtx.Offline != true { + seq_value = 0 + txFactory = txFactory.WithAccountNumber(0) + } else { + seq_value = txFactory.Sequence() + } - for sequence := txFactory.Sequence(); scanner.Scan(); sequence++ { + for sequence := seq_value; scanner.Scan(); sequence++ { unsignedStdTx := scanner.Tx() txFactory = txFactory.WithSequence(sequence) txBuilder, err := txCfg.WrapTxBuilder(unsignedStdTx) From ae00407e05e2548fb09298ef2db04e12f8b4880b Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 5 Aug 2021 14:51:48 +0530 Subject: [PATCH 03/12] improve sign-batch cli help msg --- x/auth/client/cli/tx_sign.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 453d3ff4fabc..8b661001aab3 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -28,7 +28,7 @@ func GetSignBatchCommand() *cobra.Command { Long: `Sign batch files of transactions generated with --generate-only. The command processes list of transactions from file (one StdTx each line), generate signed transactions or signatures and print their JSON encoding, delimited by '\n'. -As the signatures are generated, the command updates the account sequence number accordingly. +As the signatures are generated, the command updates the account and sequence number accordingly. If the --signature-only flag is set, it will output the signature parts only. @@ -38,6 +38,9 @@ it is required to set such parameters manually. Note, invalid values will cause the transaction to fail. The sequence will be incremented automatically for each transaction that is signed. +If --account-number or --sequence flag is used when offline=false, they are ignored and +overwritten by the default flag values. + The --multisig= flag generates a signature on behalf of a multisig account key. It implies --signature-only. `, From 6ca20cfe83acee5c01134281f5a8583a27259e41 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 5 Aug 2021 15:02:54 +0530 Subject: [PATCH 04/12] add changelod --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2880158a22f3..146edf85b8f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (cli) [\#9856](https://github.com/cosmos/cosmos-sdk/pull/9856) Overwrite `--sequence` and `--account-number` flags with default flag values when used with `offline=false` in `sign-batch` command. * (cli) [\#9593](https://github.com/cosmos/cosmos-sdk/pull/9593) Check if chain-id is blank before verifying signatures in multisign and error. * (cli) [\#9717](https://github.com/cosmos/cosmos-sdk/pull/9717) Added CLI flag `--output json/text` to `tx` cli commands. From 7fba98efd4376acb253ee2dbbbc21b13587488e0 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 5 Aug 2021 15:04:40 +0530 Subject: [PATCH 05/12] fix lint issues --- x/auth/client/cli/tx_sign.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 8b661001aab3..a59892b2fdbc 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -65,7 +65,7 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { if err != nil { return err } - var seq_value uint64 + var seqValue uint64 txFactory := tx.NewFactoryCLI(clientCtx, cmd.Flags()) txCfg := clientCtx.TxConfig printSignatureOnly, _ := cmd.Flags().GetBool(flagSigOnly) @@ -92,14 +92,14 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { } } scanner := authclient.NewBatchScanner(txCfg, infile) - if clientCtx.Offline != true { - seq_value = 0 + if !clientCtx.Offline { + seqValue = 0 txFactory = txFactory.WithAccountNumber(0) } else { - seq_value = txFactory.Sequence() + seqValue = txFactory.Sequence() } - for sequence := seq_value; scanner.Scan(); sequence++ { + for sequence := seqValue; scanner.Scan(); sequence++ { unsignedStdTx := scanner.Tx() txFactory = txFactory.WithSequence(sequence) txBuilder, err := txCfg.WrapTxBuilder(unsignedStdTx) From 30d7ac642a321046c11b8c3e583ef70e71d16ddd Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 5 Aug 2021 15:48:41 +0530 Subject: [PATCH 06/12] add tess --- x/auth/client/testutil/suite.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index 666542e30e1a..2ac9749a7661 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -126,8 +126,21 @@ func (s *IntegrationTestSuite) TestCLISignBatch() { _, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--offline") s.Require().EqualError(err, "required flag(s) \"account-number\", \"sequence\" not set") + // sign-batch file - offline and sequence is set but account-number is not set + _, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s --%s=%s", flags.FlagChainID, val.ClientCtx.ChainID, flags.FlagSequence, "1"), "--offline") + s.Require().EqualError(err, "required flag(s) \"account-number\" not set") + + // sign-batch file - offline and account-number is set but sequence is not set + _, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s --%s=%s", flags.FlagChainID, val.ClientCtx.ChainID, flags.FlagAccountNumber, "1"), "--offline") + s.Require().EqualError(err, "required flag(s) \"sequence\" not set") + + // sign-batch file - sequence and account-number are set when offline is false + res, err := TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s --%s=%s --%s=%s", flags.FlagChainID, val.ClientCtx.ChainID, flags.FlagSequence, "1", flags.FlagAccountNumber, "1")) + s.Require().NoError(err) + s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + // sign-batch file - res, err := TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID)) + res, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID)) s.Require().NoError(err) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) From cb7e57a53cd4305fdfe33d2b06039f3d00a7f49c Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 5 Aug 2021 16:30:03 +0530 Subject: [PATCH 07/12] fix failing test --- x/auth/client/testutil/suite.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index 2ac9749a7661..ef8d901903f9 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -128,11 +128,11 @@ func (s *IntegrationTestSuite) TestCLISignBatch() { // sign-batch file - offline and sequence is set but account-number is not set _, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s --%s=%s", flags.FlagChainID, val.ClientCtx.ChainID, flags.FlagSequence, "1"), "--offline") - s.Require().EqualError(err, "required flag(s) \"account-number\" not set") + s.Require().EqualError(err, "required flag(s) \"account-number\", \"sequence\" not set") // sign-batch file - offline and account-number is set but sequence is not set _, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s --%s=%s", flags.FlagChainID, val.ClientCtx.ChainID, flags.FlagAccountNumber, "1"), "--offline") - s.Require().EqualError(err, "required flag(s) \"sequence\" not set") + s.Require().EqualError(err, "required flag(s) \"account-number\", \"sequence\" not set") // sign-batch file - sequence and account-number are set when offline is false res, err := TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s --%s=%s --%s=%s", flags.FlagChainID, val.ClientCtx.ChainID, flags.FlagSequence, "1", flags.FlagAccountNumber, "1")) From ead516d095d40c20a998b7a240b27d33f50b2293 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 6 Aug 2021 13:48:00 +0530 Subject: [PATCH 08/12] small fix --- x/auth/client/testutil/suite.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index ef8d901903f9..591e91143b3e 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -127,14 +127,14 @@ func (s *IntegrationTestSuite) TestCLISignBatch() { s.Require().EqualError(err, "required flag(s) \"account-number\", \"sequence\" not set") // sign-batch file - offline and sequence is set but account-number is not set - _, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s --%s=%s", flags.FlagChainID, val.ClientCtx.ChainID, flags.FlagSequence, "1"), "--offline") - s.Require().EqualError(err, "required flag(s) \"account-number\", \"sequence\" not set") + _, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagSequence, "1"), "--offline") + s.Require().EqualError(err, "required flag(s) \"account-number\" not set") // sign-batch file - offline and account-number is set but sequence is not set - _, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s --%s=%s", flags.FlagChainID, val.ClientCtx.ChainID, flags.FlagAccountNumber, "1"), "--offline") - s.Require().EqualError(err, "required flag(s) \"account-number\", \"sequence\" not set") + _, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, "1"), "--offline") + s.Require().EqualError(err, "required flag(s) \"sequence\" not set") - // sign-batch file - sequence and account-number are set when offline is false + // sign-batch file - sequence and account-number are set when offline is falses res, err := TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s --%s=%s --%s=%s", flags.FlagChainID, val.ClientCtx.ChainID, flags.FlagSequence, "1", flags.FlagAccountNumber, "1")) s.Require().NoError(err) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) From 1141a6829cef4089970c5c1fd8e950a7ed678b84 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 6 Aug 2021 14:14:33 +0530 Subject: [PATCH 09/12] small fixes --- x/auth/client/cli/tx_sign.go | 1 + x/auth/client/testutil/suite.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index a59892b2fdbc..d1341c41d5ba 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -92,6 +92,7 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { } } scanner := authclient.NewBatchScanner(txCfg, infile) + if !clientCtx.Offline { seqValue = 0 txFactory = txFactory.WithAccountNumber(0) diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index 591e91143b3e..8cd282b378c3 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -134,8 +134,8 @@ func (s *IntegrationTestSuite) TestCLISignBatch() { _, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, "1"), "--offline") s.Require().EqualError(err, "required flag(s) \"sequence\" not set") - // sign-batch file - sequence and account-number are set when offline is falses - res, err := TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s --%s=%s --%s=%s", flags.FlagChainID, val.ClientCtx.ChainID, flags.FlagSequence, "1", flags.FlagAccountNumber, "1")) + // sign-batch file - sequence and account-number are set when offline is false + res, err := TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagSequence, "1"), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, "1")) s.Require().NoError(err) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) From 3471d78c1d99b6ea9ed8fa706545e2cceaa21c0e Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 6 Aug 2021 20:02:35 +0530 Subject: [PATCH 10/12] small refactor --- x/auth/client/cli/tx_sign.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index d1341c41d5ba..0117e22d4ab4 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -94,8 +94,7 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { scanner := authclient.NewBatchScanner(txCfg, infile) if !clientCtx.Offline { - seqValue = 0 - txFactory = txFactory.WithAccountNumber(0) + txFactory = txFactory.WithAccountNumber(0).WithSequence(0) } else { seqValue = txFactory.Sequence() } From 79cda3cc3384ccd7bb5ec499e897e8371da8b7b5 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 6 Aug 2021 20:08:43 +0530 Subject: [PATCH 11/12] code refactoring --- x/auth/client/cli/tx_sign.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 0117e22d4ab4..98dcfb9c9982 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -65,7 +65,6 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { if err != nil { return err } - var seqValue uint64 txFactory := tx.NewFactoryCLI(clientCtx, cmd.Flags()) txCfg := clientCtx.TxConfig printSignatureOnly, _ := cmd.Flags().GetBool(flagSigOnly) @@ -96,10 +95,10 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { if !clientCtx.Offline { txFactory = txFactory.WithAccountNumber(0).WithSequence(0) } else { - seqValue = txFactory.Sequence() + txFactory = txFactory.WithAccountNumber(txFactory.AccountNumber()).WithSequence(txFactory.Sequence()) } - for sequence := seqValue; scanner.Scan(); sequence++ { + for sequence := txFactory.Sequence(); scanner.Scan(); sequence++ { unsignedStdTx := scanner.Tx() txFactory = txFactory.WithSequence(sequence) txBuilder, err := txCfg.WrapTxBuilder(unsignedStdTx) From 59a947dd97e3894d049c44173617d00b9428d6ed Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Fri, 6 Aug 2021 20:29:52 +0530 Subject: [PATCH 12/12] address review comment --- x/auth/client/cli/tx_sign.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 98dcfb9c9982..08abeaa05972 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -94,8 +94,6 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { if !clientCtx.Offline { txFactory = txFactory.WithAccountNumber(0).WithSequence(0) - } else { - txFactory = txFactory.WithAccountNumber(txFactory.AccountNumber()).WithSequence(txFactory.Sequence()) } for sequence := txFactory.Sequence(); scanner.Scan(); sequence++ {