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

Readonly Smart Contract Calls #1977

Closed
gterzian opened this issue Dec 10, 2021 Discussed in #1970 · 6 comments · Fixed by #2040 or #2052
Closed

Readonly Smart Contract Calls #1977

gterzian opened this issue Dec 10, 2021 Discussed in #1970 · 6 comments · Fixed by #2040 or #2052
Assignees
Labels
smart-contracts Issue related to the smart contract world
Milestone

Comments

@gterzian
Copy link
Contributor

gterzian commented Dec 10, 2021

Discussed in #1970

Originally posted by damip December 9, 2021

Rationale

When using Massa in a Web3 context for example, one should be able to perform read-only Smart Contract calls.

See: https://ethereum.stackexchange.com/questions/765/what-is-the-difference-between-a-transaction-and-a-call/770

Massa implementation

API

Add a "sc_readonly_call" API endpoint

Parameters:

  • max_gas: u64 // max gas allowed for the readonly run
  • bytecode: Vec<u8> // bytecode to execute

Return value:

  • executed_at: Slot // slot at which the execution happened
  • result:
    • (optional) error: Error
    • (optional) return_value : Vec // return value of the bytecode's main() function (TODO this needs to be discussed)
    • (optional) output_events: Vec<SCOutputEvent> // output events generated during execution

Operation

  • when the sc_readonly_call is called, the bytecode's main() function will be called with the following execution context:

    • the execution will be done from the point of view of the current slot (even if there is currently no block there)
    • empty initial call stack (anonymous call)
  • during the call, everything is allowed as with usual SC calls, except that any syscall attempting to WRITE anything to the SCE ledger will fail. Async message sending also fails when called from within a readonly context.

@gterzian gterzian added the smart-contracts Issue related to the smart contract world label Dec 10, 2021
@damip damip added this to the TEST.6.0 milestone Dec 13, 2021
@damip damip moved this to In Progress in Smart Contracts Dec 13, 2021
@damip damip moved this from In Progress to Todo - for that week in Smart Contracts Dec 20, 2021
@damip
Copy link
Member

damip commented Dec 23, 2021

@gterzian any news or pain points on this ?

@gterzian
Copy link
Contributor Author

any news or pain points on this ?

Still in progress, is going to be for next week.

the execution will be done from the point of view of the current slot

@damip What do you mean with the current slot here?

@gterzian
Copy link
Contributor Author

gterzian commented Dec 24, 2021

Also, would it be good enough to run the code, and then undo the changes, like is currently done when there is an error? See 628e4fb

@damip
Copy link
Member

damip commented Dec 24, 2021

@damip What do you mean with the current slot here?

the current slot is the latest slot at the current timestamp (see #1982 )

@damip
Copy link
Member

damip commented Dec 24, 2021

Also, would it be good enough to run the code, and then undo the changes, like is currently done when there is an error? See 628e4fb

Hmmm maybe we can do that indeed...

@adrien-zinger @AureliaDolo @yvan-sraka any opinions ?

@adrien-zinger
Copy link
Contributor

adrien-zinger commented Dec 24, 2021

Also, would it be good enough to run the code, and then undo the changes, like is currently done when there is an error? See 628e4fb

Hmmm maybe we can do that indeed...

@adrien-zinger @AureliaDolo @yvan-sraka any opinions ?

I totally agree with that!

@damip damip linked a pull request Dec 27, 2021 that will close this issue
bors bot added a commit that referenced this issue Jan 1, 2022
2052: Read only execution api r=damip a=gterzian

Adding the API part for read-only execution of code.

Close #1977

Co-authored-by: Your Name <you@example.com>
@damip damip closed this as completed Jan 1, 2022
Repository owner moved this from Todo - for that week to Done in Smart Contracts Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
smart-contracts Issue related to the smart contract world
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants