-
Notifications
You must be signed in to change notification settings - Fork 145
actor upgrade error refactor #1910
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,9 +201,6 @@ where | |
events_root, | ||
} | ||
} | ||
|
||
Err(ExecutionError::Abort(e)) => return Err(anyhow!("actor aborted: {}", e)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
Err(ExecutionError::OutOfGas) => Receipt { | ||
exit_code: ExitCode::SYS_OUT_OF_GAS, | ||
return_data: Default::default(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ use std::convert::{TryFrom, TryInto}; | |
use std::panic::{self, UnwindSafe}; | ||
use std::path::PathBuf; | ||
|
||
use crate::syscalls::error::Abort; | ||
use anyhow::{anyhow, Context as _}; | ||
use cid::Cid; | ||
use filecoin_proofs_api::{self as proofs, ProverId, PublicReplicaInfo, SectorId}; | ||
|
@@ -874,7 +873,11 @@ where | |
.create_actor(code_id, actor_id, delegated_address) | ||
} | ||
|
||
fn upgrade_actor<K: Kernel>(&mut self, new_code_cid: Cid, params_id: BlockId) -> Result<u32> { | ||
fn upgrade_actor<K: Kernel>( | ||
&mut self, | ||
new_code_cid: Cid, | ||
params_id: BlockId, | ||
) -> Result<SendResult> { | ||
if self.read_only { | ||
return Err( | ||
syscall_error!(ReadOnly, "upgrade_actor cannot be called while read-only").into(), | ||
|
@@ -938,27 +941,18 @@ where | |
}); | ||
|
||
match result { | ||
Ok(InvocationResult { | ||
exit_code: ExitCode::OK, | ||
value, | ||
}) => { | ||
let block_id = match value { | ||
None => NO_DATA_BLOCK_ID, | ||
Some(block) => self.blocks.put_reachable(block).unwrap_or_else(|_| { | ||
log::error!("failed to write to kernel block registry"); | ||
NO_DATA_BLOCK_ID | ||
}), | ||
Ok(InvocationResult { exit_code, value }) => { | ||
let (block_stat, block_id) = match value { | ||
None => (BlockStat { codec: 0, size: 0 }, NO_DATA_BLOCK_ID), | ||
// TODO: Check error cases. At a minimum, we could run out of gas here! | ||
Some(block) => (block.stat(), self.blocks.put_reachable(block)?), | ||
Comment on lines
+947
to
+948
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, I don't see There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 But I'd avoid casting the error if possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (and remove my todo) |
||
}; | ||
Err(ExecutionError::Abort(Abort::Exit( | ||
ExitCode::OK, | ||
"actor upgraded".to_string(), | ||
Ok(SendResult { | ||
block_id, | ||
))) | ||
block_stat, | ||
exit_code, | ||
}) | ||
} | ||
Ok(InvocationResult { | ||
exit_code, | ||
value: _, | ||
}) => Ok(exit_code.value()), | ||
Err(err) => Err(err), | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,10 @@ | |
use anyhow::{anyhow, Context as _}; | ||
use fvm_shared::{sys, ActorID}; | ||
|
||
use super::bind::ControlFlow; | ||
use super::error::Abort; | ||
use super::Context; | ||
use crate::kernel::{ClassifyResult, Result}; | ||
use crate::kernel::{ClassifyResult, Result, SendResult}; | ||
use crate::{syscall_error, Kernel}; | ||
|
||
pub fn resolve_address( | ||
|
@@ -113,10 +115,31 @@ pub fn upgrade_actor<K: Kernel>( | |
context: Context<'_, K>, | ||
new_code_cid_off: u32, | ||
params_id: u32, | ||
) -> Result<u32> { | ||
let cid = context.memory.read_cid(new_code_cid_off)?; | ||
|
||
context.kernel.upgrade_actor::<K>(cid, params_id) | ||
) -> ControlFlow<sys::out::send::Send> { | ||
let cid = match context.memory.read_cid(new_code_cid_off) { | ||
Ok(cid) => cid, | ||
Err(err) => return err.into(), | ||
}; | ||
|
||
match context.kernel.upgrade_actor::<K>(cid, params_id) { | ||
fridrik01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Ok(SendResult { | ||
block_id, | ||
block_stat, | ||
exit_code, | ||
}) => { | ||
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, | ||
}) | ||
} | ||
Comment on lines
+130
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
Err(err) => err.into(), | ||
} | ||
} | ||
|
||
pub fn get_builtin_actor_type( | ||
|
Uh oh!
There was an error while loading. Please reload this page.