Skip to content

Commit fb4ece8

Browse files
committed
fix: revert RPC autodiscovery of proofs to self-heal unstored self-anchors
1 parent e88e115 commit fb4ece8

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

event-svc/src/event/service.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -544,26 +544,42 @@ impl EventService {
544544
}
545545

546546
/// Get the chain proof for a given event from the database.
547-
/// All proofs should have been validated and stored during the event validation phase (v0.55.0+).
547+
/// All proofs should have been validated and stored during the event validation phase (v0.55.0+),
548+
/// but in case it can't be found we try to dynamically discover it through the RPC provider
548549
pub(crate) async fn discover_chain_proof(
549550
&self,
550551
event: &ceramic_event::unvalidated::TimeEvent,
551552
) -> std::result::Result<ChainProof, crate::eth_rpc::Error> {
552553
let tx_hash = event.proof().tx_hash();
553554
let tx_hash = tx_hash_try_from_cid(tx_hash).unwrap().to_string();
554-
self.event_access
555+
if let Some(proof) = self
556+
.event_access
555557
.get_chain_proof(event.proof().chain_id(), &tx_hash)
556558
.await
557559
.map_err(|e| crate::eth_rpc::Error::Application(e.into()))?
558-
.ok_or_else(|| {
559-
// Note: Using InvalidProof here rather than TxNotFound because:
560-
// - TxNotFound is for "transaction not found on blockchain" (RPC-level)
561-
// - This is "proof not in local database" (local storage issue)
562-
crate::eth_rpc::Error::InvalidProof(format!(
563-
"Chain proof for tx {} not found in database.",
564-
tx_hash
565-
))
566-
})
560+
{
561+
return Ok(proof);
562+
}
563+
564+
warn!(
565+
"Chain proof for tx {} not found in database, validating and storing it now.",
566+
tx_hash
567+
);
568+
569+
// Try using the RPC provider and store the proof
570+
let proof = self
571+
.event_validator
572+
.time_event_validator()
573+
.validate_chain_inclusion(event)
574+
.await?;
575+
576+
let proof = ChainProof::from(proof);
577+
self.event_access
578+
.persist_chain_inclusion_proofs(std::slice::from_ref(&proof))
579+
.await
580+
.map_err(|e| crate::eth_rpc::Error::Application(e.into()))?;
581+
582+
Ok(proof)
567583
}
568584
}
569585

event-svc/src/event/validator/event.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ impl EventValidator {
275275
}
276276
}
277277
}
278+
279+
pub fn time_event_validator(&self) -> &TimeEventValidator {
280+
&self.time_event_validator
281+
}
278282
}
279283

280284
#[cfg(test)]

0 commit comments

Comments
 (0)