Closed lostman closed 1 year ago
@lostman
develop
(but description says it's a follow up)@lostman What's the difference between this and #1293 ?
@deekerno's PR was a starting point. This PR adds a few things. From changelog:
FFI functions can access the kill switch indicator and exit early when the kill switch has been triggered. (added in this PR) FFI functions can exit early on error, including sqlx database operation errors. (added in this PR) Add WASM error codes (from @deekerno's PR) Get an error code from the call to the indexer's WASM module. (added in this PR)
The most significant difference is how the error codes are returned:
In @deekerno's PR, the result is u32
error code. As I explain in the description, in this PR, I follow the early_exit
example—the function signature, as declared in the FFI interface mentions no Result
type. wasmer
terminates the execution immediately if the host function returns an error this way (which is exactly what we want here).
This way, even get_object
, which returns u32
, can be terminated early:
It now returns Result<u32, WasmIndexerError>
. However, in the FFI interface, it is still -> *mut u8
.
@lostman
develop
? Trying to compare what we have now (prior to this PR) to what we will have after this is merged @ra0x3, agreed. I will add a special-case for the kill switch. That is, after all, the expected behavior.
I added a WasmIndexExecutor
test for exit codes. It is a bit crude but covers the basics.
Left some more feedback
- @lostman I also wouldn't rush this PR
- We do have a deadline, but this work should be able to make it in comfortably before that date, with plenty of time to spare
- This is an extremely sensitive PR, so let's not rush it
I'd rather merge this now (very soon) and have it battle-tested for a couple of weeks than merge it just before the deadline and have no time to resolve any issues that may arise.
I need this to finish #1150 and again, I'd rather test both for a couple of weeks before the deadline is upon us.
@ra0x3, @deekerno,
I added an early_exit
function and tried using it in handler_block_wasm
:
and some trybuild
tests failed to link, complaining about missing ff_early_exit
at the linking stage:
https://github.com/FuelLabs/fuel-indexer/actions/runs/6171631718/job/16750296869#step:13:106
All integration tests succeeded, and I could compile and deploy indexers.
Any idea what could be going on?
It would've been a nice use-case for this function.
Any idea what could be going on?
@lostman
@ra0x3, yes, it helps. Thanks!
Just pushed this: https://github.com/FuelLabs/fuel-indexer/pull/1337/commits/46507e8ef0082f6d0becdff4a51bbea7cfb9a2cf
And trybuild tests pass 😄 (locally; waiting on CI)
@lostman Is this mean to be re-reviewed? I do remember leaving a previous review, but I see I'm ping'd for review again. But I also see a lot of the feedback was not implemented (and as well no reason was provided as to why).
@ra0x3, yes, it is meant to be re-reviewed. I can't re-trigger the review request since it is already re-requested.
I implemented your feedback. What is missing?
@lostman The review comments are unresolved, and they aren't labeled as "outdated". For any review comments where you implement the feedback, be sure to resolve the conversation (so it doesn't clutter the review, and look as if it's unresolved). And for anything you didn't implement, just leave a responding comment as to why you chose to to implement the feedback.
Apologies. GitHub UI tricked me a little:
Completely missed these comments. 😂
@lostman CI failing
Description
UPDATE: in addition to adding error codes to host functions as described below, this PR adds another host function:
Using this function we can remove more
unwrap
orexpect
calls.Building on https://github.com/FuelLabs/fuel-indexer/pull/1293.
This PR follows the example in
wasmer
repository:https://github.com/wasmerio/wasmer/blob/master/examples/early_exit.rs#L60
Note that the return value is
Result<(), ExitCode>
while the function is imported in WASM ashttps://github.com/wasmerio/wasmer/blob/master/examples/early_exit.rs#L41
That is, as if it were
fn early_exit();
.This PR does the same for our FFI functions. For instance:
While their types—as declared to the WASM module which will use them—doesn't mention the
Result
value:https://github.com/FuelLabs/fuel-indexer/pull/1337/files#diff-447e55cb0fae7d02ac8fd8f7de5a521cbf60d3f2422b5166c39faeb9f995bea6R21-R29
The one difference between how things are handled in
early_exit
example versus this PR is getting the error code out:https://github.com/wasmerio/wasmer/blob/master/examples/early_exit.rs#L93
When I tried the same method:
I got no error out of it. However, the error was printed as
RuntimeError(User(EarlyExit))
, so the error was handled correctly. (User
indicates that a user-defined error triggered a WASM trap).So, I ended up handling the error this way:
https://github.com/FuelLabs/fuel-indexer/pull/1337/files#diff-fa722c66d2896c684e5a26aa2c56b7ec1734888609fbb64ecbc7dfd6a420c4ffR933
I am unsure why I couldn't
downcast
the error the same way as was shown in the example.Testing steps
Manual testing:
Expected output:
In particular, this line indicates that an early termination happened due to the kill switch:
Changelog
sqlx
database operation errors.