Skip to content

Commit 1381fdc

Browse files
committed
Prefactor: move client construction out to VssStore
While having it in `VssStoreInner` makes more sense, we now opt to construt the client (soon, clients) in `VssStore` and then hand it down to `VssStoreInner`. That will allow us to use the client once for checking the schema version before actually instantiating `VssStoreInner`.
1 parent e7cab57 commit 1381fdc

1 file changed

Lines changed: 29 additions & 21 deletions

File tree

src/io/vss_store.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ impl VssStore {
8686
base_url: String, store_id: String, vss_seed: [u8; 32],
8787
header_provider: Arc<dyn VssHeaderProvider>, runtime: Arc<Runtime>,
8888
) -> Self {
89-
let inner = Arc::new(VssStoreInner::new(base_url, store_id, vss_seed, header_provider));
9089
let next_version = AtomicU64::new(1);
9190
let internal_runtime = Some(
9291
tokio::runtime::Builder::new_multi_thread()
@@ -102,6 +101,33 @@ impl VssStore {
102101
.unwrap(),
103102
);
104103

104+
let schema_version = VssSchemaVersion::V0;
105+
let (data_encryption_key, obfuscation_master_key) =
106+
derive_data_encryption_and_obfuscation_keys(&vss_seed);
107+
let key_obfuscator = KeyObfuscator::new(obfuscation_master_key);
108+
let retry_policy = ExponentialBackoffRetryPolicy::new(Duration::from_millis(10))
109+
.with_max_attempts(10)
110+
.with_max_total_delay(Duration::from_secs(15))
111+
.with_max_jitter(Duration::from_millis(10))
112+
.skip_retry_on_error(Box::new(|e: &VssError| {
113+
matches!(
114+
e,
115+
VssError::NoSuchKeyError(..)
116+
| VssError::InvalidRequestError(..)
117+
| VssError::ConflictError(..)
118+
)
119+
}) as _);
120+
121+
let client = VssClient::new_with_headers(base_url, retry_policy, header_provider);
122+
123+
let inner = Arc::new(VssStoreInner::new(
124+
schema_version,
125+
client,
126+
store_id,
127+
data_encryption_key,
128+
key_obfuscator,
129+
));
130+
105131
Self { inner, next_version, runtime, internal_runtime }
106132
}
107133

@@ -342,27 +368,9 @@ struct VssStoreInner {
342368

343369
impl VssStoreInner {
344370
pub(crate) fn new(
345-
base_url: String, store_id: String, vss_seed: [u8; 32],
346-
header_provider: Arc<dyn VssHeaderProvider>,
371+
schema_version: VssSchemaVersion, client: VssClient<CustomRetryPolicy>, store_id: String,
372+
data_encryption_key: [u8; 32], key_obfuscator: KeyObfuscator,
347373
) -> Self {
348-
let schema_version = VssSchemaVersion::V0;
349-
let (data_encryption_key, obfuscation_master_key) =
350-
derive_data_encryption_and_obfuscation_keys(&vss_seed);
351-
let key_obfuscator = KeyObfuscator::new(obfuscation_master_key);
352-
let retry_policy = ExponentialBackoffRetryPolicy::new(Duration::from_millis(10))
353-
.with_max_attempts(10)
354-
.with_max_total_delay(Duration::from_secs(15))
355-
.with_max_jitter(Duration::from_millis(10))
356-
.skip_retry_on_error(Box::new(|e: &VssError| {
357-
matches!(
358-
e,
359-
VssError::NoSuchKeyError(..)
360-
| VssError::InvalidRequestError(..)
361-
| VssError::ConflictError(..)
362-
)
363-
}) as _);
364-
365-
let client = VssClient::new_with_headers(base_url, retry_policy, header_provider);
366374
let locks = Mutex::new(HashMap::new());
367375
Self { schema_version, client, store_id, data_encryption_key, key_obfuscator, locks }
368376
}

0 commit comments

Comments
 (0)