Skip to content

Commit 293ceb4

Browse files
anorthdignifiedquireStebalien
authored
Use new ExitCode type and values, change ActorError to make bad exit codes less likely (#191)
Co-authored-by: dignifiedquire <[email protected]> Co-authored-by: Steven Allen <[email protected]>
1 parent ca81f77 commit 293ceb4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1126
-1079
lines changed

Cargo.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ members = [
3939
"test_vm",
4040
]
4141

42+
#[patch.crates-io]
43+
#fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm" }
44+
#fvm_sdk = { git = "https://github.com/filecoin-project/ref-fvm" }
45+
#fvm_ipld_hamt = { git = "https://github.com/filecoin-project/ref-fvm" }
46+
#fvm_ipld_amt = { git = "https://github.com/filecoin-project/ref-fvm" }
47+
#fvm_ipld_bitfield = { git = "https://github.com/filecoin-project/ref-fvm" }
48+
#fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm" }
49+
#fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm" }
50+
4251
## Uncomment when working locally on ref-fvm and this repo simultaneously.
4352
## Assumes the ref-fvm checkout is in a sibling directory with the same name.
4453
## (Valid while FVM modules aren't published to crates.io)
@@ -54,14 +63,14 @@ members = [
5463
## Uncomment entries below when working locally on ref-fvm and this repo simultaneously.
5564
## Assumes the ref-fvm checkout is in a sibling directory with the same name.
5665
## (Valid once FVM modules are published to crates.io)
57-
#[patch.crates-io]
58-
#fvm_shared = { path = "../ref-fvm/shared" }
59-
#fvm_sdk = { path = "../ref-fvm/sdk" }
60-
#fvm_ipld_hamt = { path = "../ref-fvm/ipld/hamt" }
61-
#fvm_ipld_amt = { path = "../ref-fvm/ipld/amt" }
62-
#fvm_ipld_bitfield = { path = "../ref-fvm/ipld/bitfield"}
63-
#fvm_ipld_encoding = { path = "../ref-fvm/ipld/encoding"}
64-
#fvm_ipld_blockstore = { path = "../ref-fvm/ipld/blockstore"}
66+
# [patch.crates-io]
67+
# fvm_shared = { path = "../ref-fvm/shared" }
68+
# fvm_sdk = { path = "../ref-fvm/sdk" }
69+
# fvm_ipld_hamt = { path = "../ref-fvm/ipld/hamt" }
70+
# fvm_ipld_amt = { path = "../ref-fvm/ipld/amt" }
71+
# fvm_ipld_bitfield = { path = "../ref-fvm/ipld/bitfield"}
72+
# fvm_ipld_encoding = { path = "../ref-fvm/ipld/encoding"}
73+
# fvm_ipld_blockstore = { path = "../ref-fvm/ipld/blockstore"}
6574

6675
[profile.wasm]
6776
inherits = "release"

actors/account/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ crate-type = ["cdylib", "lib"]
1414

1515
[dependencies]
1616
fil_actors_runtime = { version = "8.0.0-alpha.1", path = "../runtime", features = ["fil-actor"] }
17-
fvm_shared = { version = "0.4.0", default-features = false }
17+
fvm_shared = { version = "0.5.1", default-features = false }
1818
serde = { version = "1.0.136", features = ["derive"] }
1919
num-traits = "0.2.14"
2020
num-derive = "0.3.3"

actors/account/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Actor {
4343
match address.protocol() {
4444
Protocol::Secp256k1 | Protocol::BLS => {}
4545
protocol => {
46-
return Err(actor_error!(ErrIllegalArgument;
46+
return Err(actor_error!(illegal_argument;
4747
"address must use BLS or SECP protocol, got {}", protocol));
4848
}
4949
}
@@ -82,7 +82,7 @@ impl ActorCode for Actor {
8282
let addr = Self::pubkey_address(rt)?;
8383
Ok(RawBytes::serialize(addr)?)
8484
}
85-
None => Err(actor_error!(SysErrInvalidMethod; "Invalid method")),
85+
None => Err(actor_error!(unhandled_message; "Invalid method")),
8686
}
8787
}
8888
}

actors/account/tests/account_actor_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ macro_rules! account_tests {
5151
account_tests! {
5252
happy_construct_secp256k1_address: (
5353
Address::new_secp256k1(&[2; fvm_shared::address::SECP_PUB_LEN]).unwrap(),
54-
ExitCode::Ok
54+
ExitCode::OK
5555
),
5656
happy_construct_bls_address: (
5757
Address::new_bls(&[1; fvm_shared::address::BLS_PUB_LEN]).unwrap(),
58-
ExitCode::Ok
58+
ExitCode::OK
5959
),
6060
fail_construct_id_address: (
6161
Address::new_id(1),
62-
ExitCode::ErrIllegalArgument
62+
ExitCode::USR_ILLEGAL_ARGUMENT
6363
),
6464
fail_construct_actor_address: (
6565
Address::new_actor(&[1, 2, 3]),
66-
ExitCode::ErrIllegalArgument
66+
ExitCode::USR_ILLEGAL_ARGUMENT
6767
),
6868
}

actors/cron/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"]
1515

1616
[dependencies]
1717
fil_actors_runtime = { version = "8.0.0-alpha.1", path = "../runtime", features = ["fil-actor"] }
18-
fvm_shared = { version = "0.4.0", default-features = false }
18+
fvm_shared = { version = "0.5.1", default-features = false }
1919
num-traits = "0.2.14"
2020
num-derive = "0.3.3"
2121
log = "0.4.14"

actors/cron/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl ActorCode for Actor {
100100
Self::epoch_tick(rt)?;
101101
Ok(RawBytes::default())
102102
}
103-
None => Err(actor_error!(SysErrInvalidMethod; "Invalid method")),
103+
None => Err(actor_error!(unhandled_message; "Invalid method")),
104104
}
105105
}
106106
}

