Skip to content

Commit 9ff3db5

Browse files
committed
feat(miner): make precommit HAMT & AMT CIDs nullable
1 parent d5ef635 commit 9ff3db5

10 files changed

+221
-176
lines changed

actors/miner/src/bitfield_queue.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use fvm_shared::clock::ChainEpoch;
1212
use itertools::Itertools;
1313

1414
use super::QuantSpec;
15+
use super::PRECOMMIT_EXPIRY_AMT_BITWIDTH;
1516

1617
/// Wrapper for working with an AMT[ChainEpoch]*Bitfield functioning as a queue, bucketed by epoch.
1718
/// Keys in the queue are quantized (upwards), modulo some offset, to reduce the cardinality of keys.
@@ -21,7 +22,14 @@ pub struct BitFieldQueue<'db, BS> {
2122
}
2223

2324
impl<'db, BS: Blockstore> BitFieldQueue<'db, BS> {
24-
pub fn new(store: &'db BS, root: &Cid, quant: QuantSpec) -> Result<Self, AmtError> {
25+
pub fn new(store: &'db BS, quant: QuantSpec) -> Self {
26+
Self {
27+
amt: Array::<BitField, BS>::new_with_bit_width(store, PRECOMMIT_EXPIRY_AMT_BITWIDTH),
28+
quant,
29+
}
30+
}
31+
32+
pub fn load(store: &'db BS, root: &Cid, quant: QuantSpec) -> Result<Self, AmtError> {
2533
Ok(Self { amt: Array::load(root, store)?, quant })
2634
}
2735

actors/miner/src/deadline_state.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl Deadline {
314314
return Ok(());
315315
}
316316

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

477477
// Next, update the expiration queue.
478-
let mut deadline_expirations =
479-
BitFieldQueue::new(store, &self.expirations_epochs, quant)
480-
.map_err(|e| e.downcast_wrap("failed to load expiration epochs"))?;
478+
let mut deadline_expirations = BitFieldQueue::load(store, &self.expirations_epochs, quant)
479+
.map_err(|e| e.downcast_wrap("failed to load expiration epochs"))?;
481480
deadline_expirations
482481
.add_many_to_queue_values(partition_deadline_updates.iter().copied())
483482
.map_err(|e| e.downcast_wrap("failed to add expirations for new deadlines"))?;
@@ -552,7 +551,7 @@ impl Deadline {
552551
until: ChainEpoch,
553552
quant: QuantSpec,
554553
) -> anyhow::Result<(BitField, bool)> {
555-
let mut expirations = BitFieldQueue::new(store, &self.expirations_epochs, quant)?;
554+
let mut expirations = BitFieldQueue::load(store, &self.expirations_epochs, quant)?;
556555
let (popped, modified) = expirations
557556
.pop_until(until)
558557
.map_err(|e| e.downcast_wrap("failed to pop expiring partitions"))?;
@@ -741,7 +740,7 @@ impl Deadline {
741740
self.total_sectors -= removed_live_sectors + removed_dead_sectors;
742741

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

747746
expiration_epochs.cut(to_remove).map_err(|e| {

actors/miner/src/partition_state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl Partition {
458458
sectors: &BitField,
459459
) -> anyhow::Result<()> {
460460
let mut early_termination_queue =
461-
BitFieldQueue::new(store, &self.early_terminated, NO_QUANTIZATION)
461+
BitFieldQueue::load(store, &self.early_terminated, NO_QUANTIZATION)
462462
.map_err(|e| e.downcast_wrap("failed to load early termination queue"))?;
463463

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

649649
let mut processed = Vec::<u64>::new();
650650
let mut remaining: Option<(BitField, ChainEpoch)> = None;

0 commit comments

Comments
 (0)