ref-fvm
ref-fvm copied to clipboard
Fix sdk assertion macros
While working on the High level Rust SDK I found out that low level macro were not working as expected. I started to fix their behavior but also found a problem in how things were handled.
At the time when we developed the macros, it seemed relevant to @raulk and myself to use catch_unwind
to prevent a panic on an assert. But it seems that catch_unwind doesn't work in in WASM as it's behavior is panic=abort (https://github.com/rust-lang/rust/issues/58874) which will throw an error before we have time to call the abort
syscall.
I do not really see an easy way of solving this, opening a PR to share it with the team and (maybe) get some start of a solution.
Codecov Report
Merging #660 (402af40) into master (e9657a7) will decrease coverage by
0.01%
. The diff coverage isn/a
.
@@ Coverage Diff @@
## master #660 +/- ##
==========================================
- Coverage 51.06% 51.05% -0.02%
==========================================
Files 120 120
Lines 9694 9694
==========================================
- Hits 4950 4949 -1
- Misses 4744 4745 +1
Impacted Files | Coverage Δ | |
---|---|---|
ipld/amt/src/node.rs | 86.56% <0.00%> (-0.26%) |
:arrow_down: |
We solved this in the builtin actors with https://github.com/filecoin-project/builtin-actors/blob/344ea72ed5b297bfb1291ee6fe8383cb6b587ea4/runtime/src/runtime/fvm.rs#L552-L554.
Basically:
- Set panic=unwind (on build).
- Add a panic hook that aborts.
Is there any reason we need to assert than catch it? Can't we just re-implement assert and abort directly? The implementation should be pretty simple.
Alternatively, just drop the wrapping entirely. I.e.:
- Let the user call the builtin
assert
. - Register a panic hook in
invoke
to turn all panics into aborts.
Thanks for the tips @Stebalien ! Used them to fix it 👍
Conflicts developed :-(
I think there's some confusion here. We shouldn't be setting a panic hook than immediately calling assert.
- We should, ideally, not be overriding
assert
at all, instead setting a panic hook on invoke. - Or... we could override the
assert
macro to immediately callvm::abort
.
But the former would be better.
However, setting a hook a hook, then immediately asserting, is a very round-about way of going about this. Does that make sense?
Basically: Set panic=unwind (on build). Add a panic hook that aborts.
Does that mean we carry unwind information within actor bundles?
Does that mean we carry unwind information within actor bundles?
Not the deployed ones, no. However, asserts will still give you nice errors even without actual backtraces.
See #896.