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

Changes for Economic Protocol scenario 3 - "contract pays for gas" #352

Merged
merged 5 commits into from
May 8, 2024

Conversation

miloszm
Copy link
Contributor

@miloszm miloszm commented Apr 10, 2024

Changes for Economic Protocol scenario 3 - "contract pays for gas" and "contract earns fee" parts

Implements issues #350 and #353

@miloszm miloszm changed the title Changes for Economic Protocol scenario 3 Changes for Economic Protocol scenario 3 - "contract pays for gas" Apr 10, 2024
@miloszm miloszm marked this pull request as ready for review April 22, 2024 13:20
Copy link
Member

@ureeves ureeves left a comment

Choose a reason for hiding this comment

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

I've got some things I''d like to see some work on, and also some broader remarks.

My main concern this mechanism's implementation is that the contract must remember to always set the value of the economic buffer at the end of a function it exports. This because otherwise the previous value will be used. This is and of itself is not a problem, but it does become an issue when we don't make this clear/ergonomic to the user.

We can choose one of two options afaics:

  • Have the host set the "default" value every time the contract is called, erasing the need for the contract to do it.
  • Modify the wrap_call functions to make this ergonomic to the user.

There's other things interspersed below, but one thing I'd like to mention is an aesthetic concern - what do we name what is now called "buffer b"? Certainly we don't want to just keep that name. Maybe "economic buffer"?

piecrust-uplink/src/abi/state.rs Outdated Show resolved Hide resolved
piecrust-uplink/src/abi/state.rs Outdated Show resolved Hide resolved
piecrust-uplink/src/abi/state.rs Outdated Show resolved Hide resolved
piecrust-uplink/src/abi/state.rs Outdated Show resolved Hide resolved
piecrust/src/imports.rs Outdated Show resolved Hide resolved
piecrust/src/session.rs Outdated Show resolved Hide resolved
@miloszm
Copy link
Contributor Author

miloszm commented Apr 22, 2024

Re: My main concern this mechanism's implementation is that the contract must remember to always set the value of the economic buffer at the end of a function it exports. This because otherwise the previous value will be used. This is and of itself is not a problem, but it does become an issue when we don't make this clear/ergonomic to the user.

Problem of previous value is taken care of, but only for the top call (in call_inner, see session.rs line 765). I should fix it for ICC calls, good catch.

As for other remarks, they are good remarks IMO and I will follow on most of them. Not sure about CallReceipt remark yet, will need to analyse it more and provide feedback after that.

@miloszm
Copy link
Contributor Author

miloszm commented Apr 23, 2024

I addressed all Ed's review suggestions except for 2: (please also see the comments above)

  1. left set_allowance and set_charge as separate methods
  2. left setting spent in call_inner
    With 1) I am open to suggestions, while with 2) I evaluated the suggestion and concluded that it is a good suggestion - we need to pass spent along with allowance and charge downstream via CallReceipt and let block generator have access to the original spent - otherwise block generator could make wrong decisions and pack too many "free" transactions into one block. Block. generator does not care who paid for the transaction, but it does care about actual spent and a price, thus we need to pass this information to it unchanged. I will enrich the CallReceipt with data about allowance and charge given.

@miloszm miloszm requested a review from ureeves April 23, 2024 15:28
Copy link
Member

@ureeves ureeves left a comment

Choose a reason for hiding this comment

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

I think we should introduce an easy way for the contract to set the economic mode after each exposed function. My proposal would be to have it be done using the wrap_call helpers that we already have.

This is because the economic buffer is copied from any contract called, and then passed along. To make sure that no contract makes a decision on how to spend the funds for another, I think this should definitely be provided.

piecrust-uplink/src/abi/state.rs Outdated Show resolved Hide resolved
piecrust-uplink/src/lib.rs Outdated Show resolved Hide resolved
piecrust-uplink/src/types.rs Outdated Show resolved Hide resolved
@miloszm miloszm requested a review from ureeves April 24, 2024 17:11
piecrust/src/imports.rs Outdated Show resolved Hide resolved
piecrust-uplink/src/types.rs Outdated Show resolved Hide resolved
piecrust-uplink/src/abi/state.rs Show resolved Hide resolved
@miloszm miloszm requested a review from ureeves May 7, 2024 10:17
Copy link
Member

@ureeves ureeves left a comment

Choose a reason for hiding this comment

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

LGTM!

@miloszm miloszm merged commit 3d8704e into main May 8, 2024
6 checks passed
@miloszm miloszm deleted the issue-350-ep-3 branch May 8, 2024 13:24
@miloszm miloszm restored the issue-350-ep-3 branch November 21, 2024 10:06
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