Skip to content

Commit

Permalink
migrate miner
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Apr 14, 2022
1 parent 37e80f8 commit 88a7fe5
Show file tree
Hide file tree
Showing 15 changed files with 820 additions and 1,108 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion actors/miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ num-derive = "0.3.3"
lazy_static = "1.4.0"
log = "0.4.14"
byteorder = "1.4.3"
anyhow = "1.0.56"
itertools = "0.10.3"
fvm_ipld_blockstore = { version = "0.1" }
fvm_ipld_encoding = "0.1.0"
Expand Down
28 changes: 15 additions & 13 deletions actors/miner/src/bitfield_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::convert::TryInto;

use cid::Cid;
use fil_actors_runtime::{ActorDowncast, Array};
use fil_actors_runtime::{ActorContext, ActorDowncast, ActorError, Array};
use fvm_ipld_amt::Error as AmtError;
use fvm_ipld_bitfield::BitField;
use fvm_ipld_blockstore::Blockstore;
Expand All @@ -19,12 +19,16 @@ pub struct BitFieldQueue<'db, BS> {
}

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

/// Adds values to the queue entry for an epoch.
pub fn add_to_queue(&mut self, raw_epoch: ChainEpoch, values: &BitField) -> anyhow::Result<()> {
pub fn add_to_queue(
&mut self,
raw_epoch: ChainEpoch,
values: &BitField,
) -> Result<(), ActorError> {
if values.is_empty() {
// nothing to do.
return Ok(());
Expand All @@ -50,15 +54,15 @@ impl<'db, BS: Blockstore> BitFieldQueue<'db, BS> {
&mut self,
epoch: ChainEpoch,
values: impl IntoIterator<Item = u64>,
) -> anyhow::Result<()> {
) -> Result<(), ActorError> {
self.add_to_queue(epoch, &BitField::try_from_bits(values)?)
}

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

self.amt
Expand All @@ -70,22 +74,20 @@ impl<'db, BS: Blockstore> BitFieldQueue<'db, BS> {
} else {
**bitfield = bf;
}

Ok(())
})
.map_err(|e| e.downcast_wrap("failed to cut from bitfield queue"))?;
.context("failed to cut from bitfield queue")?;

self.amt
.batch_delete(epochs_to_remove, true)
.map_err(|e| e.downcast_wrap("failed to remove empty epochs from bitfield queue"))?;
.context("failed to remove empty epochs from bitfield queue")?;

Ok(())
}

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

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

self.amt.for_each_while(|epoch, bitfield| {
if epoch as ChainEpoch > until {
// break
return Ok(false);
return false;
}

popped_keys.push(epoch);
popped_values |= bitfield;
Ok(true)
true
})?;

if popped_keys.is_empty() {
Expand Down
9 changes: 4 additions & 5 deletions actors/miner/src/deadline_assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
use std::cmp::Ordering;
use std::collections::BinaryHeap;

use anyhow::anyhow;

use fil_actors_runtime::runtime::Policy;
use fil_actors_runtime::{actor_error, runtime::Policy, ActorError};

use super::{Deadline, SectorOnChainInfo};

Expand Down Expand Up @@ -140,7 +138,7 @@ pub fn assign_deadlines(
partition_size: u64,
deadlines: &[Option<Deadline>],
sectors: Vec<SectorOnChainInfo>,
) -> anyhow::Result<Vec<Vec<SectorOnChainInfo>>> {
) -> Result<Vec<Vec<SectorOnChainInfo>>, ActorError> {
struct Entry {
partition_size: u64,
info: DeadlineAssignmentInfo,
Expand Down Expand Up @@ -189,7 +187,8 @@ pub fn assign_deadlines(
let info = &mut heap.peek_mut().unwrap().info;

if info.max_partitions_reached(partition_size, max_partitions) {
return Err(anyhow!(
return Err(actor_error!(
illegal_state,
"max partitions limit {} reached for all deadlines",
max_partitions
));
Expand Down
Loading

0 comments on commit 88a7fe5

Please sign in to comment.