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

feat(cli): add --append flag to sign-batch cli cmd #13147

Merged
merged 33 commits into from
Sep 26, 2022
Merged

feat(cli): add --append flag to sign-batch cli cmd #13147

merged 33 commits into from
Sep 26, 2022

Conversation

gsk967
Copy link
Contributor

@gsk967 gsk967 commented Sep 4, 2022

Description

Added --append flags to sign-batch cli cmd, this will combine the messages which are generated from --generate-only and it will generate single transaction

ref: #13066


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 in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • 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 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)

@codecov
Copy link

codecov bot commented Sep 4, 2022

Codecov Report

Merging #13147 (d0780aa) into main (4fe7797) will decrease coverage by 1.50%.
The diff coverage is 24.13%.

❗ Current head d0780aa differs from pull request most recent head ea5d655. Consider uploading reports for the commit ea5d655 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #13147      +/-   ##
==========================================
- Coverage   55.87%   54.37%   -1.51%     
==========================================
  Files         646      645       -1     
  Lines       54895    54924      +29     
==========================================
- Hits        30675    29863     -812     
- Misses      21762    22663     +901     
+ Partials     2458     2398      -60     
Impacted Files Coverage Δ
baseapp/grpcrouter.go 90.00% <ø> (ø)
baseapp/grpcrouter_helpers.go 25.00% <ø> (ø)
baseapp/grpcserver.go 1.72% <ø> (ø)
baseapp/msg_service_router.go 85.29% <ø> (+4.41%) ⬆️
baseapp/options.go 67.92% <0.00%> (-0.60%) ⬇️
client/broadcast.go 54.54% <ø> (+2.99%) ⬆️
client/cmd.go 57.73% <ø> (ø)
client/config/toml.go 55.55% <ø> (ø)
client/context.go 54.49% <ø> (-1.79%) ⬇️
client/flags/flags.go 19.35% <ø> (-0.32%) ⬇️
... and 255 more

@gsk967 gsk967 marked this pull request as ready for review September 4, 2022 08:34
@gsk967 gsk967 requested a review from a team as a code owner September 4, 2022 08:34
x/auth/client/cli/tx_multisign.go Outdated Show resolved Hide resolved
x/auth/client/cli/tx_multisign.go Outdated Show resolved Hide resolved
x/auth/client/cli/tx_sign.go Show resolved Hide resolved
x/auth/client/cli/tx_sign.go Outdated Show resolved Hide resolved
@atheeshp
Copy link
Contributor

atheeshp commented Sep 5, 2022

How is this different from sign-batch?

CHANGELOG.md Show resolved Hide resolved
x/auth/client/cli/tx_multisign.go Outdated Show resolved Hide resolved
x/auth/client/cli/tx_multisign.go Outdated Show resolved Hide resolved
x/auth/client/cli/tx_multisign.go Outdated Show resolved Hide resolved
Comment on lines 93 to 95
txBuilder.SetMemo(fe.GetTx().GetMemo())
txBuilder.SetTip(fe.GetTx().GetTip())
txBuilder.SetGasLimit(fe.GetTx().GetGas())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're doing this in a loop, so aren't we overriding these fields, for each tx?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I am adding memo, remaining fields to tx from cmd.Flags

Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to add tests as well

x/auth/client/cli/tx_multisign.go Outdated Show resolved Hide resolved
x/auth/client/cli/tx_multisign.go Outdated Show resolved Hide resolved
x/auth/client/cli/tx_multisign.go Outdated Show resolved Hide resolved
@anilcse
Copy link
Collaborator

anilcse commented Sep 6, 2022

How is this different from sign-batch?

Oh seems like it is. @gsk967 can we merge this solution with sign-batch to accept multiple tx files. How does that sound @alexanderbez . I like some refactoring in this pr tbh

@alexanderbez
Copy link
Contributor

How is this different from sign-batch?

Oh seems like it is. @gsk967 can we merge this solution with sign-batch to accept multiple tx files. How does that sound @alexanderbez . I like some refactoring in this pr tbh

Yeah, sure!

@sahith-narahari
Copy link
Contributor

How is this different from sign-batch?

Oh seems like it is. @gsk967 can we merge this solution with sign-batch to accept multiple tx files. How does that sound @alexanderbez . I like some refactoring in this pr tbh

