Skip to content

Commit 59d46c2

Browse files
just miner and market missing
1 parent f9a008c commit 59d46c2

File tree

10 files changed

+121
-289
lines changed

10 files changed

+121
-289
lines changed

Cargo.lock

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

actors/init/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ serde = { version = "1.0.136", features = ["derive"] }
2121
num-traits = "0.2.14"
2222
num-derive = "0.3.3"
2323
cid = { version = "0.8.3", default-features = false, features = ["serde-codec"] }
24-
anyhow = "1.0.56"
2524
log = "0.4.14"
2625
fvm_ipld_blockstore = { version = "0.1" }
2726
fvm_ipld_encoding = "0.1.0"

actors/init/src/lib.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33

44
use cid::Cid;
55
use fil_actors_runtime::runtime::{ActorCode, Runtime};
6-
use fil_actors_runtime::{actor_error, cbor, ActorDowncast, ActorError, SYSTEM_ACTOR_ADDR};
6+
use fil_actors_runtime::{actor_error, cbor, ActorContext, ActorError, SYSTEM_ACTOR_ADDR};
77
use fvm_ipld_blockstore::Blockstore;
88
use fvm_ipld_encoding::RawBytes;
99
use fvm_shared::actor::builtin::Type;
1010
use fvm_shared::address::Address;
11-
use fvm_shared::error::ExitCode;
1211
use fvm_shared::{ActorID, MethodNum, METHOD_CONSTRUCTOR};
1312
use num_derive::FromPrimitive;
1413
use num_traits::FromPrimitive;
@@ -43,9 +42,8 @@ impl Actor {
4342
{
4443
let sys_ref: &Address = &SYSTEM_ACTOR_ADDR;
4544
rt.validate_immediate_caller_is(std::iter::once(sys_ref))?;
46-
let state = State::new(rt.store(), params.network_name).map_err(|e| {
47-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to construct init actor state")
48-
})?;
45+
let state = State::new(rt.store(), params.network_name)
46+
.context("failed to construct init actor state")?;
4947

5048
rt.create(&state)?;
5149

@@ -86,9 +84,8 @@ impl Actor {
8684
// Allocate an ID for this actor.
8785
// Store mapping of pubkey or actor address to actor ID
8886
let id_address: ActorID = rt.transaction(|s: &mut State, rt| {
89-
s.map_address_to_new_id(rt.store(), &robust_address).map_err(|e| {
90-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to allocate ID address")
91-
})
87+
s.map_address_to_new_id(rt.store(), &robust_address)
88+
.context("failed to allocate ID address")
9289
})?;
9390

9491
// Create an empty actor

actors/init/src/state.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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::{
76
make_empty_map, make_map_with_root_and_bitwidth, FIRST_NON_SINGLETON_ADDR,
87
};
8+
use fil_actors_runtime::{ActorContext, ActorError};
99
use fvm_ipld_blockstore::Blockstore;
1010
use fvm_ipld_encoding::tuple::*;
1111
use fvm_ipld_encoding::Cbor;
@@ -22,10 +22,11 @@ pub struct State {
2222
}
2323

2424
impl State {
25-
pub fn new<BS: Blockstore>(store: &BS, network_name: String) -> anyhow::Result<Self> {
25+
pub fn new<BS: Blockstore>(store: &BS, network_name: String) -> Result<Self, ActorError> {
2626
let empty_map = make_empty_map::<_, ()>(store, HAMT_BIT_WIDTH)
2727
.flush()
28-
.map_err(|e| anyhow!("failed to create empty map: {}", e))?;
28+
.context("failed to create empty map")?;
29+
2930
Ok(Self { address_map: empty_map, next_id: FIRST_NON_SINGLETON_ADDR, network_name })
3031
}
3132

@@ -35,7 +36,7 @@ impl State {
3536
&mut self,
3637
store: &BS,
3738
addr: &Address,
38-
) -> Result<ActorID, HamtError> {
39+
) -> Result<ActorID, HamtError<BS::Error>> {
3940
let id = self.next_id;
4041
self.next_id += 1;
4142

@@ -60,7 +61,7 @@ impl State {
6061
&self,
6162
store: &BS,
6263
addr: &Address,
63-
) -> anyhow::Result<Option<Address>> {
64+
) -> Result<Option<Address>, ActorError> {
6465
if addr.protocol() == Protocol::ID {
6566
return Ok(Some(*addr));
6667
}

actors/multisig/src/lib.rs

Lines changed: 22 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use fil_actors_runtime::cbor::serialize_vec;
77
use fil_actors_runtime::runtime::{ActorCode, Runtime, Syscalls};
88
use fil_actors_runtime::{
99
actor_error, cbor, make_empty_map, make_map_with_root, resolve_to_id_addr, ActorContext,
10-
ActorDowncast, ActorError, Map, INIT_ACTOR_ADDR,
10+
ActorError, Map, INIT_ACTOR_ADDR,
1111
};
1212
use fvm_ipld_blockstore::Blockstore;
1313
use fvm_ipld_encoding::RawBytes;
@@ -97,10 +97,9 @@ impl Actor {
9797
return Err(actor_error!(illegal_argument; "negative unlock duration disallowed"));
9898
}
9999

100-
let empty_root =
101-
make_empty_map::<_, ()>(rt.store(), HAMT_BIT_WIDTH).flush().map_err(|e| {
102-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "Failed to create empty map")
103-
})?;
100+
let empty_root = make_empty_map::<_, ()>(rt.store(), HAMT_BIT_WIDTH)
101+
.flush()
102+
.context("Failed to create empty map")?;
104103

105104
let mut st: State = State {
106105
signers: resolved_signers,
@@ -146,12 +145,8 @@ impl Actor {
146145
return Err(actor_error!(forbidden, "{} is not a signer", proposer));
147146
}
148147

149-
let mut ptx = make_map_with_root(&st.pending_txs, rt.store()).map_err(|e| {
150-
e.downcast_default(
151-
ExitCode::USR_ILLEGAL_STATE,
152-
"failed to load pending transactions",
153-
)
154-
})?;
148+
let mut ptx = make_map_with_root(&st.pending_txs, rt.store())
149+
.context("failed to load pending transactions")?;
155150

156151
let t_id = st.next_tx_id;
157152
st.next_tx_id.0 += 1;
@@ -164,19 +159,9 @@ impl Actor {
164159
approved: Vec::new(),
165160
};
166161

167-
ptx.set(t_id.key(), txn.clone()).map_err(|e| {
168-
e.downcast_default(
169-
ExitCode::USR_ILLEGAL_STATE,
170-
"failed to put transaction for propose",
171-
)
172-
})?;
162+
ptx.set(t_id.key(), txn.clone()).context("failed to put transaction for propose")?;
173163

174-
st.pending_txs = ptx.flush().map_err(|e| {
175-
e.downcast_default(
176-
ExitCode::USR_ILLEGAL_STATE,
177-
"failed to flush pending transactions",
178-
)
179-
})?;
164+
st.pending_txs = ptx.flush().context("failed to flush pending transactions")?;
180165

181166
Ok((t_id, txn))
182167
})?;
@@ -201,12 +186,8 @@ impl Actor {
201186
return Err(actor_error!(forbidden; "{} is not a signer", approver));
202187
}
203188

204-
let ptx = make_map_with_root(&st.pending_txs, rt.store()).map_err(|e| {
205-
e.downcast_default(
206-
ExitCode::USR_ILLEGAL_STATE,
207-
"failed to load pending transactions",
208-
)
209-
})?;
189+
let ptx = make_map_with_root(&st.pending_txs, rt.store())
190+
.context("failed to load pending transactions")?;
210191

211192
let txn = get_transaction(rt, &ptx, params.id, params.proposal_hash)?;
212193

@@ -241,21 +222,11 @@ impl Actor {
241222
}
242223

243224
let mut ptx = make_map_with_root::<_, Transaction>(&st.pending_txs, rt.store())
244-
.map_err(|e| {
245-
e.downcast_default(
246-
ExitCode::USR_ILLEGAL_STATE,
247-
"failed to load pending transactions",
248-
)
249-
})?;
225+
.context("failed to load pending transactions")?;
250226

251227
let (_, tx) = ptx
252228
.delete(&params.id.key())
253-
.map_err(|e| {
254-
e.downcast_default(
255-
ExitCode::USR_ILLEGAL_STATE,
256-
format!("failed to pop transaction {:?} for cancel", params.id),
257-
)
258-
})?
229+
.with_context(|| format!("failed to pop transaction {:?} for cancel", params.id,))?
259230
.ok_or_else(|| {
260231
actor_error!(not_found, "no such transaction {:?} to cancel", params.id)
261232
})?;
@@ -273,12 +244,7 @@ impl Actor {
273244
return Err(actor_error!(illegal_state, "hash does not match proposal params"));
274245
}
275246

276-
st.pending_txs = ptx.flush().map_err(|e| {
277-
e.downcast_default(
278-
ExitCode::USR_ILLEGAL_STATE,
279-
"failed to flush pending transactions",
280-
)
281-
})?;
247+
st.pending_txs = ptx.flush().context("failed to flush pending transactions")?;
282248

283249
Ok(())
284250
})
@@ -481,29 +447,16 @@ impl Actor {
481447
}
482448

483449
let st = rt.transaction(|st: &mut State, rt| {
484-
let mut ptx = make_map_with_root(&st.pending_txs, rt.store()).map_err(|e| {
485-
e.downcast_default(
486-
ExitCode::USR_ILLEGAL_STATE,
487-
"failed to load pending transactions",
488-
)
489-
})?;
450+
let mut ptx = make_map_with_root(&st.pending_txs, rt.store())
451+
.context("failed to load pending transactions")?;
490452

491453
// update approved on the transaction
492454
txn.approved.push(rt.message().caller());
493455

494-
ptx.set(tx_id.key(), txn.clone()).map_err(|e| {
495-
e.downcast_default(
496-
ExitCode::USR_ILLEGAL_STATE,
497-
format!("failed to put transaction {} for approval", tx_id.0),
498-
)
499-
})?;
456+
ptx.set(tx_id.key(), txn.clone())
457+
.with_context(|| format!("failed to put transaction {} for approval", tx_id.0,))?;
500458

501-
st.pending_txs = ptx.flush().map_err(|e| {
502-
e.downcast_default(
503-
ExitCode::USR_ILLEGAL_STATE,
504-
"failed to flush pending transactions",
505-
)
506-
})?;
459+
st.pending_txs = ptx.flush().context("failed to flush pending transactions")?;
507460

508461
// Go implementation holds reference to state after transaction so this must be cloned
509462
// to match to handle possible exit code inconsistency
@@ -544,26 +497,11 @@ where
544497

545498
rt.transaction(|st: &mut State, rt| {
546499
let mut ptx = make_map_with_root::<_, Transaction>(&st.pending_txs, rt.store())
547-
.map_err(|e| {
548-
e.downcast_default(
549-
ExitCode::USR_ILLEGAL_STATE,
550-
"failed to load pending transactions",
551-
)
552-
})?;
500+
.context("failed to load pending transactions")?;
553501

554-
ptx.delete(&txn_id.key()).map_err(|e| {
555-
e.downcast_default(
556-
ExitCode::USR_ILLEGAL_STATE,
557-
"failed to delete transaction for cleanup",
558-
)
559-
})?;
502+
ptx.delete(&txn_id.key()).context("failed to delete transaction for cleanup")?;
560503

561-
st.pending_txs = ptx.flush().map_err(|e| {
562-
e.downcast_default(
563-
ExitCode::USR_ILLEGAL_STATE,
564-
"failed to flush pending transactions",
565-
)
566-
})?;
504+
st.pending_txs = ptx.flush().context("failed to flush pending transactions")?;
567505
Ok(())
568506
})?;
569507
}
@@ -583,12 +521,7 @@ where
583521
{
584522
let txn = ptx
585523
.get(&txn_id.key())
586-
.map_err(|e| {
587-
e.downcast_default(
588-
ExitCode::USR_ILLEGAL_STATE,
589-
format!("failed to load transaction {:?} for approval", txn_id),
590-
)
591-
})?
524+
.with_context(|| format!("failed to load transaction {:?} for approval", txn_id,))?
592525
.ok_or_else(|| actor_error!(not_found, "no such transaction {:?} for approval", txn_id))?;
593526

594527
if !proposal_hash.is_empty() {

actors/paych/src/lib.rs

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

44
use fil_actors_runtime::runtime::{ActorCode, Runtime};
5-
use fil_actors_runtime::{
6-
actor_error, cbor, resolve_to_id_addr, ActorContext, ActorDowncast, ActorError, Array,
7-
};
5+
use fil_actors_runtime::{actor_error, cbor, resolve_to_id_addr, ActorContext, ActorError, Array};
86
use fvm_ipld_blockstore::Blockstore;
97
use fvm_ipld_encoding::RawBytes;
108
use fvm_shared::actor::builtin::Type;
@@ -60,9 +58,7 @@ impl Actor {
6058
let empty_arr_cid =
6159
Array::<(), _>::new_with_bit_width(rt.store(), LANE_STATES_AMT_BITWIDTH)
6260
.flush()
63-
.map_err(|e| {
64-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to create empty AMT")
65-
})?;
61+
.context("failed to create empty AMT")?;
6662

6763
rt.create(&State::new(from, to, empty_arr_cid))?;
6864
Ok(())
@@ -133,9 +129,7 @@ impl Actor {
133129
})?;
134130

135131
// Validate signature
136-
rt.verify_signature(sig, &signer, &sv_bz).map_err(|e| {
137-
e.downcast_default(ExitCode::USR_ILLEGAL_ARGUMENT, "voucher signature invalid")
138-
})?;
132+
rt.verify_signature(sig, &signer, &sv_bz).context("voucher signature invalid")?;
139133

140134
let pch_addr = rt.message().receiver();
141135
let svpch_id_addr = rt.resolve_address(&sv.channel_addr).ok_or_else(|| {
@@ -182,9 +176,8 @@ impl Actor {
182176
}
183177

184178
rt.transaction(|st: &mut State, rt| {
185-
let mut l_states = Array::load(&st.lane_states, rt.store()).map_err(|e| {
186-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to load lane states")
187-
})?;
179+
let mut l_states =
180+
Array::load(&st.lane_states, rt.store()).context("failed to load lane states")?;
188181

189182
// Find the voucher lane, create and insert it in sorted order if necessary.
190183
let lane_id = sv.lane;
@@ -224,12 +217,9 @@ impl Actor {
224217

225218
redeemed_from_others += &other_ls.redeemed;
226219
other_ls.nonce = merge.nonce;
227-
l_states.set(merge.lane, other_ls).map_err(|e| {
228-
e.downcast_default(
229-
ExitCode::USR_ILLEGAL_STATE,
230-
format!("failed to store lane {}", merge.lane),
231-
)
232-
})?;
220+
l_states
221+
.set(merge.lane, other_ls)
222+
.with_context(|| format!("failed to store lane {}", merge.lane,))?;
233223
}
234224

235225
// 2. To prevent double counting, remove already redeemed amounts (from
@@ -266,16 +256,11 @@ impl Actor {
266256
}
267257
}
268258

269-
l_states.set(lane_id, lane_state).map_err(|e| {
270-
e.downcast_default(
271-
ExitCode::USR_ILLEGAL_STATE,
272-
format!("failed to store lane {}", lane_id),
273-
)
274-
})?;
259+
l_states
260+
.set(lane_id, lane_state)
261+
.with_context(|| format!("failed to store lane {}", lane_id,))?;
275262

276-
st.lane_states = l_states.flush().map_err(|e| {
277-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to save lanes")
278-
})?;
263+
st.lane_states = l_states.flush().context("failed to save lanes")?;
279264
Ok(())
280265
})
281266
}
@@ -336,9 +321,7 @@ where
336321
return Err(actor_error!(illegal_argument; "maximum lane ID is 2^63-1"));
337322
}
338323

339-
ls.get(id).map_err(|e| {
340-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, format!("failed to load lane {}", id))
341-
})
324+
ls.get(id).with_context(|| format!("failed to load lane {}", id))
342325
}
343326

344327
impl ActorCode for Actor {

0 commit comments

Comments
 (0)