Skip to content

Commit 0bc8a7e

Browse files
committed
fix: apply review comments
1 parent bf6b1fd commit 0bc8a7e

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

mithril-aggregator/src/configuration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub struct Configuration {
155155
pub allow_unparsable_block: bool,
156156

157157
/// Cardano transactions prover cache pool size
158-
pub cardano_transactions_prover_cache_pool_size: u32,
158+
pub cardano_transactions_prover_cache_pool_size: usize,
159159
}
160160

161161
/// Uploader needed to copy the snapshot once computed.

mithril-aggregator/src/dependency_injection/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ impl DependenciesBuilder {
13671367
pub async fn build_prover_service(&mut self) -> Result<Arc<dyn ProverService>> {
13681368
let mk_map_pool_size = self
13691369
.configuration
1370-
.cardano_transactions_prover_cache_pool_size as usize;
1370+
.cardano_transactions_prover_cache_pool_size;
13711371
let transaction_retriever = self.get_transaction_repository().await?;
13721372
let block_range_root_retriever = self.get_transaction_repository().await?;
13731373
let logger = self.get_logger().await?;

mithril-aggregator/src/services/prover.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl ProverService for MithrilProverService {
150150
// 5 - Compute the proof for all transactions
151151
if let Ok(mk_proof) = mk_map.compute_proof(transaction_hashes) {
152152
self.mk_map_pool
153-
.return_resource(mk_map.into_inner(), mk_map.discriminant())?;
153+
.give_back_resource(mk_map.into_inner(), mk_map.discriminant())?;
154154

155155
let transaction_hashes_certified: Vec<TransactionHash> = transaction_hashes
156156
.iter()
@@ -171,7 +171,7 @@ impl ProverService for MithrilProverService {
171171
let pool_size = self.mk_map_pool.size();
172172
info!(
173173
self.logger,
174-
"Prover starts computing the Merkle map pool pool resource of size {pool_size}"
174+
"Prover starts computing the Merkle map pool resource of size {pool_size}"
175175
);
176176
let mk_map_cache = self
177177
.block_range_root_retriever
@@ -185,15 +185,15 @@ impl ProverService for MithrilProverService {
185185
.map(|i| {
186186
debug!(
187187
self.logger,
188-
"Prover is computing the Merkle map pool pool resource {i}/{pool_size}"
188+
"Prover is computing the Merkle map pool resource {i}/{pool_size}"
189189
);
190190
self.mk_map_pool
191-
.return_resource(mk_map_cache.clone(), discriminant_new)
191+
.give_back_resource(mk_map_cache.clone(), discriminant_new)
192192
})
193193
.collect::<StdResult<()>>()?;
194194
info!(
195195
self.logger,
196-
"Prover completed computing the Merkle map pool pool resource of size {pool_size}"
196+
"Prover completed computing the Merkle map pool resource of size {pool_size}"
197197
);
198198

199199
Ok(())

mithril-common/src/resource_pool.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ impl<T: Send + Sync> ResourcePool<T> {
6969
Ok(ResourcePoolItem::new(self, resources.pop_front().unwrap()))
7070
}
7171

72-
/// Return a resource to the pool
73-
/// A resource is returned to the pool only if the discriminant matches
72+
/// Give back a resource to the pool
73+
/// A resource is given back to the pool only if the discriminant matches
7474
/// and if the pool is not already full
75-
pub fn return_resource(&self, resource: T, discriminant: u64) -> StdResult<()> {
75+
pub fn give_back_resource(&self, resource: T, discriminant: u64) -> StdResult<()> {
7676
if self.count()? == self.size {
7777
// Pool is full
7878
return Ok(());
@@ -81,7 +81,7 @@ impl<T: Send + Sync> ResourcePool<T> {
8181
.resources
8282
.lock()
8383
.map_err(|_| ResourcePoolError::PoisonedLock())
84-
.with_context(|| "Resource pool 'return_resource' failed locking Mutex")?;
84+
.with_context(|| "Resource pool 'give_back_resource' failed locking Mutex")?;
8585
if self.discriminant()? != discriminant {
8686
// Stale resource
8787
return Ok(());
@@ -195,7 +195,7 @@ impl<T: Send + Sync> Drop for ResourcePoolItem<'_, T> {
195195
let resource = self.into_inner();
196196
let _ = self
197197
.resource_pool
198-
.return_resource(resource, self.discriminant);
198+
.give_back_resource(resource, self.discriminant);
199199
}
200200
}
201201
}
@@ -254,28 +254,29 @@ mod tests {
254254
}
255255

256256
#[tokio::test]
257-
async fn test_resource_pool_returns_fresh_resource() {
257+
async fn test_resource_pool_gives_back_fresh_resource() {
258258
let pool_size = 10;
259259
let resources_expected: Vec<String> = (0..pool_size).map(|i| i.to_string()).collect();
260260
let pool = ResourcePool::<String>::new(pool_size, resources_expected.clone());
261261
assert_eq!(pool.count().unwrap(), pool_size);
262262

263263
let mut resource_item = pool.acquire_resource(Duration::from_millis(1000)).unwrap();
264264
assert_eq!(pool.count().unwrap(), pool_size - 1);
265-
pool.return_resource(resource_item.into_inner(), pool.discriminant().unwrap())
265+
pool.give_back_resource(resource_item.into_inner(), pool.discriminant().unwrap())
266266
.unwrap();
267267

268268
assert_eq!(pool.count().unwrap(), pool_size);
269269
}
270270

271271
#[tokio::test]
272-
async fn test_resource_pool_returns_resource_automatically() {
272+
async fn test_resource_pool_gives_back_resource_automatically() {
273273
let pool_size = 10;
274274
let resources_expected: Vec<String> = (0..pool_size).map(|i| i.to_string()).collect();
275275
let pool = ResourcePool::<String>::new(pool_size, resources_expected.clone());
276276
assert_eq!(pool.count().unwrap(), pool_size);
277277

278278
{
279+
// Resource will be returned when resource item is dropped (will occur when exiting this block scope)
279280
let _resource_item = pool.acquire_resource(Duration::from_millis(1000)).unwrap();
280281
assert_eq!(pool.count().unwrap(), pool_size - 1);
281282
}
@@ -284,20 +285,20 @@ mod tests {
284285
}
285286

286287
#[tokio::test]
287-
async fn test_resource_pool_does_not_return_resource_when_pool_is_full() {
288+
async fn test_resource_pool_does_not_give_back_resource_when_pool_is_full() {
288289
let pool_size = 10;
289290
let resources_expected: Vec<String> = (0..pool_size).map(|i| i.to_string()).collect();
290291
let pool = ResourcePool::<String>::new(pool_size, resources_expected.clone());
291292
assert_eq!(pool.count().unwrap(), pool_size);
292293

293-
pool.return_resource("resource".to_string(), pool.discriminant().unwrap())
294+
pool.give_back_resource("resource".to_string(), pool.discriminant().unwrap())
294295
.unwrap();
295296

296297
assert_eq!(pool.count().unwrap(), pool_size);
297298
}
298299

299300
#[tokio::test]
300-
async fn test_resource_pool_does_not_return_stale_resource() {
301+
async fn test_resource_pool_does_not_giev_back_stale_resource() {
301302
let pool_size = 10;
302303
let resources_expected: Vec<String> = (0..pool_size).map(|i| i.to_string()).collect();
303304
let pool = ResourcePool::<String>::new(pool_size, resources_expected.clone());
@@ -308,7 +309,7 @@ mod tests {
308309
let discriminant_stale = pool.discriminant().unwrap();
309310
pool.set_discriminant(pool.discriminant().unwrap() + 1)
310311
.unwrap();
311-
pool.return_resource(resource_item.into_inner(), discriminant_stale)
312+
pool.give_back_resource(resource_item.into_inner(), discriminant_stale)
312313
.unwrap();
313314

314315
assert_eq!(pool.count().unwrap(), pool_size - 1);

0 commit comments

Comments
 (0)