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(gstd): Introduce critical hook #3503

Merged
merged 41 commits into from
Jan 10, 2024
Merged

feat(gstd): Introduce critical hook #3503

merged 41 commits into from
Jan 10, 2024

Conversation

ark0f
Copy link
Member

@ark0f ark0f commented Nov 18, 2023

Release notes:
Introduce critical hook API. Similar to std::panic::set_hook but sets on per-message basis and takes into account specific program halts like gas outage, memory overflow, backend error and so on

@ark0f ark0f added A0-pleasereview PR is ready to be reviewed by the team D3-gstd Gear Standard Library labels Nov 18, 2023
@ark0f ark0f force-pushed the al/critical-section branch from 4dd2dc2 to af4f5b1 Compare November 18, 2023 19:18
@DennisInSky
Copy link
Member

I am a bit confused by the behaviour of the HandleAction::Panic and the HandleAction::WaitAndPanic - in both cases we create a section with no the execute method being called, but in the second case it gets executed anyway. I can imagine this is a result of having the wait op before the panic, but it is absolutely not intuitive when you read the code w/o impl behind it

@DennisInSky
Copy link
Member

I am a bit confused by the behaviour of the HandleAction::Panic and the HandleAction::WaitAndPanic - in both cases we create a section with no the execute method being called, but in the second case it gets executed anyway. I can imagine this is a result of having the wait op before the panic, but it is absolutely not intuitive when you read the code w/o impl behind it

To me it would be more comprehended if I had an option to register my compensation logic in relation to a future returned by some async call. This would clearly say that this functionality is about executing compensation with regards to this async/await. It doesn't seem the implemented functionality is relevant to any other cases.

@ark0f
Copy link
Member Author

ark0f commented Nov 20, 2023

but it is absolutely not intuitive when you read the code w/o impl behind it

What about module docs?

@DennisInSky
Copy link
Member

but it is absolutely not intuitive when you read the code w/o impl behind it

What about module docs?

This is not quite about docs - I read some code which uses some libraries and from reading it, it is vague what happens and how it works

@shamilsan shamilsan added the B1-releasenotes The feature deserves to be added to the Release Notes label Nov 20, 2023
@NikVolf
Copy link
Member

NikVolf commented Nov 26, 2023

User-facing API should be per-call

i.e. critical section is created, fired, and disposed once corresponding call handling is out of scope

gstd/src/critical.rs Outdated Show resolved Hide resolved
gstd/src/critical.rs Outdated Show resolved Hide resolved
examples/async-critical/src/wasm.rs Outdated Show resolved Hide resolved
pallets/gear/src/tests.rs Show resolved Hide resolved
pallets/gear/src/tests.rs Outdated Show resolved Hide resolved
@breathx
Copy link
Member

breathx commented Dec 2, 2023

Anything except comments above LGTM

@breathx
Copy link
Member

breathx commented Dec 11, 2023

@ark0f kind reminder to finish this awesome work

@breathx breathx added the A3-gotissues PR occurred to have issues after the review label Dec 11, 2023
@ark0f ark0f requested a review from breathx December 11, 2023 15:27
@ark0f ark0f removed the A3-gotissues PR occurred to have issues after the review label Dec 11, 2023
@NikVolf
Copy link
Member

NikVolf commented Dec 26, 2023

why is it stalling? @DennisInSky @breathx ?

Copy link
Member

@DennisInSky DennisInSky left a comment

Choose a reason for hiding this comment

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

You know the difficulties arose during taking this design decision better, but I am still not quite happy with the solution as it still doesn't hihjlight that functionality is applicable to async code executed after await completion only. Probably, at least renaming the set_hook method into something like set_hook_for_async or moving it into the async_runtime module would give some hint to users about the context of this method.
I would also showcase that

set_hook(...);
panic!(...);

doesn't cause the hook to get executed. Whereas

some_async(...).await;
take_hook();
panic!(...);

will do

examples/async-critical/src/wasm.rs Outdated Show resolved Hide resolved
@breathx breathx added A2-mergeoncegreen PR is ready to merge after CI passes and removed A0-pleasereview PR is ready to be reviewed by the team labels Jan 8, 2024
@ark0f
Copy link
Member Author

ark0f commented Jan 10, 2024

Probably, at least renaming the set_hook method into something like set_hook_for_async or moving it into the async_runtime module would give some hint to users about the context of this method.

This would be a bit incorrect because it's not about async actually. It's about program state change (e.g. gr_wait for now which can be in sync code)

@ark0f ark0f merged commit ab427a1 into master Jan 10, 2024
11 checks passed
@ark0f ark0f deleted the al/critical-section branch January 10, 2024 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A2-mergeoncegreen PR is ready to merge after CI passes B1-releasenotes The feature deserves to be added to the Release Notes D3-gstd Gear Standard Library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants