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

Implement simple transaction memos #1280

Merged
merged 17 commits into from
Jun 20, 2018
Merged

Implement simple transaction memos #1280

merged 17 commits into from
Jun 20, 2018

Conversation

cwgoes
Copy link
Contributor

@cwgoes cwgoes commented Jun 16, 2018

Expected use case: simple, cheap way to associate a transaction with a reference to an external resource (exchange account, coffee payment, sender identity).

Memos are not indexed or query-able, but they are included in the signature. Memos are per-transaction, not per-message. Memos cost a bit of gas and are capped at 100 characters (presently).

Closes #904
Ref #669

  • Renames AltBytes to memo
  • Memo is now a string
  • Caps memos at 100 characters (can be changed)
  • Adds CLI flag to send a memo along with a transaction
  • Gas is now charged proportional to memo size
  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG.md
  • Updated Gaia/Examples
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@cwgoes cwgoes added the wip label Jun 16, 2018
@cwgoes cwgoes requested a review from ebuchman as a code owner June 16, 2018 02:18
@codecov
Copy link

codecov bot commented Jun 16, 2018

Codecov Report

Merging #1280 into develop will increase coverage by 0.01%.
The diff coverage is 78.26%.

@@             Coverage Diff             @@
##           develop    #1280      +/-   ##
===========================================
+ Coverage    65.26%   65.28%   +0.01%     
===========================================
  Files          102      102              
  Lines         5519     5533      +14     
===========================================
+ Hits          3602     3612      +10     
- Misses        1708     1712       +4     
  Partials       209      209

@ValarDragon
Copy link
Contributor

Why don't transaction memos have fees? Is it because the implementation details would be complicated? Intuitively it seems as though they should to me, since its taking long term storage on the chain. (Unless there is an in-protocol way to specify "Prune memos after blocks")

@cwgoes
Copy link
Contributor Author

cwgoes commented Jun 16, 2018

Why don't transaction memos have fees? Is it because the implementation details would be complicated? Intuitively it seems as though they should to me, since its taking long term storage on the chain. (Unless there is an in-protocol way to specify "Prune memos after blocks")

Memos are stored in history, but not state (so they can be discarded by non-archiving nodes). Maybe we should still charge a bit, although the UX is easier if a memo is free. Memos now have a small fee.

@ValarDragon
Copy link
Contributor

I think we need to add to the godoc somewhere, that the reason memo gas is significantly cheaper than normal gas per byte is that we plan to have them rapidly pruned once pruning has been implemented.

@cwgoes cwgoes changed the title WIP: Implement simple transaction memos Implement simple transaction memos Jun 20, 2018
@cwgoes cwgoes requested a review from ValarDragon June 20, 2018 02:47
@cwgoes
Copy link
Contributor Author

cwgoes commented Jun 20, 2018

I think we need to add to the godoc somewhere, that the reason memo gas is significantly cheaper than normal gas per byte is that we plan to have them rapidly pruned once pruning has been implemented.

Agreed, let's do that in #1289 though.

Copy link
Contributor

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

Overall looks good to me! Minor nitpicks, but I think the requested change on TestAnteHandlerMemoGas should block this merge however!

x/auth/ante.go Outdated

if len(memo) > maxMemoCharacters {
return ctx,
sdk.ErrMemoTooLarge(fmt.Sprintf("maximum %d characters but was %d characters", maxMemoCharacters, len(memo))).Result(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider changing to something more verbose, e.g. "maximum number of characters is %d, but received %d characters"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

// tx has enough gas
fee = NewStdFee(1000, sdk.NewCoin("atom", 0))
tx = newTestTx(ctx, msg, privs, accnums, seqs, fee)
checkValidTx(t, anteHandler, ctx, tx)
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't test the inclusion of memo when it is of a correct size, and enough fees is provided. Such a test needs to show that the memo is included in the state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test for inclusion of memo less than maximum size. State isn't really a property of the ante handler, that would make sense to test elsewhere.

barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barCech, flags))
assert.Equal(t, int64(30), barAcc.GetCoins().AmountOf("steak").Int64())
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooCech, flags))
assert.Equal(t, int64(20), fooAcc.GetCoins().AmountOf("steak").Int64())
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if possible through just cli commands, but ideally this should check that the memo field is in history. Currently this is just checking that inclusion of the memo field doesn't break sends.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking memo in history would be nice but is inconvenient to do through CLI tests, ideally in the future we'll have better Tendermint integration tests - #1313.

@@ -45,12 +45,12 @@ func GenTx(msg sdk.Msg, accnums []int64, seq []int64, priv ...crypto.PrivKeyEd25
for i, p := range priv {
sigs[i] = auth.StdSignature{
PubKey: p.PubKey(),
Signature: p.Sign(auth.StdSignBytes(chainID, accnums, seq, fee, msg)),
Signature: p.Sign(auth.StdSignBytes(chainID, accnums, seq, fee, msg, "")),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this ideally just be checking on an empty memo? I think we may want to include some non-empty message, just to check that memo inclusion doesn't break stuff.

Copy link
Contributor Author

@cwgoes cwgoes Jun 20, 2018

Choose a reason for hiding this comment

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

Changed to include a non-empty message.

@cwgoes cwgoes dismissed ValarDragon’s stale review June 20, 2018 19:23

Addressed (pending final review).

Copy link
Contributor

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

utACK

@cwgoes cwgoes merged commit 918e217 into develop Jun 20, 2018
@cwgoes cwgoes deleted the cwgoes/alt-bytes-to-memo branch June 20, 2018 19:27
@cwgoes cwgoes mentioned this pull request Jun 20, 2018
6 tasks
@ValarDragon ValarDragon mentioned this pull request Jun 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants