11use polycentric_common:: {
22 error:: CoreError ,
3- models:: protos_v2:: { Identity , PublicKey , VectorClock } ,
3+ models:: protos_v2:: { EventKey , Identity , PublicKey , VectorClock } ,
44} ;
55
66use crate :: store:: event_store:: EventStore ;
77
8- /// Structural check against the identity doc + every non-self non-zero
9- /// entry must reference an event we've seen from that co-signer.
8+ /// Check a vector clock against the identity doc.
9+ ///
10+ /// Returns `Err` if the clock is structurally invalid (wrong length, unknown
11+ /// signer, or a self entry that doesn't match the event's sequence).
12+ ///
13+ /// Returns `Ok(missing)` with the referenced events from the identity's other
14+ /// keys that we haven't synced. A missing event does not make the referencing
15+ /// event invalid — it's just an event to fetch. Building the identity chain
16+ /// needs `missing` empty; content readers keep the event either way.
1017pub fn verify_vector_clock (
1118 store : & EventStore ,
1219 vc : & VectorClock ,
@@ -15,9 +22,10 @@ pub fn verify_vector_clock(
1522 collection : i32 ,
1623 signer : & PublicKey ,
1724 expected_self_sequence : u64 ,
18- ) -> Result < ( ) , CoreError > {
25+ ) -> Result < Vec < EventKey > , CoreError > {
1926 let self_position = vc. get_signer_position ( doc, signer, expected_self_sequence) ?;
2027 let dedup = doc. deduplicated_keys ( ) ;
28+ let mut missing = Vec :: new ( ) ;
2129 for ( pos, & observed) in vc. sequence . iter ( ) . enumerate ( ) {
2230 if pos == self_position || observed == 0 {
2331 continue ;
@@ -27,11 +35,13 @@ pub fn verify_vector_clock(
2735 . by_identity_collection_signer ( identity, collection, other. key_type , & other. key , 0 )
2836 . any ( |( k, _) | k. sequence == observed) ;
2937 if !seen {
30- return Err ( CoreError :: InvalidEvent ( format ! (
31- "vector_clock references unseen event from co-signer at sequence {}" ,
32- observed
33- ) ) ) ;
38+ missing. push ( EventKey {
39+ collection,
40+ identity : identity. to_string ( ) ,
41+ signed_by : Some ( other. clone ( ) ) ,
42+ sequence : observed,
43+ } ) ;
3444 }
3545 }
36- Ok ( ( ) )
46+ Ok ( missing )
3747}
0 commit comments