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

Allow specifying host query price #362

Merged
merged 2 commits into from
May 21, 2024
Merged

Allow specifying host query price #362

merged 2 commits into from
May 21, 2024

Conversation

ureeves
Copy link
Member

@ureeves ureeves commented May 16, 2024

Host queries are modified to be able to specify their price. The calling of a such a query proceeds in two stages - deserializing and pricing, and then execution. In between the two stages, piecrust is able to make the choice of whether to continue with execution or not, based on the gas remaining for the execution.

To achieve this, the HostQuery trait is modified by adding two functions - deserialize_and_price and execute - and by removing the Fn(&mut [u8], u32) -> u32 bound. This structure allows the implementer to price queries fairly, as well as prevent double deserialization by leveraging Box<dyn Any> to pass data between the two functions.

HostQuery remains implemented for all Fn(&mut [u8], u32) -> u32 that are also Send and Sync, so this is not a breaking change.

See-also: #359

Eduardo Leegwater Simões added 2 commits May 16, 2024 17:00
Host queries are modified to be able to specify their price. The calling
of a such a query proceeds in two stages - deserializing and pricing,
and then execution. In between the two stages, `piecrust` is able to
make the choice of whether to continue with execution or not, based on
the gas remaining for the execution.

To achieve this, the `HostQuery` trait is modified by adding two
functions - `deserialize_and_price` and `execute` - and by removing the
`Fn(&mut [u8], u32) -> u32` bound. This structure allows the implementer
to price queries fairly, as well as prevent double deserialization by
leveraging `Box<dyn Any>` to pass data between the two functions.

`HostQuery` remains implemented for all `Fn(&mut [u8], u32) -> u32` that
are also `Send` and `Sync`, so this is not a breaking change.

See-also: #359
Copy link
Member

@HDauven HDauven left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@fed-franz fed-franz left a comment

Choose a reason for hiding this comment

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

LGTM, but I'm not confident with the code, so I'll just "Comment" :)

@ureeves ureeves merged commit 67f96c8 into main May 21, 2024
6 checks passed
@ureeves ureeves deleted the host-fn-costs branch May 21, 2024 10:19
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.

3 participants