Skip to content

Commit cf7d42d

Browse files
authored
feat(dips): enhance logging with agreement ID in DIPs processing (#678)
Signed-off-by: Lorenzo Delgado <[email protected]>
1 parent 0abcb89 commit cf7d42d

File tree

2 files changed

+72
-18
lines changed

2 files changed

+72
-18
lines changed

crates/dips/src/lib.rs

Lines changed: 70 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ pub async fn validate_and_create_agreement(
325325

326326
decoded_voucher.validate(signer_validator, domain, expected_payee, allowed_payers)?;
327327

328+
// Extract and parse the agreement ID from the voucher
329+
let agreement_id = Uuid::from_bytes(decoded_voucher.voucher.agreement_id.into());
330+
328331
let manifest = ipfs_fetcher.fetch(&metadata.subgraphDeploymentId).await?;
329332

330333
let network = match registry.get_network_by_id(&metadata.chainId) {
@@ -337,7 +340,9 @@ pub async fn validate_and_create_agreement(
337340

338341
match manifest.network() {
339342
Some(manifest_network_name) => {
340-
tracing::debug!("Subgraph manifest network: {}", manifest_network_name);
343+
tracing::debug!(
344+
agreement_id = %agreement_id,
345+
"Subgraph manifest network: {}", manifest_network_name);
341346
if manifest_network_name != network {
342347
return Err(DipsError::InvalidSubgraphManifest(
343348
metadata.subgraphDeploymentId,
@@ -354,32 +359,66 @@ pub async fn validate_and_create_agreement(
354359
let offered_epoch_price = metadata.basePricePerEpoch;
355360
match price_calculator.get_minimum_price(&metadata.chainId) {
356361
Some(price) if offered_epoch_price.lt(&Uint::from(price)) => {
362+
tracing::debug!(
363+
agreement_id = %agreement_id,
364+
chain_id = %metadata.chainId,
365+
deployment_id = %metadata.subgraphDeploymentId,
366+
"offered epoch price '{}' is lower than minimum price '{}'",
367+
offered_epoch_price,
368+
price
369+
);
357370
return Err(DipsError::PricePerEpochTooLow(
358371
network,
359372
price,
360373
offered_epoch_price.to_string(),
361-
))
374+
));
362375
}
363376
Some(_) => {}
364-
None => return Err(DipsError::UnsupportedChainId(metadata.chainId)),
377+
None => {
378+
tracing::debug!(
379+
agreement_id = %agreement_id,
380+
chain_id = %metadata.chainId,
381+
deployment_id = %metadata.subgraphDeploymentId,
382+
"chain id '{}' is not supported",
383+
metadata.chainId
384+
);
385+
return Err(DipsError::UnsupportedChainId(metadata.chainId));
386+
}
365387
}
366388

367389
let offered_entity_price = metadata.pricePerEntity;
368390
if offered_entity_price < price_calculator.entity_price() {
391+
tracing::debug!(
392+
agreement_id = %agreement_id,
393+
chain_id = %metadata.chainId,
394+
deployment_id = %metadata.subgraphDeploymentId,
395+
"offered entity price '{}' is lower than minimum price '{}'",
396+
offered_entity_price,
397+
price_calculator.entity_price()
398+
);
369399
return Err(DipsError::PricePerEntityTooLow(
370400
network,
371401
price_calculator.entity_price(),
372402
offered_entity_price.to_string(),
373403
));
374404
}
375405

406+
tracing::debug!(
407+
agreement_id = %agreement_id,
408+
chain_id = %metadata.chainId,
409+
deployment_id = %metadata.subgraphDeploymentId,
410+
"creating agreement"
411+
);
412+
376413
store
377414
.create_agreement(decoded_voucher.clone(), metadata)
378-
.await?;
415+
.await
416+
.map_err(|error| {
417+
tracing::error!(%agreement_id, %error, "failed to create agreement");
418+
error
419+
})?;
379420

380-
Ok(Uuid::from_bytes(
381-
decoded_voucher.voucher.agreement_id.into(),
382-
))
421+
Ok(agreement_id)
383422
}
384423

385424
pub async fn validate_and_cancel_agreement(
@@ -391,22 +430,35 @@ pub async fn validate_and_cancel_agreement(
391430
SignedCancellationRequest::abi_decode(cancellation_request.as_ref(), true)
392431
.map_err(|e| DipsError::AbiDecoding(e.to_string()))?;
393432

394-
let result = store
395-
.get_by_id(Uuid::from_bytes(
396-
decoded_request.request.agreement_id.into(),
397-
))
398-
.await?;
399-
let stored_agreement = result.ok_or(DipsError::AgreementNotFound)?;
433+
// Get the agreement ID from the cancellation request
434+
let agreement_id = Uuid::from_bytes(decoded_request.request.agreement_id.into());
435+
436+
let stored_agreement = store.get_by_id(agreement_id).await?.ok_or_else(|| {
437+
tracing::warn!(%agreement_id, "agreement not found");
438+
DipsError::AgreementNotFound
439+
})?;
440+
441+
// Get the deployment ID from the stored agreement
442+
let deployment_id = stored_agreement.metadata.subgraphDeploymentId;
443+
400444
if stored_agreement.cancelled {
445+
tracing::warn!(%agreement_id, %deployment_id, "agreement already cancelled");
401446
return Err(DipsError::AgreementCancelled);
402447
}
403-
let expected_signer = stored_agreement.voucher.voucher.payer;
404-
let id = Uuid::from_bytes(decoded_request.request.agreement_id.into());
405-
decoded_request.validate(domain, &expected_signer)?;
406448

407-
store.cancel_agreement(decoded_request).await?;
449+
decoded_request.validate(domain, &stored_agreement.voucher.voucher.payer)?;
450+
451+
tracing::debug!(%agreement_id, %deployment_id, "cancelling agreement");
452+
453+
store
454+
.cancel_agreement(decoded_request)
455+
.await
456+
.map_err(|error| {
457+
tracing::error!(%agreement_id, %deployment_id, %error, "failed to cancel agreement");
458+
error
459+
})?;
408460

409-
Ok(id)
461+
Ok(agreement_id)
410462
}
411463

412464
#[cfg(test)]

crates/monitor/src/escrow_accounts.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ async fn get_escrow_accounts_v1(
144144

145145
let response = response?;
146146

147+
tracing::trace!("Escrow accounts response: {:?}", response);
148+
147149
let senders_balances: HashMap<Address, U256> = response
148150
.escrow_accounts
149151
.iter()

0 commit comments

Comments
 (0)