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(gnoland): Define and implement SponsorTransaction concept #2630

Open
wants to merge 71 commits into
base: master
Choose a base branch
from

Conversation

linhpn99
Copy link
Contributor

@linhpn99 linhpn99 commented Jul 25, 2024

Blocked by #2209

This PR performs the following tasks:

  1. Refactor the code structure in the gnoclient directory : remove redundant code, and write reusable functions
  2. Update the logic in the anteHandler to allow the creation of a non-existent on-chain account if it is processed in a valid sponsor transaction (I need to review this part)
  3. Define a new concept of sponsor transaction in gnoclient: it is a type of transaction signed twice, first by the person who wants to perform the transaction, and second by the person sponsoring the gas for this transaction. A transaction is considered a sponsor transaction when it contains a vm.MsgNoop as the first message in the list of messages
  4. Similarly, support the sponsor transaction feature in gnokey (I am not sure if this is necessary)
  5. Implement necessary test cases for the newly added/updated code mentioned above
  6. A demo with gnokey will be uploaded in the comments section below
  7. A full-flow demo with UI describing the process of a user performing a gas-sponsored transaction

From Proposal #2152 :

  • Before integrating this pull request (PR) into the main codebase, thorough testing and evaluation are crucial. Once verified, we can explore its integration into an external decentralized application (sponsor service) to cover gas fees for user transactions

  • Instead of users directly interacting with the blockchain (like sending tokens or calling specific Realm functions), they will engage with a sponsor service. Users will sign and send requests to the sponsor service , which will handle all necessary checks for their on-chain address. If everything checks out, the sponsor service will countersign the transaction, and cover the gas fees

  • Updates to the vm handler module: A NoopMsg has been defined in this PR to skip gas consumption calculation for messages bearing the dApp's signature. These modules will only process messages (e.g., Run, Call, AddPkg, Send) with user-provided arguments, tagging the caller as their on-chain address

  • At the conclusion of the process, users can filter events to track the outcomes effectively

  • Now we are finalizing the sponsor service implementation for the full-flow design described below

SponsorTransaction_Flow (3)

Related Pull Requests:

  1. feat(examples): Implement sponsors (p+r) for sponsor service management #2411: This pull request introduces a set (p+r) to manage onchain sponsor services
  2. feat(gnoland): Define NoopMsg to facilitate the creation of sponsor transaction (gasless transaction) #2209: This pull request introduces a sponsor management concept

I greatly appreciate everyone's feedback to improve this feature.

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@linhpn99
Copy link
Contributor Author

linhpn99 commented Jul 25, 2024

I created a demo using gnokey to show how this feature works, assuming that the user (who wants to perform an on-chain action without paying gas fees) and sponsor (who covers all the gas fees) are on the same machine and use the same keybase. The steps and outputs are described below :

