-
Notifications
You must be signed in to change notification settings - Fork 81
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
DO NOT MERGE: Prototype some potential error handling ways #192
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,9 @@ use num_derive::FromPrimitive; | |
use num_traits::FromPrimitive; | ||
|
||
use fil_actors_runtime::builtin::singletons::SYSTEM_ACTOR_ADDR; | ||
use fil_actors_runtime::cbor; | ||
use fil_actors_runtime::runtime::{ActorCode, Runtime}; | ||
use fil_actors_runtime::{actor_error, ActorError}; | ||
use fil_actors_runtime::{actor_error, ensure_args}; | ||
use fil_actors_runtime::{cbor, Abort}; | ||
|
||
pub use self::state::State; | ||
|
||
|
@@ -34,25 +34,23 @@ pub enum Method { | |
pub struct Actor; | ||
impl Actor { | ||
/// Constructor for Account actor | ||
pub fn constructor<BS, RT>(rt: &mut RT, address: Address) -> Result<(), ActorError> | ||
pub fn constructor<BS, RT>(rt: &mut RT, address: Address) -> Result<(), Abort> | ||
where | ||
BS: Blockstore, | ||
RT: Runtime<BS>, | ||
{ | ||
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?; | ||
match address.protocol() { | ||
Protocol::Secp256k1 | Protocol::BLS => {} | ||
protocol => { | ||
return Err(actor_error!(ErrIllegalArgument; | ||
"address must use BLS or SECP protocol, got {}", protocol)); | ||
} | ||
} | ||
rt.validate_immediate_caller_is([&*SYSTEM_ACTOR_ADDR])?; | ||
ensure_args!( | ||
matches!(address.protocol(), Protocol::Secp256k1 | Protocol::BLS), | ||
"address must use BLS or SECP protocol, got {}", | ||
address.protocol(), | ||
); | ||
rt.create(&State { address })?; | ||
Ok(()) | ||
} | ||
|
||
// Fetches the pubkey-type address from this actor. | ||
pub fn pubkey_address<BS, RT>(rt: &mut RT) -> Result<Address, ActorError> | ||
pub fn pubkey_address<BS, RT>(rt: &mut RT) -> Result<Address, Abort> | ||
where | ||
BS: Blockstore, | ||
RT: Runtime<BS>, | ||
|
@@ -68,7 +66,7 @@ impl ActorCode for Actor { | |
rt: &mut RT, | ||
method: MethodNum, | ||
params: &RawBytes, | ||
) -> Result<RawBytes, ActorError> | ||
) -> Result<RawBytes, Abort> | ||
where | ||
BS: Blockstore, | ||
RT: Runtime<BS>, | ||
|
@@ -82,7 +80,7 @@ impl ActorCode for Actor { | |
let addr = Self::pubkey_address(rt)?; | ||
Ok(RawBytes::serialize(addr)?) | ||
} | ||
None => Err(actor_error!(SysErrInvalidMethod; "Invalid method")), | ||
None => Err(actor_error!(SysErrInvalidMethod; "Invalid method").into()), | ||
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. I get this is just prototyping, but I want only one of the 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. They definitely should survive both in this construction. The conversion into an 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. I don't think ActorError should be used for recoverable errors. I don't think there are use cases for that. I would say recoverable errors should not specify an abort code. 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. where would that mapping to codes live then? |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that
Abort
can't happen, why not just return()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I wanted to potential for actually returning an error in debug scenarios. My idea was that we could have sth like a
debug
feature, whereAbort
would collect data and actually be a returned value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One alternative design I had was
to make it even more visual that this is a special kind of exit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that's reasonable. Although, IMO, we get better information if we abort immediately (and ask wasmtime for a backtrace). See https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_backtrace_details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some scope for divergent behaviour between the two cases here. I guess that this Abort is intended to always be immediately propagated with
?
.Up at this high level of the actor entry points, I would probably lean towards Steb's initial take that actually aborting is better. We would want a way to shim that call for testing, though, wrapping out the underlying static call so we can use a mock/fake VM instead.