Skip to content

Commit

Permalink
refactor: define conflicting features in a more general way
Browse files Browse the repository at this point in the history
  • Loading branch information
vmx committed Dec 19, 2023
1 parent 1f3b235 commit e2153ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
18 changes: 8 additions & 10 deletions filecoin-proofs/src/types/porep_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,16 @@ impl PoRepConfig {

#[inline]
pub fn enable_feature(&mut self, feat: ApiFeature) -> Result<()> {
for conflict in feat.conflicting_features() {
if self.feature_enabled(*conflict) {
return Err(anyhow!(
"Cannot enable feature `{feat}` when `{conflict}` is already enabled"
));
}
}

match feat {
ApiFeature::SyntheticPoRep => {
if self.feature_enabled(ApiFeature::NonInteractivePoRep) {
return Err(anyhow!(
"Cannot enable Synthetic PoRep when Non-interactive PoRep is already enabled"));
}

self.partitions = PoRepProofPartitions(
*POREP_PARTITIONS
.read()
Expand All @@ -116,11 +119,6 @@ impl PoRepConfig {
);
}
ApiFeature::NonInteractivePoRep => {
if self.feature_enabled(ApiFeature::SyntheticPoRep) {
return Err(anyhow!(
"Cannot enable Non-interactive PoRep when Synthetic PoRep is already enabled"));
}

self.partitions = PoRepProofPartitions(
constants::get_porep_non_interactive_partitions(self.sector_size.into()),
);
Expand Down
18 changes: 18 additions & 0 deletions storage-proofs-core/src/api_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@ impl ApiFeature {
ApiFeature::SyntheticPoRep | ApiFeature::NonInteractivePoRep => None,
}
}

/// Return the features that are in conflict with the current one.
pub fn conflicting_features(&self) -> &[ApiFeature] {
match self {
ApiFeature::SyntheticPoRep => &[ApiFeature::NonInteractivePoRep],
ApiFeature::NonInteractivePoRep => &[ApiFeature::SyntheticPoRep],
}
}
}

impl Display for ApiFeature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let api_feature_str = match self {
Self::SyntheticPoRep => "synthetic-porep",
Self::NonInteractivePoRep => "non-interactive-porep",
};
write!(f, "{}", api_feature_str)
}
}

#[test]
Expand Down

0 comments on commit e2153ad

Please sign in to comment.