Skip to content

Commit

Permalink
feat(miner): make precommit HAMT & AMT CIDs nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jan 22, 2025
1 parent d5ef635 commit 75c7ba3
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 176 deletions.
10 changes: 9 additions & 1 deletion actors/miner/src/bitfield_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use fvm_shared::clock::ChainEpoch;
use itertools::Itertools;

use super::QuantSpec;
use super::PRECOMMIT_EXPIRY_AMT_BITWIDTH;

/// Wrapper for working with an AMT[ChainEpoch]*Bitfield functioning as a queue, bucketed by epoch.
/// Keys in the queue are quantized (upwards), modulo some offset, to reduce the cardinality of keys.
Expand All @@ -21,7 +22,14 @@ 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, quant: QuantSpec) -> Self {
Self {
amt: Array::<BitField, BS>::new_with_bit_width(store, PRECOMMIT_EXPIRY_AMT_BITWIDTH),
quant,
}
}

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

Expand Down
11 changes: 5 additions & 6 deletions actors/miner/src/deadline_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ impl Deadline {
return Ok(());
}

let mut queue = BitFieldQueue::new(store, &self.expirations_epochs, quant)
let mut queue = BitFieldQueue::load(store, &self.expirations_epochs, quant)
.map_err(|e| e.downcast_wrap("failed to load expiration queue"))?;
queue
.add_to_queue_values(expiration_epoch, partitions.iter().copied())
Expand Down Expand Up @@ -475,9 +475,8 @@ impl Deadline {
self.partitions = partitions.flush()?;

// Next, update the expiration queue.
let mut deadline_expirations =
BitFieldQueue::new(store, &self.expirations_epochs, quant)
.map_err(|e| e.downcast_wrap("failed to load expiration epochs"))?;
let mut deadline_expirations = BitFieldQueue::load(store, &self.expirations_epochs, quant)
.map_err(|e| e.downcast_wrap("failed to load expiration epochs"))?;
deadline_expirations
.add_many_to_queue_values(partition_deadline_updates.iter().copied())
.map_err(|e| e.downcast_wrap("failed to add expirations for new deadlines"))?;
Expand Down Expand Up @@ -552,7 +551,7 @@ impl Deadline {
until: ChainEpoch,
quant: QuantSpec,
) -> anyhow::Result<(BitField, bool)> {
let mut expirations = BitFieldQueue::new(store, &self.expirations_epochs, quant)?;
let mut expirations = BitFieldQueue::load(store, &self.expirations_epochs, quant)?;
let (popped, modified) = expirations
.pop_until(until)
.map_err(|e| e.downcast_wrap("failed to pop expiring partitions"))?;
Expand Down Expand Up @@ -741,7 +740,7 @@ impl Deadline {
self.total_sectors -= removed_live_sectors + removed_dead_sectors;

// Update expiration bitfields.
let mut expiration_epochs = BitFieldQueue::new(store, &self.expirations_epochs, quant)
let mut expiration_epochs = BitFieldQueue::load(store, &self.expirations_epochs, quant)
.map_err(|e| e.downcast_wrap("failed to load expiration queue"))?;

expiration_epochs.cut(to_remove).map_err(|e| {
Expand Down
4 changes: 2 additions & 2 deletions actors/miner/src/partition_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl Partition {
sectors: &BitField,
) -> anyhow::Result<()> {
let mut early_termination_queue =
BitFieldQueue::new(store, &self.early_terminated, NO_QUANTIZATION)
BitFieldQueue::load(store, &self.early_terminated, NO_QUANTIZATION)
.map_err(|e| e.downcast_wrap("failed to load early termination queue"))?;

early_termination_queue
Expand Down Expand Up @@ -644,7 +644,7 @@ impl Partition {
) -> anyhow::Result<(TerminationResult, /* has more */ bool)> {
// Load early terminations.
let mut early_terminated_queue =
BitFieldQueue::new(store, &self.early_terminated, NO_QUANTIZATION)?;
BitFieldQueue::load(store, &self.early_terminated, NO_QUANTIZATION)?;

let mut processed = Vec::<u64>::new();
let mut remaining: Option<(BitField, ChainEpoch)> = None;
Expand Down
Loading

0 comments on commit 75c7ba3

Please sign in to comment.