@@ -4,6 +4,7 @@ use ceramic_core::{Cid, EventId, NodeId};
44use ceramic_event:: unvalidated;
55use ipld_core:: ipld:: Ipld ;
66use recon:: ReconItem ;
7+ use tokio:: try_join;
78
89use 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 > {
0 commit comments