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
12 changes: 12 additions & 0 deletions xmtp_api_d14n/proptest-regressions/protocol/sort/causal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 482a9860cc0bd87984e25141e258ed3dd0a46526ab2987bed337f2a82ac232f8 # shrinks to mut envelopes = [TestEnvelope { cursor: Cursor { originator_id: 10, sequence_id: 1 }, depends_on: GlobalCursor { inner: {10: 1} } }, TestEnvelope { cursor: Cursor { originator_id: 40, sequence_id: 1 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { originator_id: 10, sequence_id: 2 }, depends_on: GlobalCursor { inner: {40: 1} } }, TestEnvelope { cursor: Cursor { originator_id: 40, sequence_id: 2 }, depends_on: GlobalCursor { inner: {10: 2, 40: 1} } }, TestEnvelope { cursor: Cursor { originator_id: 30, sequence_id: 1 }, depends_on: GlobalCursor { inner: {40: 2, 10: 2} } }, TestEnvelope { cursor: Cursor { originator_id: 20, sequence_id: 1 }, depends_on: GlobalCursor { inner: {10: 1, 30: 1, 40: 2} } }, TestEnvelope { cursor: Cursor { originator_id: 40, sequence_id: 3 }, depends_on: GlobalCursor { inner: {40: 2, 10: 2} } }, TestEnvelope { cursor: Cursor { originator_id: 10, sequence_id: 3 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { originator_id: 20, sequence_id: 1 }, depends_on: GlobalCursor { inner: {10: 3} } }, TestEnvelope { cursor: Cursor { originator_id: 20, sequence_id: 1 }, depends_on: GlobalCursor { inner: {10: 3, 40: 3, 20: 1, 30: 1} } }]
cc ef7e3e08b816b5d5754da2da39332f27798cedd3a49cd782a8f74ef59512b093 # shrinks to mut env = EnvelopesWithMissing { missing: [TestEnvelope { cursor: Cursor { originator_id: 20, sequence_id: 1 }, depends_on: GlobalCursor { inner: {10: 2, 40: 1} } }], envelopes: [TestEnvelope { cursor: Cursor { originator_id: 20, sequence_id: 1 }, depends_on: GlobalCursor { inner: {10: 2, 40: 1} } }] }
cc 6f3ddf561ffc8eaf9cbef3bd127263538efbc1729b599fa72a7e399d799e23fc # shrinks to mut envelopes = EnvelopesWithMissing { removed: [TestEnvelope { cursor: Cursor { originator_id: 10, sequence_id: 1 }, depends_on: GlobalCursor { inner: {10: 1} } }, TestEnvelope { cursor: Cursor { originator_id: 30, sequence_id: 1 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { originator_id: 40, sequence_id: 1 }, depends_on: GlobalCursor { inner: {} } }], envelopes: [TestEnvelope { cursor: Cursor { originator_id: 10, sequence_id: 2 }, depends_on: GlobalCursor { inner: {40: 1, 10: 1, 30: 1} } }, TestEnvelope { cursor: Cursor { originator_id: 30, sequence_id: 2 }, depends_on: GlobalCursor { inner: {30: 1, 10: 1} } }, TestEnvelope { cursor: Cursor { originator_id: 30, sequence_id: 2 }, depends_on: GlobalCursor { inner: {10: 1, 40: 1} } }, TestEnvelope { cursor: Cursor { originator_id: 40, sequence_id: 2 }, depends_on: GlobalCursor { inner: {10: 2, 40: 1, 30: 2} } }, TestEnvelope { cursor: Cursor { originator_id: 20, sequence_id: 1 }, depends_on: GlobalCursor { inner: {30: 2, 10: 2, 40: 2} } }, TestEnvelope { cursor: Cursor { originator_id: 40, sequence_id: 3 }, depends_on: GlobalCursor { inner: {10: 2, 30: 1, 20: 1, 40: 1} } }, TestEnvelope { cursor: Cursor { originator_id: 30, sequence_id: 3 }, depends_on: GlobalCursor { inner: {30: 2, 20: 1, 10: 2, 40: 2} } }] }
cc d3aa9570c1634dda88771dd96b3bd9ecc3667df1b1202ab686ebe1e49d02e7f0 # shrinks to mut envelopes = EnvelopesWithMissing { removed: [TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 10 }, depends_on: GlobalCursor { inner: {10: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 40 }, depends_on: GlobalCursor { inner: {} } }], envelopes: [TestEnvelope { cursor: Cursor { sequence_id: 2, originator_id: 10 }, depends_on: GlobalCursor { inner: {10: 1, 40: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 20 }, depends_on: GlobalCursor { inner: {40: 1, 10: 2} } }, TestEnvelope { cursor: Cursor { sequence_id: 3, originator_id: 10 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { sequence_id: 3, originator_id: 10 }, depends_on: GlobalCursor { inner: {10: 2, 20: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 2, originator_id: 20 }, depends_on: GlobalCursor { inner: {40: 1, 10: 3, 20: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 4, originator_id: 10 }, depends_on: GlobalCursor { inner: {40: 1, 20: 2} } }, TestEnvelope { cursor: Cursor { sequence_id: 3, originator_id: 20 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { sequence_id: 4, originator_id: 10 }, depends_on: GlobalCursor { inner: {20: 3} } }], original: [TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 10 }, depends_on: GlobalCursor { inner: {10: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 40 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { sequence_id: 2, originator_id: 10 }, depends_on: GlobalCursor { inner: {10: 1, 40: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 20 }, depends_on: GlobalCursor { inner: {40: 1, 10: 2} } }, TestEnvelope { cursor: Cursor { sequence_id: 3, originator_id: 10 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { sequence_id: 3, originator_id: 10 }, depends_on: GlobalCursor { inner: {10: 2, 20: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 2, originator_id: 20 }, depends_on: GlobalCursor { inner: {40: 1, 10: 3, 20: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 4, originator_id: 10 }, depends_on: GlobalCursor { inner: {40: 1, 20: 2} } }, TestEnvelope { cursor: Cursor { sequence_id: 3, originator_id: 20 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { sequence_id: 4, originator_id: 10 }, depends_on: GlobalCursor { inner: {20: 3} } }] }
cc a7823ae07a99a89f88e8382b6515351fd82e6c5fad881286950445e178d87009 # shrinks to mut envelopes = EnvelopesWithMissing { removed: [TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 10 }, depends_on: GlobalCursor { inner: {40: 1} } }], envelopes: [TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 40 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { sequence_id: 2, originator_id: 10 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 30 }, depends_on: GlobalCursor { inner: {10: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 3, originator_id: 10 }, depends_on: GlobalCursor { inner: {10: 2, 30: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 4, originator_id: 10 }, depends_on: GlobalCursor { inner: {40: 1, 10: 3, 30: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 20 }, depends_on: GlobalCursor { inner: {40: 1, 10: 4} } }, TestEnvelope { cursor: Cursor { sequence_id: 2, originator_id: 20 }, depends_on: GlobalCursor { inner: {10: 4, 30: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 2, originator_id: 30 }, depends_on: GlobalCursor { inner: {20: 2, 10: 4} } }], original: [TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 40 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 10 }, depends_on: GlobalCursor { inner: {40: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 2, originator_id: 10 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 30 }, depends_on: GlobalCursor { inner: {10: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 3, originator_id: 10 }, depends_on: GlobalCursor { inner: {10: 2, 30: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 4, originator_id: 10 }, depends_on: GlobalCursor { inner: {40: 1, 10: 3, 30: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 20 }, depends_on: GlobalCursor { inner: {40: 1, 10: 4} } }, TestEnvelope { cursor: Cursor { sequence_id: 2, originator_id: 20 }, depends_on: GlobalCursor { inner: {10: 4, 30: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 2, originator_id: 30 }, depends_on: GlobalCursor { inner: {20: 2, 10: 4} } }] }
cc 74bdcdf7b3791b00386579747f51d6767fb40b8b4578910bd844a4eec08af6b4 # shrinks to mut envelopes = EnvelopesWithMissing { removed: [TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 10 }, depends_on: GlobalCursor { inner: {20: 1, 40: 2} } }], envelopes: [TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 30 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 40 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { sequence_id: 2, originator_id: 40 }, depends_on: GlobalCursor { inner: {40: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 2, originator_id: 30 }, depends_on: GlobalCursor { inner: {30: 1, 40: 1} } }, TestEnvelope { cursor: Cursor { sequence_id: 1, originator_id: 20 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { sequence_id: 2, originator_id: 10 }, depends_on: GlobalCursor { inner: {10: 1, 40: 2, 20: 1, 30: 2} } }, TestEnvelope { cursor: Cursor { sequence_id: 3, originator_id: 10 }, depends_on: GlobalCursor { inner: {} } }, TestEnvelope { cursor: Cursor { sequence_id: 4, originator_id: 10 }, depends_on: GlobalCursor { inner: {10: 2} } }] }
2 changes: 2 additions & 0 deletions xmtp_api_d14n/src/protocol/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ mod cursor;
pub use cursor::*;
mod timestamp;
pub use timestamp::*;
mod depends_on;
pub use depends_on::*;

