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

Add Tx Middleware for Tips #9912

Closed
1 task done
amaury1093 opened this issue Aug 11, 2021 · 1 comment · Fixed by #10208
Closed
1 task done

Add Tx Middleware for Tips #9912

amaury1093 opened this issue Aug 11, 2021 · 1 comment · Fixed by #10208
Assignees

Comments

@amaury1093
Copy link
Contributor

amaury1093 commented Aug 11, 2021

Part of the Tx working group.

Summary

The Tips proto definitions have been merged in #9406. Once we switch to the middleware design (#9585), we should add a new TxMiddleware which consumes tips.

Problem definition

The use case is the following (as an example): user1 has Regen tokens, and wants to execute a Msg on the hub (e.g. MsgVote on a proposal that would impact regen) but does not have Atoms. Tips try to solve this issue by allowing user1 to tip someone (user2) on the Hub using regen tokens. Basically user1 sends regen tokens to user2 to cover the Tx fees on the hub.

user1 == tipper
user2 == fee payer

We assume that user1's regen tokens for the Tip are already on the Hub's bank module, via IBC.

To do so, user1 builds a Tx where the TxBody contains MsgVote, adds a Tip (and populates relevant fields like accSeq, pk...), and signs it using SIGN_MODE_DIRECT_AUX. But user1 does NOT broadcast the tx. Instead, user1 sends the tx_bytes to user2. Now user2 builds the following Tx:

  • body_bytes == user1's tx's body_bytes
  • auth_info with Tip and Fee both set:
    • Tip is the tip chosen (and signed over) by user1
    • Fee is the fee user2 chooses to pay for the Tx on the hub
    • two signer_infos: the 1st one is the tipper's SIGN_MODE_AUX info, the second one is user2's info (can be DIRECT or LEGACY_AMINO_JSON).
  • signatures: 2 sigs, corresponding to the two signer_infos.

user2 then sends this tx on the Hub, and if it passes, then the Tips middleware will automatically transfer the regen tokens (on the hub) from user2 to user1.

Below are the requirements to make tips work. Given an AuthInfo with both Fee and Tip set, we should check:

  • the tipper signs over Tip
  • the feePayer signs over fees
  • make the Tip transfer only if there was enough gas during the tx execution phase

Depends on:

Proposal

Create a TipsTxMiddleware in x/auth/middleware/tips.go with the following features:

type tipsTxHandler struct {
  bankKeeper bank.Keeper
}
  • In the pre-hook:
    • Make sure the tipper signs over the Tip. In practice, it means that we need to check the tipper's signMode must be SIGN_MODE_AUX. Note: the feePayer is always the last signer_info
    • Make sure the feePayer signs over the Fee. In practice, it means that we need to check the feePayer's signMode must be either SIGN_MODE_DIRECT or SIGN_MODE_AMINO.
  • run the next middleware
  • In the post-hook
    • do a bank transfer of the Tip coins from tipper to feePayer.
@amaury1093
Copy link
Contributor Author

I added some acceptance tests in #9997. When working on this issue, I believe it would be good to have some of those tests as CLI integration tests too.

@mergify mergify bot closed this as completed in #10208 Nov 16, 2021
mergify bot pushed a commit that referenced this issue Nov 16, 2021
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

## Description

R4R

Closes: #9912 

This PR introduces 1 new middleware:
- `TipsMiddleware`: transfer tip from tipper to feePayer when relevant.

It also makes sure in the DIRECT_AUX sign mode handler that the fee payer cannot use that sign mode.

Depends on:
- [x]  #10028 
- [x] #10268 
- [x] #10322 
- [x] #10346 

<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->

---

### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)
blewater pushed a commit to e-money/cosmos-sdk that referenced this issue Dec 8, 2021
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

## Description

R4R

Closes: cosmos#9912 

This PR introduces 1 new middleware:
- `TipsMiddleware`: transfer tip from tipper to feePayer when relevant.

It also makes sure in the DIRECT_AUX sign mode handler that the fee payer cannot use that sign mode.

Depends on:
- [x]  cosmos#10028 
- [x] cosmos#10268 
- [x] cosmos#10322 
- [x] cosmos#10346 

<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->

---

### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)
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 a pull request may close this issue.

1 participant