Skip to content

Commit 10a30e2

Browse files
committed
wip
1 parent 11925fc commit 10a30e2

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

actors/init/src/state.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
// Copyright 2019-2022 ChainSafe Systems
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

4-
use anyhow::anyhow;
54
use cid::Cid;
65
use fil_actors_runtime::{
7-
actor_error, make_empty_map, make_map_with_root_and_bitwidth, FIRST_NON_SINGLETON_ADDR,
6+
actor_error, make_empty_map, make_map_with_root_and_bitwidth, AsActorError,
7+
FIRST_NON_SINGLETON_ADDR,
88
};
99
use fvm_ipld_blockstore::Blockstore;
1010
use fvm_ipld_encoding::tuple::*;
1111
use fvm_ipld_encoding::Cbor;
1212
use fvm_shared::address::{Address, Protocol};
13+
use fvm_shared::error::ExitCode;
1314
use fvm_shared::{ActorID, HAMT_BIT_WIDTH};
1415

1516
/// State is reponsible for creating
@@ -24,7 +25,7 @@ impl State {
2425
pub fn new<BS: Blockstore>(store: &BS, network_name: String) -> anyhow::Result<Self> {
2526
let empty_map = make_empty_map::<_, ()>(store, HAMT_BIT_WIDTH)
2627
.flush()
27-
.map_err(|e| anyhow!("failed to create empty map: {}", e))?;
28+
.context_code(ExitCode::USR_ILLEGAL_STATE, "failed to create empty map")?;
2829
Ok(Self { address_map: empty_map, next_id: FIRST_NON_SINGLETON_ADDR, network_name })
2930
}
3031

actors/system/src/lib.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright 2019-2022 ChainSafe Systems
22
// SPDX-License-Identifier: Apache-2.0, MIT
3-
use anyhow::anyhow;
43
use cid::{multihash, Cid};
54
use fvm_ipld_blockstore::Blockstore;
65
use fvm_ipld_encoding::tuple::*;
@@ -12,13 +11,13 @@ use num_derive::FromPrimitive;
1211
use num_traits::FromPrimitive;
1312

1413
use fil_actors_runtime::runtime::{ActorCode, Runtime};
15-
use fil_actors_runtime::{actor_error, ActorDowncast, ActorError, SYSTEM_ACTOR_ADDR};
14+
use fil_actors_runtime::{
15+
actor_error, ActorContext, ActorDowncast, ActorError, AsActorError, SYSTEM_ACTOR_ADDR,
16+
};
1617

1718
#[cfg(feature = "fil-actor")]
1819
fil_actors_runtime::wasm_trampoline!(Actor);
1920

20-
// * Updated to specs-actors commit: 845089a6d2580e46055c24415a6c32ee688e5186 (v3.0.0)
21-
2221
/// System actor methods.
2322
#[derive(FromPrimitive)]
2423
#[repr(u64)]
@@ -35,10 +34,10 @@ pub struct State {
3534
impl Cbor for State {}
3635

3736
impl State {
38-
pub fn new<BS: Blockstore>(store: &BS) -> anyhow::Result<Self> {
37+
pub fn new<BS: Blockstore>(store: &BS) -> Result<Self, ActorError> {
3938
let c = store
4039
.put_cbor(&Vec::<(String, Cid)>::new(), multihash::Code::Blake2b256)
41-
.map_err(|e| anyhow!("failed to put system state to store: {}", e))?;
40+
.context_code(ExitCode::USR_ILLEGAL_STATE, "failed to store system state")?;
4241
Ok(Self { builtin_actors: c })
4342
}
4443

@@ -65,9 +64,7 @@ impl Actor {
6564
{
6665
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
6766

68-
let state = State::new(rt.store()).map_err(|e| {
69-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to construct state")
70-
})?;
67+
let state = State::new(rt.store()).context("failed to construct state")?;
7168
rt.create(&state)?;
7269
Ok(())
7370
}

0 commit comments

Comments
 (0)