#[cfg(test)]
pub mod test_utils;
Expand Down
43 changes: 43 additions & 0 deletions xmtp_api_d14n/src/protocol/extractors/depends_on.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Extractor for an MLS Data field
//! useful for verifing a message has been read or maybe duplicates.
use xmtp_proto::ConversionError;
use xmtp_proto::types::GlobalCursor;
use xmtp_proto::xmtp::xmtpv4::envelopes::ClientEnvelope;

use crate::protocol::{EnvelopeVisitor, Extractor};

/// Extract DependsOn from Envelopes
/// If the envelope does not have dependency, or is already
/// ordered (as is the case for v3), then returns `None`.
#[derive(Default, Clone, Debug)]
pub struct DependsOnExtractor {
cursor: Option<GlobalCursor>,
}

impl DependsOnExtractor {
pub fn new() -> Self {
Default::default()
}
}

impl Extractor for DependsOnExtractor {
type Output = Option<GlobalCursor>;

fn get(self) -> Self::Output {
self.cursor
}
}

impl EnvelopeVisitor<'_> for DependsOnExtractor {
type Error = ConversionError;

fn visit_client(&mut self, e: &ClientEnvelope) -> Result<(), Self::Error> {
// to avoid clone here & elsewhere
// https://github.com/xmtp/libxmtp/issues/2691
self.cursor = e
.aad
.as_ref()
.and_then(|a| a.depends_on.clone().map(Into::into));
Ok(())
}
}
11 changes: 10 additions & 1 deletion xmtp_api_d14n/src/protocol/impls/vector_clock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashSet;

use xmtp_proto::types::{ClockOrdering, GlobalCursor};
use xmtp_proto::types::{ClockOrdering, Cursor, GlobalCursor};

use crate::protocol::VectorClock;

Expand Down Expand Up @@ -40,4 +40,13 @@ impl VectorClock for GlobalCursor {
(true, true) => ClockOrdering::Concurrent,
}
}

fn apply(&mut self, cursor: &Cursor) {
let Cursor {
originator_id: node,
sequence_id: seq,
} = &cursor;
let entry = self.entry(*node).or_insert(0);
*entry = (*entry).max(*seq)
}
}
4 changes: 2 additions & 2 deletions xmtp_api_d14n/src/protocol/sort.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Sorting Implelementations on Envelope Collections [XIP](https://github.com/xmtp/XIPs/blob/main/XIPs/xip-49-decentralized-backend.md#335-cross-originator-message-ordering)
// mod causal;
// pub use causal::*;
mod causal;
pub use causal::*;
mod timestamp;
pub use timestamp::*;
Loading
Loading