Skip to content

Commit

Permalink
remove prints
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Oct 12, 2024
1 parent cec9c94 commit f439723
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
36 changes: 18 additions & 18 deletions src/factor_instances_provider/provider/factor_instances_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> {
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::<Result<IndexMap<IndexAgnosticPath, FactorInstances>>>()?;
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();

Expand Down Expand Up @@ -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)
Expand All @@ -174,7 +174,7 @@ impl FactorInstancesCache {
/// Inserts all instance in `per_factor`.
pub fn insert_all(
&mut self,
per_factor: IndexMap<FactorSourceIDFromHash, FactorInstances>,
per_factor: &IndexMap<FactorSourceIDFromHash, FactorInstances>,
) -> Result<()> {
for (factor_source_id, instances) in per_factor {
_ = self.insert_for_factor(factor_source_id, instances)?;
Expand Down Expand Up @@ -319,14 +319,14 @@ impl FactorInstancesCache {
Some(instances.clone())
}

pub fn delete(&mut self, pf_instances: IndexMap<FactorSourceIDFromHash, FactorInstances>) {
pub fn delete(&mut self, pf_instances: &IndexMap<FactorSourceIDFromHash, FactorInstances>) {
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()
Expand Down Expand Up @@ -391,7 +391,7 @@ impl FactorInstancesCache {
fn factor_source_ids(&self) -> IndexSet<FactorSourceIDFromHash> {
self.map.keys().cloned().collect()
}
pub fn insert(&mut self, pf_instances: IndexMap<FactorSourceIDFromHash, FactorInstances>) {
pub fn insert(&mut self, pf_instances: &IndexMap<FactorSourceIDFromHash, FactorInstances>) {
self.insert_all(pf_instances).expect("works")
}

Expand Down Expand Up @@ -465,15 +465,15 @@ 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,
HDPathComponent::unsecurified_hardening_base_index(2), // OH NO! Skipping `1`
fsid,
);
assert!(sut
.insert_for_factor(fsid, FactorInstances::from_iter([fi2]))
.insert_for_factor(&fsid, &FactorInstances::from_iter([fi2]))
.unwrap(),);
}

Expand All @@ -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());
}
Expand Down Expand Up @@ -523,11 +523,11 @@ mod tests {
})
.collect::<IndexSet<_>>();

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,
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl FactorInstancesProvider {
interactors,
)
.await?;
cache.insert(derived.clone());
cache.insert(&derived);

let derived = derived
.get(&factor_source.factor_source_id())
Expand Down Expand Up @@ -290,10 +290,6 @@ impl FactorInstancesProvider {
cache: &mut FactorInstancesCache,
interactors: Arc<dyn KeysDerivationInteractors>,
) -> Result<InternalFactorInstancesProviderOutcome> {
println!("\n\n🌈 start: {:?}", quantified_derivation_preset,);

println!("🎭 cache {:?}", cache);

let originally_requested_quantified_derivation_preset = quantified_derivation_preset;

let profile = profile.into();
Expand All @@ -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(
Expand All @@ -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 {

Check warning on line 326 in src/factor_instances_provider/provider/factor_instances_provider.rs

View check run for this annotation

Codecov / codecov/patch

src/factor_instances_provider/provider/factor_instances_provider.rs#L326

Added line #L326 was not covered by tests
pf_to_use_directly,
pf_to_cache,
Expand All @@ -376,39 +332,8 @@ impl FactorInstancesProvider {
&pf_newly_derived,

Check warning on line 332 in src/factor_instances_provider/provider/factor_instances_provider.rs

View check run for this annotation

Codecov / codecov/patch

src/factor_instances_provider/provider/factor_instances_provider.rs#L331-L332

Added lines #L331 - L332 were not covered by tests
);

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,
Expand Down Expand Up @@ -466,7 +391,6 @@ impl FactorInstancesProvider {
cache: &FactorInstancesCache,
interactors: Arc<dyn KeysDerivationInteractors>,
) -> Result<IndexMap<FactorSourceIDFromHash, FactorInstances>> {
println!("🔮 deriving more: {:?}", pf_pdp_quantity_to_derive);
let next_index_assigner =
NextDerivationEntityIndexAssigner::new(network_id, profile, cache.clone());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 2 additions & 7 deletions src/factor_instances_provider/provider/test_sargon_os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,7 @@ impl SargonOS {
shield: MatrixOfFactorSources,
) -> Result<(IndexSet<E>, FactorInstancesProviderOutcome)> {
let profile_snapshot = self.profile_snapshot();
println!(
"🛡️ securifying #{} entities with shield: {:?}",
addresses_of_entities.len(),
shield
);

let outcome = FactorInstancesProvider::for_entity_mfa::<E::BaseEntity>(
&mut self.cache,
shield.clone(),
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f439723

Please sign in to comment.