Skip to content

Commit 971b6a6

Browse files
part 1, setup
1 parent ec878ed commit 971b6a6

File tree

19 files changed

+350
-349
lines changed

19 files changed

+350
-349
lines changed

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ members = [
6969
## Uncomment entries below when working locally on ref-fvm and this repo simultaneously.
7070
## Assumes the ref-fvm checkout is in a sibling directory with the same name.
7171
## (Valid once FVM modules are published to crates.io)
72-
# [patch.crates-io]
73-
# fvm_shared = { path = "../ref-fvm/shared" }
74-
# fvm_sdk = { path = "../ref-fvm/sdk" }
75-
# fvm_ipld_hamt = { path = "../ref-fvm/ipld/hamt" }
76-
# fvm_ipld_amt = { path = "../ref-fvm/ipld/amt" }
77-
# fvm_ipld_bitfield = { path = "../ref-fvm/ipld/bitfield"}
78-
# fvm_ipld_encoding = { path = "../ref-fvm/ipld/encoding"}
79-
# fvm_ipld_blockstore = { path = "../ref-fvm/ipld/blockstore"}
72+
[patch.crates-io]
73+
fvm_shared = { path = "../ref-fvm/shared" }
74+
fvm_sdk = { path = "../ref-fvm/sdk" }
75+
fvm_ipld_hamt = { path = "../ref-fvm/ipld/hamt" }
76+
fvm_ipld_amt = { path = "../ref-fvm/ipld/amt" }
77+
fvm_ipld_bitfield = { path = "../ref-fvm/ipld/bitfield"}
78+
fvm_ipld_encoding = { path = "../ref-fvm/ipld/encoding"}
79+
fvm_ipld_blockstore = { path = "../ref-fvm/ipld/blockstore"}
8080

8181
[profile.wasm]
8282
inherits = "release"

actors/power/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ cid = { version = "0.8.3", default-features = false, features = ["serde-codec"]
2525
integer-encoding = { version = "3.0.3", default-features = false }
2626
lazy_static = "1.4.0"
2727
serde = { version = "1.0.136", features = ["derive"] }
28-
anyhow = "1.0.56"
2928
fvm_ipld_blockstore = { version = "0.1" }
3029
fvm_ipld_encoding = "0.1.0"
3130

actors/power/src/lib.rs

Lines changed: 36 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
use std::collections::BTreeSet;
55
use std::convert::TryInto;
66

7-
use anyhow::anyhow;
87
use ext::init;
98
use fil_actors_runtime::runtime::{ActorCode, Runtime};
109
use fil_actors_runtime::{
11-
actor_error, cbor, make_map_with_root_and_bitwidth, ActorDowncast, ActorError, Multimap,
12-
CRON_ACTOR_ADDR, INIT_ACTOR_ADDR, REWARD_ACTOR_ADDR, SYSTEM_ACTOR_ADDR,
10+
actor_error, cbor, make_map_with_root_and_bitwidth, ActorContext, ActorDowncast, ActorError,
11+
Multimap, CRON_ACTOR_ADDR, INIT_ACTOR_ADDR, REWARD_ACTOR_ADDR, SYSTEM_ACTOR_ADDR,
1312
};
1413
use fvm_ipld_blockstore::Blockstore;
1514
use fvm_ipld_encoding::RawBytes;
@@ -74,9 +73,7 @@ impl Actor {
7473
{
7574
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
7675

77-
let st = State::new(rt.store()).map_err(|e| {
78-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "Failed to create power actor state")
79-
})?;
76+
let st = State::new(rt.store()).context("Failed to create power actor state")?;
8077
rt.create(&st)?;
8178
Ok(())
8279
}
@@ -130,12 +127,8 @@ impl Actor {
130127
raw_byte_power: Default::default(),
131128
},
132129
)
133-
.map_err(|e| {
134-
e.downcast_default(
135-
ExitCode::USR_ILLEGAL_STATE,
136-
"failed to put power in claimed table while creating miner",
137-
)
138-
})?;
130+
.context("failed to put power in claimed table while creating miner")?;
131+
139132
st.miner_count += 1;
140133

141134
st.update_stats_for_new_miner(window_post_proof_type).map_err(|e| {
@@ -180,13 +173,10 @@ impl Actor {
180173
&params.raw_byte_delta,
181174
&params.quality_adjusted_delta,
182175
)
183-
.map_err(|e| {
184-
e.downcast_default(
185-
ExitCode::USR_ILLEGAL_STATE,
186-
format!(
187-
"failed to update power raw {}, qa {}",
188-
params.raw_byte_delta, params.quality_adjusted_delta,
189-
),
176+
.with_context(|| {
177+
format!(
178+
"failed to update power raw {}, qa {}",
179+
params.raw_byte_delta, params.quality_adjusted_delta,
190180
)
191181
})?;
192182

@@ -225,17 +215,12 @@ impl Actor {
225215
CRON_QUEUE_HAMT_BITWIDTH,
226216
CRON_QUEUE_AMT_BITWIDTH,
227217
)
228-
.map_err(|e| {
229-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to load cron events")
230-
})?;
218+
.context("failed to load cron events")?;
231219

232-
st.append_cron_event(&mut events, params.event_epoch, miner_event).map_err(|e| {
233-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to enroll cron event")
234-
})?;
220+
st.append_cron_event(&mut events, params.event_epoch, miner_event)
221+
.context("failed to enroll cron event")?;
235222

236-
st.cron_event_queue = events.root().map_err(|e| {
237-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to flush cron events")
238-
})?;
223+
st.cron_event_queue = events.root().context("failed to flush cron events")?;
239224
Ok(())
240225
})?;
241226
Ok(())
@@ -326,22 +311,14 @@ impl Actor {
326311
HAMT_BIT_WIDTH,
327312
PROOF_VALIDATION_BATCH_AMT_BITWIDTH,
328313
)
329-
.map_err(|e| {
330-
e.downcast_default(
331-
ExitCode::USR_ILLEGAL_STATE,
332-
"failed to load proof batching set",
333-
)
334-
})?
314+
.context("failed to load proof batching set")?
335315
} else {
336316
debug!("ProofValidationBatch created");
337317
Multimap::new(rt.store(), HAMT_BIT_WIDTH, PROOF_VALIDATION_BATCH_AMT_BITWIDTH)
338318
};
339319
let miner_addr = rt.message().caller();
340-
let arr = mmap.get::<SealVerifyInfo>(&miner_addr.to_bytes()).map_err(|e| {
341-
e.downcast_default(
342-
ExitCode::USR_ILLEGAL_STATE,
343-
format!("failed to get seal verify infos at addr {}", miner_addr),
344-
)
320+
let arr = mmap.get::<SealVerifyInfo>(&miner_addr.to_bytes()).with_context(|| {
321+
format!("failed to get seal verify infos at addr {}", miner_addr)
345322
})?;
346323
if let Some(arr) = arr {
347324
if arr.count() >= MAX_MINER_PROVE_COMMITS_PER_EPOCH {
@@ -355,13 +332,10 @@ impl Actor {
355332
}
356333
}
357334

358-
mmap.add(miner_addr.to_bytes().into(), seal_info).map_err(|e| {
359-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to insert proof into set")
360-
})?;
335+
mmap.add(miner_addr.to_bytes().into(), seal_info)
336+
.context("failed to insert proof into set")?;
361337

362-
let mmrc = mmap.root().map_err(|e| {
363-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to flush proofs batch map")
364-
})?;
338+
let mmrc = mmap.root().context("failed to flush proofs batch map")?;
365339

366340
rt.charge_gas("OnSubmitVerifySeal", GAS_ON_SUBMIT_VERIFY_SEAL);
367341
st.proof_validation_batch = Some(mmrc);
@@ -434,35 +408,37 @@ impl Actor {
434408
}
435409
};
436410

437-
if let Err(e) = mmap.for_all::<_, SealVerifyInfo>(|k, arr| {
411+
if let Err(e) = mmap.for_all::<_, SealVerifyInfo, _>(|k, arr| {
438412
let addr = match Address::from_bytes(&k.0) {
439413
Ok(addr) => addr,
440414
Err(e) => {
441-
return Err(anyhow!("failed to parse address key: {}", e));
415+
return Err(format!("failed to parse address key: {}", e));
442416
}
443417
};
444418

445419
let contains_claim = match claims.contains_key(&addr.to_bytes()) {
446420
Ok(contains_claim) => contains_claim,
447-
Err(e) => return Err(anyhow!("failed to look up clain: {}", e)),
421+
Err(e) => return Err(format!("failed to look up clain: {}", e)),
448422
};
449423

450424
if !contains_claim {
451425
debug!("skipping batch verifies for unknown miner: {}", addr);
452426
return Ok(());
453427
}
454428

455-
let num_proofs: usize = arr.count().try_into()?;
429+
let num_proofs: usize = arr
430+
.count()
431+
.try_into()
432+
.map_err(|_| "can not convert u64 to usize".to_string())?;
456433
infos.reserve(num_proofs);
457-
arr.for_each(|_, svi| {
434+
arr.for_each::<_, ActorError>(|_, svi| {
458435
infos.push(svi.clone());
459436
Ok(())
460437
})
461438
.map_err(|e| {
462-
anyhow!(
439+
format!(
463440
"failed to iterate over proof verify array for miner {}: {}",
464-
addr,
465-
e
441+
addr, e
466442
)
467443
})?;
468444

@@ -545,22 +521,16 @@ impl Actor {
545521
CRON_QUEUE_HAMT_BITWIDTH,
546522
CRON_QUEUE_AMT_BITWIDTH,
547523
)
548-
.map_err(|e| {
549-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to load cron events")
550-
})?;
524+
.context("failed to load cron events")?;
551525

552526
let claims =
553527
make_map_with_root_and_bitwidth::<_, Claim>(&st.claims, rt.store(), HAMT_BIT_WIDTH)
554528
.map_err(|e| {
555529
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to load claims")
556530
})?;
557531
for epoch in st.first_cron_epoch..=rt_epoch {
558-
let epoch_events = load_cron_events(&events, epoch).map_err(|e| {
559-
e.downcast_default(
560-
ExitCode::USR_ILLEGAL_STATE,
561-
format!("failed to load cron events at {}", epoch),
562-
)
563-
})?;
532+
let epoch_events = load_cron_events(&events, epoch)
533+
.with_context(|| format!("failed to load cron events at {}", epoch))?;
564534

565535
if epoch_events.is_empty() {
566536
continue;
@@ -581,18 +551,13 @@ impl Actor {
581551
cron_events.push(evt);
582552
}
583553

584-
events.remove_all(&epoch_key(epoch)).map_err(|e| {
585-
e.downcast_default(
586-
ExitCode::USR_ILLEGAL_STATE,
587-
format!("failed to clear cron events at {}", epoch),
588-
)
589-
})?;
554+
events
555+
.remove_all(&epoch_key(epoch))
556+
.with_context(|| format!("failed to clear cron events at {}", epoch))?;
590557
}
591558

592559
st.first_cron_epoch = rt_epoch + 1;
593-
st.cron_event_queue = events.root().map_err(|e| {
594-
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "failed to flush events")
595-
})?;
560+
st.cron_event_queue = events.root().context("failed to flush events")?;
596561

597562
Ok(())
598563
})?;

0 commit comments

Comments
 (0)