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

Generate a MsgWirePayForMessage via CLI #32

Merged
merged 11 commits into from
Feb 26, 2021
Merged

Conversation

evan-forbes
Copy link
Member

@evan-forbes evan-forbes commented Feb 19, 2021

Description

This PR adds a sub command to the cli to generate a MsgWirePayForMessage transaction.

Usage:
  lazyledgerapp tx lazyledgerapp payForMessage [hexNamespace] [hexMessage] [flags]

Breaking down the above command,

  • lazyledgerappd is the root command for everything lazyledger-app, including starting the node and generating transactions, but of this can change.
  • the tx sub-command contains other sub-commands related to generating transactions
  • the lazyledgerapp sub-command specifies the module that is being used
  • payForMessage is the sub-command to generate a MsgWirePayForMessage

The only necessary inputs are the namespace and the message, where everything else can be optional with sane defaults.

This PR should not be merged until #21 is merged. ✔️

the full --help message:

Usage:
  lazyledgerapp tx lazyledgerapp payForMessage [hexNamespace] [hexMessage] [flags]

Flags:
  -a, --account-number uint      The account number of the signing account (offline mode only)
  -b, --broadcast-mode string    Transaction broadcasting mode (sync|async|block) (default "sync")
      --dry-run                  ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it
      --fees string              Fees to pay along with transaction; eg: 10uatom
      --from string              Name or address of private key with which to sign
      --gas string               gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically (default 200000)
      --gas-adjustment float     adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored  (default 1)
      --gas-prices string        Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom)
      --generate-only            Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase is not accessible)
  -h, --help                     help for payForMessage
      --keyring-backend string   Select keyring's backend (os|file|kwallet|pass|test) (default "test")
      --keyring-dir string       The client Keyring directory; if omitted, the default 'home' directory will be used
      --ledger                   Use a connected Ledger device
      --memo string              Memo to send along with transaction
      --node string              <host>:<port> to tendermint rpc interface for this chain (default "tcp://localhost:26657")
      --offline                  Offline mode (does not allow any online functionality
  -s, --sequence uint            The sequence number of the signing account (offline mode only)
      --sign-mode string         Choose sign mode (direct|amino-json), this is an advanced feature
      --timeout-height uint      Set a block timeout height to prevent the tx from being committed past a certain height
  -y, --yes                      Skip tx broadcasting prompt confirmation

Global Flags:
      --chain-id string     The network chain ID
      --home string         directory for config and data (default "/home/evan/.lazyledgerapp")
      --log_format string   The logging format (json|plain) (default "plain")
      --log_level string    The logging level (trace|debug|info|warn|error|fatal|panic) (default "info")
      --trace               print out full stack trace on errors

closes: #31 #35

TODO:


  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@evan-forbes evan-forbes added the enhancement New feature or request label Feb 19, 2021
@evan-forbes evan-forbes self-assigned this Feb 19, 2021
@evan-forbes evan-forbes changed the title Evan/client pfm Generate a MsgWirePayForMessage via CLI Feb 19, 2021
@codecov-io
Copy link

codecov-io commented Feb 19, 2021

Codecov Report

Merging #32 (db5a91c) into master (1e64b39) will increase coverage by 0.62%.
The diff coverage is 72.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #32      +/-   ##
==========================================
+ Coverage   15.04%   15.66%   +0.62%     
==========================================
  Files          14       14              
  Lines        1888     1909      +21     
==========================================
+ Hits          284      299      +15     
- Misses       1588     1591       +3     
- Partials       16       19       +3     
Impacted Files Coverage Δ
x/lazyledgerapp/types/tx.pb.go 0.66% <ø> (ø)
x/lazyledgerapp/types/payformessage.go 54.67% <72.72%> (+2.98%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e64b39...db5a91c. Read the comment docs.

@evan-forbes evan-forbes marked this pull request as draft February 23, 2021 12:10
@evan-forbes evan-forbes marked this pull request as ready for review February 23, 2021 15:42
Comment on lines +11 to +18
// MsgServer is the server API for Msg service.
type MsgServer interface {
// PayForMessage allows the user to post data to made be available.
PayForMessage(context.Context, *types.MsgWirePayForMessage) (*types.MsgPayForMessageResponse, error)
// PayForMessage allows the user to post data to made be available.
SignedTransactionDataPayForMessage(context.Context, *types.SignedTransactionDataPayForMessage) (*types.SignedTransactionDataPayForMessageResponse, error)
}

Copy link
Member

Choose a reason for hiding this comment

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

What is the relation of this interface to the MsgServer interface in x/lazyledgerapp/types/tx.pb.go?

Copy link
Member Author

@evan-forbes evan-forbes Feb 23, 2021

Choose a reason for hiding this comment

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

The MsgServer interface in x/lazyledgerapp/types/tx.pb.go only accounts for rpc endpoints, as the generated code assumes that there will always be 1 enpoint per 1 handler. That is not the case in our situation, where we need 2 handlers, but only 1 endpoint.

Copy link
Member

Choose a reason for hiding this comment

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

What was the reason again to only have one endpoint here?

Copy link
Member Author

@evan-forbes evan-forbes Feb 23, 2021

Choose a reason for hiding this comment

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

because each MsgWirePayForMessage will have the information for multiple SignedTransactionDataPayForMessages in it, and one SignedTransactionDataPayForMessage is picked during PreprocessTxs, so having an endpoint for SignedTransactionDataPayForMessage could be confusing.

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense!

Comment on lines -550 to -551
// PayForMessage allows the user to post data to made be available.
SignedTransactionDataPayForMessage(context.Context, *SignedTransactionDataPayForMessage) (*SignedTransactionDataPayForMessageResponse, error)
Copy link
Member

@liamsi liamsi Feb 23, 2021

Choose a reason for hiding this comment

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

Why are there changes in this file with no changes in the corresponding proto file?

// Code generated by protoc-gen-gogo. DO NOT EDIT.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had manually changed them in the last PR when I added the handler for SignedTransactionDataPayForMessage 😬 , which was definitely the wrong approach to change MsgServer without adding an rpc endpoint. It was also my fault for force pushing the repo, otherwise someone would have probably caught it and informed me that it was a bad idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

does this need to be a separate PR?

Copy link
Member

Choose a reason for hiding this comment

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

No worries! Thanks for the explanation. Hmm, yeah probably a good idea to rip out the rpc/endpoint/handler changes and clean that up in a separate PR.

Copy link
Member

@liamsi liamsi Feb 23, 2021

Choose a reason for hiding this comment

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

Actually, if that means self-contained small changes, feel free to address this in this PR. Probably good to open a tiny issue explaining the changes for reference though (amend a closes #XXX referencing that issue too in the opening comment).

// transaction.
func CmdCreatePayForMessage() *cobra.Command {
cmd := &cobra.Command{
Use: "payForMessage [hexNamespace] [hexMessage]",
Copy link
Member

Choose a reason for hiding this comment

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

Other Tx are in JSON encoding or hex, too? (I mean on the cli)

Copy link
Member Author

Choose a reason for hiding this comment

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

That is a good question. I'm not sure. In other tx, each argument is parsed individually, and the only ones handling raw bytes are using either amino or the Bech32 address encoding. For example lazyledger-appd tx decode [amino-byte-string] [flags] uses the amino byte string, and all addresses are inputted as a Bech32 string. Should it use amino? Something else to handle bytes?

Copy link
Member

@liamsi liamsi Feb 24, 2021

Choose a reason for hiding this comment

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

Should it use amino?

NOOOOOOO! please don't :-D

But seriously, let's go with hex bytes for now. Let's open an issue about the UX/UI of the CLI. I'm also not sure what would be best here. We can address this much later anyway (before mainnet). Probably the main usage won't be over the CLI but from other chains too.

And I find payForMessage [hexNamespace] [hexMessage] clear and simple enough.

Comment on lines +58 to +71
func (msg *MsgWirePayForMessage) SignShareCommitments(accName string, ring keyring.Keyring) error {
for i, commit := range msg.MessageShareCommitment {
bytesToSign, err := msg.GetCommitmentSignBytes(commit.K)
if err != nil {
return err
}
sig, _, err := ring.Sign(accName, bytesToSign)
if err != nil {
return err
}
msg.MessageShareCommitment[i].Signature = sig
}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Dope! Can we create at least a small unit test for this method?

Comment on lines 169 to 170
msg.Message = PadMessage(msg.Message)
msg.padMessage()
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be obsolete if the MsgWirePayForMessage was constructed via NewMsgWirePayForMessage?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes it is redundant, and it reminded me of why I put it there in the first place. The last PR #21 uses MsgWirePayForMessages in the tests but obviously doesn't use the new NewMsgWirePayForMessage function, so those tests need a quick refactor along with getting rid of this msg.padMessage

Copy link
Member Author

Choose a reason for hiding this comment

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

resolved by de38b72 and e15b95b

liamsi
liamsi previously approved these changes Feb 25, 2021
Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

✅ 🎉 👍🏼

tzdybal
tzdybal previously approved these changes Feb 25, 2021
Copy link
Member

@tzdybal tzdybal left a comment

Choose a reason for hiding this comment

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

Looks good. I have only one tiny comment.

// decode the message
message, err := hex.DecodeString(args[1])
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

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

For better UX, maybe you can wrap error and provide info what argument (namespace or message) is wrong?

Copy link
Member Author

Choose a reason for hiding this comment

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

nice catch! You just saved someone some time 🙂 not all heroes wear capes 😉

resolved db5a91c

@evan-forbes evan-forbes dismissed stale reviews from tzdybal and liamsi via db5a91c February 25, 2021 15:04
Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

Left some nit about error wrapping.
See "Wrapping errors with %w": https://blog.golang.org/go1.13-errors

Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

@evan-forbes evan-forbes merged commit e4b0bc4 into master Feb 26, 2021
@evan-forbes evan-forbes deleted the evan/client-PFM branch February 26, 2021 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a way to generate a MsgWirePayForMessage from the cli
4 participants