Skip to content

Commit 3381ec3

Browse files
committed
f Avoid moving things into determine_and_write_schema_version
1 parent 6c5d357 commit 3381ec3

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/io/vss_store.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,13 @@ impl VssStore {
113113
);
114114

115115
let runtime_handle = internal_runtime.handle();
116-
let schema_store_id = store_id.clone();
117-
let schema_key_obfuscator = KeyObfuscator::new(obfuscation_master_key);
118-
let (schema_version, blocking_client) = tokio::task::block_in_place(move || {
116+
let schema_version = tokio::task::block_in_place(|| {
119117
runtime_handle.block_on(async {
120118
determine_and_write_schema_version(
121-
blocking_client,
122-
schema_store_id,
119+
&blocking_client,
120+
&store_id,
123121
data_encryption_key,
124-
schema_key_obfuscator,
122+
&key_obfuscator,
125123
)
126124
.await
127125
})
@@ -697,13 +695,10 @@ fn retry_policy() -> CustomRetryPolicy {
697695
}) as _)
698696
}
699697

700-
// FIXME: This returns the used client as currently `VssClient`'s `RetryPolicy`s aren't `Clone`. So
701-
// we're forced to take the owned client and return it to be able to reuse the same connection
702-
// later.
703698
async fn determine_and_write_schema_version(
704-
client: VssClient<CustomRetryPolicy>, store_id: String, data_encryption_key: [u8; 32],
705-
key_obfuscator: KeyObfuscator,
706-
) -> io::Result<(VssSchemaVersion, VssClient<CustomRetryPolicy>)> {
699+
client: &VssClient<CustomRetryPolicy>, store_id: &String, data_encryption_key: [u8; 32],
700+
key_obfuscator: &KeyObfuscator,
701+
) -> io::Result<VssSchemaVersion> {
707702
// Build the obfuscated `vss_schema_version` key.
708703
let obfuscated_prefix = key_obfuscator.obfuscate(&format! {"{}#{}", "", ""});
709704
let obfuscated_key = key_obfuscator.obfuscate(VSS_SCHEMA_VERSION_KEY);
@@ -749,7 +744,7 @@ async fn determine_and_write_schema_version(
749744
let msg = format!("Failed to decode schema version: {}", e);
750745
Error::new(ErrorKind::Other, msg)
751746
})?;
752-
Ok((schema_version, client))
747+
Ok(schema_version)
753748
} else {
754749
// The schema version wasn't present, this either means we're running for the first time *or* it's V0 pre-migration (predating writing of the schema version).
755750

@@ -771,7 +766,7 @@ async fn determine_and_write_schema_version(
771766
let wallet_data_present = !response.key_versions.is_empty();
772767
if wallet_data_present {
773768
// If the wallet data is present, it means we're not running for the first time.
774-
Ok((VssSchemaVersion::V0, client))
769+
Ok(VssSchemaVersion::V0)
775770
} else {
776771
// We're running for the first time, write the schema version to save unnecessary IOps
777772
// on future startup.
@@ -785,7 +780,7 @@ async fn determine_and_write_schema_version(
785780
storable_builder.build(encoded_version, vss_version, &data_encryption_key, aad);
786781

787782
let request = PutObjectRequest {
788-
store_id,
783+
store_id: store_id.clone(),
789784
global_version: None,
790785
transaction_items: vec![KeyValue {
791786
key: store_key,
@@ -800,7 +795,7 @@ async fn determine_and_write_schema_version(
800795
Error::new(ErrorKind::Other, msg)
801796
})?;
802797

803-
Ok((schema_version, client))
798+
Ok(schema_version)
804799
}
805800
}
806801
}

0 commit comments

Comments
 (0)