Skip to content

Commit 6bef6d0

Browse files
author
Damien LACHAUME / PALO-IT
committed
Add context for signed_entity db provider calling functions
1 parent 04e28fd commit 6bef6d0

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

mithril-aggregator/src/database/provider/signed_entity.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ pub trait SignedEntityStorer: Sync + Send {
374374
) -> StdResult<Option<SignedEntityRecord>>;
375375

376376
/// Get signed entities type by certificates ids
377-
async fn get_signed_entity_by_certificates_ids<'a>(
377+
async fn get_signed_entities_by_certificates_ids<'a>(
378378
&self,
379379
certificates_ids: &[&'a str],
380380
) -> StdResult<Vec<SignedEntityRecord>>;
@@ -449,7 +449,7 @@ impl SignedEntityStorer for SignedEntityStoreAdapter {
449449
Ok(signed_entity)
450450
}
451451

452-
async fn get_signed_entity_by_certificates_ids<'a>(
452+
async fn get_signed_entities_by_certificates_ids<'a>(
453453
&self,
454454
certificates_ids: &[&'a str],
455455
) -> StdResult<Vec<SignedEntityRecord>> {
@@ -855,7 +855,7 @@ mod tests {
855855
.collect();
856856

857857
let queried_records = store
858-
.get_signed_entity_by_certificates_ids(&certificates_ids)
858+
.get_signed_entities_by_certificates_ids(&certificates_ids)
859859
.await
860860
.expect("querying signed entity record by certificates ids should not fail");
861861

mithril-aggregator/src/services/signed_entity.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! This service is responsible of dealing with [SignedEntity] type.
44
//! It creates [Artifact] that can be accessed by clients.
5+
use anyhow::Context;
56
use async_trait::async_trait;
67
use chrono::Utc;
78
use slog_scope::info;
@@ -144,7 +145,7 @@ impl SignedEntityService for MithrilSignedEntityService {
144145

145146
self.signed_entity_storer
146147
.store_signed_entity(&signed_entity)
147-
.await?;
148+
.await.with_context(|| "Signed Entity Service can not store signed entity with type: '{signed_entity_type}'")?;
148149

149150
Ok(())
150151
}
@@ -159,7 +160,13 @@ impl SignedEntityService for MithrilSignedEntityService {
159160
&SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
160161
total,
161162
)
162-
.await?;
163+
.await
164+
.with_context(|| {
165+
format!(
166+
"Signed Entity Service can not get last signed entities with type: '{:?}'",
167+
&SignedEntityTypeDiscriminants::CardanoImmutableFilesFull
168+
)
169+
})?;
163170
let mut signed_entities: Vec<SignedEntity<Snapshot>> = Vec::new();
164171

165172
for record in signed_entities_records {
@@ -179,7 +186,13 @@ impl SignedEntityService for MithrilSignedEntityService {
179186
&SignedEntityTypeDiscriminants::MithrilStakeDistribution,
180187
total,
181188
)
182-
.await?;
189+
.await
190+
.with_context(|| {
191+
format!(
192+
"Signed Entity Service can not get last signed entities with type: '{:?}'",
193+
&SignedEntityTypeDiscriminants::MithrilStakeDistribution
194+
)
195+
})?;
183196
let mut signed_entities: Vec<SignedEntity<MithrilStakeDistribution>> = Vec::new();
184197

185198
for record in signed_entities_records {
@@ -196,8 +209,10 @@ impl SignedEntityService for MithrilSignedEntityService {
196209
let entity: Option<SignedEntity<Snapshot>> = match self
197210
.signed_entity_storer
198211
.get_signed_entity(signed_entity_id)
199-
.await?
200-
{
212+
.await
213+
.with_context(|| {
214+
"Signed Entity Service can not get signed entity with id: '{signed_entity_id}'"
215+
})? {
201216
Some(entity) => Some(entity.try_into()?),
202217
None => None,
203218
};
@@ -212,8 +227,10 @@ impl SignedEntityService for MithrilSignedEntityService {
212227
let entity: Option<SignedEntity<MithrilStakeDistribution>> = match self
213228
.signed_entity_storer
214229
.get_signed_entity(signed_entity_id)
215-
.await?
216-
{
230+
.await
231+
.with_context(|| {
232+
"Signed Entity Service can not get signed entity with id: '{signed_entity_id}'"
233+
})? {
217234
Some(entity) => Some(entity.try_into()?),
218235
None => None,
219236
};

mithril-aggregator/src/tools/certificates_hash_migrator.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ impl CertificatesHashMigrator {
129129
.collect();
130130
let mut records_to_migrate = self
131131
.signed_entity_storer
132-
.get_signed_entity_by_certificates_ids(&old_hashes)
133-
.await?;
132+
.get_signed_entities_by_certificates_ids(&old_hashes)
133+
.await
134+
.with_context(|| {
135+
"Certificates Hash Migrator can not get signed entities by certificates ids with hashes: '{old_hashes}'"
136+
})?;
134137

135138
debug!("🔧 Certificate Hash Migrator: updating signed entities certificate_ids to new computed hash");
136139
for signed_entity_record in records_to_migrate.iter_mut() {
@@ -155,7 +158,8 @@ impl CertificatesHashMigrator {
155158
debug!("🔧 Certificate Hash Migrator: updating migrated signed entities in the database");
156159
self.signed_entity_storer
157160
.update_signed_entities(records_to_migrate)
158-
.await?;
161+
.await
162+
.with_context(|| "Certificates Hash Migrator can not update signed entities")?;
159163

160164
Ok(())
161165
}
@@ -165,7 +169,9 @@ impl CertificatesHashMigrator {
165169
self.certificate_repository
166170
.delete_certificates(&old_certificates.iter().collect::<Vec<_>>())
167171
.await
168-
.with_context(|| "Certificate Hash Migrator can not delete certificates")?;
172+
.with_context(|| {
173+
"Certificates Hash Migrator can not delete certificates with hashes: '{old_hashes}'"
174+
})?;
169175

170176
Ok(())
171177
}
@@ -277,7 +283,10 @@ mod test {
277283

278284
signed_entity_store
279285
.store_signed_entity(&signed_entity_record)
280-
.await?;
286+
.await
287+
.with_context(|| {
288+
"Certificates Hash Migrator can not store signed entity"
289+
})?;
281290

282291
Some(signed_entity_record)
283292
}
@@ -408,7 +417,8 @@ mod test {
408417
} else {
409418
let record = signed_entity_store
410419
.get_signed_entity_by_certificate_id(&certificate.hash)
411-
.await?;
420+
.await
421+
.with_context(|| "Certificates Hash Migrator can not get signed entity type by certificate id with hash: '{&certificate.hash}'")?;
412422
result.push((certificate, record));
413423
}
414424
}

0 commit comments

Comments
 (0)