Skip to content

Commit

Permalink
its working, its working its woooooooooorkiiiiiiing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Oct 12, 2024
1 parent 79aab62 commit cec9c94
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
22 changes: 6 additions & 16 deletions src/factor_instances_provider/provider/factor_instances_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,8 @@ impl FactorInstancesCache {
factor_source_id: FactorSourceIDFromHash,
agnostic_path: IndexAgnosticPath,
) -> Option<HDPathComponent> {
let Some(for_factor) = self.map.get(&factor_source_id) else {
return None;
};
let Some(instances) = for_factor.get(&agnostic_path) else {
return None;
};
let for_factor = self.map.get(&factor_source_id)?;
let instances = for_factor.get(&agnostic_path)?;
instances
.factor_instances()
.last()
Expand All @@ -210,7 +206,7 @@ impl FactorInstancesCache {
else {
continue;
};
pf.insert(factor_source_id.clone(), instances);
pf.insert(*factor_source_id, instances);
}
Ok(pf)
}
Expand Down Expand Up @@ -253,9 +249,7 @@ impl FactorInstancesCache {
[..requested_qty];
pf_instances.insert(
*factor_source_id,
FactorInstances::from_iter(
instances_enough_to_satisfy.into_iter().cloned(),
),
FactorInstances::from_iter(instances_enough_to_satisfy.iter().cloned()),
);
}
is_qty_satisfied_for_all_factor_sources =
Expand Down Expand Up @@ -320,12 +314,8 @@ impl FactorInstancesCache {
factor_source_id: &FactorSourceIDFromHash,
index_agnostic_path: &IndexAgnosticPath,
) -> Option<FactorInstances> {
let Some(for_factor) = self.map.get(factor_source_id) else {
return None;
};
let Some(instances) = for_factor.get(index_agnostic_path) else {
return None;
};
let for_factor = self.map.get(factor_source_id)?;
let instances = for_factor.get(index_agnostic_path)?;
Some(instances.clone())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl FactorInstancesProvider {
),
network_id,
profile,
&cache,
cache,
interactors,
)
.await?;
Expand Down Expand Up @@ -261,7 +261,7 @@ impl FactorInstancesProvider {

let outcome = Self::with(
network_id,
factor_sources,
factor_sources_to_use,
QuantifiedDerivationPresets {
quantity: addresses_of_entities.len(),
derivation_preset,

Check warning on line 267 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#L267

Added line #L267 was not covered by tests
Expand Down Expand Up @@ -416,7 +416,7 @@ impl FactorInstancesProvider {
pf_found_in_cache_leq_requested,
pf_newly_derived,
);
let outcome = outcome.into();
let outcome = outcome;

Check warning on line 419 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#L419

Added line #L419 was not covered by tests
Ok(outcome)
}

Expand Down Expand Up @@ -492,7 +492,7 @@ impl FactorInstancesProvider {
.collect::<Result<Vec<IndexSet<DerivationPath>>>>()?;

Check warning on line 492 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#L492

Added line #L492 was not covered by tests

// flatten (I was unable to use `flat_map` above combined with `Result`...)
let paths = paths.into_iter().flat_map(|xs| xs).collect::<IndexSet<_>>();
let paths = paths.into_iter().flatten().collect::<IndexSet<_>>();

Ok((factor_source_id, paths))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,6 @@ async fn securify_accounts_when_cache_is_half_full_multiple_factor_sources() {
)
.await
.unwrap();

assert!(
!stats.derived_any_new_instance_for_any_factor_source(),
"should have used cache"
Expand Down
20 changes: 19 additions & 1 deletion src/factor_instances_provider/provider/test_sargon_os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ 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 All @@ -187,6 +191,18 @@ impl SargonOS {
.map(|(k, outcome_per_factor)| (k, outcome_per_factor.to_use_directly))
.collect::<IndexMap<FactorSourceIDFromHash, FactorInstances>>();

assert_eq!(
instance_per_factor
.keys()
.cloned()
.collect::<HashSet<FactorSourceIDFromHash>>(),
shield
.all_factors()
.into_iter()
.map(|f| f.factor_source_id())
.collect::<HashSet<FactorSourceIDFromHash>>()
);

// Now we need to map the flat set of instances into many MatrixOfFactorInstances, and assign
// one to each account
let updated_entities = addresses_of_entities
Expand All @@ -200,6 +216,8 @@ 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 cec9c94

Please sign in to comment.