dusk-network / piecrust

General purpose virtual machine for running WASM smart contracts
Mozilla Public License 2.0
23 stars 15 forks source link

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

Closed miloszm closed 6 months ago

miloszm commented 7 months ago

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

Implements issues #350 and #353

miloszm commented 7 months ago

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 commented 7 months ago

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.