From bcad63cbc9d5493854bbe71b6e80767bb50ae823 Mon Sep 17 00:00:00 2001 From: nemo Date: Tue, 5 Dec 2023 10:29:13 -0500 Subject: [PATCH] Simpify testing of api features (#1740) * feat: simpify testing of api features * feat: rename aggregate_proofs to aggregate_seal_proofs --- filecoin-proofs/src/types/porep_config.rs | 21 +++ filecoin-proofs/tests/api.rs | 213 ++++++++++++---------- 2 files changed, 142 insertions(+), 92 deletions(-) diff --git a/filecoin-proofs/src/types/porep_config.rs b/filecoin-proofs/src/types/porep_config.rs index 2af5ea5f2..a923d95ed 100644 --- a/filecoin-proofs/src/types/porep_config.rs +++ b/filecoin-proofs/src/types/porep_config.rs @@ -73,6 +73,27 @@ impl PoRepConfig { } } + pub fn new_groth16_with_features( + sector_size: u64, + porep_id: [u8; 32], + api_version: ApiVersion, + api_features: Vec, + ) -> Self { + Self { + sector_size: SectorSize(sector_size), + partitions: PoRepProofPartitions( + *POREP_PARTITIONS + .read() + .expect("POREP_PARTITIONS poisoned") + .get(§or_size) + .expect("unknown sector size"), + ), + porep_id, + api_version, + api_features, + } + } + #[inline] pub fn enable_feature(&mut self, feat: ApiFeature) { if !self.feature_enabled(feat) { diff --git a/filecoin-proofs/tests/api.rs b/filecoin-proofs/tests/api.rs index 3f9350139..c6f67cc84 100644 --- a/filecoin-proofs/tests/api.rs +++ b/filecoin-proofs/tests/api.rs @@ -86,32 +86,35 @@ fn to_porep_id_verified(registered_seal_proof: u64, api_version: ApiVersion) -> fn test_seal_lifecycle_2kib_base_8() -> Result<()> { // The first value is RegisteredSealProof value // The second value is the ApiVersion to use - // The third value is whether to use SyntheticPoRep + // The third value is enabled Api features let test_inputs = vec![ - (0u64, ApiVersion::V1_0_0, false), + (0u64, ApiVersion::V1_0_0, Vec::new()), ( MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1, ApiVersion::V1_1_0, - false, + Vec::new(), ), ( MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1, ApiVersion::V1_2_0, - false, + Vec::new(), ), ( MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1, ApiVersion::V1_2_0, - true, + vec![ApiFeature::SyntheticPoRep], ), ]; - for (porep_id_num, api_version, use_synthetic) in test_inputs { + for (porep_id_num, api_version, features) in test_inputs { let porep_id = to_porep_id_verified(porep_id_num, api_version); - let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_2_KIB, porep_id, api_version); - if use_synthetic { - porep_config.enable_feature(ApiFeature::SyntheticPoRep); - } + let porep_config = PoRepConfig::new_groth16_with_features( + SECTOR_SIZE_2_KIB, + porep_id, + api_version, + features, + ); + seal_lifecycle::(&porep_config)?; } @@ -123,31 +126,34 @@ fn test_seal_lifecycle_2kib_base_8() -> Result<()> { fn test_seal_lifecycle_upgrade_2kib_base_8() -> Result<()> { // The first value is RegisteredSealProof value // The second value is the ApiVersion to use - // The third value is whether to use SyntheticPoRep + // The third value is enabled Api features let test_inputs = vec![ ( MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1, ApiVersion::V1_1_0, - false, + Vec::new(), ), ( MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1, ApiVersion::V1_2_0, - false, + Vec::new(), ), ( MAX_LEGACY_REGISTERED_SEAL_PROOF_ID + 1, ApiVersion::V1_2_0, - true, + vec![ApiFeature::SyntheticPoRep], ), ]; - for (porep_id_num, api_version, use_synthetic) in test_inputs { + for (porep_id_num, api_version, features) in test_inputs { let porep_id = to_porep_id_verified(porep_id_num, api_version); - let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_2_KIB, porep_id, api_version); - if use_synthetic { - porep_config.enable_feature(ApiFeature::SyntheticPoRep); - } + let porep_config = PoRepConfig::new_groth16_with_features( + SECTOR_SIZE_2_KIB, + porep_id, + api_version, + features, + ); + seal_lifecycle_upgrade::(&porep_config)?; } @@ -158,17 +164,24 @@ fn test_seal_lifecycle_upgrade_2kib_base_8() -> Result<()> { #[ignore] fn test_seal_lifecycle_4kib_base_8() -> Result<()> { let test_inputs = vec![ - (ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, false), - (ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, false), - (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, false), - (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, true), + (ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()), + (ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()), + (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()), + ( + ARBITRARY_POREP_ID_V1_2_0, + ApiVersion::V1_2_0, + vec![ApiFeature::SyntheticPoRep], + ), ]; - for (porep_id, api_version, use_synthetic) in test_inputs { - let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_4_KIB, porep_id, api_version); - if use_synthetic { - porep_config.enable_feature(ApiFeature::SyntheticPoRep); - } + for (porep_id, api_version, features) in test_inputs { + let porep_config = PoRepConfig::new_groth16_with_features( + SECTOR_SIZE_4_KIB, + porep_id, + api_version, + features, + ); + seal_lifecycle::(&porep_config)?; } @@ -179,17 +192,24 @@ fn test_seal_lifecycle_4kib_base_8() -> Result<()> { #[ignore] fn test_seal_lifecycle_upgrade_4kib_base_8() -> Result<()> { let test_inputs = vec![ - (ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, false), - (ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, false), - (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, false), - (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, true), + (ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()), + (ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()), + (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()), + ( + ARBITRARY_POREP_ID_V1_2_0, + ApiVersion::V1_2_0, + vec![ApiFeature::SyntheticPoRep], + ), ]; - for (porep_id, api_version, use_synthetic) in test_inputs { - let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_4_KIB, porep_id, api_version); - if use_synthetic { - porep_config.enable_feature(ApiFeature::SyntheticPoRep); - } + for (porep_id, api_version, features) in test_inputs { + let porep_config = PoRepConfig::new_groth16_with_features( + SECTOR_SIZE_4_KIB, + porep_id, + api_version, + features, + ); + seal_lifecycle_upgrade::(&porep_config)?; } @@ -200,17 +220,24 @@ fn test_seal_lifecycle_upgrade_4kib_base_8() -> Result<()> { #[ignore] fn test_seal_lifecycle_16kib_base_8() -> Result<()> { let test_inputs = vec![ - (ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, false), - (ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, false), - (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, false), - (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, true), + (ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()), + (ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()), + (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()), + ( + ARBITRARY_POREP_ID_V1_2_0, + ApiVersion::V1_2_0, + vec![ApiFeature::SyntheticPoRep], + ), ]; - for (porep_id, api_version, use_synthetic) in test_inputs { - let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_16_KIB, porep_id, api_version); - if use_synthetic { - porep_config.enable_feature(ApiFeature::SyntheticPoRep); - } + for (porep_id, api_version, features) in test_inputs { + let porep_config = PoRepConfig::new_groth16_with_features( + SECTOR_SIZE_16_KIB, + porep_id, + api_version, + features, + ); + seal_lifecycle::(&porep_config)?; } @@ -221,17 +248,24 @@ fn test_seal_lifecycle_16kib_base_8() -> Result<()> { #[ignore] fn test_seal_lifecycle_upgrade_16kib_base_8() -> Result<()> { let test_inputs = vec![ - (ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, false), - (ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, false), - (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, false), - (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, true), + (ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()), + (ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()), + (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()), + ( + ARBITRARY_POREP_ID_V1_2_0, + ApiVersion::V1_2_0, + vec![ApiFeature::SyntheticPoRep], + ), ]; - for (porep_id, api_version, use_synthetic) in test_inputs { - let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_16_KIB, porep_id, api_version); - if use_synthetic { - porep_config.enable_feature(ApiFeature::SyntheticPoRep); - } + for (porep_id, api_version, features) in test_inputs { + let porep_config = PoRepConfig::new_groth16_with_features( + SECTOR_SIZE_16_KIB, + porep_id, + api_version, + features, + ); + seal_lifecycle_upgrade::(&porep_config)?; } @@ -242,17 +276,24 @@ fn test_seal_lifecycle_upgrade_16kib_base_8() -> Result<()> { #[ignore] fn test_seal_lifecycle_32kib_base_8() -> Result<()> { let test_inputs = vec![ - (ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, false), - (ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, false), - (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, false), - (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, true), + (ARBITRARY_POREP_ID_V1_0_0, ApiVersion::V1_0_0, Vec::new()), + (ARBITRARY_POREP_ID_V1_1_0, ApiVersion::V1_1_0, Vec::new()), + (ARBITRARY_POREP_ID_V1_2_0, ApiVersion::V1_2_0, Vec::new()), + ( + ARBITRARY_POREP_ID_V1_2_0, + ApiVersion::V1_2_0, + vec![ApiFeature::SyntheticPoRep], + ), ]; - for (porep_id, api_version, use_synthetic) in test_inputs { - let mut porep_config = PoRepConfig::new_groth16(SECTOR_SIZE_32_KIB, porep_id, api_version); - if use_synthetic { - porep_config.enable_feature(ApiFeature::SyntheticPoRep); - } + for (porep_id, api_version, features) in test_inputs { + let porep_config = PoRepConfig::new_groth16_with_features( + SECTOR_SIZE_32_KIB, + porep_id, + api_version, + features, + ); + seal_lifecycle::(&porep_config)?; } @@ -386,9 +427,12 @@ fn test_seal_lifecycle_64gib_porep_id_v1_2_top_8_8_2_api_v1_2() -> Result<()> { let porep_id = to_porep_id_verified(porep_id_v1_2, ApiVersion::V1_2_0); assert!(!is_legacy_porep_id(porep_id)); - let mut porep_config = - PoRepConfig::new_groth16(SECTOR_SIZE_64_GIB, porep_id, ApiVersion::V1_2_0); - porep_config.enable_feature(ApiFeature::SyntheticPoRep); + let porep_config = PoRepConfig::new_groth16_with_features( + SECTOR_SIZE_64_GIB, + porep_id, + ApiVersion::V1_2_0, + vec![ApiFeature::SyntheticPoRep], + ); seal_lifecycle::(&porep_config) } @@ -448,7 +492,7 @@ fn test_seal_proof_aggregation_1_2kib_porep_id_v1_1_base_8() -> Result<()> { let mut porep_id = [0u8; 32]; porep_id[..8].copy_from_slice(&porep_id_v1_1.to_le_bytes()); assert!(!is_legacy_porep_id(porep_id)); - aggregate_proofs::(SECTOR_SIZE_2_KIB, &porep_id, proofs_to_aggregate) + aggregate_seal_proofs::(SECTOR_SIZE_2_KIB, &porep_id, proofs_to_aggregate) } #[test] @@ -458,7 +502,7 @@ fn test_seal_proof_aggregation_3_2kib_porep_id_v1_1_base_8() -> Result<()> { let porep_id = ARBITRARY_POREP_ID_V1_1_0; assert!(!is_legacy_porep_id(porep_id)); - aggregate_proofs::(SECTOR_SIZE_2_KIB, &porep_id, proofs_to_aggregate) + aggregate_seal_proofs::(SECTOR_SIZE_2_KIB, &porep_id, proofs_to_aggregate) } #[test] @@ -468,7 +512,7 @@ fn test_seal_proof_aggregation_5_2kib_porep_id_v1_1_base_8() -> Result<()> { let porep_id = ARBITRARY_POREP_ID_V1_1_0; assert!(!is_legacy_porep_id(porep_id)); - aggregate_proofs::(SECTOR_SIZE_2_KIB, &porep_id, proofs_to_aggregate) + aggregate_seal_proofs::(SECTOR_SIZE_2_KIB, &porep_id, proofs_to_aggregate) } #[test] @@ -478,7 +522,7 @@ fn test_seal_proof_aggregation_257_2kib_porep_id_v1_1_base_8() -> Result<()> { let porep_id = ARBITRARY_POREP_ID_V1_1_0; assert!(!is_legacy_porep_id(porep_id)); - aggregate_proofs::(SECTOR_SIZE_2_KIB, &porep_id, proofs_to_aggregate) + aggregate_seal_proofs::(SECTOR_SIZE_2_KIB, &porep_id, proofs_to_aggregate) } #[test] @@ -488,7 +532,7 @@ fn test_seal_proof_aggregation_2_4kib_porep_id_v1_1_base_8() -> Result<()> { let porep_id = ARBITRARY_POREP_ID_V1_1_0; assert!(!is_legacy_porep_id(porep_id)); - aggregate_proofs::(SECTOR_SIZE_4_KIB, &porep_id, proofs_to_aggregate) + aggregate_seal_proofs::(SECTOR_SIZE_4_KIB, &porep_id, proofs_to_aggregate) } #[test] @@ -498,7 +542,7 @@ fn test_seal_proof_aggregation_1_32kib_porep_id_v1_1_base_8() -> Result<()> { let porep_id = ARBITRARY_POREP_ID_V1_1_0; assert!(!is_legacy_porep_id(porep_id)); - aggregate_proofs::(SECTOR_SIZE_32_KIB, &porep_id, proofs_to_aggregate) + aggregate_seal_proofs::(SECTOR_SIZE_32_KIB, &porep_id, proofs_to_aggregate) } #[test] @@ -508,7 +552,7 @@ fn test_seal_proof_aggregation_818_32kib_porep_id_v1_1_base_8() -> Result<()> { let porep_id = ARBITRARY_POREP_ID_V1_1_0; assert!(!is_legacy_porep_id(porep_id)); - aggregate_proofs::(SECTOR_SIZE_32_KIB, &porep_id, proofs_to_aggregate) + aggregate_seal_proofs::(SECTOR_SIZE_32_KIB, &porep_id, proofs_to_aggregate) } //#[test] @@ -518,7 +562,7 @@ fn test_seal_proof_aggregation_818_32kib_porep_id_v1_1_base_8() -> Result<()> { // // let porep_id = ARBITRARY_POREP_ID_V1_1_0; // assert!(!is_legacy_porep_id(porep_id)); -// let verified = aggregate_proofs::( +// let verified = aggregate_seal_proofs::( // SECTOR_SIZE_32_GIB, // &porep_id, // ApiVersion::V1_1_0, @@ -536,7 +580,7 @@ fn test_seal_proof_aggregation_818_32kib_porep_id_v1_1_base_8() -> Result<()> { // // let porep_id = ARBITRARY_POREP_ID_V1_1_0; // assert!(!is_legacy_porep_id(porep_id)); -// let verified = aggregate_proofs::( +// let verified = aggregate_seal_proofs::( // SECTOR_SIZE_64_GIB, // &porep_id, // ApiVersion::V1_1_0, @@ -547,21 +591,7 @@ fn test_seal_proof_aggregation_818_32kib_porep_id_v1_1_base_8() -> Result<()> { // Ok(()) //} -//#[test] -//#[ignore] -//fn test_seal_proof_aggregation_1024_2kib_porep_id_v1_1_base_8() -> Result<()> { -// let proofs_to_aggregate = 1024; -// inner_test_seal_proof_aggregation_2kib_porep_id_v1_1_base_8(proofs_to_aggregate) -//} -// -//#[test] -//#[ignore] -//fn test_seal_proof_aggregation_65536_2kib_porep_id_v1_1_base_8() -> Result<()> { -// let proofs_to_aggregate = 65536; -// inner_test_seal_proof_aggregation_2kib_porep_id_v1_1_base_8(proofs_to_aggregate) -//} - -fn aggregate_proofs( +fn aggregate_seal_proofs( sector_size: u64, porep_id: &[u8; 32], num_proofs_to_aggregate: usize, @@ -632,7 +662,6 @@ fn aggregate_proofs( Ok(()) } - fn get_layer_file_paths(cache_dir: &tempfile::TempDir) -> Vec { let mut list: Vec<_> = read_dir(cache_dir) .unwrap_or_else(|_| panic!("failed to read directory {:?}", cache_dir))