Skip to content

Commit 4ec0049

Browse files
committed
fix: review comments
1 parent 2c5d4da commit 4ec0049

5 files changed

Lines changed: 41 additions & 38 deletions

File tree

event-svc/src/event/service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ impl EventService {
541541
}
542542
}
543543

544-
/// This is a helper function to get the chain proof for a given event from the database, or to validate and store
545-
/// it if it doesn't exist.
544+
/// This is a helper function to get the chain proof for a given event from the database, or throw an error if it
545+
/// wasn't found.
546546
async fn get_chain_proof(
547547
&self,
548548
event: &ceramic_event::unvalidated::TimeEvent,

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

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use ceramic_core::{Cid, EventId, NodeId};
44
use ceramic_event::unvalidated;
55
use ipld_core::ipld::Ipld;
66
use recon::ReconItem;
7+
use tokio::try_join;
78

89
use crate::{
910
blockchain::eth_rpc,
@@ -157,22 +158,14 @@ impl EventValidator {
157158
// Partition the events by type of validation needed and delegate to validators
158159
let grouped = GroupedEvents::from(parsed_events);
159160

160-
// Time events are always validated
161-
let validated_time = self.validate_time_events(grouped.time_batch).await?;
161+
let (validated_signed, validated_time) = try_join!(
162+
self.validate_signed_events(grouped.signed_batch, validation_req),
163+
// Time events are always validated
164+
self.validate_time_events(grouped.time_batch)
165+
)?;
166+
validated.extend_with(validated_signed);
162167
validated.extend_with(validated_time);
163168

164-
if let Some(req) = validation_req {
165-
let validated_signed = self
166-
.validate_signed_events(grouped.signed_batch, req)
167-
.await?;
168-
validated.extend_with(validated_signed);
169-
} else {
170-
// Return all data events as valid
171-
validated
172-
.valid
173-
.extend(Vec::<ValidatedEvent>::from(grouped.signed_batch));
174-
};
175-
176169
if !validated.invalid.is_empty() {
177170
tracing::warn!(count=%validated.invalid.len(), "invalid events discovered");
178171
}
@@ -183,23 +176,33 @@ impl EventValidator {
183176
async fn validate_signed_events(
184177
&self,
185178
events: SignedValidationBatch,
186-
validation_req: &ValidationRequirement,
179+
validation_req: Option<&ValidationRequirement>,
187180
) -> Result<ValidatedEvents> {
188-
let opts = if validation_req.check_exp {
189-
ceramic_validation::VerifyJwsOpts::default()
181+
if let Some(req) = validation_req {
182+
let opts = if req.check_exp {
183+
ceramic_validation::VerifyJwsOpts::default()
184+
} else {
185+
ceramic_validation::VerifyJwsOpts {
186+
at_time: ceramic_validation::AtTime::SkipTimeChecks,
187+
..Default::default()
188+
}
189+
};
190+
SignedEventValidator::validate_events(
191+
Arc::clone(&self.event_access),
192+
&opts,
193+
events,
194+
req.require_local_init,
195+
)
196+
.await
190197
} else {
191-
ceramic_validation::VerifyJwsOpts {
192-
at_time: ceramic_validation::AtTime::SkipTimeChecks,
193-
..Default::default()
194-
}
195-
};
196-
SignedEventValidator::validate_events(
197-
Arc::clone(&self.event_access),
198-
&opts,
199-
events,
200-
validation_req.require_local_init,
201-
)
202-
.await
198+
// If no validation requirement is specified, we assume all events are valid.
199+
Ok(ValidatedEvents {
200+
valid: events.into(),
201+
unvalidated: Vec::new(),
202+
invalid: Vec::new(),
203+
proofs: Vec::new(),
204+
})
205+
}
203206
}
204207

205208
async fn validate_time_events(&self, events: TimeValidationBatch) -> Result<ValidatedEvents> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct TimeEventValidator {
1717
/// we could support multiple providers for each chain (to get around rate limits)
1818
/// but we'll just force people to run a light client if they really need the throughput
1919
chain_providers: HashMap<caip2::ChainId, ChainInclusionProvider>,
20-
// add a sql connection / block table access
20+
// TODO: add a sql connection / block table access
2121
}
2222

2323
impl std::fmt::Debug for TimeEventValidator {

event-svc/src/store/sql/entities/chain_proof.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct ChainProof {
88
pub chain_id: String,
99
/// The transaction hash of the proof
1010
pub transaction_hash: String,
11-
/// The transaction input of the proof
11+
/// The transaction input of the proof (i.e. the CID of the root of the Merkle tree being anchored)
1212
pub transaction_input: String,
1313
/// The block hash of the proof
1414
pub block_hash: String,

pipeline/src/resolver/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,11 @@ pub struct StreamStateMsg {
441441
pub id: StreamId,
442442
}
443443
impl Message for StreamStateMsg {
444-
type Result = anyhow::Result<Option<StreamState>>;
444+
type Result = anyhow::Result<Option<ResolvedStreamState>>;
445445
}
446446

447-
/// State of a single stream
448-
pub struct StreamState {
447+
/// State of a single stream after conflict resolution
448+
pub struct ResolvedStreamState {
449449
/// Multibase encoding of the stream id
450450
pub id: StreamId,
451451

@@ -462,7 +462,7 @@ pub struct StreamState {
462462
pub data: Vec<u8>,
463463
}
464464

465-
impl std::fmt::Debug for StreamState {
465+
impl std::fmt::Debug for ResolvedStreamState {
466466
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
467467
if !f.alternate() {
468468
f.debug_struct("StreamState")
@@ -583,7 +583,7 @@ impl Handler<StreamStateMsg> for Resolver {
583583
let value = values.value(i);
584584
dimensions.insert(key.to_string(), value.to_vec());
585585
}
586-
Ok(Some(StreamState {
586+
Ok(Some(ResolvedStreamState {
587587
id,
588588
event_cid: Cid::read_bytes(event_cid.value(0)).context("event_cid as a CID")?,
589589
controller: controller.value(0).to_string(),

0 commit comments

Comments
 (0)