From 746cb281b3e2961eba66cbd8a6f818687c3d46c6 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Wed, 11 Nov 2026 05:23:10 -0600 Subject: [PATCH] pkgs/id crate split step 2b-2: move event store family into id-events (#4405) --- pkgs/id/Cargo.lock | 5 +++ pkgs/id/crates/id-events/Cargo.toml | 6 +++ .../{ => crates/id-events}/src/attestation.rs | 4 +- .../id-events}/src/event_store/chat.rs | 22 +++++------ .../id-events}/src/event_store/claims.rs | 8 ++-- .../id-events}/src/event_store/documents.rs | 4 +- .../id-events}/src/event_store/ingest.rs | 28 +++++++------- .../id-events}/src/event_store/mod.rs | 12 +++--- .../id-events}/src/event_store/range.rs | 0 .../id-events}/src/event_store/resolve.rs | 10 ++--- .../id-events}/src/event_store/sync.rs | 31 +++++++++------ .../src/event_store/waiting_rows.rs | 6 +-- .../id-events}/src/event_store/writer_set.rs | 4 +- .../{ => crates/id-events}/src/event_sync.rs | 16 +++++--- pkgs/id/crates/id-events/src/lib.rs | 11 +++--- .../id-events}/src/local_events.rs | 38 +++++++++---------- pkgs/id/src/lib.rs | 8 ++-- 17 files changed, 120 insertions(+), 93 deletions(-) rename pkgs/id/{ => crates/id-events}/src/attestation.rs (99%) rename pkgs/id/{ => crates/id-events}/src/event_store/chat.rs (97%) rename pkgs/id/{ => crates/id-events}/src/event_store/claims.rs (96%) rename pkgs/id/{ => crates/id-events}/src/event_store/documents.rs (97%) rename pkgs/id/{ => crates/id-events}/src/event_store/ingest.rs (99%) rename pkgs/id/{ => crates/id-events}/src/event_store/mod.rs (99%) rename pkgs/id/{ => crates/id-events}/src/event_store/range.rs (100%) rename pkgs/id/{ => crates/id-events}/src/event_store/resolve.rs (99%) rename pkgs/id/{ => crates/id-events}/src/event_store/sync.rs (98%) rename pkgs/id/{ => crates/id-events}/src/event_store/waiting_rows.rs (98%) rename pkgs/id/{ => crates/id-events}/src/event_store/writer_set.rs (99%) rename pkgs/id/{ => crates/id-events}/src/event_sync.rs (96%) rename pkgs/id/{ => crates/id-events}/src/local_events.rs (98%) diff --git a/pkgs/id/Cargo.lock b/pkgs/id/Cargo.lock index 7befd8029..4c947688f 100644 --- a/pkgs/id/Cargo.lock +++ b/pkgs/id/Cargo.lock @@ -4010,15 +4010,20 @@ dependencies = [ "clap", "id-core", "id-store", + "iroh", "iroh-base", "iroh-blobs", "p2panda-auth", "p2panda-core", "proptest", + "redb 4.3.0", "serde", "serde_json", "tempfile", "thiserror 2.0.21", + "tokio", + "tracing", + "tracing-subscriber", "unicode-normalization", ] diff --git a/pkgs/id/crates/id-events/Cargo.toml b/pkgs/id/crates/id-events/Cargo.toml index ee4c04fc6..45fff0cf4 100644 --- a/pkgs/id/crates/id-events/Cargo.toml +++ b/pkgs/id/crates/id-events/Cargo.toml @@ -30,16 +30,22 @@ id-core = { path = "../id-core", default-features = false } id-store = { path = "../id-store", default-features = false } iroh-base = "1" iroh-blobs = "0.103" +iroh = "1" p2panda-auth = { git = "https://github.com/p2panda/p2panda", rev = "da80c05b95269926bf58121cf6a2d3dd5ca41dfc", features = ["serde"] } p2panda-core = { git = "https://github.com/p2panda/p2panda", rev = "da80c05b95269926bf58121cf6a2d3dd5ca41dfc" } serde = { version = "1", features = ["derive"] } serde_json = "1" +redb = "=4.3.0" +tokio = { version = "1", features = ["full"] } +tracing = "0.1" thiserror = "2" unicode-normalization = "0.1" [dev-dependencies] proptest = "1.12" tempfile = "3" +tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } +tokio = { version = "1", features = ["test-util"] } [lints.rust] # Rust compiler lints diff --git a/pkgs/id/src/attestation.rs b/pkgs/id/crates/id-events/src/attestation.rs similarity index 99% rename from pkgs/id/src/attestation.rs rename to pkgs/id/crates/id-events/src/attestation.rs index 98006bb9d..0c04cf370 100644 --- a/pkgs/id/src/attestation.rs +++ b/pkgs/id/crates/id-events/src/attestation.rs @@ -4,7 +4,7 @@ //! API is built on it without the review round the epic (#2056) requires. //! //! The PoC composes the existing primitives — signed chained events -//! ([`crate::chain`]) and the event store — with two new object shapes, +//! ([`id_store::chain`]) and the event store — with two new object shapes, //! carried as ordinary signed events whose bodies are the JSON objects: //! //! - **Genesis agreement** (kind `attestation.genesis`): one event per @@ -40,7 +40,7 @@ use p2panda_core::{Hash, SeqNum, SigningKey}; use serde::{Deserialize, Serialize}; -use crate::chain::{self, ChainExt, Event}; +use id_store::chain::{self, ChainExt, Event}; /// The event kind carrying a genesis agreement body. pub const GENESIS_KIND: &str = "attestation.genesis"; diff --git a/pkgs/id/src/event_store/chat.rs b/pkgs/id/crates/id-events/src/event_store/chat.rs similarity index 97% rename from pkgs/id/src/event_store/chat.rs rename to pkgs/id/crates/id-events/src/event_store/chat.rs index 70c56c8d0..239ad84ff 100644 --- a/pkgs/id/src/event_store/chat.rs +++ b/pkgs/id/crates/id-events/src/event_store/chat.rs @@ -2,7 +2,7 @@ //! //! A chat message is its `chat.message.v1` event in the channel group. The event applies //! like any content event, and the store keeps it either way. [`EventStore::chat_records`] -//! is the record conversion the causal projection in [`crate::chat`] consumes: a stored +//! is the record conversion the causal projection in [`id_store::chat`] consumes: a stored //! event becomes a [`ChatRecord`] with its `after` taken from the header extension and its //! author's previous event taken from the header backlink (the store keeps the author's //! own head out of `after`; see `local_events`). @@ -10,7 +10,7 @@ //! [`EventStore::chat_timeline`] is the policy-enforcing read: a reader who is not on the //! group's roster reads nothing ([`StoreError::NotMember`]), and a member reads the //! projected timeline cut by the group policy's history rule (see -//! [`crate::chat::visible_history`] for the exact semantics of each rule). +//! [`id_store::chat::visible_history`] for the exact semantics of each rule). use std::collections::{HashMap, HashSet}; @@ -23,10 +23,10 @@ use super::{ ACTIONS, APPLIED, DEVICE_OPS, EVENTS, EventStore, FORKS, PROOF_HEADERS, StoreError, corrupt, decode_stored, }; -use crate::chat::{CHAT_MESSAGE_KIND, ChatRecord, project, visible_history}; +use id_store::chat::{CHAT_MESSAGE_KIND, ChatRecord, project, visible_history}; use crate::groups::policy::{History, Policy}; -use crate::membership::AuthId; -use crate::waiting::AuthorKey; +use id_core::membership::AuthId; +use id_core::waiting::AuthorKey; impl EventStore { /// The chat records of `group`: each applied `chat.message.v1` event that names the @@ -253,10 +253,10 @@ fn past_size(id: Hash, parents: &HashMap>) -> usize { #[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] mod tests { use super::*; - use crate::chain::{ChainExt, sign}; - use crate::chat::ChatMessage; - use crate::membership::body::encode_body; - use crate::waiting::WaitingLimits; + use id_store::chain::{ChainExt, sign}; + use id_store::chat::ChatMessage; + use id_core::membership::body::encode_body; + use id_core::waiting::WaitingLimits; use p2panda_core::{SeqNum, SigningKey}; fn key(n: u8) -> SigningKey { @@ -285,7 +285,7 @@ mod tests { after: Vec, group: Option, action: &GroupAction, - ) -> (crate::chain::Event, Vec) { + ) -> (id_store::chain::Event, Vec) { let body = encode_body(action).unwrap(); let ext = ChainExt { kind: "group.op".to_owned(), @@ -312,7 +312,7 @@ mod tests { after: Vec, group: Hash, text: &str, - ) -> crate::chain::Event { + ) -> id_store::chain::Event { let ext = ChainExt { kind: CHAT_MESSAGE_KIND.to_owned(), group: Some(group), diff --git a/pkgs/id/src/event_store/claims.rs b/pkgs/id/crates/id-events/src/event_store/claims.rs similarity index 96% rename from pkgs/id/src/event_store/claims.rs rename to pkgs/id/crates/id-events/src/event_store/claims.rs index 2f827d242..2cba5b1ed 100644 --- a/pkgs/id/src/event_store/claims.rs +++ b/pkgs/id/crates/id-events/src/event_store/claims.rs @@ -13,10 +13,10 @@ use redb::ReadableDatabase; use super::resolve::{self, author_of}; use super::{ACTIONS, DEVICE_OPS, EVENTS, EventStore, FORKS, PROOF_HEADERS, StoreError, corrupt}; -use crate::chain::Event; +use id_store::chain::Event; use crate::groups::{Projection, Role as GroupRole}; -use crate::tag_claims::{Applied, Claim, TagOp, compacted_claims, is_tag_kind}; -use crate::tag_index::TagIndex; +use id_store::tag_claims::{Applied, Claim, TagOp, compacted_claims, is_tag_kind}; +use id_store::tag_index::TagIndex; /// The events an event names: its `after` hashes, and its backlink. fn parents_of(event: &Event) -> Vec { @@ -112,7 +112,7 @@ fn default_view_events( subject_groups: &HashMap, projection: Option<&Projection>, ) -> Vec { - let claims: HashMap = applied + let claims: HashMap = applied .iter() .filter_map(|event| match &event.op { TagOp::Set { subject, .. } => Some((event.id, (event.author, *subject))), diff --git a/pkgs/id/src/event_store/documents.rs b/pkgs/id/crates/id-events/src/event_store/documents.rs similarity index 97% rename from pkgs/id/src/event_store/documents.rs rename to pkgs/id/crates/id-events/src/event_store/documents.rs index f0a8a3571..4a846d8bb 100644 --- a/pkgs/id/src/event_store/documents.rs +++ b/pkgs/id/crates/id-events/src/event_store/documents.rs @@ -16,8 +16,8 @@ use redb::{ReadableDatabase, ReadableTable}; use super::resolve::author_of; use super::{APPLIED, EVENTS, EventStore, StoreError, corrupt, decode_stored}; -use crate::documents::{DOCUMENT_KIND, DocumentRecord, REMOVAL_KIND}; -use crate::waiting::AuthorKey; +use id_store::documents::{DOCUMENT_KIND, DocumentRecord, REMOVAL_KIND}; +use id_core::waiting::AuthorKey; impl EventStore { /// The documents in the store: each applied `document.put`, sorted by event ID. A document diff --git a/pkgs/id/src/event_store/ingest.rs b/pkgs/id/crates/id-events/src/event_store/ingest.rs similarity index 99% rename from pkgs/id/src/event_store/ingest.rs rename to pkgs/id/crates/id-events/src/event_store/ingest.rs index e1ab26a6d..61b064d15 100644 --- a/pkgs/id/src/event_store/ingest.rs +++ b/pkgs/id/crates/id-events/src/event_store/ingest.rs @@ -103,13 +103,13 @@ use super::{ store_chain, store_event, store_fork, }; use super::{Ingest, Refusal}; -use crate::chain::{self, Event}; -use crate::documents::{is_document_kind, is_removal_kind}; -use crate::membership::AuthId; -use crate::membership::body::decode_body; -use crate::rejection::Reason; -use crate::tag_claims::is_tag_kind; -use crate::waiting::{AuthorKey, WaitingPool}; +use id_store::chain::{self, Event}; +use id_store::documents::{is_document_kind, is_removal_kind}; +use id_core::membership::AuthId; +use id_core::membership::body::decode_body; +use id_core::rejection::Reason; +use id_store::tag_claims::is_tag_kind; +use id_core::waiting::{AuthorKey, WaitingPool}; /// What the store decides for one event, before the waiting pool sees it. #[derive(Debug, PartialEq, Eq)] @@ -146,7 +146,7 @@ impl EventStore { /// Verifies one received event with its body, and applies what it allows. This is the /// production path. The membership action comes from the body, by the body codec in - /// [`crate::membership::body`]: + /// [`id_core::membership::body`]: /// /// - A body that is not a group operation, or no body at all, makes the event content. /// - A body that claims to be a group operation decodes to its action, or it is refused. @@ -1138,10 +1138,10 @@ pub(super) fn present_in( #[allow(clippy::unwrap_used, clippy::expect_used)] mod tests { use super::*; - use crate::chain::{ChainExt, sign}; + use id_store::chain::{ChainExt, sign}; use crate::event_store::waiting_rows::{self, Row}; - use crate::rejection::Reason; - use crate::waiting::WaitingLimits; + use id_core::rejection::Reason; + use id_core::waiting::WaitingLimits; use p2panda_core::SigningKey; use redb::ReadableDatabase; @@ -1551,7 +1551,7 @@ mod tests { /// is released by that event's arrival, and reads back byte for byte. #[test] fn test_a_session_checkpoint_waits_and_round_trips() { - use crate::session_checkpoint::{ + use id_store::session_checkpoint::{ MacScope, SegmentCheckpoint, SessionCheckpoint, SessionHeader, }; @@ -1615,7 +1615,7 @@ mod tests { segment_seq: u64, prev: Option, ) -> Event { - use crate::session_checkpoint::{ + use id_store::session_checkpoint::{ MacScope, SegmentCheckpoint, SessionCheckpoint, SessionHeader, }; @@ -1927,7 +1927,7 @@ mod tests { group: Option, action: &GroupAction, ) -> (Event, Vec) { - let body = crate::membership::body::encode_body(action).unwrap(); + let body = id_core::membership::body::encode_body(action).unwrap(); let ext = ChainExt { kind: "group.op".to_owned(), group, diff --git a/pkgs/id/src/event_store/mod.rs b/pkgs/id/crates/id-events/src/event_store/mod.rs similarity index 99% rename from pkgs/id/src/event_store/mod.rs rename to pkgs/id/crates/id-events/src/event_store/mod.rs index 98a338b1d..39d7db09d 100644 --- a/pkgs/id/src/event_store/mod.rs +++ b/pkgs/id/crates/id-events/src/event_store/mod.rs @@ -60,7 +60,7 @@ use redb::{ ReadableTable, StorageError, TableDefinition, WriteTransaction, }; -use crate::chain::{self, Event}; +use id_store::chain::{self, Event}; mod chat; mod claims; @@ -72,7 +72,7 @@ pub mod sync; mod waiting_rows; mod writer_set; -use crate::waiting::{AuthorKey, WaitRefusal, WaitingLimits, WaitingPool}; +use id_core::waiting::{AuthorKey, WaitRefusal, WaitingLimits, WaitingPool}; pub use id_store::event_types::{Ingest, Refusal}; use ingest::{is_present, is_proof_header, present_in}; use waiting_rows::{Mirror, Row}; @@ -370,7 +370,7 @@ impl BlockList for EventStore { fn is_blocked(&self, kind: BlockKind, value: &[u8]) -> bool { // A read error invents no block: the seam fails open, and the // store's error still surfaces on the store's own read paths. - EventStore::is_blocked(self, kind, value, crate::time::unix_ms()).unwrap_or(false) + EventStore::is_blocked(self, kind, value, id_core::time::unix_ms()).unwrap_or(false) } } @@ -617,7 +617,7 @@ impl EventStore { // `after`: the note it revises and the parent revisions it builds on are // dependencies too, so a surviving revision keeps its note and its whole // parent history alive through a prune (#3814). - if let Some(crate::notes::NoteOp::Revise { + if let Some(id_store::notes::NoteOp::Revise { note, parents: note_parents, .. @@ -631,7 +631,7 @@ impl EventStore { // optional pinned revision are dependencies too, so a surviving link // keeps them alive through a prune; otherwise rebuilding the link // projection after the prune would fail with UnknownTarget (#3816). - if let Some(crate::note_links::NoteLinkOp::Assert { + if let Some(id_store::note_links::NoteLinkOp::Assert { source, revision, target, @@ -1423,7 +1423,7 @@ impl EventStore { #[allow(clippy::unwrap_used, clippy::expect_used)] mod tests { use super::*; - use crate::chain::{ChainExt, sign}; + use id_store::chain::{ChainExt, sign}; use p2panda_core::SigningKey; fn key(n: u8) -> SigningKey { diff --git a/pkgs/id/src/event_store/range.rs b/pkgs/id/crates/id-events/src/event_store/range.rs similarity index 100% rename from pkgs/id/src/event_store/range.rs rename to pkgs/id/crates/id-events/src/event_store/range.rs diff --git a/pkgs/id/src/event_store/resolve.rs b/pkgs/id/crates/id-events/src/event_store/resolve.rs similarity index 99% rename from pkgs/id/src/event_store/resolve.rs rename to pkgs/id/crates/id-events/src/event_store/resolve.rs index 7d1ef9732..8edbb55ff 100644 --- a/pkgs/id/src/event_store/resolve.rs +++ b/pkgs/id/crates/id-events/src/event_store/resolve.rs @@ -45,15 +45,15 @@ use p2panda_core::{Hash, SeqNum}; use redb::ReadableTable; use super::{StoreError, corrupt, decode_proof, decode_stored, split_position}; -use crate::chain::Event; -use crate::chat::CHAT_MESSAGE_KIND; +use id_store::chain::Event; +use id_store::chat::CHAT_MESSAGE_KIND; use crate::groups::{ Body as GroupBody, Create as GroupCreate, DeviceOp, Event as GroupEvent, MemberOp, Policy, Projection, Role as GroupRole, Template, }; -use crate::membership::{AuthId, CausalEvent, Membership, Role}; -use crate::rejection::Reason; -use crate::waiting::AuthorKey; +use id_core::membership::{AuthId, CausalEvent, Membership, Role}; +use id_core::rejection::Reason; +use id_core::waiting::AuthorKey; /// One stored event, with the membership action it carries when it is a group operation. #[derive(Clone, Debug)] diff --git a/pkgs/id/src/event_store/sync.rs b/pkgs/id/crates/id-events/src/event_store/sync.rs similarity index 98% rename from pkgs/id/src/event_store/sync.rs rename to pkgs/id/crates/id-events/src/event_store/sync.rs index a5c9d2d21..4bc0386f9 100644 --- a/pkgs/id/src/event_store/sync.rs +++ b/pkgs/id/crates/id-events/src/event_store/sync.rs @@ -1,7 +1,7 @@ //! Range sync over the event store, on `/id-range-sync/1`. //! //! The ALPN is this protocol's alone (#179). Range sessions used to share `/id-sync/1` -//! with the `LogSync` handshake sessions in [`crate::log_sync`], whose first frame is a +//! with the `LogSync` handshake sessions in `id::log_sync`, whose first frame is a //! `Request` - two different session shapes on one ALPN, so a peer opening with one //! shape was misread by an acceptor expecting the other. The split is deliberate and //! documented here rather than silent: `/id-sync/1` is the handshake session's, and a @@ -53,9 +53,14 @@ use super::{ EVENTS, EventStore, HASHES, Ingest, PROOF_HEADERS, StoreError, corrupt, decode_stored, position_key, }; -use crate::chain::{self, Event}; +use id_store::chain::{self, Event}; use crate::pull_policy::{PullGate, PullRefused}; -use crate::store_traits::SharedEventStore; +use id_store::store_traits::SharedEventStore; + +/// The shared handle over this crate's [`EventStore`](super::EventStore): +/// the pin the facade's `store_traits` alias names, owned here since +/// step 2b so the range sessions below can implement over it. +type Shared = SharedEventStore; /// The protocol ID. The wire version only; K and T are not in it. Distinct from /// `log_sync`'s `/id-sync/1` since #179 (see the module docs): the two session shapes @@ -252,11 +257,15 @@ pub async fn sync_over( /// A session touches its store in short steps — the sync set once at the start, one /// event's bytes per offer, one ingest batch per flush — and never needs the store /// across an await: [`run_session`] guards the store with a `Mutex` it locks per step. -/// That is the seam that lets a session run over [`SharedEventStore`] (#179): its +/// That is the seam that lets a session run over [`Shared`] (#179): its /// implementation takes the shared `RwLock` per step, read for the queries and write /// for one batch, instead of holding a write guard for the session's whole life, which /// would block every other user of the store behind a network wait. -pub(crate) trait RangeStore { +/// The store seam one range session runs over. `pub` since step 2b: +/// the facade's `log_sync` drives sessions through +/// [`sync_on_streams`] over this trait, as it did when both lived in +/// one crate. +pub trait RangeStore { /// The sync set, as [`EventStore::sync_entries`]. fn sync_entries(&self) -> Result>; @@ -281,7 +290,7 @@ impl RangeStore for EventStore { } } -impl RangeStore for SharedEventStore { +impl RangeStore for Shared { fn sync_entries(&self) -> Result> { Ok(self.range_entries()?) } @@ -301,7 +310,7 @@ impl RangeStore for SharedEventStore { /// `log_sync::answer`, exactly as for a `Log` session, and the caller's deadline bounds /// this call. The sync set is the store's whole set, as in [`sync_over`]: range sync /// has no topic subset. -pub(crate) async fn sync_on_streams( +pub async fn sync_on_streams( store: &mut S, send: &mut SendStream, recv: &mut RecvStream, @@ -783,9 +792,9 @@ mod tests { use std::time::Duration; use super::*; - use crate::chain::ChainExt; + use id_store::chain::ChainExt; use crate::pull_policy::{PullPolicy, PullRefused, testing}; - use crate::waiting::WaitingLimits; + use id_core::waiting::WaitingLimits; use p2panda_core::{Hash, SigningKey}; use std::sync::Arc; @@ -1254,8 +1263,8 @@ mod tests { /// turned away, while this one is kept. #[tokio::test(flavor = "multi_thread")] async fn test_a_range_session_counts_a_stored_but_unapplied_arrival_as_voided() { - use crate::membership::AuthId; - use crate::membership::body::encode_body; + use id_core::membership::AuthId; + use id_core::membership::body::encode_body; use p2panda_auth::Access; use p2panda_auth::group::{GroupAction, GroupMember}; diff --git a/pkgs/id/src/event_store/waiting_rows.rs b/pkgs/id/crates/id-events/src/event_store/waiting_rows.rs similarity index 98% rename from pkgs/id/src/event_store/waiting_rows.rs rename to pkgs/id/crates/id-events/src/event_store/waiting_rows.rs index bcb9678bb..fc0c42576 100644 --- a/pkgs/id/src/event_store/waiting_rows.rs +++ b/pkgs/id/crates/id-events/src/event_store/waiting_rows.rs @@ -3,7 +3,7 @@ //! //! An event is held when it has arrived but cannot apply yet: a dependency is missing, or it //! can never apply and is parked, so that a conflict with it is still seen. The pool holds it -//! in memory, under the caps in [`WaitingLimits`](crate::waiting::WaitingLimits). The same +//! in memory, under the caps in [`WaitingLimits`](id_core::waiting::WaitingLimits). The same //! events are written to two tables: //! //! - `waiting`: an event's ID to its row. The row holds the author, the sequence number, the @@ -20,8 +20,8 @@ use p2panda_core::{Hash, SeqNum}; use redb::{ReadableMultimapTable, ReadableTable, WriteTransaction}; use super::{StoreError, WAITING, WAITING_BY_DEP, be_u64, corrupt, hash_of, row_event, seq_num}; -use crate::chain::Event; -use crate::waiting::{AuthorKey, WaitRefusal, WaitingPool}; +use id_store::chain::Event; +use id_core::waiting::{AuthorKey, WaitRefusal, WaitingPool}; /// Bytes before a row's dependencies: the author, the sequence number, the arrival time, the /// arrival number, and the dependency count. diff --git a/pkgs/id/src/event_store/writer_set.rs b/pkgs/id/crates/id-events/src/event_store/writer_set.rs similarity index 99% rename from pkgs/id/src/event_store/writer_set.rs rename to pkgs/id/crates/id-events/src/event_store/writer_set.rs index f5cc72d55..6146e49b7 100644 --- a/pkgs/id/src/event_store/writer_set.rs +++ b/pkgs/id/crates/id-events/src/event_store/writer_set.rs @@ -41,7 +41,7 @@ use redb::{ReadableDatabase, ReadableTable}; use crate::groups::Role; use crate::idset::view::{ExpandedWriters, GroupMembers, ProjectionError, expand_set}; use crate::idset::{IdsetError, Rescind, WriterSet, decode_rescind_body, decode_writer_body}; -use crate::waiting::AuthorKey; +use id_core::waiting::AuthorKey; use super::{EventStore, StoreError, WRITER_SET_BODIES, resolve}; @@ -161,7 +161,7 @@ impl EventStore { &self, id: &Hash, kind: &str, - ) -> Result)>, WriterSetStoreError> { + ) -> Result)>, WriterSetStoreError> { let Some(event) = self.event_by_id(id)? else { return Ok(None); }; diff --git a/pkgs/id/src/event_sync.rs b/pkgs/id/crates/id-events/src/event_sync.rs similarity index 96% rename from pkgs/id/src/event_sync.rs rename to pkgs/id/crates/id-events/src/event_sync.rs index 84681e4c1..36b910350 100644 --- a/pkgs/id/src/event_sync.rs +++ b/pkgs/id/crates/id-events/src/event_sync.rs @@ -40,7 +40,7 @@ use iroh::{Endpoint, EndpointAddr}; use iroh_base::EndpointId; use tokio::sync::Mutex; -use crate::blob_gate::WorldAccess; +use crate::world_access::WorldAccess; use crate::event_store::sync::{ALPN, Outcome}; use crate::local_events::LocalEvents; use crate::pull_policy::{PullGate, PullPolicy}; @@ -55,7 +55,10 @@ pub const SYNC_INTERVAL: Duration = Duration::from_secs(30); /// How long the accepting side waits, after a completed session, for the dialer /// to close the connection before it lets the router close it instead (see /// `EventSyncProtocol::accept`). -pub(crate) const CLOSE_WAIT: Duration = Duration::from_secs(5); +/// How long a closing session waits for its peer. `pub` since step +/// 2b: the facade's artifact serving names it, as it did when both +/// lived in one crate. +pub const CLOSE_WAIT: Duration = Duration::from_secs(5); /// Membership answers for this store, which is not a world and has no membership /// source. [`PullPolicy::Open`] admits every peer without reading membership, so @@ -182,7 +185,7 @@ pub async fn sync_with_peer( events: &Arc>, gate: &PullGate, ) -> Result { - let conn = crate::connectivity::connect(endpoint, peer, ALPN).await?; + let conn = id_core::connectivity::connect(endpoint, peer, ALPN).await?; let outcome = { let mut events = events.lock().await; events @@ -254,9 +257,12 @@ mod tests { /// session opens with a range flight, and the two shapes misread each other. #[test] fn test_range_alpn_is_distinct_from_handshake_alpn() { - assert_ne!(ALPN, crate::log_sync::SYNC_ALPN); + // The handshake ALPN is the facade's `log_sync::SYNC_ALPN` + // (`/id-sync/1`); it stays a literal here since step 2b — + // `log_sync` is above this crate, and the value is the wire + // constant the distinctness rule is about. + assert_ne!(ALPN, b"/id-sync/1"); assert_eq!(ALPN, b"/id-range-sync/1"); - assert_eq!(crate::log_sync::SYNC_ALPN, b"/id-sync/1"); } /// The #792 acceptance test: a document revision published (saved) on node A is diff --git a/pkgs/id/crates/id-events/src/lib.rs b/pkgs/id/crates/id-events/src/lib.rs index 9002017e7..2f2077074 100644 --- a/pkgs/id/crates/id-events/src/lib.rs +++ b/pkgs/id/crates/id-events/src/lib.rs @@ -17,14 +17,15 @@ //! event sync paths name. The facade's blob gate keeps its //! enforcement logic and re-exports [`world_access::WorldAccess`]. //! -//! The event-store implementation itself (`event_store`, -//! `local_events`, `event_sync`, `attestation`) joins this crate in -//! step 2b's second half. The facade re-exports each module at its -//! historical `id::` path, so no call site outside the moved modules -//! changed. +//! The facade re-exports each module at its historical `id::` path, +//! so no call site outside the moved modules changed. +pub mod attestation; +pub mod event_store; +pub mod event_sync; pub mod groups; pub mod idset; pub mod local_claims; +pub mod local_events; pub mod pull_policy; pub mod world_access; diff --git a/pkgs/id/src/local_events.rs b/pkgs/id/crates/id-events/src/local_events.rs similarity index 98% rename from pkgs/id/src/local_events.rs rename to pkgs/id/crates/id-events/src/local_events.rs index 9c901c2d8..6b0212a70 100644 --- a/pkgs/id/src/local_events.rs +++ b/pkgs/id/crates/id-events/src/local_events.rs @@ -12,7 +12,7 @@ //! next session carries to a peer (#792). //! //! The reads walk every applied event, which is fine for the CLI and is not an index. The document -//! and tag rules are the ones in [`crate::documents`] and [`crate::tag_claims`]. +//! and tag rules are the ones in [`id_store::documents`] and [`id_store::tag_claims`]. use std::collections::{HashMap, HashSet}; use std::path::Path; @@ -21,20 +21,20 @@ use std::time::{SystemTime, UNIX_EPOCH}; use anyhow::{Context, Result, bail}; use p2panda_core::{Hash, SigningKey}; -use crate::chain::{ChainExt, Event, MAX_AFTER, sign}; -use crate::chat::{CHAT_MESSAGE_KIND, ChatMessage, ChatRecord, SendRate}; -use crate::documents::{DOCUMENT_KIND, DocumentRef, REMOVAL_KIND}; +use id_store::chain::{ChainExt, Event, MAX_AFTER, sign}; +use id_store::chat::{CHAT_MESSAGE_KIND, ChatMessage, ChatRecord, SendRate}; +use id_store::documents::{DOCUMENT_KIND, DocumentRef, REMOVAL_KIND}; use crate::event_store::{Block, BlockKind, EventStore, Ingest}; use crate::local_claims::LocalClaims; -use crate::notes::{ +use id_store::notes::{ AppliedNote, CREATE_KIND as NOTE_CREATE_KIND, NoteFoldError, NoteOp, NoteRecord, REVISE_KIND as NOTE_REVISE_KIND, check_note_op, fold_notes, }; -use crate::search::{Hit, ValueMatch, search_store}; -use crate::tag_claims::{ +use id_store::search::{Hit, ValueMatch, search_store}; +use id_store::tag_claims::{ CLEAR_KIND, Claim, LocalClaim, MAX_CLEAR_CLAIMS, SET_KIND, TagOp, TagScope, check_op, }; -use crate::waiting::{AuthorKey, WaitingLimits}; +use id_core::waiting::{AuthorKey, WaitingLimits}; /// The directory the event store lives in, under the data directory, unless `--event-store` names /// another. @@ -278,7 +278,7 @@ impl LocalEvents { /// Adds `block` to the operator block list (#2245), replacing any row /// that names the same kind and value. The enforcement seams - /// ([`crate::abuse`], [`crate::blob_gate`], [`crate::pull_policy`]) + /// (`id::abuse`, `id::blob_gate`, [`crate::pull_policy`]) /// read the list live, so a block lands on the next check. /// /// # Errors @@ -315,7 +315,7 @@ impl LocalEvents { /// Whether (`kind`, `value`) is blocked right now, judged against the /// wall clock exactly as the enforcement seams judge it (#2245). /// Reads go through [`crate::event_store::BlockList`], the same trait - /// [`crate::abuse`], [`crate::blob_gate`] and [`crate::pull_policy`] + /// `id::abuse`, `id::blob_gate` and [`crate::pull_policy`] /// consult, so a web-written row and an enforced row are one row. #[must_use] pub fn is_blocked(&self, kind: BlockKind, value: &[u8]) -> bool { @@ -387,8 +387,8 @@ impl LocalEvents { if !self.chat_rate.admit(now_ms()) { bail!( "the chat send rate is exhausted: at most {} messages in {} ms", - crate::chat::SEND_RATE_MAX, - crate::chat::SEND_RATE_WINDOW_MS + id_store::chat::SEND_RATE_MAX, + id_store::chat::SEND_RATE_WINDOW_MS ); } self.record( @@ -431,7 +431,7 @@ impl LocalEvents { /// A [`TagScope::Shared`] claim is a signed `tag.set` event, exactly as [`LocalEvents::set_tag`] /// records it, and its ID is the event's. A [`TagScope::Local`] claim is never signed and never /// enters the event store, so it never reaches another node; its ID is derived from its content - /// ([`crate::tag_claims::LocalClaim::id_for`]). Both kinds are returned by + /// ([`id_store::tag_claims::LocalClaim::id_for`]). Both kinds are returned by /// [`LocalEvents::tags_on`], [`LocalEvents::search`] and [`LocalEvents::review_tags`], each /// carrying its scope. /// @@ -686,7 +686,7 @@ impl LocalEvents { Ok(claims) } - /// The live claims that match `name`, and `value` if given, as [`crate::search`] returns them. + /// The live claims that match `name`, and `value` if given, as [`id_store::search`] returns them. /// /// # Errors /// @@ -1215,7 +1215,7 @@ mod tests { // subject -- more distinct authors than MAX_AFTER, so the clear must // split by author. The markers name exactly those claims, and each // named claim sits in its marker's causal past, which is what removes - // a claim in the fold (crate::tag_claims). A claim with a different + // a claim in the fold (id_store::tag_claims). A claim with a different // name on the same subject, and a same-name claim on a different // subject, are named by no marker. // @@ -1272,7 +1272,7 @@ mod tests { // Each named claim sits in this marker's causal past. let seen = parents .get(id) - .map(|named_parents| crate::tag_claims::causal_past(named_parents, &parents)) + .map(|named_parents| id_store::tag_claims::causal_past(named_parents, &parents)) .unwrap_or_default(); for claim in claims { assert!(named.insert(*claim), "a claim is named by two markers"); @@ -1722,8 +1722,8 @@ mod tests { #[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] mod chat_tests { use super::*; - use crate::membership::AuthId; - use crate::membership::body::encode_body; + use id_core::membership::AuthId; + use id_core::membership::body::encode_body; use p2panda_auth::group::{GroupAction, GroupMember}; fn key(n: u8) -> SigningKey { @@ -1843,7 +1843,7 @@ mod chat_tests { // The configuration seam (#3950): a small burst in a wide window, so the test // does not depend on how fast the sends happen. The default configuration is // the world-chat 50 per 10 seconds, unit-tested in the chat module. - node.chat_rate = SendRate::new(crate::chat::ChatRateConfig { + node.chat_rate = SendRate::new(id_store::chat::ChatRateConfig { max: 3, window_ms: 60_000, }); diff --git a/pkgs/id/src/lib.rs b/pkgs/id/src/lib.rs index 0f0d7c281..ee337750f 100644 --- a/pkgs/id/src/lib.rs +++ b/pkgs/id/src/lib.rs @@ -158,7 +158,7 @@ pub mod aliases; pub mod app_manifest; #[cfg(feature = "world")] pub mod artifact; -pub mod attestation; +pub use id_events::attestation; pub mod backup; pub mod blob_gate; #[cfg(feature = "world")] @@ -192,8 +192,8 @@ pub mod encryption; pub mod envelope_net; #[cfg(feature = "world")] pub mod envelope_outbox; -pub mod event_store; -pub mod event_sync; +pub use id_events::event_store; +pub use id_events::event_sync; pub mod fileops; pub mod foreign_libsql; pub mod frames; @@ -210,7 +210,7 @@ pub use id_store::issuer_rotation; pub(crate) mod key_envelope; pub mod local; pub use id_events::local_claims; -pub mod local_events; +pub use id_events::local_events; pub mod log_sync; mod peer_announcement; pub mod serve_proxy;