How about we add a flag append to common TxFlags which takes file name and adds the tx to a common file. This should limit changes to sign-batch command and is better ux than handling one file per tx imo.

@alexanderbez
Copy link
Contributor

How would that work? Say we have a new flag, e.g. multi-msg-file=<some-file>. Would this require the tx to be not signed and be appended to the file <some-file>? What changes would be made to sign-batch?

@sahith-narahari
Copy link
Contributor

So sign-batch expects a file to have multiple unsigned txs seperated by next line. The command flow would look something like this

$ simd tx bank send <args...|flags...> --generate-only > txs.json
$ simd tx staking delegate <args...|flags...> --generate-only --append txs.json
$ simd auth sign-batch txs.json --from key1

@alexanderbez
Copy link
Contributor

Makes sense. But I would have all txs use the new flag so make the UX easier. If the flag is present and the file is empty, then just populate the empty file 👍

@atheeshp
Copy link
Contributor

atheeshp commented Sep 7, 2022

So sign-batch expects a file to have multiple unsigned txs seperated by next line. The command flow would look something like this

$ simd tx bank send <args...|flags...> --generate-only > txs.json
$ simd tx staking delegate <args...|flags...> --generate-only --append txs.json
$ simd auth sign-batch txs.json --from key1

I think we don't need any flag to be introduced here, since we have >> (file append operation) by default.

  • > replaces text in file
  • >> appends to the file with newline delimiter

The following lines will do the same as above mentioned lines by @sahith-narahari .

$ simd tx bank send <args...|flags...> --generate-only >> txs.json
$ simd tx staking delegate <args...|flags...> --generate-only >> txs.json
$ simd tx sign-batch txs.json --from key1

We can just update the documentation.

cc: @anilcse , @alexanderbez

@sahith-narahari
Copy link
Contributor

Oh right, we can close the issue in this case then

@alexanderbez
Copy link
Contributor

alexanderbez commented Sep 7, 2022

@atheeshp I don't understand how directing output will work though? The >> operator will just append one JSON blob into an existing file, giving you malformed JSON. What we want is a single tx, i.e. a single JSON blob that appends messages.

@gsk967
Copy link
Contributor Author

gsk967 commented Sep 22, 2022

@atheeshp @alexanderbez @AmauryM @anilcse

Added --append flag to the sign-batch cli cmd to combine multiple messages and generate the single signed tx

return err
}
if ms == "" {
from, _ := cmd.Flags().GetString(flags.FlagFrom)

Check warning

Code scanning / gosec

Returned error is not propagated up the stack.

Returned error is not propagated up the stack.
txBuilder, err := txCfg.WrapTxBuilder(unsignedStdTx)
if err != nil {
return err
appendMessagesToSingleMsg, _ := cmd.Flags().GetBool(flagAppend)

Check warning

Code scanning / gosec

Returned error is not propagated up the stack.

Returned error is not propagated up the stack.
}
// set the new appened msgs into builder
txBuilder.SetMsgs(msgs...)

Check warning

Code scanning / gosec

Errors unhandled.

Errors unhandled.
@alexanderbez
Copy link
Contributor

Amazing! @julienrbrt or @facundomedica would be willing to help test this feature with me please?

@julienrbrt
Copy link
Member

Amazing! @julienrbrt or @facundomedica would be willing to help test this feature with me please?

I can check tomorrow morning :)

@gsk967 gsk967 changed the title feat(cli): add multi-msg-sign feat(cli): add --append flag to sign-batch cli cmd Sep 23, 2022
@julienrbrt julienrbrt self-assigned this Sep 23, 2022
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK

@julienrbrt
Copy link
Member

Tested and works, but if there is documentation to update, we should do it in this PR.

Copy link
Collaborator

@anilcse anilcse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@alexanderbez
Copy link
Contributor

alexanderbez commented Sep 26, 2022

There are definitely CLI docs that we can look to update. Doesn't have to be super in depth, but maybe just a note in a CLI doc?

@julienrbrt
Copy link
Member

There are definitely CLI docs that we can look to update. Doesn't have to be super in depth, but maybe just a note in a CLI doc?

Looking at the auth docs, there is actually no documentation for any tx auth commands: https://docs.cosmos.network/main/modules/auth/section_06.html.
It probably shouldn't be done in this issue then. I'll create an issue to do this as follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants