Skip to content

Commit 94671d0

Browse files
migrate miner
1 parent 272041b commit 94671d0

15 files changed

+820
-1108
lines changed

Cargo.lock

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

actors/miner/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ num-derive = "0.3.3"
2626
lazy_static = "1.4.0"
2727
log = "0.4.14"
2828
byteorder = "1.4.3"
29-
anyhow = "1.0.56"
3029
itertools = "0.10.3"
3130
fvm_ipld_blockstore = { version = "0.1" }
3231
fvm_ipld_encoding = "0.1.0"

actors/miner/src/bitfield_queue.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::convert::TryInto;
55

66
use cid::Cid;
7-
use fil_actors_runtime::{ActorDowncast, Array};
7+
use fil_actors_runtime::{ActorContext, ActorDowncast, ActorError, Array};
88
use fvm_ipld_amt::Error as AmtError;
99
use fvm_ipld_bitfield::BitField;
1010
use fvm_ipld_blockstore::Blockstore;
@@ -19,12 +19,16 @@ pub struct BitFieldQueue<'db, BS> {
1919
}
2020

2121
impl<'db, BS: Blockstore> BitFieldQueue<'db, BS> {
22-
pub fn new(store: &'db BS, root: &Cid, quant: QuantSpec) -> Result<Self, AmtError> {
22+
pub fn new(store: &'db BS, root: &Cid, quant: QuantSpec) -> Result<Self, AmtError<BS::Error>> {
2323
Ok(Self { amt: Array::load(root, store)?, quant })
2424
}
2525

2626
/// Adds values to the queue entry for an epoch.
27-
pub fn add_to_queue(&mut self, raw_epoch: ChainEpoch, values: &BitField) -> anyhow::Result<()> {
27+
pub fn add_to_queue(
28+
&mut self,
29+
raw_epoch: ChainEpoch,
30+
values: &BitField,
31+
) -> Result<(), ActorError> {
2832
if values.is_empty() {
2933
// nothing to do.
3034
return Ok(());
@@ -50,15 +54,15 @@ impl<'db, BS: Blockstore> BitFieldQueue<'db, BS> {
5054
&mut self,
5155
epoch: ChainEpoch,
5256
values: impl IntoIterator<Item = u64>,
53-
) -> anyhow::Result<()> {
57+
) -> Result<(), ActorError> {
5458
self.add_to_queue(epoch, &BitField::try_from_bits(values)?)
5559
}
5660

5761
/// Cut cuts the elements from the bits in the given bitfield out of the queue,
5862
/// shifting other bits down and removing any newly empty entries.
5963
///
6064
/// See the docs on `BitField::cut` to better understand what it does.
61-
pub fn cut(&mut self, to_cut: &BitField) -> anyhow::Result<()> {
65+
pub fn cut(&mut self, to_cut: &BitField) -> Result<(), ActorError> {
6266
let mut epochs_to_remove = Vec::<u64>::new();
6367

6468
self.amt
@@ -70,22 +74,20 @@ impl<'db, BS: Blockstore> BitFieldQueue<'db, BS> {
7074
} else {
7175
**bitfield = bf;
7276
}
73-
74-
Ok(())
7577
})
76-
.map_err(|e| e.downcast_wrap("failed to cut from bitfield queue"))?;
78+
.context("failed to cut from bitfield queue")?;
7779

7880
self.amt
7981
.batch_delete(epochs_to_remove, true)
80-
.map_err(|e| e.downcast_wrap("failed to remove empty epochs from bitfield queue"))?;
82+
.context("failed to remove empty epochs from bitfield queue")?;
8183

8284
Ok(())
8385
}
8486

8587
pub fn add_many_to_queue_values(
8688
&mut self,
8789
values: impl IntoIterator<Item = (ChainEpoch, u64)>,
88-
) -> anyhow::Result<()> {
90+
) -> Result<(), ActorError> {
8991
// Pre-quantize to reduce the number of updates.
9092
let mut quantized_values: Vec<_> = values
9193
.into_iter()
@@ -110,19 +112,19 @@ impl<'db, BS: Blockstore> BitFieldQueue<'db, BS> {
110112

111113
/// Removes and returns all values with keys less than or equal to until.
112114
/// Modified return value indicates whether this structure has been changed by the call.
113-
pub fn pop_until(&mut self, until: ChainEpoch) -> anyhow::Result<(BitField, bool)> {
115+
pub fn pop_until(&mut self, until: ChainEpoch) -> Result<(BitField, bool), ActorError> {
114116
let mut popped_values = BitField::new();
115117
let mut popped_keys = Vec::<u64>::new();
116118

117119
self.amt.for_each_while(|epoch, bitfield| {
118120
if epoch as ChainEpoch > until {
119121
// break
120-
return Ok(false);
122+
return false;
121123
}
122124

123125
popped_keys.push(epoch);
124126
popped_values |= bitfield;
125-
Ok(true)
127+
true
126128
})?;
127129

128130
if popped_keys.is_empty() {

actors/miner/src/deadline_assignment.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
use std::cmp::Ordering;
55
use std::collections::BinaryHeap;
66

7-
use anyhow::anyhow;
8-
9-
use fil_actors_runtime::runtime::Policy;
7+
use fil_actors_runtime::{actor_error, runtime::Policy, ActorError};
108

119
use super::{Deadline, SectorOnChainInfo};
1210

@@ -140,7 +138,7 @@ pub fn assign_deadlines(
140138
partition_size: u64,
141139
deadlines: &[Option<Deadline>],
142140
sectors: Vec<SectorOnChainInfo>,
143-
) -> anyhow::Result<Vec<Vec<SectorOnChainInfo>>> {
141+
) -> Result<Vec<Vec<SectorOnChainInfo>>, ActorError> {
144142
struct Entry {
145143
partition_size: u64,
146144
info: DeadlineAssignmentInfo,
@@ -189,7 +187,8 @@ pub fn assign_deadlines(
189187
let info = &mut heap.peek_mut().unwrap().info;
190188

191189
if info.max_partitions_reached(partition_size, max_partitions) {
192-
return Err(anyhow!(
190+
return Err(actor_error!(
191+
illegal_state,
193192
"max partitions limit {} reached for all deadlines",
194193
max_partitions
195194
));

0 commit comments

Comments
 (0)