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

Get sequence number for non multisig signing #755

Closed
4 tasks done
dudong2 opened this issue Oct 25, 2022 · 0 comments · Fixed by #754
Closed
4 tasks done

Get sequence number for non multisig signing #755

dudong2 opened this issue Oct 25, 2022 · 0 comments · Fixed by #754
Assignees
Labels
A: bug Something isn't working

Comments

@dudong2
Copy link
Contributor

dudong2 commented Oct 25, 2022

Summary

Currently, signing is performed with incorrect sequence number(0) for non-multisig singing in sign-batch function.
So, we need to provide the appropriate sequence number for signing.

Problem Definition

func populateAccountFromState(
	txBldr tx.Factory, clientCtx client.Context, addr sdk.AccAddress,
) (tx.Factory, error) {

	num, seq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, addr)
	if err != nil {
		return txBldr, err
	}

	return txBldr.WithAccountNumber(num).WithSequence(seq), nil
}

func SignTx(txFactory tx.Factory, clientCtx client.Context, name string, txBuilder client.TxBuilder, offline, overwriteSig bool) error {
	//...

	if !offline {
		txFactory, err = populateAccountFromState(txFactory, clientCtx, addr)
		if err != nil {
			return err
		}
	}

	return tx.Sign(txFactory, name, txBuilder, overwriteSig)
}

If offline is given as false in the SignTx function, populateAccountFromState is called and the appropriate account number and sequence number are set.

func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error {
	//...
			if ms == "" {
				from, _ := cmd.Flags().GetString(flags.FlagFrom)
				_, fromName, _, err := client.GetFromFields(txFactory.Keybase(), from, clientCtx.GenerateOnly)
				if err != nil {
					return fmt.Errorf("error getting account from keybase: %w", err)
				}
				err = authclient.SignTx(txFactory, clientCtx, fromName, txBuilder, true, true)
				if err != nil {
					return err
				}
			} else {
	//...
}

In the makeSignBatchCmd function, if it is not multisig, the SignTx function is always called with offline value set to true.

Proposal

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)
	}
}

We need to add the above logic to the makeSignBatchCmd function.

ref. cosmos/cosmos-sdk#13200


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@dudong2 dudong2 added the A: bug Something isn't working label Oct 25, 2022
@dudong2 dudong2 self-assigned this Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant