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

runtime: drop unused exit() #1162

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions runtime/src/runtime/fvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,6 @@ where
.context_code(ExitCode::USR_ASSERTION_FAILED, "failed to emit event")
}

fn exit(&self, code: u32, data: Option<IpldBlock>, msg: Option<&str>) -> ! {
fvm::vm::exit(code, data, msg)
}

fn read_only(&self) -> bool {
fvm::vm::read_only()
}
Expand Down
4 changes: 0 additions & 4 deletions runtime/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,6 @@ pub trait Runtime: Primitives + Verifier + RuntimePolicy {
/// Emits an event denoting that something externally noteworthy has ocurred.
fn emit_event(&self, event: &ActorEvent) -> Result<(), ActorError>;

/// Exit the current computation with an error code and optionally data and a debugging
/// message.
fn exit(&self, code: u32, data: Option<IpldBlock>, msg: Option<&str>) -> !;

/// Returns true if the call is read_only.
/// All state updates, including actor creation and balance transfers, are rejected in read_only calls.
fn read_only(&self) -> bool;
Expand Down
36 changes: 1 addition & 35 deletions runtime/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ pub fn init_logging() -> Result<(), log::SetLoggerError> {
pretty_env_logger::try_init()
}

pub struct ActorExit {
code: u32,
data: Option<IpldBlock>,
msg: Option<String>,
}

pub struct MockRuntime<BS = MemoryBlockstore> {
pub epoch: ChainEpoch,
pub miner: Address,
Expand Down Expand Up @@ -187,9 +181,6 @@ pub struct MockRuntime<BS = MemoryBlockstore> {
pub actor_balances: HashMap<ActorID, TokenAmount>,
pub tipset_timestamp: u64,
pub tipset_cids: Vec<Cid>,

// actor exits
pub actor_exit: RefCell<Option<ActorExit>>,
}

#[derive(Default)]
Expand Down Expand Up @@ -365,7 +356,6 @@ impl<BS> MockRuntime<BS> {
actor_balances: Default::default(),
tipset_timestamp: Default::default(),
tipset_cids: Default::default(),
actor_exit: Default::default(),
}
}
}
Expand Down Expand Up @@ -563,26 +553,7 @@ impl<BS: Blockstore> MockRuntime<BS> {
) -> Result<Option<IpldBlock>, ActorError> {
self.in_call = true;
let prev_state = self.state;
let res: Result<Option<IpldBlock>, ActorError> =
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
A::invoke_method(self, method_num, params)
}))
.unwrap_or_else(|panic| {
if self.actor_exit.borrow().is_some() {
let exit = self.actor_exit.take().unwrap();
if exit.code == 0 {
Ok(exit.data)
} else {
Err(ActorError::unchecked_with_data(
ExitCode::new(exit.code),
exit.msg.unwrap_or_else(|| "actor exited".to_owned()),
exit.data,
))
}
} else {
std::panic::resume_unwind(panic)
}
});
let res = A::invoke_method(self, method_num, params);

if res.is_err() {
self.state = prev_state;
Expand Down Expand Up @@ -1311,11 +1282,6 @@ impl<BS: Blockstore> Runtime for MockRuntime<BS> {
Ok(())
}

fn exit(&self, code: u32, data: Option<IpldBlock>, msg: Option<&str>) -> ! {
self.actor_exit.replace(Some(ActorExit { code, data, msg: msg.map(|s| s.to_owned()) }));
std::panic::panic_any("actor exit");
}

fn chain_id(&self) -> ChainID {
self.chain_id
}
Expand Down
40 changes: 2 additions & 38 deletions test_vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,8 @@ impl<'bs> VM<'bs> {
read_only: false,
policy: &Policy::default(),
subinvocations: RefCell::new(vec![]),
actor_exit: RefCell::new(None),
};
let res = new_ctx.invoke_actor();
let res = new_ctx.invoke();

let invoc = new_ctx.gather_trace(res.clone());
RefMut::map(self.invocations.borrow_mut(), |invocs| {
Expand Down Expand Up @@ -608,13 +607,6 @@ pub struct InvocationCtx<'invocation, 'bs> {
read_only: bool,
policy: &'invocation Policy,
subinvocations: RefCell<Vec<InvocationTrace>>,
actor_exit: RefCell<Option<ActorExit>>,
}

struct ActorExit {
code: u32,
data: Option<IpldBlock>,
msg: Option<String>,
}

impl<'invocation, 'bs> InvocationCtx<'invocation, 'bs> {
Expand Down Expand Up @@ -676,7 +668,6 @@ impl<'invocation, 'bs> InvocationCtx<'invocation, 'bs> {
read_only: false,
policy: self.policy,
subinvocations: RefCell::new(vec![]),
actor_exit: RefCell::new(None),
};
if is_account {
new_ctx.create_actor(*ACCOUNT_ACTOR_CODE_ID, target_id, None).unwrap();
Expand Down Expand Up @@ -714,27 +705,6 @@ impl<'invocation, 'bs> InvocationCtx<'invocation, 'bs> {
self.resolve_target(&self.msg.to).unwrap().1
}

fn invoke_actor(&mut self) -> Result<Option<IpldBlock>, ActorError> {
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| self.invoke())).unwrap_or_else(
|panic| {
if self.actor_exit.borrow().is_some() {
let exit = self.actor_exit.take().unwrap();
if exit.code == 0 {
Ok(exit.data)
} else {
Err(ActorError::unchecked_with_data(
ExitCode::new(exit.code),
exit.msg.unwrap_or_else(|| "actor exited".to_owned()),
exit.data,
))
}
} else {
std::panic::resume_unwind(panic)
}
},
)
}

fn invoke(&mut self) -> Result<Option<IpldBlock>, ActorError> {
let prior_root = self.v.checkpoint();

Expand Down Expand Up @@ -1019,9 +989,8 @@ impl<'invocation, 'bs> Runtime for InvocationCtx<'invocation, 'bs> {
read_only: send_flags.read_only(),
policy: self.policy,
subinvocations: RefCell::new(vec![]),
actor_exit: RefCell::new(None),
};
let res = new_ctx.invoke_actor();
let res = new_ctx.invoke();
let invoc = new_ctx.gather_trace(res.clone());
RefMut::map(self.subinvocations.borrow_mut(), |subinvocs| {
subinvocs.push(invoc);
Expand Down Expand Up @@ -1149,11 +1118,6 @@ impl<'invocation, 'bs> Runtime for InvocationCtx<'invocation, 'bs> {
Ok(())
}

fn exit(&self, code: u32, data: Option<IpldBlock>, msg: Option<&str>) -> ! {
self.actor_exit.replace(Some(ActorExit { code, data, msg: msg.map(|s| s.to_owned()) }));
std::panic::panic_any("actor exit");
}

fn read_only(&self) -> bool {
self.read_only
}
Expand Down