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

feat: gas hook on ExecutionFinalResult #284

merged 27 commits into from Oct 5, 2023

Conversation

ghost
Copy link

@ghost ghost 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.

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

ghost commented Aug 1, 2023

@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)

@ghost
Copy link
Author

ghost commented Aug 11, 2023

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.

@ghost
Copy link
Author

ghost commented Aug 15, 2023

Hi @ChaoticTempest can you check this

@ghost ghost 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

@ghost
Copy link
Author

ghost commented Aug 30, 2023

@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+

@ghost
Copy link
Author

ghost commented Aug 31, 2023

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
@ghost ghost requested a review from ChaoticTempest September 18, 2023 06:39
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
@ghost ghost requested a review from ChaoticTempest October 5, 2023 19:18
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
2 participants