From f439723c1675e46330f5e89eed9d44326a131397 Mon Sep 17 00:00:00 2001 From: Alexander Cyon Date: Sat, 12 Oct 2024 08:40:09 +0200 Subject: [PATCH] remove prints --- .../next_derivation_entity_index_assigner.rs | 13 +-- .../provider/factor_instances_cache.rs | 36 ++++---- .../provider/factor_instances_provider.rs | 88 ++----------------- .../factor_instances_provider_unit_tests.rs | 4 - .../provider/test_sargon_os.rs | 9 +- 5 files changed, 27 insertions(+), 123 deletions(-) diff --git a/src/factor_instances_provider/next_index_assigner/next_derivation_entity_index_assigner.rs b/src/factor_instances_provider/next_index_assigner/next_derivation_entity_index_assigner.rs index b65e7417..84716ea1 100644 --- a/src/factor_instances_provider/next_index_assigner/next_derivation_entity_index_assigner.rs +++ b/src/factor_instances_provider/next_index_assigner/next_derivation_entity_index_assigner.rs @@ -109,17 +109,6 @@ impl NextDerivationEntityIndexAssigner { let max_index = std::cmp::max(next_from_profile, next_from_cache); - let next = max_index.add_n(ephemeral); - println!( - "šŸ± {} => adding ephemeral {} ===> next: {:?}", - if next_from_cache > next_from_profile { - format!(" using `next_from_cache`: {:?}", next_from_cache) - } else { - format!(" using `next_from_profile`: {:?}", next_from_profile) - }, - ephemeral, - next - ); - next + max_index.add_n(ephemeral) } } diff --git a/src/factor_instances_provider/provider/factor_instances_cache.rs b/src/factor_instances_provider/provider/factor_instances_cache.rs index f634ab9a..650d064e 100644 --- a/src/factor_instances_provider/provider/factor_instances_cache.rs +++ b/src/factor_instances_provider/provider/factor_instances_cache.rs @@ -116,24 +116,24 @@ impl FactorInstancesCache { /// in the future. pub fn insert_for_factor( &mut self, - factor_source_id: FactorSourceIDFromHash, - instances: FactorInstances, + factor_source_id: &FactorSourceIDFromHash, + instances: &FactorInstances, ) -> Result { - let instances = instances.into_iter().collect_vec(); + let instances = instances.clone().into_iter().collect_vec(); let instances_by_agnostic_path = instances .into_iter() .into_group_map_by(|f| f.agnostic_path()) .into_iter() .map(|(k, v)| { - if v.iter().any(|f| f.factor_source_id != factor_source_id) { + if v.iter().any(|f| f.factor_source_id != *factor_source_id) { return Err(CommonError::FactorSourceDiscrepancy); } Ok((k, FactorInstances::from_iter(v))) }) .collect::>>()?; let mut skipped_an_index_resulting_in_non_contiguousness = false; - if let Some(existing_for_factor) = self.map.get_mut(&factor_source_id) { + if let Some(existing_for_factor) = self.map.get_mut(factor_source_id) { for (agnostic_path, instances) in instances_by_agnostic_path { let instances = instances.factor_instances(); @@ -165,7 +165,7 @@ impl FactorInstancesCache { } } else { self.map - .insert(factor_source_id, instances_by_agnostic_path); + .insert(*factor_source_id, instances_by_agnostic_path); } Ok(skipped_an_index_resulting_in_non_contiguousness) @@ -174,7 +174,7 @@ impl FactorInstancesCache { /// Inserts all instance in `per_factor`. pub fn insert_all( &mut self, - per_factor: IndexMap, + per_factor: &IndexMap, ) -> Result<()> { for (factor_source_id, instances) in per_factor { _ = self.insert_for_factor(factor_source_id, instances)?; @@ -319,14 +319,14 @@ impl FactorInstancesCache { Some(instances.clone()) } - pub fn delete(&mut self, pf_instances: IndexMap) { + pub fn delete(&mut self, pf_instances: &IndexMap) { for (factor_source_id, instances_to_delete) in pf_instances { if instances_to_delete.is_empty() { continue; } let existing_for_factor = self .map - .get_mut(&factor_source_id) + .get_mut(factor_source_id) .expect("expected to delete factors"); let instances_to_delete_by_path = instances_to_delete.factor_instances() @@ -391,7 +391,7 @@ impl FactorInstancesCache { fn factor_source_ids(&self) -> IndexSet { self.map.keys().cloned().collect() } - pub fn insert(&mut self, pf_instances: IndexMap) { + pub fn insert(&mut self, pf_instances: &IndexMap) { self.insert_all(pf_instances).expect("works") } @@ -465,7 +465,7 @@ mod tests { fsid, ); assert!(!sut - .insert_for_factor(fsid, FactorInstances::from_iter([fi0])) + .insert_for_factor(&fsid, &FactorInstances::from_iter([fi0])) .unwrap()); let fi2 = HierarchicalDeterministicFactorInstance::mainnet_tx( CAP26EntityKind::Account, @@ -473,7 +473,7 @@ mod tests { fsid, ); assert!(sut - .insert_for_factor(fsid, FactorInstances::from_iter([fi2])) + .insert_for_factor(&fsid, &FactorInstances::from_iter([fi2])) .unwrap(),); } @@ -487,8 +487,8 @@ mod tests { ); assert!(sut .insert_for_factor( - FactorSourceIDFromHash::fs1(), - FactorInstances::from_iter([fi0]) + &FactorSourceIDFromHash::fs1(), + &FactorInstances::from_iter([fi0]) ) .is_err()); } @@ -523,11 +523,11 @@ mod tests { }) .collect::>(); - sut.insert_for_factor(fsid, FactorInstances::from(instances)) + sut.insert_for_factor(&fsid, &FactorInstances::from(instances)) .unwrap(); } - sut.delete(to_delete); + sut.delete(&to_delete); assert_eq!( sut.get_poly_factor( &factor_source_ids, @@ -558,11 +558,11 @@ mod tests { fsid, ); assert!(!sut - .insert_for_factor(fsid, FactorInstances::from_iter([fi0.clone(), fi1])) + .insert_for_factor(&fsid, &FactorInstances::from_iter([fi0.clone(), fi1])) .unwrap()); assert_eq!( - sut.insert_for_factor(fsid, FactorInstances::from_iter([fi0.clone()])) + sut.insert_for_factor(&fsid, &FactorInstances::from_iter([fi0.clone()])) .err() .unwrap(), CommonError::CacheAlreadyContainsFactorInstance { diff --git a/src/factor_instances_provider/provider/factor_instances_provider.rs b/src/factor_instances_provider/provider/factor_instances_provider.rs index 9aa60f1d..c3442ff5 100644 --- a/src/factor_instances_provider/provider/factor_instances_provider.rs +++ b/src/factor_instances_provider/provider/factor_instances_provider.rs @@ -49,7 +49,7 @@ impl FactorInstancesProvider { interactors, ) .await?; - cache.insert(derived.clone()); + cache.insert(&derived); let derived = derived .get(&factor_source.factor_source_id()) @@ -290,10 +290,6 @@ impl FactorInstancesProvider { cache: &mut FactorInstancesCache, interactors: Arc, ) -> Result { - println!("\n\nšŸŒˆ start: {:?}", quantified_derivation_preset,); - - println!("šŸŽ­ cache {:?}", cache); - let originally_requested_quantified_derivation_preset = quantified_derivation_preset; let profile = profile.into(); @@ -309,24 +305,10 @@ impl FactorInstancesProvider { )?; if let Some(satisfied_by_cache) = cached.satisfied() { - let outcome = InternalFactorInstancesProviderOutcome::satisfied_by_cache( + cache.delete(&satisfied_by_cache); // Consume! + return Ok(InternalFactorInstancesProviderOutcome::satisfied_by_cache( satisfied_by_cache.clone(), - ); - println!( - "šŸ—ƒļøā­ļø Satisfied by cache: {:?}", - satisfied_by_cache - .values() - .flat_map(|xs| { - xs.factor_instances() - .into_iter() - .map(|x| x.derivation_entity_index()) - .collect_vec() - }) - .collect_vec() - ); - // consume - cache.delete(satisfied_by_cache); - return Ok(outcome); + )); } let pf_newly_derived = Self::derive_more( @@ -341,32 +323,6 @@ impl FactorInstancesProvider { let pf_found_in_cache_leq_requested = cached.partially_satisfied()?; - println!( - "šŸ¤” pf_newly_derived {:?}", - pf_newly_derived - .values() - .flat_map(|xs| { - xs.factor_instances() - .into_iter() - .map(|x| x.derivation_entity_index()) - .collect_vec() - }) - .collect_vec() - ); - - println!( - "šŸ¤” pf_found_in_cache_leq_requested {:?}", - pf_found_in_cache_leq_requested - .values() - .flat_map(|xs| { - xs.factor_instances() - .into_iter() - .map(|x| x.derivation_entity_index()) - .collect_vec() - }) - .collect_vec() - ); - let Split { pf_to_use_directly, pf_to_cache, @@ -376,39 +332,8 @@ impl FactorInstancesProvider { &pf_newly_derived, ); - println!( - "šŸ¤” pf_to_use_directly {:?}", - pf_to_use_directly - .values() - .flat_map(|xs| { - xs.factor_instances() - .into_iter() - .map(|x| x.derivation_entity_index()) - .collect_vec() - }) - .collect_vec() - ); - - println!( - "šŸ¤” pf_to_cache {:?}", - pf_to_cache - .values() - .flat_map(|xs| { - xs.factor_instances() - .into_iter() - .map(|x| x.derivation_entity_index()) - .collect_vec() - }) - .collect_vec() - ); - println!("šŸŽ­ cache {:?}", cache); - println!("šŸ deleting #{}", pf_found_in_cache_leq_requested.len()); - cache.delete(pf_found_in_cache_leq_requested.clone()); - - println!("šŸŽ­ cache {:?}", cache); - println!("šŸ inserting #{}", pf_to_cache.len()); - cache.insert(pf_to_cache.clone()); - println!("šŸŽ­ cache {:?}", cache); + cache.delete(&pf_found_in_cache_leq_requested); + cache.insert(&pf_to_cache); let outcome = InternalFactorInstancesProviderOutcome::transpose( pf_to_cache, @@ -466,7 +391,6 @@ impl FactorInstancesProvider { cache: &FactorInstancesCache, interactors: Arc, ) -> Result> { - println!("šŸ”® deriving more: {:?}", pf_pdp_quantity_to_derive); let next_index_assigner = NextDerivationEntityIndexAssigner::new(network_id, profile, cache.clone()); diff --git a/src/factor_instances_provider/provider/factor_instances_provider_unit_tests.rs b/src/factor_instances_provider/provider/factor_instances_provider_unit_tests.rs index 47320586..955c0da6 100644 --- a/src/factor_instances_provider/provider/factor_instances_provider_unit_tests.rs +++ b/src/factor_instances_provider/provider/factor_instances_provider_unit_tests.rs @@ -496,10 +496,6 @@ async fn cache_is_always_filled_account_veci_then_after_all_used_we_start_over_a .peek_all_instances_of_factor_source(bdfs.factor_source_id()) .unwrap(); - println!( - "šŸ‘»šŸ‘»šŸ‘»šŸ‘»šŸ‘»šŸ‘» EMPTY RIGHT??? {:?}", - cached.get(&DerivationPreset::AccountVeci.index_agnostic_path_on_network(network)) - ); assert!( cached .get(&DerivationPreset::AccountVeci.index_agnostic_path_on_network(network)) diff --git a/src/factor_instances_provider/provider/test_sargon_os.rs b/src/factor_instances_provider/provider/test_sargon_os.rs index 3d1b965e..da6083fa 100644 --- a/src/factor_instances_provider/provider/test_sargon_os.rs +++ b/src/factor_instances_provider/provider/test_sargon_os.rs @@ -169,11 +169,7 @@ impl SargonOS { shield: MatrixOfFactorSources, ) -> Result<(IndexSet, FactorInstancesProviderOutcome)> { let profile_snapshot = self.profile_snapshot(); - println!( - "šŸ›”ļø securifying #{} entities with shield: {:?}", - addresses_of_entities.len(), - shield - ); + let outcome = FactorInstancesProvider::for_entity_mfa::( &mut self.cache, shield.clone(), @@ -216,8 +212,7 @@ impl SargonOS { shield.clone(), ) .unwrap(); - println!("šŸ‡øšŸ‡Ŗ instance_per_factor: {:?}", instance_per_factor); - println!("šŸ‡øšŸ‡Ŗ matrix_of_instances: {:?}", matrix_of_instances); + let access_controller = match entity.security_state() { EntitySecurityState::Unsecured(_) => { AccessController::from_unsecurified_address(a)