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: gas hook on ExecutionFinalResult #284

Merged
merged 27 commits into from Oct 5, 2023
Merged

Conversation

shariffdev
Copy link
Contributor

@shariffdev shariffdev commented Aug 1, 2023

Closes #29

This approach as suggested by @ChaoticTempest does not add state to the worker and a hook can be offered instead, the the on_transaction method takes a hook that can collect the gas burnt information.

A GasMeter type is added with updated test code on how this all comes together to meter the gas burnt on doing asynchronous calls.

This approach allows to aggregate total_gas_burnt from all transactions that the Worker sees while transactions are being called.

@shariffdev shariffdev marked this pull request as ready for review August 1, 2023 11:07
@shariffdev
Copy link
Contributor Author

@frol Since I can't invite reviewers currently, any comments from reviewers are welcome.

@frol frol mentioned this pull request Aug 11, 2023
Copy link
Collaborator

@frol frol left a comment

Choose a reason for hiding this comment

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

@shariffdev I don't think it is what was described in the issue, see my comment there: #29 (comment)

@shariffdev
Copy link
Contributor Author

Checking right now

@shariffdev I don't think it is what was described in the issue, see my comment there: #29 (comment)

@ChaoticTempest
Copy link
Member

From what I see, this is only hooking onto the current transaction. We want to have the callback be executed on all transactions since the creation of the GasMeter. Worker here should still store a list of hooks so that it can call back on all of them whenever it receives a transaction result from the network. Sorry if my previous wording there didn't make sense.

What I suggest is to have a very similar API to Rust's Instant so that when it's created via GasMeter::now(&worker), it doesn't need to know about previous calls similar to the Instant::now API for time.

@shariffdev
Copy link
Contributor Author

shariffdev commented Aug 15, 2023

Hi @ChaoticTempest can you check this

@shariffdev shariffdev requested a review from frol August 22, 2023 14:56
@frol
Copy link
Collaborator

frol commented Aug 30, 2023

@shariffdev Please, make the CI pass. I see there is a dependency issue, use the following workaround: https://github.com/near/near-sdk-rs/pull/1075/files#diff-748c9b7c0e525461124dec4c258406a92d81a9b610f7b47a79efe9a0cb52553c

@shariffdev
Copy link
Contributor Author

@frol The error is related to the clap requiring a newer rust version (1.70) I am looking into creating a new PR which we can update rustc to 1.70+, This issue seems to have been resolved so we can update to the latest 1.70+

@shariffdev
Copy link
Contributor Author

This PR should take care of the dependency issue as we are using a newer stable toolchain

workspaces/src/worker/mod.rs Outdated Show resolved Hide resolved
workspaces/src/types/gas_meter.rs Show resolved Hide resolved
workspaces/src/types/gas_meter.rs Outdated Show resolved Hide resolved
workspaces/src/types/gas_meter.rs Outdated Show resolved Hide resolved
workspaces/src/worker/mod.rs Outdated Show resolved Hide resolved
workspaces/src/types/gas_meter.rs Outdated Show resolved Hide resolved
Copy link
Member

@ChaoticTempest ChaoticTempest left a comment

Choose a reason for hiding this comment

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

Aside from the error unwrappings, this one is good to go

workspaces/src/operations.rs Outdated Show resolved Hide resolved
workspaces/src/types/gas_meter.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@frol frol left a comment

Choose a reason for hiding this comment

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

@shariffdev Thanks for working on it and adding the documentation with an actionable example!

@frol frol merged commit 17d8f8d into near:main Oct 5, 2023
6 checks passed
@frol frol mentioned this pull request Oct 5, 2023
@frol frol mentioned this pull request Oct 22, 2023
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.

Add API for measuring gas
3 participants