Case where the user account already exists on-chain

  1. Both the user and the sponsor have accounts that exist on-chain
  2. The user creates a transaction containing a no_op message (contains sponsor's address)
  3. The user signs the created transaction
  4. The sponsor signs the transaction that the user has previously signed (in practice, this step requires a way to transmit the transaction from the user to the sponsor)
  5. The sponsor broadcasts the transaction to the chain

Screenshot from 2024-07-08 10-43-39

The result is that the user's balance remains unchanged, and all transaction fees are deducted from the sponsor's balance

Screenshot from 2024-07-08 10-44-14

Case where the user account does not yet exist on-chain

The steps are similar to the previous case (the difference being that the query results show that the user account does not yet exist on-chain)

Screenshot from 2024-07-08 10-46-51

The result is that the user account has been created on-chain with a balance of 0, and the public key is set to the public key that the user used to sign the initial transaction

Screenshot from 2024-07-08 10-47-02

Copy link

codecov bot commented Jul 25, 2024

Codecov Report

Attention: Patch coverage is 63.24786% with 86 lines in your changes missing coverage. Please review.

Project coverage is 61.04%. Comparing base (9897b66) to head (7588907).

Files with missing lines Patch % Lines
gno.land/pkg/integration/testing_integration.go 22.72% 16 Missing and 1 partial ⚠️
gno.land/pkg/keyscli/run.go 0.00% 13 Missing and 1 partial ⚠️
tm2/pkg/crypto/keys/client/send.go 0.00% 14 Missing ⚠️
tm2/pkg/crypto/keys/client/maketx.go 33.33% 12 Missing ⚠️
tm2/pkg/crypto/keys/client/sign.go 80.55% 5 Missing and 2 partials ⚠️
gno.land/pkg/keyscli/maketx.go 0.00% 6 Missing ⚠️
gno.land/pkg/sdk/vm/msgs.go 53.84% 6 Missing ⚠️
gno.land/pkg/keyscli/addpkg.go 85.71% 1 Missing and 1 partial ⚠️
gno.land/pkg/keyscli/call.go 85.71% 1 Missing and 1 partial ⚠️
gno.land/pkg/sdk/vm/handler.go 0.00% 2 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2630      +/-   ##
==========================================
+ Coverage   60.87%   61.04%   +0.17%     
==========================================
  Files         563      563              
  Lines       75193    75357     +164     
==========================================
+ Hits        45770    45999     +229     
+ Misses      26055    25988      -67     
- Partials     3368     3370       +2     
Flag Coverage Δ
contribs/gnodev 61.46% <ø> (ø)
contribs/gnofaucet 14.46% <ø> (-0.86%) ⬇️
gno.land 68.25% <66.20%> (+1.08%) ⬆️
gnovm 65.63% <ø> (ø)
misc/genstd 80.54% <ø> (ø)
misc/logos 20.23% <ø> (ø)
tm2 62.26% <58.42%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@linhpn99 linhpn99 requested review from a team, ajnavarro, mvertes and deelawn as code owners July 25, 2024 15:44
@github-actions github-actions bot added 🧾 package/realm Tag used for new Realms or Packages. 📦 🤖 gnovm Issues or PRs gnovm related labels Jul 25, 2024
@leohhhn
Copy link
Contributor

leohhhn commented Sep 11, 2024

#2333 (comment)

@linhpn99
Copy link
Contributor Author

linhpn99 commented Sep 17, 2024

@moul Do you still have any concerns about the changes to this feature? Examples of sponsoring for multiple messages are available at https://github.com/gnolang/gno/blob/24c486f133f5274d3c253c6fa2653a90c1ca3299/gno.land/pkg/gnoclient/integration_test.go

However, gnokey does not support creating multi-message transactions to demonstrate similar functionality

@Kouteki Kouteki added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Oct 3, 2024
@jefft0
Copy link
Contributor

jefft0 commented Oct 31, 2024

@linhpn99 Is this PR still being worked on?
cc @sunspirit99

@sunspirit99
Copy link
Contributor

@linhpn99 Is this PR still being worked on?

cc @sunspirit99

I'm no longer continuing with this, but I’m sure the others are still waiting for a review and ready to keep developing


// MsgNoop - executes nothing
type MsgNoop struct {
Caller crypto.Address `json:"caller" yaml:"caller"`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Caller crypto.Address `json:"caller" yaml:"caller"`

msg := vm.MsgRun{
Caller: caller,
Package: memPkg,
}

// if a sponsor onchain address is specified
if cfg.RootCfg.Sponsor != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Move this if after line 149, and just prepend noop to the existing tx and print.

Memo: cfg.RootCfg.Memo,
}

cmdio.Println(string(amino.MustMarshalJSON(tx)))
Copy link
Member

Choose a reason for hiding this comment

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

It should also be signed.

msg := vm.MsgRun{
Caller: caller,
Package: memPkg,
}

// if a sponsor onchain address is specified
if cfg.RootCfg.Sponsor != "" {
Copy link
Member

Choose a reason for hiding this comment

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

We don’t need to know the sponsor address, just that this will be a sponsored tx.

Copy link
Member

@moul moul left a comment

Choose a reason for hiding this comment

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

We should nt specify the sponsor or sponsoree addr. Instead:

  1. A user calls maketx —sponsorizable —sign {addpkg,run,call,whatever}, generating a signed json tx with a noop first message.
  2. A sponsor verifies that the messages are not impersonating it, and then calls sign —prepend-sig and broadcast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages. review/triage-pending PRs opened by external contributors that are waiting for the 1st review
Projects
Status: In Progress
Status: 👀 Watching
Status: In Review
Development

Successfully merging this pull request may close these issues.

6 participants