actors/cron/tests/cron_actor_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,31 @@ fn epoch_tick_with_entries() {
7373
RawBytes::default(),
7474
0u8.into(),
7575
RawBytes::default(),
76-
ExitCode::Ok,
76+
ExitCode::OK,
7777
);
7878
rt.expect_send(
7979
entry2.receiver,
8080
entry2.method_num,
8181
RawBytes::default(),
8282
0u8.into(),
8383
RawBytes::default(),
84-
ExitCode::ErrIllegalArgument,
84+
ExitCode::USR_ILLEGAL_ARGUMENT,
8585
);
8686
rt.expect_send(
8787
entry3.receiver,
8888
entry3.method_num,
8989
RawBytes::default(),
9090
0u8.into(),
9191
RawBytes::default(),
92-
ExitCode::Ok,
92+
ExitCode::OK,
9393
);
9494
rt.expect_send(
9595
entry4.receiver,
9696
entry4.method_num,
9797
RawBytes::default(),
9898
0u8.into(),
9999
RawBytes::default(),
100-
ExitCode::Ok,
100+
ExitCode::OK,
101101
);
102102

103103
epoch_tick_and_verify(&mut rt);

actors/init/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"]
1515

1616
[dependencies]
1717
fil_actors_runtime = { version = "8.0.0-alpha.1", path = "../runtime", features = ["fil-actor"] }
18-
fvm_shared = { version = "0.4.0", default-features = false }
18+
fvm_shared = { version = "0.5.1", default-features = false }
1919
fvm_ipld_hamt = "0.4.0"
2020
serde = { version = "1.0.136", features = ["derive"] }
2121
num-traits = "0.2.14"

actors/init/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Actor {
4444
let sys_ref: &Address = &SYSTEM_ACTOR_ADDR;
4545
rt.validate_immediate_caller_is(std::iter::once(sys_ref))?;
4646
let state = State::new(rt.store(), params.network_name).map_err(|e| {
47-
e.downcast_default(ExitCode::ErrIllegalState, "failed to construct init actor state")
47+
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to construct init actor state")
4848
})?;
4949

5050
rt.create(&state)?;
@@ -63,13 +63,13 @@ impl Actor {
6363
log::trace!("called exec; params.code_cid: {:?}", &params.code_cid);
6464

6565
let caller_code = rt.get_actor_code_cid(&rt.message().caller()).ok_or_else(|| {
66-
actor_error!(ErrIllegalState, "no code for caller as {}", rt.message().caller())
66+
actor_error!(illegal_state, "no code for caller as {}", rt.message().caller())
6767
})?;
6868

6969
log::trace!("caller code CID: {:?}", &caller_code);
7070

7171
if !can_exec(rt, &caller_code, &params.code_cid) {
72-
return Err(actor_error!(ErrForbidden;
72+
return Err(actor_error!(forbidden;
7373
"called type {} cannot exec actor type {}",
7474
&caller_code, &params.code_cid
7575
));
@@ -87,7 +87,7 @@ impl Actor {
8787
// Store mapping of pubkey or actor address to actor ID
8888
let id_address: ActorID = rt.transaction(|s: &mut State, rt| {
8989
s.map_address_to_new_id(rt.store(), &robust_address).map_err(|e| {
90-
e.downcast_default(ExitCode::ErrIllegalState, "failed to allocate ID address")
90+
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to allocate ID address")
9191
})
9292
})?;
9393

@@ -126,7 +126,7 @@ impl ActorCode for Actor {
126126
let res = Self::exec(rt, cbor::deserialize_params(params)?)?;
127127
Ok(RawBytes::serialize(res)?)
128128
}
129-
None => Err(actor_error!(SysErrInvalidMethod; "Invalid method")),
129+
None => Err(actor_error!(unhandled_message; "Invalid method")),
130130
}
131131
}
132132
}

0 commit comments

Comments
 (0)