Skip to content

Commit 941c558

Browse files
committed
feat: remove beneficiary from self-destruct (#1362)
part of filecoin-project/ref-fvm#1837
1 parent afd34e0 commit 941c558

File tree

6 files changed

+29
-25
lines changed

6 files changed

+29
-25
lines changed

actors/paych/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,11 @@ impl Actor {
293293
extract_send_result(rt.send_simple(&st.to, METHOD_SEND, None, st.to_send))
294294
.map_err(|e| e.wrap("Failed to send funds to `to` address"))?;
295295

296-
// the remaining balance will be returned to "From" upon deletion.
297-
rt.delete_actor(&st.from)?;
296+
// return remaining balance back to the "from" address.
297+
extract_send_result(rt.send_simple(&st.from, METHOD_SEND, None, rt.current_balance()))
298+
.map_err(|e| e.wrap("Failed to send funds to `from` address"))?;
299+
300+
rt.delete_actor()?;
298301

299302
Ok(())
300303
}

actors/paych/tests/paych_actor_test.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,15 @@ mod actor_collect {
949949
// Collect.
950950
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, st.to);
951951
rt.expect_validate_caller_addr(vec![st.from, st.to]);
952-
rt.expect_delete_actor(st.from);
952+
rt.expect_send_simple(
953+
st.from,
954+
METHOD_SEND,
955+
Default::default(),
956+
&*rt.balance.borrow() - &st.to_send,
957+
Default::default(),
958+
ExitCode::OK,
959+
);
960+
rt.expect_delete_actor();
953961
let res = call(&rt, Method::Collect as u64, None);
954962
assert!(res.is_none());
955963
check_state(&rt);

runtime/src/runtime/fvm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,13 @@ where
350350
})
351351
}
352352

353-
fn delete_actor(&self, beneficiary: &Address) -> Result<(), ActorError> {
353+
fn delete_actor(&self) -> Result<(), ActorError> {
354354
if *self.in_transaction.borrow() {
355355
return Err(
356356
actor_error!(assertion_failed; "delete_actor is not allowed during transaction"),
357357
);
358358
}
359-
Ok(fvm::sself::self_destruct(beneficiary)?)
359+
Ok(fvm::sself::self_destruct(false)?)
360360
}
361361

362362
fn total_fil_circ_supply(&self) -> TokenAmount {

runtime/src/runtime/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,11 @@ pub trait Runtime: Primitives + Verifier + RuntimePolicy {
206206
predictable_address: Option<Address>,
207207
) -> Result<(), ActorError>;
208208

209-
/// Deletes the executing actor from the state tree, transferring any balance to beneficiary.
210-
/// Aborts if the beneficiary does not exist.
209+
/// Deletes the executing actor from the state tree. Fails if there is any unspent balance in
210+
/// the actor.
211+
///
211212
/// May only be called by the actor itself.
212-
fn delete_actor(&self, beneficiary: &Address) -> Result<(), ActorError>;
213+
fn delete_actor(&self) -> Result<(), ActorError>;
213214

214215
/// Returns whether the specified CodeCID belongs to a built-in actor.
215216
fn resolve_builtin_actor_type(&self, code_id: &Cid) -> Option<Type>;

runtime/src/test_utils.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub struct Expectations {
191191
pub expect_validate_caller_type: Option<Vec<Type>>,
192192
pub expect_sends: VecDeque<ExpectedMessage>,
193193
pub expect_create_actor: Option<ExpectCreateActor>,
194-
pub expect_delete_actor: Option<Address>,
194+
pub expect_delete_actor: bool,
195195
pub expect_verify_sigs: VecDeque<ExpectedVerifySig>,
196196
pub expect_verify_post: Option<ExpectVerifyPoSt>,
197197
pub expect_compute_unsealed_sector_cid: VecDeque<ExpectComputeUnsealedSectorCid>,
@@ -245,11 +245,7 @@ impl Expectations {
245245
"expected actor to be created, uncreated actor: {:?}",
246246
this.expect_create_actor
247247
);
248-
assert!(
249-
this.expect_delete_actor.is_none(),
250-
"expected actor to be deleted: {:?}",
251-
this.expect_delete_actor
252-
);
248+
assert!(!this.expect_delete_actor, "expected actor to be deleted",);
253249
assert!(
254250
this.expect_verify_sigs.is_empty(),
255251
"expect_verify_sigs: {:?}, not received",
@@ -624,8 +620,8 @@ impl<BS: Blockstore> MockRuntime<BS> {
624620
}
625621

626622
#[allow(dead_code)]
627-
pub fn expect_delete_actor(&self, beneficiary: Address) {
628-
self.expectations.borrow_mut().expect_delete_actor = Some(beneficiary);
623+
pub fn expect_delete_actor(&self) {
624+
self.expectations.borrow_mut().expect_delete_actor = true;
629625
}
630626

631627
#[allow(dead_code)]
@@ -1185,18 +1181,14 @@ impl<BS: Blockstore> Runtime for MockRuntime<BS> {
11851181
Ok(())
11861182
}
11871183

1188-
fn delete_actor(&self, addr: &Address) -> Result<(), ActorError> {
1184+
fn delete_actor(&self) -> Result<(), ActorError> {
11891185
self.require_in_call();
11901186
if *self.in_transaction.borrow() {
11911187
return Err(actor_error!(assertion_failed; "side-effect within transaction"));
11921188
}
1193-
let exp_act = self.expectations.borrow_mut().expect_delete_actor.take();
1194-
if exp_act.is_none() {
1195-
panic!("unexpected call to delete actor: {}", addr);
1196-
}
1197-
if exp_act.as_ref().unwrap() != addr {
1198-
panic!("attempt to delete wrong actor. Expected: {}, got: {}", exp_act.unwrap(), addr);
1199-
}
1189+
let mut exp = self.expectations.borrow_mut();
1190+
assert!(exp.expect_delete_actor, "unexpected call to delete actor");
1191+
exp.expect_delete_actor = false;
12001192
Ok(())
12011193
}
12021194

test_vm/src/messaging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ where
611611
Ok(Address::new_actor(&b))
612612
}
613613

614-
fn delete_actor(&self, _beneficiary: &Address) -> Result<(), ActorError> {
614+
fn delete_actor(&self) -> Result<(), ActorError> {
615615
panic!("TODO implement me")
616616
}
617617

0 commit comments

Comments
 (0)