diff --git a/filecoin-proofs/src/types/porep_config.rs b/filecoin-proofs/src/types/porep_config.rs index e255e8387..2eff1b324 100644 --- a/filecoin-proofs/src/types/porep_config.rs +++ b/filecoin-proofs/src/types/porep_config.rs @@ -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() @@ -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()), ); diff --git a/storage-proofs-core/src/api_version.rs b/storage-proofs-core/src/api_version.rs index 8dacfd745..a0966b54f 100644 --- a/storage-proofs-core/src/api_version.rs +++ b/storage-proofs-core/src/api_version.rs @@ -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]