Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(miner): make precommit HAMT & AMT CIDs nullable #1605

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading