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

actor upgrade error refactor #1910

Merged
merged 1 commit into from
Oct 5, 2023
Merged

Conversation

Stebalien
Copy link
Member

Add a general-purpose ControlFlow syscall return value and use it. This way we don't need to add an ::Abort case to the ExecutionError itself.

Add a general-purpose ControlFlow syscall return value and use it.
@codecov-commenter
Copy link

Codecov Report

Merging #1910 (2f9944d) into actor-upgrades (22d00c5) will decrease coverage by 47.45%.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##           actor-upgrades    #1910       +/-   ##
===================================================
- Coverage           75.91%   28.46%   -47.45%     
===================================================
  Files                 153      114       -39     
  Lines               15220    10581     -4639     
===================================================
- Hits                11554     3012     -8542     
- Misses               3666     7569     +3903     
Files Coverage Δ
fvm/src/executor/default.rs 5.48% <ø> (-71.08%) ⬇️
fvm/src/syscalls/context.rs 60.37% <ø> (-36.80%) ⬇️
fvm/src/syscalls/error.rs 0.00% <ø> (-47.23%) ⬇️
shared/src/error/mod.rs 0.00% <ø> (-48.58%) ⬇️
fvm/src/kernel/error.rs 55.81% <0.00%> (-11.58%) ⬇️
fvm/src/call_manager/mod.rs 12.50% <0.00%> (-75.00%) ⬇️
fvm/src/syscalls/vm.rs 0.00% <0.00%> (-58.34%) ⬇️
fvm/src/call_manager/default.rs 0.00% <0.00%> (-89.84%) ⬇️
fvm/src/kernel/default.rs 14.03% <0.00%> (-47.47%) ⬇️
fvm/src/syscalls/bind.rs 0.00% <0.00%> (-97.50%) ⬇️
... and 1 more

... and 115 files with indirect coverage changes

@@ -201,9 +201,6 @@ where
events_root,
}
}

Err(ExecutionError::Abort(e)) => return Err(anyhow!("actor aborted: {}", e)),
Copy link
Member Author

Choose a reason for hiding this comment

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

This was one of the cases I was worried about. Aborting with a fatal error here isn't really correct.

/// The helper trait used by `BindSyscall` to convert kernel results with execution errors into
/// results that can be handled by wasmtime. See the documentation on `BindSyscall` for details.
#[doc(hidden)]
pub trait IntoSyscallResult: Sized {
pub trait IntoControlFlow: Sized {
Copy link
Member Author

Choose a reason for hiding this comment

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

I wish we could just use Into<ControlFlow<T>> instead of having to define a new trait but... the same type could implement Into<ControlFlow<T>> and IntoControlFlow<U>>. So we need a trait with an associated type (i.e., like this one).

Copy link
Contributor

@fridrik01 fridrik01 left a comment

Choose a reason for hiding this comment

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

Looks great!

Comment on lines +130 to +139
if exit_code.is_success() {
ControlFlow::Abort(Abort::Exit(exit_code, String::new(), block_id))
} else {
ControlFlow::Return(sys::out::send::Send {
exit_code: exit_code.value(),
return_id: block_id,
return_codec: block_stat.codec,
return_size: block_stat.size,
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

plus having it here, especially with the explicit naming makes it very easy to read and maintain

Comment on lines -77 to -84
fn into(self) -> Result<Result<Self::Value, SyscallError>, Abort> {
fn into_control_flow(self) -> ControlFlow<Self::Value> {
match self {
Ok(value) => Ok(Ok(value)),
Ok(value) => ControlFlow::Return(value),
Err(e) => match e {
ExecutionError::Syscall(err) => Ok(Err(err)),
ExecutionError::OutOfGas => Err(Abort::OutOfGas),
ExecutionError::Fatal(err) => Err(Abort::Fatal(err)),
ExecutionError::Abort(e) => Err(e),
Copy link
Contributor

Choose a reason for hiding this comment

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

+1!

@fridrik01 fridrik01 merged commit e8ddd7d into actor-upgrades Oct 5, 2023
@fridrik01 fridrik01 deleted the steb/error-refactor branch October 5, 2023 11:24
Comment on lines +947 to +948
// TODO: Check error cases. At a minimum, we could run out of gas here!
Some(block) => (block.stat(), self.blocks.put_reachable(block)?),
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, I don't see put_reachable ever checking if we run out of gas

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm. You're right... It looks like the only failure case is the LimitExceeded case which... likely shouldn't fail.

But I'd avoid casting the error if possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

(and remove my todo)

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.

3 participants