Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkgs/id/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkgs/id/crates/id-events/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
//!
//! 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`).
//!
//! [`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};

Expand All @@ -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
Expand Down Expand Up @@ -253,10 +253,10 @@ fn past_size(id: Hash, parents: &HashMap<Hash, Vec<Hash>>) -> 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 {
Expand Down Expand Up @@ -285,7 +285,7 @@ mod tests {
after: Vec<Hash>,
group: Option<Hash>,
action: &GroupAction<AuthId, ()>,
) -> (crate::chain::Event, Vec<u8>) {
) -> (id_store::chain::Event, Vec<u8>) {
let body = encode_body(action).unwrap();
let ext = ChainExt {
kind: "group.op".to_owned(),
Expand All @@ -312,7 +312,7 @@ mod tests {
after: Vec<Hash>,
group: Hash,
text: &str,
) -> crate::chain::Event {
) -> id_store::chain::Event {
let ext = ChainExt {
kind: CHAT_MESSAGE_KIND.to_owned(),
group: Some(group),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Hash> {
Expand Down Expand Up @@ -112,7 +112,7 @@ fn default_view_events(
subject_groups: &HashMap<Hash, Hash>,
projection: Option<&Projection>,
) -> Vec<Applied> {
let claims: HashMap<Hash, (crate::waiting::AuthorKey, Hash)> = applied
let claims: HashMap<Hash, (id_core::waiting::AuthorKey, Hash)> = applied
.iter()
.filter_map(|event| match &event.op {
TagOp::Set { subject, .. } => Some((event.id, (event.author, *subject))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
};

Expand Down Expand Up @@ -1615,7 +1615,7 @@ mod tests {
segment_seq: u64,
prev: Option<Hash>,
) -> Event {
use crate::session_checkpoint::{
use id_store::session_checkpoint::{
MacScope, SegmentCheckpoint, SessionCheckpoint, SessionHeader,
};

Expand Down Expand Up @@ -1927,7 +1927,7 @@ mod tests {
group: Option<Hash>,
action: &GroupAction<AuthId, ()>,
) -> (Event, Vec<u8>) {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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,
..
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<super::EventStore>;

/// 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
Expand Down Expand Up @@ -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<Vec<(Key, Id)>>;

Expand All @@ -281,7 +290,7 @@ impl RangeStore for EventStore {
}
}

impl RangeStore for SharedEventStore {
impl RangeStore for Shared {
fn sync_entries(&self) -> Result<Vec<(Key, Id)>> {
Ok(self.range_entries()?)
}
Expand All @@ -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<S: RangeStore>(
pub async fn sync_on_streams<S: RangeStore>(
store: &mut S,
send: &mut SendStream,
recv: &mut RecvStream,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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};

Expand Down
Loading
Loading