repo: newtype commit cid & rev to CidLink & Tid

Lewis: May this revision serve well! <lu5a@proton.me>
This commit is contained in:
Lewis
2026-07-12 08:03:14 +02:00
parent 469255f5a9
commit d238affd76
51 changed files with 356 additions and 317 deletions
+2 -2
View File
@@ -17,7 +17,7 @@ use tranquil_pds::delegation::{
};
use tranquil_pds::rate_limit::{AccountCreationLimit, RateLimited};
use tranquil_pds::state::AppState;
use tranquil_pds::types::{Did, Handle};
use tranquil_pds::types::{CidLink, Did, Handle};
pub async fn list_controllers(
State(state): State<AppState>,
@@ -394,7 +394,7 @@ pub async fn create_delegated_account(
controller_scopes: input.controller_scopes.as_str().to_string(),
encrypted_key_bytes: repo.encrypted_key_bytes,
encryption_version: tranquil_pds::config::ENCRYPTION_VERSION,
commit_cid: repo.commit_cid.to_string(),
commit_cid: CidLink::from(repo.commit_cid.to_string()),
repo_rev: repo.repo_rev.clone(),
genesis_block_cids: repo.genesis_block_cids,
};
+12 -20
View File
@@ -14,7 +14,7 @@ use tranquil_pds::api::invite::check_registration_invite;
use tranquil_pds::auth::{ServiceTokenVerifier, extract_auth_token_from_header, is_service_token};
use tranquil_pds::rate_limit::{AccountCreationLimit, RateLimited};
use tranquil_pds::state::AppState;
use tranquil_pds::types::{Did, Handle, PlainPassword};
use tranquil_pds::types::{CidLink, Did, Handle, Nsid, PlainPassword};
use tranquil_pds::validation::validate_password;
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
@@ -438,23 +438,15 @@ pub async fn create_account(
None
};
let did_for_commit: Did = match did.parse() {
Ok(d) => d,
Err(_) => return ApiError::InternalError(Some("Invalid DID".into())).into_response(),
};
let repo = match super::provision::init_genesis_repo(
&state,
&did_for_commit,
&signing_key,
&secret_key_bytes,
)
.await
{
Ok(r) => r,
Err(e) => return e.into_response(),
};
let commit_cid_str = repo.commit_cid.to_string();
let rev_str = repo.repo_rev.clone();
let repo =
match super::provision::init_genesis_repo(&state, &did, &signing_key, &secret_key_bytes)
.await
{
Ok(r) => r,
Err(e) => return e.into_response(),
};
let commit_cid = CidLink::from(repo.commit_cid.to_string());
let repo_rev = repo.repo_rev.clone();
let birthdate_pref = if tranquil_config::get().server.age_assurance_override {
Some(json!({
@@ -487,8 +479,8 @@ pub async fn create_account(
encrypted_key_bytes: repo.encrypted_key_bytes,
encryption_version: tranquil_pds::config::ENCRYPTION_VERSION,
reserved_key_id,
commit_cid: commit_cid_str.clone(),
repo_rev: rev_str.clone(),
commit_cid: commit_cid.clone(),
repo_rev: repo_rev.clone(),
genesis_block_cids: repo.genesis_block_cids,
invite_code: invite_registration.into_invite_code(),
birthdate_pref,
@@ -1,4 +1,4 @@
use jacquard_common::types::{integer::LimitedU32, string::Tid};
use jacquard_common::types::{integer::LimitedU32, string::Tid as JacquardTid};
use jacquard_repo::{mst::Mst, storage::BlockStore};
use k256::ecdsa::SigningKey;
use std::sync::Arc;
@@ -6,7 +6,7 @@ use tranquil_db_traits::CommsChannel;
use tranquil_pds::api::error::ApiError;
use tranquil_pds::repo_ops::create_signed_commit;
use tranquil_pds::state::AppState;
use tranquil_pds::types::{Did, Handle};
use tranquil_pds::types::{CidLink, Did, Handle, Tid};
pub struct PlcDidResult {
pub did: Did,
@@ -74,7 +74,7 @@ pub struct GenesisRepo {
pub encrypted_key_bytes: Vec<u8>,
pub commit_cid: cid::Cid,
pub mst_root_cid: cid::Cid,
pub repo_rev: String,
pub repo_rev: Tid,
pub genesis_block_cids: Vec<Vec<u8>>,
}
@@ -96,8 +96,8 @@ pub async fn init_genesis_repo(
ApiError::InternalError(None)
})?;
let rev = Tid::now(LimitedU32::MIN);
let (commit_bytes, _sig) = create_signed_commit(did, mst_root, rev.as_ref(), None, signing_key)
let rev = JacquardTid::now(LimitedU32::MIN);
let (commit_bytes, _sig) = create_signed_commit(did, mst_root, &rev, None, signing_key)
.map_err(|e| {
tracing::error!("Error creating genesis commit: {:?}", e);
ApiError::InternalError(None)
@@ -112,7 +112,7 @@ pub async fn init_genesis_repo(
encrypted_key_bytes,
commit_cid,
mst_root_cid: mst_root,
repo_rev: rev.as_ref().to_string(),
repo_rev: Tid::from(rev.as_ref().to_string()),
genesis_block_cids: vec![mst_root.to_bytes(), commit_cid.to_bytes()],
})
}
@@ -201,7 +201,7 @@ pub async fn sequence_new_account(
if let Err(e) = tranquil_pds::repo_ops::sequence_sync_event(
state,
did,
&repo.commit_cid.to_string(),
&CidLink::from(repo.commit_cid.to_string()),
Some(&repo.repo_rev),
)
.await
+1 -1
View File
@@ -16,7 +16,7 @@ use tranquil_pds::api::error::{ApiError, DbResultExt};
use tranquil_pds::auth::{Auth, AuthAny, NotTakendown, Permissive, VerifyScope};
use tranquil_pds::delegation::DelegationActionType;
use tranquil_pds::state::AppState;
use tranquil_pds::types::{CidLink, Did};
use tranquil_pds::types::{CidLink, Did, Nsid};
use tranquil_pds::util::get_header_str;
fn detect_mime_type(data: &[u8], client_hint: &str) -> String {
+1
View File
@@ -238,6 +238,7 @@ pub async fn import_repo(
ApiError::InternalError(None)
})?;
let new_root_cid_link = CidLink::from(&new_root_cid);
let new_rev_tid = tranquil_pds::types::Tid::from(new_rev_str.clone());
state
.repos
.repo
+2 -2
View File
@@ -18,7 +18,7 @@ use tranquil_pds::repo_ops::{
finalize_repo_write, with_repair_retry,
};
use tranquil_pds::state::AppState;
use tranquil_pds::types::{AtIdentifier, AtUri, Did, Nsid, Rkey};
use tranquil_pds::types::{AtIdentifier, AtUri, CidLink, Did, Nsid, Rkey};
use tranquil_pds::validation::ValidationStatus;
const MAX_BATCH_WRITES: usize = 200;
@@ -27,7 +27,7 @@ struct WriteAccumulator {
mst: Mst<TrackingBlockStore>,
results: Vec<WriteResult>,
ops: Vec<RecordOp>,
all_blob_cids: Vec<String>,
all_blob_cids: Vec<CidLink>,
backlinks_to_add: Vec<Backlink>,
backlinks_to_remove: Vec<AtUri>,
}
+2 -2
View File
@@ -17,7 +17,7 @@ use tranquil_pds::repo_ops::{
finalize_repo_write, with_repair_retry,
};
use tranquil_pds::state::AppState;
use tranquil_pds::types::{AtIdentifier, AtUri, Did, Nsid, Rkey};
use tranquil_pds::types::{AtIdentifier, AtUri, Did, Nsid, Rkey, Tid};
use tranquil_pds::validation::ValidationStatus;
use uuid::Uuid;
@@ -102,7 +102,7 @@ pub struct CreateRecordInput {
#[serde(rename_all = "camelCase")]
pub struct CommitInfo {
pub cid: String,
pub rev: String,
pub rev: Tid,
}
#[derive(Serialize)]
@@ -18,7 +18,7 @@ use tranquil_pds::cache::Cache;
use tranquil_pds::oauth::scopes::{AccountAction, AccountAttr};
use tranquil_pds::plc::PlcClient;
use tranquil_pds::state::AppState;
use tranquil_pds::types::PlainPassword;
use tranquil_pds::types::{PlainPassword, Tid};
use uuid::Uuid;
#[derive(Serialize)]
@@ -27,7 +27,7 @@ pub struct CheckAccountStatusOutput {
pub activated: bool,
pub valid_did: bool,
pub repo_commit: String,
pub repo_rev: String,
pub repo_rev: Tid,
pub repo_blocks: i64,
pub indexed_records: i64,
pub private_state_values: i64,
@@ -72,16 +72,16 @@ pub async fn check_account_status(
if let Ok(Some(block)) = state.block_store.get(&cid).await {
Commit::from_cbor(&block)
.ok()
.map(|c| c.rev().to_string())
.unwrap_or_default()
.map(|c| Tid::from(c.rev().to_string()))
.unwrap_or_else(|| Tid::from(String::new()))
} else {
String::new()
Tid::from(String::new())
}
} else {
String::new()
Tid::from(String::new())
}
} else {
String::new()
Tid::from(String::new())
};
let record_count: i64 = state.repos.repo.count_records(user_id).await.unwrap_or(0);
let imported_blobs: i64 = state
@@ -449,7 +449,9 @@ pub async fn activate_account(
);
let rev = if let Ok(cid) = Cid::from_str(root_cid_link.as_str()) {
if let Ok(Some(block)) = state.block_store.get(&cid).await {
Commit::from_cbor(&block).ok().map(|c| c.rev().to_string())
Commit::from_cbor(&block)
.ok()
.map(|c| Tid::from(c.rev().to_string()))
} else {
None
}
@@ -459,8 +461,8 @@ pub async fn activate_account(
if let Err(e) = tranquil_pds::repo_ops::sequence_sync_event(
&state,
&did,
root_cid_link.as_str(),
rev.as_deref(),
&root_cid_link,
rev.as_ref(),
)
.await
{
@@ -318,7 +318,7 @@ pub async fn create_passkey_account(
encrypted_key_bytes: repo.encrypted_key_bytes,
encryption_version: tranquil_pds::config::ENCRYPTION_VERSION,
reserved_key_id,
commit_cid: repo.commit_cid.to_string(),
commit_cid: tranquil_types::CidLink::from(repo.commit_cid.to_string()),
repo_rev: repo.repo_rev.clone(),
genesis_block_cids: repo.genesis_block_cids,
invite_code: invite_registration.into_invite_code(),
+3 -1
View File
@@ -58,7 +58,9 @@ pub async fn dereference_scope(
for part in scope_parts {
if let Some(cid_str) = part.strip_prefix("ref:") {
let cache_key = tranquil_pds::cache_keys::scope_ref_key(cid_str);
let cache_key = tranquil_pds::cache_keys::scope_ref_key(
&tranquil_types::CidLink::from(cid_str.to_string()),
);
if let Some(cached) = state.cache.get(&cache_key).await {
for s in cached.split_whitespace() {
if !resolved_scopes.contains(&s.to_string()) {
+2 -2
View File
@@ -1,6 +1,6 @@
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use tranquil_types::{AtUri, CidLink, Did};
use tranquil_types::{AtUri, CidLink, Did, Tid};
use uuid::Uuid;
use crate::DbError;
@@ -58,7 +58,7 @@ pub trait BlobRepository: Send + Sync {
limit: i64,
) -> Result<Vec<CidLink>, DbError>;
async fn list_blobs_since_rev(&self, did: &Did, since: &str) -> Result<Vec<CidLink>, DbError>;
async fn list_blobs_since_rev(&self, did: &Did, since: &Tid) -> Result<Vec<CidLink>, DbError>;
async fn count_blobs_by_user(&self, user_id: Uuid) -> Result<i64, DbError>;
+1 -1
View File
@@ -1,7 +1,7 @@
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use tranquil_types::{CidLink, Did, Handle};
use tranquil_types::{CidLink, Did, Handle, InviteCode};
use uuid::Uuid;
use crate::DbError;
+18 -18
View File
@@ -1,7 +1,7 @@
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use tranquil_types::{AtUri, CidLink, Did, Handle, Nsid, Rkey};
use tranquil_types::{AtUri, CidLink, Did, Handle, Nsid, Rkey, Tid};
use uuid::Uuid;
use crate::DbError;
@@ -137,7 +137,7 @@ pub struct RepoAccountInfo {
pub struct RepoInfo {
pub user_id: Uuid,
pub repo_root_cid: CidLink,
pub repo_rev: Option<String>,
pub repo_rev: Option<Tid>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -169,7 +169,7 @@ pub struct RepoWithoutRev {
pub struct UserWithoutBlocks {
pub user_id: Uuid,
pub repo_root_cid: CidLink,
pub repo_rev: Option<String>,
pub repo_rev: Option<Tid>,
}
#[derive(Debug, Clone)]
@@ -225,7 +225,7 @@ pub struct EventBlockInline {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum EventBlocks {
Inline(Vec<EventBlockInline>),
LegacyCids(Vec<String>),
LegacyCids(Vec<CidLink>),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -238,12 +238,12 @@ pub struct SequencedEvent {
pub prev_cid: Option<CidLink>,
pub prev_data_cid: Option<CidLink>,
pub ops: Option<serde_json::Value>,
pub blobs: Option<Vec<String>>,
pub blobs: Option<Vec<CidLink>>,
pub blocks: Option<EventBlocks>,
pub handle: Option<Handle>,
pub active: Option<bool>,
pub status: Option<AccountStatus>,
pub rev: Option<String>,
pub rev: Option<Tid>,
}
#[derive(Debug, Clone)]
@@ -253,10 +253,10 @@ pub struct CommitEventData {
pub commit_cid: Option<CidLink>,
pub prev_cid: Option<CidLink>,
pub ops: Option<serde_json::Value>,
pub blobs: Option<Vec<String>>,
pub blobs: Option<Vec<CidLink>>,
pub blocks: Option<Vec<EventBlockInline>>,
pub prev_data_cid: Option<CidLink>,
pub rev: Option<String>,
pub rev: Option<Tid>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -265,7 +265,7 @@ pub struct RepoListItem {
pub deactivated_at: Option<DateTime<Utc>>,
pub takedown_ref: Option<String>,
pub repo_root_cid: CidLink,
pub repo_rev: Option<String>,
pub repo_rev: Option<Tid>,
}
#[derive(Debug, Clone)]
@@ -307,7 +307,7 @@ pub struct ApplyCommitInput {
pub did: Did,
pub expected_root_cid: Option<CidLink>,
pub new_root_cid: CidLink,
pub new_rev: String,
pub new_rev: Tid,
pub new_block_cids: Vec<Vec<u8>>,
pub obsolete_block_cids: Vec<Vec<u8>>,
pub record_upserts: Vec<RecordUpsert>,
@@ -337,17 +337,17 @@ pub trait RepoRepository: Send + Sync {
did: &Did,
handle: &Handle,
repo_root_cid: &CidLink,
repo_rev: &str,
repo_rev: &Tid,
) -> Result<(), DbError>;
async fn update_repo_root(
&self,
user_id: Uuid,
repo_root_cid: &CidLink,
repo_rev: &str,
repo_rev: &Tid,
) -> Result<(), DbError>;
async fn update_repo_rev(&self, user_id: Uuid, repo_rev: &str) -> Result<(), DbError>;
async fn update_repo_rev(&self, user_id: Uuid, repo_rev: &Tid) -> Result<(), DbError>;
async fn update_repo_status(
&self,
@@ -375,7 +375,7 @@ pub trait RepoRepository: Send + Sync {
collections: &[Nsid],
rkeys: &[Rkey],
record_cids: &[CidLink],
repo_rev: &str,
repo_rev: &Tid,
) -> Result<(), DbError>;
async fn delete_records(
@@ -427,7 +427,7 @@ pub trait RepoRepository: Send + Sync {
&self,
user_id: Uuid,
block_cids: &[Vec<u8>],
repo_rev: &str,
repo_rev: &Tid,
) -> Result<(), DbError>;
async fn delete_user_blocks(
@@ -439,7 +439,7 @@ pub trait RepoRepository: Send + Sync {
async fn get_user_block_cids_since_rev(
&self,
user_id: Uuid,
since_rev: &str,
since_rev: &Tid,
) -> Result<Vec<Vec<u8>>, DbError>;
async fn count_user_blocks(&self, user_id: Uuid) -> Result<i64, DbError>;
@@ -458,7 +458,7 @@ pub trait RepoRepository: Send + Sync {
&self,
did: &Did,
commit_cid: &CidLink,
rev: Option<&str>,
rev: Option<&Tid>,
commit_bytes: &[u8],
) -> Result<(), DbError>;
@@ -467,7 +467,7 @@ pub trait RepoRepository: Send + Sync {
did: &Did,
commit_cid: &CidLink,
mst_root_cid: &CidLink,
rev: &str,
rev: &Tid,
commit_bytes: &[u8],
mst_root_bytes: &[u8],
) -> Result<(), DbError>;
+8 -8
View File
@@ -1003,8 +1003,8 @@ pub struct CreatePasswordAccountInput {
pub encrypted_key_bytes: Vec<u8>,
pub encryption_version: i32,
pub reserved_key_id: Option<Uuid>,
pub commit_cid: String,
pub repo_rev: String,
pub commit_cid: CidLink,
pub repo_rev: Tid,
pub genesis_block_cids: Vec<Vec<u8>>,
pub invite_code: Option<String>,
pub birthdate_pref: Option<serde_json::Value>,
@@ -1035,8 +1035,8 @@ pub struct CreateDelegatedAccountInput {
pub controller_scopes: String,
pub encrypted_key_bytes: Vec<u8>,
pub encryption_version: i32,
pub commit_cid: String,
pub repo_rev: String,
pub commit_cid: CidLink,
pub repo_rev: Tid,
pub genesis_block_cids: Vec<Vec<u8>>,
}
@@ -1055,8 +1055,8 @@ pub struct CreatePasskeyAccountInput {
pub encrypted_key_bytes: Vec<u8>,
pub encryption_version: i32,
pub reserved_key_id: Option<Uuid>,
pub commit_cid: String,
pub repo_rev: String,
pub commit_cid: CidLink,
pub repo_rev: Tid,
pub genesis_block_cids: Vec<Vec<u8>>,
pub invite_code: Option<String>,
pub birthdate_pref: Option<serde_json::Value>,
@@ -1073,8 +1073,8 @@ pub struct CreateSsoAccountInput {
pub signal_username: Option<String>,
pub encrypted_key_bytes: Vec<u8>,
pub encryption_version: i32,
pub commit_cid: String,
pub repo_rev: String,
pub commit_cid: CidLink,
pub repo_rev: Tid,
pub genesis_block_cids: Vec<Vec<u8>>,
pub invite_code: Option<String>,
pub birthdate_pref: Option<serde_json::Value>,
+2 -2
View File
@@ -3,7 +3,7 @@ use sqlx::PgPool;
use tranquil_db_traits::{
BlobForExport, BlobMetadata, BlobRepository, BlobWithTakedown, DbError, MissingBlobInfo,
};
use tranquil_types::{AtUri, CidLink, Did};
use tranquil_types::{AtUri, CidLink, Did, Tid};
use uuid::Uuid;
use super::user::map_sqlx_error;
@@ -112,7 +112,7 @@ impl BlobRepository for PostgresBlobRepository {
Ok(results.into_iter().map(CidLink::from).collect())
}
async fn list_blobs_since_rev(&self, did: &Did, since: &str) -> Result<Vec<CidLink>, DbError> {
async fn list_blobs_since_rev(&self, did: &Did, since: &Tid) -> Result<Vec<CidLink>, DbError> {
let results = sqlx::query_scalar!(
r#"SELECT DISTINCT unnest(blobs) as "cid!"
FROM repo_seq
+1 -1
View File
@@ -7,7 +7,7 @@ use tranquil_db_traits::{
InviteCodeSortOrder, InviteCodeState, InviteCodeUse, NotificationHistoryRow, PlcTokenInfo,
QueuedComms, ReservedSigningKey, ReservedSigningKeyFull, ValidatedInviteCode,
};
use tranquil_types::{CidLink, Did, Handle};
use tranquil_types::{CidLink, Did, Handle, InviteCode};
use uuid::Uuid;
use super::user::map_sqlx_error;
+28 -24
View File
@@ -7,7 +7,7 @@ use tranquil_db_traits::{
RepoAccountInfo, RepoEventType, RepoInfo, RepoListItem, RepoRepository, RepoWithoutRev,
SequenceNumber, SequencedEvent, UserNeedingRecordBlobsBackfill, UserWithoutBlocks,
};
use tranquil_types::{AtUri, CidLink, Did, Handle, Nsid, Rkey};
use tranquil_types::{AtUri, CidLink, Did, Handle, Nsid, Rkey, Tid};
use uuid::Uuid;
use super::user::map_sqlx_error;
@@ -63,7 +63,9 @@ fn row_to_event_blocks(
fn legacy_fallback(legacy_blocks_cids: Option<Vec<String>>) -> Option<EventBlocks> {
match legacy_blocks_cids {
Some(cids) if !cids.is_empty() => Some(EventBlocks::LegacyCids(cids)),
Some(cids) if !cids.is_empty() => Some(EventBlocks::LegacyCids(
cids.into_iter().map(CidLink::from).collect(),
)),
_ => None,
}
}
@@ -102,12 +104,14 @@ fn map_sequenced_row(r: SequencedEventRow) -> Result<SequencedEvent, DbError> {
prev_cid: r.prev_cid.map(CidLink::from),
prev_data_cid: r.prev_data_cid.map(CidLink::from),
ops: r.ops,
blobs: r.blobs,
blobs: r
.blobs
.map(|blobs| blobs.into_iter().map(CidLink::from).collect()),
blocks,
handle: r.handle.map(Handle::from),
active: r.active,
status,
rev: r.rev,
rev: r.rev.map(Tid::from),
})
}
@@ -197,13 +201,13 @@ impl RepoRepository for PostgresRepoRepository {
_did: &Did,
_handle: &Handle,
repo_root_cid: &CidLink,
repo_rev: &str,
repo_rev: &Tid,
) -> Result<(), DbError> {
sqlx::query!(
"INSERT INTO repos (user_id, repo_root_cid, repo_rev) VALUES ($1, $2, $3)",
user_id,
repo_root_cid.as_str(),
repo_rev
repo_rev.as_str()
)
.execute(&self.pool)
.await
@@ -216,12 +220,12 @@ impl RepoRepository for PostgresRepoRepository {
&self,
user_id: Uuid,
repo_root_cid: &CidLink,
repo_rev: &str,
repo_rev: &Tid,
) -> Result<(), DbError> {
sqlx::query!(
"UPDATE repos SET repo_root_cid = $1, repo_rev = $2, updated_at = NOW() WHERE user_id = $3",
repo_root_cid.as_str(),
repo_rev,
repo_rev.as_str(),
user_id
)
.execute(&self.pool)
@@ -231,10 +235,10 @@ impl RepoRepository for PostgresRepoRepository {
Ok(())
}
async fn update_repo_rev(&self, user_id: Uuid, repo_rev: &str) -> Result<(), DbError> {
async fn update_repo_rev(&self, user_id: Uuid, repo_rev: &Tid) -> Result<(), DbError> {
sqlx::query!(
"UPDATE repos SET repo_rev = $1 WHERE user_id = $2",
repo_rev,
repo_rev.as_str(),
user_id
)
.execute(&self.pool)
@@ -277,7 +281,7 @@ impl RepoRepository for PostgresRepoRepository {
Ok(row.map(|r| RepoInfo {
user_id: r.user_id,
repo_root_cid: CidLink::from(r.repo_root_cid),
repo_rev: r.repo_rev,
repo_rev: r.repo_rev.map(Tid::from),
}))
}
@@ -323,7 +327,7 @@ impl RepoRepository for PostgresRepoRepository {
collections: &[Nsid],
rkeys: &[Rkey],
record_cids: &[CidLink],
repo_rev: &str,
repo_rev: &Tid,
) -> Result<(), DbError> {
let collections_str: Vec<&str> = collections.iter().map(|c| c.as_str()).collect();
let rkeys_str: Vec<&str> = rkeys.iter().map(|r| r.as_str()).collect();
@@ -341,7 +345,7 @@ impl RepoRepository for PostgresRepoRepository {
&collections_str as &[&str],
&rkeys_str as &[&str],
&cids_str as &[&str],
repo_rev
repo_rev.as_str()
)
.execute(&self.pool)
.await
@@ -705,7 +709,7 @@ impl RepoRepository for PostgresRepoRepository {
&self,
user_id: Uuid,
block_cids: &[Vec<u8>],
repo_rev: &str,
repo_rev: &Tid,
) -> Result<(), DbError> {
sqlx::query(
r#"
@@ -716,7 +720,7 @@ impl RepoRepository for PostgresRepoRepository {
)
.bind(user_id)
.bind(block_cids)
.bind(repo_rev)
.bind(repo_rev.as_str())
.execute(&self.pool)
.await
.map_err(map_sqlx_error)?;
@@ -756,7 +760,7 @@ impl RepoRepository for PostgresRepoRepository {
async fn get_user_block_cids_since_rev(
&self,
user_id: Uuid,
since_rev: &str,
since_rev: &Tid,
) -> Result<Vec<Vec<u8>>, DbError> {
let rows: Vec<(Vec<u8>,)> = sqlx::query_as(
r#"
@@ -790,7 +794,7 @@ impl RepoRepository for PostgresRepoRepository {
&block_cids as &[Vec<u8>],
&block_data as &[Vec<u8>],
data.prev_data_cid.as_ref().map(|c| c.as_str()),
data.rev
data.rev.as_deref()
)
.execute(&self.pool)
.await
@@ -846,7 +850,7 @@ impl RepoRepository for PostgresRepoRepository {
&self,
did: &Did,
commit_cid: &CidLink,
rev: Option<&str>,
rev: Option<&Tid>,
commit_bytes: &[u8],
) -> Result<(), DbError> {
let cid_bytes = commit_cid
@@ -862,7 +866,7 @@ impl RepoRepository for PostgresRepoRepository {
"#,
did.as_str(),
commit_cid.as_str(),
rev,
rev.map(|r| r.as_str()),
&block_cids as &[Vec<u8>],
&block_data as &[Vec<u8>]
)
@@ -879,7 +883,7 @@ impl RepoRepository for PostgresRepoRepository {
did: &Did,
commit_cid: &CidLink,
mst_root_cid: &CidLink,
rev: &str,
rev: &Tid,
commit_bytes: &[u8],
mst_root_bytes: &[u8],
) -> Result<(), DbError> {
@@ -909,7 +913,7 @@ impl RepoRepository for PostgresRepoRepository {
&blobs,
&block_cids as &[Vec<u8>],
&block_data as &[Vec<u8>],
rev
rev.as_str()
)
.execute(&self.pool)
.await
@@ -1154,7 +1158,7 @@ impl RepoRepository for PostgresRepoRepository {
deactivated_at: r.deactivated_at,
takedown_ref: r.takedown_ref,
repo_root_cid: CidLink::from(r.repo_root_cid),
repo_rev: r.repo_rev,
repo_rev: r.repo_rev.map(Tid::from),
})
.collect())
}
@@ -1477,7 +1481,7 @@ impl RepoRepository for PostgresRepoRepository {
&event_block_cids as &[Vec<u8>],
&event_block_data as &[Vec<u8>],
event.prev_data_cid.as_ref().map(|c| c.as_str()),
event.rev
event.rev.as_deref()
)
.execute(&mut *tx)
.await
@@ -1513,7 +1517,7 @@ impl RepoRepository for PostgresRepoRepository {
.map(|(user_id, repo_root_cid, repo_rev)| UserWithoutBlocks {
user_id,
repo_root_cid: CidLink::from(repo_root_cid),
repo_rev,
repo_rev: repo_rev.map(Tid::from),
})
.collect())
}
+8 -8
View File
@@ -2530,8 +2530,8 @@ impl UserRepository for PostgresUserRepository {
sqlx::query!(
"INSERT INTO repos (user_id, repo_root_cid, repo_rev) VALUES ($1, $2, $3)",
user_id,
input.commit_cid,
input.repo_rev
input.commit_cid.as_str(),
input.repo_rev.as_str()
)
.execute(&mut *tx)
.await
@@ -2647,8 +2647,8 @@ impl UserRepository for PostgresUserRepository {
sqlx::query!(
"INSERT INTO repos (user_id, repo_root_cid, repo_rev) VALUES ($1, $2, $3)",
user_id,
input.commit_cid,
input.repo_rev
input.commit_cid.as_str(),
input.repo_rev.as_str()
)
.execute(&mut *tx)
.await
@@ -2763,8 +2763,8 @@ impl UserRepository for PostgresUserRepository {
sqlx::query!(
"INSERT INTO repos (user_id, repo_root_cid, repo_rev) VALUES ($1, $2, $3)",
user_id,
input.commit_cid,
input.repo_rev
input.commit_cid.as_str(),
input.repo_rev.as_str()
)
.execute(&mut *tx)
.await
@@ -2898,8 +2898,8 @@ impl UserRepository for PostgresUserRepository {
sqlx::query!(
"INSERT INTO repos (user_id, repo_root_cid, repo_rev) VALUES ($1, $2, $3)",
user_id,
input.commit_cid,
input.repo_rev
input.commit_cid.as_str(),
input.repo_rev.as_str()
)
.execute(&mut *tx)
.await
@@ -1099,7 +1099,7 @@ pub async fn complete_registration(
let (commit_bytes, _sig) = match tranquil_pds::repo_ops::create_signed_commit(
&did_typed,
mst_root,
rev.as_ref(),
&rev,
None,
&signing_key,
) {
@@ -1151,8 +1151,8 @@ pub async fn complete_registration(
.filter(|s| !s.is_empty()),
encrypted_key_bytes: encrypted_key_bytes.clone(),
encryption_version: tranquil_pds::config::ENCRYPTION_VERSION,
commit_cid: commit_cid.to_string(),
repo_rev: rev.as_ref().to_string(),
commit_cid: tranquil_types::CidLink::from(commit_cid.to_string()),
repo_rev: tranquil_types::Tid::from(rev.as_ref().to_string()),
genesis_block_cids,
invite_code: invite_registration.into_invite_code(),
birthdate_pref,
+4 -2
View File
@@ -1,4 +1,6 @@
pub fn session_key(did: &str, jti: &str) -> String {
use crate::types::{CidLink, Did, Handle, Jti};
pub fn session_key(did: &Did, jti: &Jti) -> String {
format!("auth:session:{}:{}", did, jti)
}
@@ -30,7 +32,7 @@ pub fn email_update_key(did: &str) -> String {
format!("email_update:{}", did)
}
pub fn scope_ref_key(cid: &str) -> String {
pub fn scope_ref_key(cid: &CidLink) -> String {
format!("scope_ref:{}", cid)
}
+18 -22
View File
@@ -107,7 +107,7 @@ pub async fn get_current_root_cid(state: &AppState, user_id: Uuid) -> Result<Com
.map_err(|_| ApiError::InternalError(Some("Invalid repo root CID".into())))
}
pub fn extract_blob_cids(record: &Value) -> Vec<String> {
pub fn extract_blob_cids(record: &Value) -> Vec<crate::types::CidLink> {
crate::sync::import::find_blob_refs(record, 0)
.into_iter()
.map(|b| b.cid)
@@ -167,7 +167,7 @@ pub struct FinalizeParams<'a> {
pub controller_did: Option<&'a Did>,
pub delegation_detail: Option<serde_json::Value>,
pub ops: Vec<RecordOp>,
pub blob_cids: &'a [String],
pub blob_cids: &'a [crate::types::CidLink],
pub backlinks_to_add: Vec<Backlink>,
pub backlinks_to_remove: Vec<AtUri>,
}
@@ -264,7 +264,7 @@ pub async fn repair_repo_structure(
ApiError::InternalError(None)
})?;
let data_root = commit.data;
let repo_rev = commit.rev().to_string();
let repo_rev = crate::types::Tid::from(commit.rev().to_string());
let records = state
.repos
@@ -614,15 +614,13 @@ pub async fn finalize_repo_write(
pub fn create_signed_commit(
did: &Did,
data: Cid,
rev: &str,
rev: &Tid,
prev: Option<Cid>,
signing_key: &SigningKey,
) -> Result<(Vec<u8>, Bytes), CommitError> {
let did = jacquard_common::types::string::Did::new(did.as_str())
.map_err(|e| CommitError::InvalidDid(format!("{:?}", e)))?;
let rev = jacquard_common::types::string::Tid::from_str(rev)
.map_err(|e| CommitError::InvalidTid(format!("{:?}", e)))?;
let unsigned = Commit::new_unsigned(did, data, rev, prev);
let unsigned = Commit::new_unsigned(did, data, rev.clone(), prev);
let signed = unsigned
.sign(signing_key)
.map_err(|e| CommitError::SigningFailed(format!("{:?}", e)))?;
@@ -670,7 +668,7 @@ impl RecordOp {
pub struct CommitResult {
pub commit_cid: Cid,
pub rev: String,
pub rev: crate::types::Tid,
}
pub struct CommitParams<'a> {
@@ -683,7 +681,7 @@ pub struct CommitParams<'a> {
pub ops: Vec<RecordOp>,
pub block_bytes: std::collections::HashMap<Cid, Bytes>,
pub new_tree_cids: Vec<Cid>,
pub blobs: &'a [String],
pub blobs: &'a [crate::types::CidLink],
pub obsolete_cids: Vec<Cid>,
pub backlinks_to_add: Vec<Backlink>,
pub backlinks_to_remove: Vec<AtUri>,
@@ -732,7 +730,7 @@ pub async fn commit_and_log(
let rev = Tid::now(LimitedU32::MIN);
let rev_str = rev.to_string();
let (new_commit_bytes, _sig) =
create_signed_commit(did, new_mst_root, &rev_str, current_root_cid, &signing_key)?;
create_signed_commit(did, new_mst_root, &rev, current_root_cid, &signing_key)?;
let new_root_cid =
compute_cid(&new_commit_bytes).map_err(|e| CommitError::BlockStoreFailed(e.to_string()))?;
@@ -868,7 +866,7 @@ pub async fn commit_and_log(
blobs: Some(blobs.to_vec()),
blocks: Some(inline_blocks),
prev_data_cid: prev_data_cid.map(crate::types::CidLink::from),
rev: Some(rev_str.clone()),
rev: Some(crate::types::Tid::from(rev_str.clone())),
};
let input = ApplyCommitInput {
@@ -876,7 +874,7 @@ pub async fn commit_and_log(
did: did.clone(),
expected_root_cid: current_root_cid.map(crate::types::CidLink::from),
new_root_cid: crate::types::CidLink::from(new_root_cid),
new_rev: rev_str.clone(),
new_rev: crate::types::Tid::from(rev_str.clone()),
new_block_cids: all_block_cids,
obsolete_block_cids: obsolete_bytes,
record_upserts,
@@ -924,7 +922,7 @@ pub async fn commit_and_log(
Ok(CommitResult {
commit_cid: new_root_cid,
rev: rev_str,
rev: crate::types::Tid::from(rev_str),
})
}
pub async fn create_record_internal(
@@ -1030,14 +1028,12 @@ pub async fn sequence_account_event(
pub async fn sequence_sync_event(
state: &AppState,
did: &Did,
commit_cid: &str,
rev: Option<&str>,
commit_cid: &crate::types::CidLink,
rev: Option<&crate::types::Tid>,
) -> Result<(), CommitError> {
let cid_link: crate::types::CidLink = commit_cid
.parse()
.map_err(|_| CommitError::InvalidCid(commit_cid.to_string()))?;
let commit_cid_parsed =
Cid::from_str(commit_cid).map_err(|e| CommitError::InvalidCid(e.to_string()))?;
let commit_cid_parsed = commit_cid
.to_cid()
.ok_or_else(|| CommitError::InvalidCid(commit_cid.to_string()))?;
let commit_bytes = state
.block_store
.get(&commit_cid_parsed)
@@ -1049,7 +1045,7 @@ pub async fn sequence_sync_event(
state
.repos
.repo
.insert_sync_event(did, &cid_link, rev, &commit_bytes)
.insert_sync_event(did, commit_cid, rev, &commit_bytes)
.await
.map_err(|e| CommitError::DatabaseError(format!("sync event: {}", e)))
}
@@ -1059,7 +1055,7 @@ pub async fn sequence_genesis_commit(
did: &Did,
commit_cid: &Cid,
mst_root_cid: &Cid,
rev: &str,
rev: &crate::types::Tid,
) -> Result<(), CommitError> {
let commit_cid_link = crate::types::CidLink::from(commit_cid);
let mst_root_cid_link = crate::types::CidLink::from(mst_root_cid);
+3 -3
View File
@@ -37,7 +37,7 @@ async fn process_repo_rev(
}
};
let commit = Commit::from_cbor(&block).map_err(|_| user_id)?;
let rev = commit.rev().to_string();
let rev = crate::types::Tid::from(commit.rev().to_string());
repo_repo
.update_repo_rev(user_id, &rev)
.await
@@ -95,7 +95,7 @@ async fn process_user_blocks(
block_store: &AnyBlockStore,
user_id: uuid::Uuid,
repo_root_cid: String,
repo_rev: Option<String>,
repo_rev: Option<crate::types::Tid>,
) -> Result<(uuid::Uuid, usize), uuid::Uuid> {
let root_cid = Cid::from_str(&repo_root_cid).map_err(|_| user_id)?;
let block_cids = collect_current_repo_blocks(block_store, &root_cid)
@@ -105,7 +105,7 @@ async fn process_user_blocks(
return Err(user_id);
}
let count = block_cids.len();
let rev = repo_rev.unwrap_or_else(|| "0".to_string());
let rev = repo_rev.unwrap_or_else(|| crate::types::Tid::from("0".to_string()));
repo_repo
.insert_user_blocks(user_id, &block_cids, &rev)
.await
+15 -18
View File
@@ -3,7 +3,7 @@ use cid::Cid;
use serde::{Deserialize, Serialize};
use std::str::FromStr;
use tranquil_scopes::RepoAction;
use tranquil_types::Did;
use tranquil_types::{CidLink, Did, Handle, Tid};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum FrameType {
@@ -33,8 +33,8 @@ pub struct CommitFrame {
pub too_big: bool,
pub repo: Did,
pub commit: Cid,
pub rev: String,
pub since: Option<String>,
pub rev: Tid,
pub since: Option<Tid>,
#[serde(with = "serde_bytes")]
pub blocks: Vec<u8>,
pub ops: Vec<RepoOp>,
@@ -83,7 +83,7 @@ pub struct AccountFrame {
#[derive(Debug, Serialize, Deserialize)]
pub struct SyncFrame {
pub did: Did,
pub rev: String,
pub rev: Tid,
#[serde(with = "serde_bytes")]
pub blocks: Vec<u8>,
pub seq: i64,
@@ -145,25 +145,23 @@ pub struct CommitFrameBuilder {
ops_json: serde_json::Value,
blob_cids: Vec<Cid>,
time: chrono::DateTime<chrono::Utc>,
rev: Option<String>,
rev: Option<Tid>,
}
impl CommitFrameBuilder {
pub fn new(
seq: i64,
did: Did,
commit_cid_str: &str,
commit_cid: &CidLink,
ops_json: serde_json::Value,
blob_strs: Vec<String>,
blob_links: Vec<CidLink>,
time: chrono::DateTime<chrono::Utc>,
rev: Option<String>,
rev: Option<Tid>,
) -> Result<Self, CommitFrameError> {
let commit_cid = Cid::from_str(commit_cid_str)
.map_err(|_| CommitFrameError::InvalidCommitCid(commit_cid_str.to_string()))?;
let blob_cids: Vec<Cid> = blob_strs
.iter()
.filter_map(|s| Cid::from_str(s).ok())
.collect();
let commit_cid = commit_cid
.to_cid()
.ok_or_else(|| CommitFrameError::InvalidCommitCid(commit_cid.to_string()))?;
let blob_cids: Vec<Cid> = blob_links.iter().filter_map(|s| s.to_cid()).collect();
Ok(Self {
seq,
did,
@@ -208,9 +206,8 @@ impl CommitFrameBuilder {
}
}
fn placeholder_rev() -> String {
use jacquard_common::types::{integer::LimitedU32, string::Tid};
Tid::now(LimitedU32::MIN).to_string()
fn placeholder_rev() -> Tid {
Tid::now()
}
fn format_atproto_time(dt: chrono::DateTime<chrono::Utc>) -> String {
@@ -227,7 +224,7 @@ impl TryFrom<SequencedEvent> for CommitFrame {
let builder = CommitFrameBuilder::new(
event.seq.as_i64(),
event.did.clone(),
commit_cid.as_str(),
&commit_cid,
event.ops.unwrap_or_default(),
event.blobs.unwrap_or_default(),
event.created_at,
+5 -4
View File
@@ -9,7 +9,7 @@ use std::sync::Arc;
use thiserror::Error;
use tracing::debug;
use tranquil_db_traits::{ImportBlock, ImportRecord, ImportRepoError, RepoRepository};
use tranquil_types::CidLink;
use tranquil_types::{CidLink, Nsid, Rkey};
use uuid::Uuid;
#[derive(Error, Debug)]
@@ -52,7 +52,7 @@ impl From<ImportRepoError> for ImportError {
#[derive(Debug, Clone)]
pub struct BlobRef {
pub cid: String,
pub cid: CidLink,
pub mime_type: Option<String>,
}
@@ -91,11 +91,11 @@ pub fn find_blob_refs_ipld(value: &Ipld, depth: usize) -> Vec<BlobRef> {
&& type_str == "blob"
{
let cid_str = if let Some(Ipld::Link(link_cid)) = obj.get("ref") {
Some(link_cid.to_string())
Some(CidLink::from(link_cid))
} else if let Some(Ipld::Map(ref_obj)) = obj.get("ref")
&& let Some(Ipld::String(link)) = ref_obj.get("$link")
{
Some(link.clone())
CidLink::new(link.as_str()).ok()
} else {
None
};
@@ -136,6 +136,7 @@ pub fn find_blob_refs(value: &JsonValue, depth: usize) -> Vec<BlobRef> {
&& type_str == "blob"
&& let Some(JsonValue::Object(ref_obj)) = obj.get("ref")
&& let Some(JsonValue::String(link)) = ref_obj.get("$link")
&& let Ok(cid) = CidLink::new(link.as_str())
{
let mime = obj
.get("mimeType")
+3 -3
View File
@@ -16,7 +16,7 @@ use std::io::Cursor;
use std::str::FromStr;
use tokio::io::AsyncWriteExt;
use tranquil_db_traits::{AccountStatus, EventBlocks, RepoEventType, RepoRepository};
use tranquil_types::Did;
use tranquil_types::{Did, Tid};
#[derive(Debug)]
pub enum SyncFrameError {
@@ -181,10 +181,10 @@ pub async fn assert_repo_availability(
Ok(account)
}
fn extract_rev_from_commit_bytes(commit_bytes: &[u8]) -> Option<String> {
fn extract_rev_from_commit_bytes(commit_bytes: &[u8]) -> Option<Tid> {
Commit::from_cbor(commit_bytes)
.ok()
.map(|c| c.rev().to_string())
.and_then(|c| Tid::new(c.rev().to_string()).ok())
}
async fn write_car_blocks(
+1 -1
View File
@@ -104,7 +104,7 @@ fn test_create_signed_commit_helper() {
.expect("valid test DID");
let data_cid =
Cid::from_str("bafyreib2rxk3ryblouj3fxza5jvx6psmwewwessc4m6g6e7pqhhkwqomfi").unwrap();
let rev = Tid::now(LimitedU32::MIN).to_string();
let rev = Tid::now(LimitedU32::MIN);
let (signed_bytes, sig) = create_signed_commit(&did, data_cid, &rev, None, &signing_key)
.expect("signing should succeed");
@@ -145,12 +145,12 @@ async fn sync_event_carries_inline_commit_block() {
let commit_bytes = b"synthetic sync commit block payload".to_vec();
let commit_cid = synthetic_cid(&commit_bytes);
let cid_link: CidLink = (&commit_cid).into();
let rev = "3kabcdefghij2";
let rev = tranquil_types::Tid::from("3kabcdefghij2".to_string());
let baseline = repos.repo.get_max_seq().await.expect("get_max_seq");
repos
.repo
.insert_sync_event(&did, &cid_link, Some(rev), &commit_bytes)
.insert_sync_event(&did, &cid_link, Some(&rev), &commit_bytes)
.await
.expect("insert_sync_event");
@@ -192,7 +192,7 @@ async fn genesis_commit_event_carries_inline_blocks() {
let mst_root_cid = synthetic_cid(&mst_root_bytes);
let commit_link: CidLink = (&commit_cid).into();
let mst_link: CidLink = (&mst_root_cid).into();
let rev = "3kabcdefghij3";
let rev = tranquil_types::Tid::from("3kabcdefghij3".to_string());
let baseline = repos.repo.get_max_seq().await.expect("get_max_seq");
repos
@@ -201,7 +201,7 @@ async fn genesis_commit_event_carries_inline_blocks() {
&did,
&commit_link,
&mst_link,
rev,
&rev,
&commit_bytes,
&mst_root_bytes,
)
@@ -144,7 +144,7 @@ async fn repair_fails_loud_on_missing_leaf_block() {
let recorded = repos
.repo
.get_user_block_cids_since_rev(user_id, "")
.get_user_block_cids_since_rev(user_id, &tranquil_types::Tid::from(String::new()))
.await
.expect("read user_blocks");
assert!(
+12 -5
View File
@@ -4,7 +4,7 @@ mod helpers;
use std::sync::Arc;
use tranquil_db::PostgresRepositories;
use tranquil_db_traits::{Backlink, BacklinkPath, CommsChannel, CommsType};
use tranquil_types::{AtUri, CidLink, Did, Handle, Nsid, Rkey};
use tranquil_types::{AtUri, CidLink, Did, Handle, Nsid, Rkey, Tid};
use uuid::Uuid;
async fn create_store_repos() -> Arc<PostgresRepositories> {
@@ -139,7 +139,7 @@ fn test_at_uri(did: &Did, collection: &Nsid, rkey: &Rkey) -> AtUri {
}
async fn seed_user(repos: &PostgresRepositories, did: &Did, handle: &Handle) -> Uuid {
let commit_cid = helpers::make_cid(did.as_str().as_bytes()).to_string();
let commit_cid = CidLink::from(helpers::make_cid(did.as_str().as_bytes()).to_string());
let input = tranquil_db_traits::CreatePasswordAccountInput {
handle: handle.clone(),
email: None,
@@ -155,7 +155,7 @@ async fn seed_user(repos: &PostgresRepositories, did: &Did, handle: &Handle) ->
encryption_version: 0,
reserved_key_id: None,
commit_cid,
repo_rev: "rev0".to_string(),
repo_rev: Tid::from("rev0".to_string()),
genesis_block_cids: vec![],
invite_code: None,
birthdate_pref: None,
@@ -185,7 +185,13 @@ async fn seed_records(
let cids: Vec<CidLink> = records.iter().map(|(_, c)| c.clone()).collect();
repos
.repo
.upsert_records(repo_id, &collections, &rkeys, &cids, "rev1")
.upsert_records(
repo_id,
&collections,
&rkeys,
&cids,
&Tid::from("rev1".to_string()),
)
.await
.unwrap();
}
@@ -1412,6 +1418,7 @@ async fn parity_repo_root_operations() {
assert_eq!(pg_root, store_root);
let new_root = test_cid(99);
let rev1 = Tid::from("rev1".to_string());
f.pg.repo
.update_repo_root(pg_uid, &new_root, "rev1")
.await
@@ -1625,7 +1632,7 @@ async fn parity_prune_events_older_than() {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev0".to_string()),
rev: Some(Tid::from("rev0".to_string())),
};
let baseline = f.pg.repo.get_max_seq().await.unwrap();
+31 -13
View File
@@ -6,7 +6,7 @@ use tokio::sync::oneshot;
use tranquil_db_traits::{
ApplyCommitInput, CommitEventData, RecordUpsert, RepoEventType, RepoRepository,
};
use tranquil_types::{CidLink, Did, Handle, Nsid, Rkey};
use tranquil_types::{CidLink, Did, Handle, Nsid, Rkey, Tid};
use uuid::Uuid;
use tranquil_store::RealIO;
@@ -85,8 +85,8 @@ fn test_cid_bytes(seed: u8) -> Vec<u8> {
cid::Cid::new_v1(0x71, mh).to_bytes()
}
fn make_rev(n: u64) -> String {
format!("rev{n:010}")
fn make_rev(n: u64) -> Tid {
Tid::from(format!("rev{n:010}"))
}
struct BenchHarness {
@@ -143,7 +143,7 @@ async fn create_user(pool: &HandlerPool, user_id: Uuid, did: &Did, cid: &CidLink
did: did.clone(),
handle: Handle::from(format!("bench.{}.invalid", user_id.as_simple())),
repo_root_cid: cid.clone(),
repo_rev: "rev0000000000".to_string(),
repo_rev: Tid::from("rev0000000000".to_string()),
tx,
}))
.unwrap();
@@ -509,9 +509,15 @@ async fn bench_pg_upsert_records(
pg_create_user(pg, *uid, did).await;
let did_typed = Did::from(did.clone());
let handle = Handle::from(format!("bench.{}.invalid", uid.as_simple()));
repo.create_repo(*uid, &did_typed, &handle, &test_cid(1), "rev0000000000")
.await
.unwrap();
repo.create_repo(
*uid,
&did,
&handle,
&test_cid(1),
&Tid::from("rev0000000000".to_string()),
)
.await
.unwrap();
})
.await;
@@ -608,9 +614,15 @@ async fn bench_pg_get_record_cid(pg: &sqlx::PgPool, concurrency: usize, ops_per_
let repo = tranquil_db::postgres::PostgresRepoRepository::new(pg.clone());
let did_typed = Did::from(did.clone());
let handle = Handle::from(format!("bench.{}.invalid", user_id.as_simple()));
repo.create_repo(user_id, &did_typed, &handle, &test_cid(1), "rev0000000000")
.await
.unwrap();
repo.create_repo(
user_id,
&did,
&handle,
&test_cid(1),
&Tid::from("rev0000000000".to_string()),
)
.await
.unwrap();
pg_seed_records(&repo, user_id, &collection, 1000).await;
let total_records = 1000usize;
@@ -658,9 +670,15 @@ async fn bench_pg_list_records(pg: &sqlx::PgPool, concurrency: usize, ops_per_ta
let repo = tranquil_db::postgres::PostgresRepoRepository::new(pg.clone());
let did_typed = Did::from(did.clone());
let handle = Handle::from(format!("bench.{}.invalid", user_id.as_simple()));
repo.create_repo(user_id, &did_typed, &handle, &test_cid(1), "rev0000000000")
.await
.unwrap();
repo.create_repo(
user_id,
&did,
&handle,
&test_cid(1),
&Tid::from("rev0000000000".to_string()),
)
.await
.unwrap();
pg_seed_records(&repo, user_id, &collection, 1000).await;
let start = Instant::now();
@@ -6,7 +6,7 @@ use tokio::sync::oneshot;
use tranquil_db_traits::{
ApplyCommitInput, CommitEventData, RecordUpsert, RepoEventType, RepoRepository,
};
use tranquil_types::{CidLink, Did, Handle, Nsid, Rkey};
use tranquil_types::{CidLink, Did, Handle, Nsid, Rkey, Tid};
use uuid::Uuid;
use tranquil_store::RealIO;
@@ -85,8 +85,8 @@ fn test_cid_bytes(seed: u8) -> Vec<u8> {
cid::Cid::new_v1(0x71, mh).to_bytes()
}
fn make_rev(n: u64) -> String {
format!("rev{n:010}")
fn make_rev(n: u64) -> Tid {
Tid::from(format!("rev{n:010}"))
}
struct BenchHarness {
@@ -197,7 +197,7 @@ async fn seed_users(pool: &HandlerPool, count: usize) -> Vec<UserInfo> {
user.user_id.as_simple()
)),
repo_root_cid: test_cid(1),
repo_rev: "rev0000000000".to_string(),
repo_rev: Tid::from("rev0000000000".to_string()),
tx,
}))
.unwrap();
@@ -612,9 +612,15 @@ async fn pg_seed_users(pg: &sqlx::PgPool, count: usize) -> Vec<UserInfo> {
"u{}.pgscale.invalid",
user.user_id.as_simple()
));
repo.create_repo(user.user_id, &user.did, &handle, &test_cid(1), "rev0000000000")
.await
.unwrap();
repo.create_repo(
user.user_id,
&user.did,
&handle,
&test_cid(1),
&Tid::from("rev0000000000".to_string()),
)
.await
.unwrap();
})
.await;
if (batch_idx + 1) % 20 == 0 || batch_idx + 1 == total_batches {
@@ -669,7 +675,7 @@ async fn pg_seed_all_records(pg: &sqlx::PgPool, users: &[UserInfo], records_per_
&collections,
&rkeys,
&cids,
"rev0000000001",
&Tid::from("rev0000000001".to_string()),
)
.await
.unwrap();
@@ -4,7 +4,7 @@ use std::time::{Duration, Instant};
use futures::StreamExt;
use tokio::sync::oneshot;
use tranquil_db_traits::{ApplyCommitInput, CommitEventData, RecordUpsert, RepoEventType};
use tranquil_types::{CidLink, Did, Handle, Nsid, Rkey};
use tranquil_types::{CidLink, Did, Handle, Nsid, Rkey, Tid};
use uuid::Uuid;
use tranquil_store::RealIO;
@@ -56,7 +56,7 @@ async fn seed_users(pool: &HandlerPool, count: usize) -> Vec<UserInfo> {
did: user.did.clone(),
handle: Handle::from(format!("u{}.prof.invalid", user.user_id.as_simple())),
repo_root_cid: test_cid(1),
repo_rev: "rev0000000000".to_string(),
repo_rev: Tid::from("rev0000000000".to_string()),
tx,
}))
.unwrap();
@@ -114,7 +114,7 @@ async fn seed_records(pool: &Arc<HandlerPool>, users: &[UserInfo], records_per_u
did: user.did.clone(),
expected_root_cid: None,
new_root_cid: test_cid(2),
new_rev: "rev0000000001".to_string(),
new_rev: Tid::from("rev0000000001".to_string()),
new_block_cids,
obsolete_block_cids: vec![],
record_upserts,
@@ -130,7 +130,7 @@ async fn seed_records(pool: &Arc<HandlerPool>, users: &[UserInfo], records_per_u
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev0000000001".to_string()),
rev: Some(Tid::from("rev0000000001".to_string())),
},
};
let (tx, rx) = oneshot::channel();
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use tranquil_db_traits::{
AccountStatus, EventBlockInline, EventBlocks, SequenceNumber, SequencedEvent,
};
use tranquil_types::{CidLink, Did, Handle};
use tranquil_types::{CidLink, Did, Handle, Tid};
use crate::eventlog::reader::RawEvent;
@@ -117,7 +117,7 @@ pub fn encode_payload_with_mutations(
.map(|h: &Handle| h.as_str().to_owned()),
active: event.active,
status: event.status.as_ref().map(account_status_to_u8),
rev: event.rev.clone(),
rev: event.rev.as_ref().map(|r| r.as_str().to_owned()),
mutation_set: mutation_set.map(|b| b.to_vec()),
};
@@ -215,12 +215,15 @@ pub fn to_sequenced_event(
.transpose()?
.flatten(),
ops,
blobs: payload.blobs.clone(),
blobs: payload
.blobs
.clone()
.map(|v| v.into_iter().map(CidLink::from).collect()),
blocks: payload.blocks.clone().map(EventBlocks::Inline),
handle,
active: payload.active,
status: payload.status.and_then(u8_to_account_status),
rev: payload.rev.clone(),
rev: payload.rev.clone().map(Tid::from),
})
}
@@ -286,7 +289,7 @@ mod tests {
prev_cid: Some(cid.clone()),
prev_data_cid: Some(cid.clone()),
ops: Some(ops.clone()),
blobs: Some(vec!["bafkreibtest".to_owned()]),
blobs: Some(vec![CidLink::from("bafkreibtest".to_owned())]),
blocks: Some(EventBlocks::Inline(vec![EventBlockInline {
cid_bytes: cid_link_to_bytes(&cid).unwrap(),
data: b"hello block".to_vec(),
@@ -294,7 +297,7 @@ mod tests {
handle: Some(Handle::new("test.bsky.social").unwrap()),
active: None,
status: None,
rev: Some("rev123".to_owned()),
rev: Some(Tid::from("rev123".to_owned())),
};
let encoded = encode_payload(&event);
@@ -567,7 +567,7 @@ mod tests {
use sha2::Digest;
use std::path::Path;
use tranquil_db_traits::{AccountStatus, RepoEventType, SequenceNumber, SequencedEvent};
use tranquil_types::{Did, Handle};
use tranquil_types::{CidLink, Did, Handle, Tid};
fn test_did() -> Did {
Did::new("did:plc:testuser1234567890abcdef").unwrap()
@@ -604,12 +604,12 @@ mod tests {
prev_cid: Some(cid.clone()),
prev_data_cid: Some(cid),
ops: Some(ops),
blobs: Some(vec!["bafkreibtest".to_owned()]),
blobs: Some(vec![CidLink::from("bafkreibtest".to_owned())]),
blocks: None,
handle: Some(Handle::new("test.bsky.social").unwrap()),
active: None,
status: None,
rev: Some("rev123".to_owned()),
rev: Some(Tid::from("rev123".to_owned())),
}
}
+13 -13
View File
@@ -28,7 +28,7 @@ use tranquil_db_traits::{
};
use tranquil_oauth::{AuthorizedClientData, DeviceData, RequestData, TokenData};
use tranquil_types::{
AtUri, AuthorizationCode, CidLink, ClientId, DPoPProofId, DeviceId, Did, Handle, Nsid,
AtIdentifier, AtUri, AuthorizationCode, CidLink, ClientId, DPoPProofId, DeviceId, Did, Handle,
InviteCode, Jti, Nsid, PasswordHash, RefreshToken, RequestId, Rkey, Tid, TokenId,
};
use uuid::Uuid;
@@ -125,7 +125,7 @@ impl<S: StorageIO> MetastoreClient<S> {
did: &Did,
handle: &Handle,
repo_root_cid: &CidLink,
repo_rev: &str,
repo_rev: &Tid,
) -> Result<(), DbError> {
let (tx, rx) = oneshot::channel();
self.pool
@@ -134,7 +134,7 @@ impl<S: StorageIO> MetastoreClient<S> {
did: did.clone(),
handle: handle.clone(),
repo_root_cid: repo_root_cid.clone(),
repo_rev: repo_rev.to_string(),
repo_rev: repo_rev.clone(),
tx,
}))?;
recv(rx).await
@@ -149,7 +149,7 @@ impl<S: StorageIO + 'static> tranquil_db_traits::RepoRepository for MetastoreCli
did: &Did,
handle: &Handle,
repo_root_cid: &CidLink,
repo_rev: &str,
repo_rev: &Tid,
) -> Result<(), DbError> {
self.create_repo_full(user_id, did, handle, repo_root_cid, repo_rev)
.await
@@ -178,7 +178,7 @@ impl<S: StorageIO + 'static> tranquil_db_traits::RepoRepository for MetastoreCli
&self,
user_id: Uuid,
repo_root_cid: &CidLink,
repo_rev: &str,
repo_rev: &Tid,
) -> Result<(), DbError> {
let (tx, rx) = oneshot::channel();
self.pool
@@ -191,7 +191,7 @@ impl<S: StorageIO + 'static> tranquil_db_traits::RepoRepository for MetastoreCli
recv(rx).await
}
async fn update_repo_rev(&self, user_id: Uuid, repo_rev: &str) -> Result<(), DbError> {
async fn update_repo_rev(&self, user_id: Uuid, repo_rev: &Tid) -> Result<(), DbError> {
let (tx, rx) = oneshot::channel();
self.pool
.send(MetastoreRequest::Repo(RepoRequest::UpdateRepoRev {
@@ -261,7 +261,7 @@ impl<S: StorageIO + 'static> tranquil_db_traits::RepoRepository for MetastoreCli
collections: &[Nsid],
rkeys: &[Rkey],
record_cids: &[CidLink],
repo_rev: &str,
repo_rev: &Tid,
) -> Result<(), DbError> {
let (tx, rx) = oneshot::channel();
self.pool
@@ -420,7 +420,7 @@ impl<S: StorageIO + 'static> tranquil_db_traits::RepoRepository for MetastoreCli
&self,
user_id: Uuid,
block_cids: &[Vec<u8>],
repo_rev: &str,
repo_rev: &Tid,
) -> Result<(), DbError> {
let (tx, rx) = oneshot::channel();
self.pool.send(MetastoreRequest::UserBlock(
@@ -453,7 +453,7 @@ impl<S: StorageIO + 'static> tranquil_db_traits::RepoRepository for MetastoreCli
async fn get_user_block_cids_since_rev(
&self,
user_id: Uuid,
since_rev: &str,
since_rev: &Tid,
) -> Result<Vec<Vec<u8>>, DbError> {
let (tx, rx) = oneshot::channel();
self.pool.send(MetastoreRequest::UserBlock(
@@ -514,7 +514,7 @@ impl<S: StorageIO + 'static> tranquil_db_traits::RepoRepository for MetastoreCli
&self,
did: &Did,
commit_cid: &CidLink,
rev: Option<&str>,
rev: Option<&Tid>,
commit_bytes: &[u8],
) -> Result<(), DbError> {
let (tx, rx) = oneshot::channel();
@@ -522,7 +522,7 @@ impl<S: StorageIO + 'static> tranquil_db_traits::RepoRepository for MetastoreCli
.send(MetastoreRequest::Event(EventRequest::InsertSyncEvent {
did: did.clone(),
commit_cid: commit_cid.clone(),
rev: rev.map(str::to_owned),
rev: rev.map(|r| r.to_string()),
commit_bytes: commit_bytes.to_vec(),
tx,
}))?;
@@ -534,7 +534,7 @@ impl<S: StorageIO + 'static> tranquil_db_traits::RepoRepository for MetastoreCli
did: &Did,
commit_cid: &CidLink,
mst_root_cid: &CidLink,
rev: &str,
rev: &Tid,
commit_bytes: &[u8],
mst_root_bytes: &[u8],
) -> Result<(), DbError> {
@@ -910,7 +910,7 @@ impl<S: StorageIO + 'static> tranquil_db_traits::BlobRepository for MetastoreCli
async fn list_blobs_since_rev(
&self,
did: &tranquil_types::Did,
since: &str,
since: &Tid,
) -> Result<Vec<CidLink>, DbError> {
let (tx, rx) = oneshot::channel();
self.pool
@@ -28,7 +28,7 @@ use tranquil_db_traits::{
ApplyCommitError, ApplyCommitInput, ApplyCommitResult, ImportBlock, ImportRecord,
ImportRepoError, UserNeedingRecordBlobsBackfill, UserWithoutBlocks,
};
use tranquil_types::{AtUri, CidLink, Did};
use tranquil_types::{AtUri, CidLink, Did, Tid};
use serde::{Deserialize, Serialize};
@@ -148,7 +148,7 @@ impl<S: StorageIO + 'static> CommitOps<S> {
let updated_meta = RepoMetaValue {
repo_root_cid: new_cid_bytes.clone(),
repo_rev: input.new_rev.clone(),
repo_rev: input.new_rev.to_string(),
..meta
};
@@ -393,7 +393,7 @@ impl<S: StorageIO + 'static> CommitOps<S> {
repo_root_cid: root_cid,
repo_rev: match meta.repo_rev.is_empty() {
true => None,
false => Some(meta.repo_rev),
false => Some(Tid::from(meta.repo_rev)),
},
})
},
@@ -573,7 +573,7 @@ mod tests {
did: did.clone(),
expected_root_cid: Some(root_cid.clone()),
new_root_cid: new_root.clone(),
new_rev: "rev1".to_string(),
new_rev: Tid::from("rev1".to_string()),
new_block_cids: vec![vec![0x01, 0x02]],
obsolete_block_cids: vec![],
record_upserts: vec![tranquil_db_traits::RecordUpsert {
@@ -593,7 +593,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev1".to_string()),
rev: Some(Tid::from("rev1".to_string())),
},
};
@@ -627,7 +627,7 @@ mod tests {
did,
expected_root_cid: Some(stale_root),
new_root_cid: new_root,
new_rev: "rev1".to_string(),
new_rev: Tid::from("rev1".to_string()),
new_block_cids: vec![],
obsolete_block_cids: vec![],
record_upserts: vec![],
@@ -643,7 +643,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev1".to_string()),
rev: Some(Tid::from("rev1".to_string())),
},
};
@@ -664,7 +664,7 @@ mod tests {
did: test_did("nonexistent"),
expected_root_cid: None,
new_root_cid: test_cid_link(1),
new_rev: "rev1".to_string(),
new_rev: Tid::from("rev1".to_string()),
new_block_cids: vec![],
obsolete_block_cids: vec![],
record_upserts: vec![],
@@ -706,7 +706,7 @@ mod tests {
did: did.clone(),
expected_root_cid: Some(root_cid.clone()),
new_root_cid: mid_root.clone(),
new_rev: "rev1".to_string(),
new_rev: Tid::from("rev1".to_string()),
new_block_cids: vec![],
obsolete_block_cids: vec![],
record_upserts: vec![tranquil_db_traits::RecordUpsert {
@@ -726,7 +726,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev1".to_string()),
rev: Some(Tid::from("rev1".to_string())),
},
};
ops.apply_commit(insert_input).unwrap();
@@ -745,7 +745,7 @@ mod tests {
did: did.clone(),
expected_root_cid: Some(mid_root.clone()),
new_root_cid: final_root.clone(),
new_rev: "rev2".to_string(),
new_rev: Tid::from("rev2".to_string()),
new_block_cids: vec![],
obsolete_block_cids: vec![],
record_upserts: vec![],
@@ -764,7 +764,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev2".to_string()),
rev: Some(Tid::from("rev2".to_string())),
},
};
ops.apply_commit(delete_input).unwrap();
@@ -790,7 +790,7 @@ mod tests {
did: did.clone(),
expected_root_cid: Some(root_cid.clone()),
new_root_cid: new_root.clone(),
new_rev: "rev1".to_string(),
new_rev: Tid::from("rev1".to_string()),
new_block_cids: vec![],
obsolete_block_cids: vec![],
record_upserts: vec![],
@@ -806,7 +806,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev1".to_string()),
rev: Some(Tid::from("rev1".to_string())),
},
};
@@ -898,7 +898,7 @@ mod tests {
did: did_a.clone(),
expected_root_cid: Some(root_a),
new_root_cid: new_root.clone(),
new_rev: "rev1".to_string(),
new_rev: Tid::from("rev1".to_string()),
new_block_cids: vec![vec![0x01, 0x02, 0x03]],
obsolete_block_cids: vec![],
record_upserts: vec![],
@@ -914,7 +914,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev1".to_string()),
rev: Some(Tid::from("rev1".to_string())),
},
};
ops.apply_commit(input).unwrap();
@@ -936,7 +936,7 @@ mod tests {
did: did.clone(),
expected_root_cid: None,
new_root_cid: new_root.clone(),
new_rev: "rev_force".to_string(),
new_rev: Tid::from("rev_force".to_string()),
new_block_cids: vec![],
obsolete_block_cids: vec![],
record_upserts: vec![],
@@ -952,7 +952,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev_force".to_string()),
rev: Some(Tid::from("rev_force".to_string())),
},
};
@@ -979,7 +979,7 @@ mod tests {
did: did.clone(),
expected_root_cid: Some(root_cid.clone()),
new_root_cid: mid_root.clone(),
new_rev: "rev1".to_string(),
new_rev: Tid::from("rev1".to_string()),
new_block_cids: vec![],
obsolete_block_cids: vec![],
record_upserts: vec![tranquil_db_traits::RecordUpsert {
@@ -1003,7 +1003,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev1".to_string()),
rev: Some(Tid::from("rev1".to_string())),
},
};
ops.apply_commit(create_input).unwrap();
@@ -1023,7 +1023,7 @@ mod tests {
did: did.clone(),
expected_root_cid: Some(mid_root.clone()),
new_root_cid: final_root.clone(),
new_rev: "rev2".to_string(),
new_rev: Tid::from("rev2".to_string()),
new_block_cids: vec![],
obsolete_block_cids: vec![],
record_upserts: vec![tranquil_db_traits::RecordUpsert {
@@ -1047,7 +1047,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev2".to_string()),
rev: Some(Tid::from("rev2".to_string())),
},
};
ops.apply_commit(update_input).unwrap();
@@ -1121,7 +1121,7 @@ mod tests {
did: did.clone(),
expected_root_cid: Some(initial_root.clone()),
new_root_cid: new_root.clone(),
new_rev: "rev1".to_string(),
new_rev: Tid::from("rev1".to_string()),
new_block_cids: vec![vec![0xAA, 0xBB]],
obsolete_block_cids: vec![],
record_upserts: vec![tranquil_db_traits::RecordUpsert {
@@ -1141,7 +1141,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev1".to_string()),
rev: Some(Tid::from("rev1".to_string())),
},
};
@@ -1266,7 +1266,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev1".to_string()),
rev: Some(Tid::from("rev1".to_string())),
};
let mut batch = metastore.database().batch();
@@ -1355,7 +1355,7 @@ mod tests {
did: did.clone(),
expected_root_cid: Some(root_cid.clone()),
new_root_cid: mid_root.clone(),
new_rev: "rev1".to_string(),
new_rev: Tid::from("rev1".to_string()),
new_block_cids: vec![],
obsolete_block_cids: vec![],
record_upserts: vec![
@@ -1393,7 +1393,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev1".to_string()),
rev: Some(Tid::from("rev1".to_string())),
},
};
ops.apply_commit(input).unwrap();
@@ -1424,7 +1424,7 @@ mod tests {
did: did.clone(),
expected_root_cid: Some(mid_root.clone()),
new_root_cid: final_root.clone(),
new_rev: "rev2".to_string(),
new_rev: Tid::from("rev2".to_string()),
new_block_cids: vec![],
obsolete_block_cids: vec![],
record_upserts: vec![],
@@ -1440,7 +1440,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev2".to_string()),
rev: Some(Tid::from("rev2".to_string())),
},
};
ops.apply_commit(remove_like).unwrap();
@@ -7,7 +7,7 @@ use tracing::warn;
use tranquil_db_traits::{
AccountStatus, CommitEventData, DbError, RepoEventType, SequenceNumber, SequencedEvent,
};
use tranquil_types::{CidLink, Did, Handle};
use tranquil_types::{CidLink, Did, Handle, Tid};
use super::encoding::{KeyReader, exclusive_upper_bound};
use super::event_keys::{
@@ -175,7 +175,7 @@ impl<S: StorageIO + 'static> EventOps<S> {
handle: None,
active: None,
status: None,
rev: rev.map(str::to_owned),
rev: rev.map(|r| Tid::from(r.to_owned())),
};
self.append_and_index(&event, did, rev)
@@ -221,7 +221,7 @@ impl<S: StorageIO + 'static> EventOps<S> {
handle: None,
active: None,
status: None,
rev: Some(rev.to_owned()),
rev: Some(Tid::from(rev.to_owned())),
};
self.append_and_index(&event, did, Some(rev))
@@ -732,6 +732,10 @@ mod tests {
use sha2::Digest;
use tranquil_db_traits::RepoEventType;
fn tid(s: &str) -> Tid {
Tid::from(s.to_owned())
}
struct TestHarness {
_metastore_dir: tempfile::TempDir,
_eventlog_dir: tempfile::TempDir,
@@ -794,7 +798,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("3k2abcde".to_owned()),
rev: Some(tid("3k2abcde")),
};
let seq = h.event_ops.insert_commit_event(&data).unwrap();
@@ -804,7 +808,7 @@ mod tests {
assert_eq!(event.did.as_str(), test_did().as_str());
assert_eq!(event.event_type, RepoEventType::Commit);
assert_eq!(event.commit_cid, Some(cid));
assert_eq!(event.rev, Some("3k2abcde".to_owned()));
assert_eq!(event.rev, Some(tid("3k2abcde")));
}
#[test]
@@ -855,7 +859,7 @@ mod tests {
let event = h.event_ops.get_event_by_seq(seq).unwrap().unwrap();
assert_eq!(event.event_type, RepoEventType::Sync);
assert_eq!(event.commit_cid, Some(cid));
assert_eq!(event.rev, Some("rev1".to_owned()));
assert_eq!(event.rev, Some(tid("rev1")));
}
#[test]
@@ -881,7 +885,7 @@ mod tests {
assert_eq!(event.event_type, RepoEventType::Commit);
assert_eq!(event.commit_cid, Some(commit_cid));
assert_eq!(event.prev_data_cid, Some(mst_cid));
assert_eq!(event.rev, Some("genesis_rev".to_owned()));
assert_eq!(event.rev, Some(tid("genesis_rev")));
}
#[test]
@@ -1003,7 +1007,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev_a".to_owned()),
rev: Some(tid("rev_a")),
})
.unwrap();
@@ -1018,7 +1022,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev_b".to_owned()),
rev: Some(tid("rev_b")),
})
.unwrap();
@@ -1045,7 +1049,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev_x".to_owned()),
rev: Some(tid("rev_x")),
})
.unwrap();
@@ -1060,7 +1064,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev_y".to_owned()),
rev: Some(tid("rev_y")),
})
.unwrap();
@@ -1146,7 +1150,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("r1".to_owned()),
rev: Some(tid("r1")),
})
.unwrap();
let s2 = h.event_ops.insert_identity_event(&did, None).unwrap();
@@ -1191,7 +1195,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev_keep".to_owned()),
rev: Some(tid("rev_keep")),
})
.unwrap();
@@ -1246,7 +1250,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev_old".to_owned()),
rev: Some(tid("rev_old")),
})
.unwrap();
@@ -1261,7 +1265,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev_keep".to_owned()),
rev: Some(tid("rev_keep")),
})
.unwrap();
@@ -1312,7 +1316,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev_a".to_owned()),
rev: Some(tid("rev_a")),
})
.unwrap();
@@ -1327,7 +1331,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev_b".to_owned()),
rev: Some(tid("rev_b")),
})
.unwrap();
@@ -1369,7 +1373,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev_1".to_owned()),
rev: Some(tid("rev_1")),
})
.unwrap();
@@ -1398,7 +1402,7 @@ mod tests {
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some("rev_1".to_owned()),
rev: Some(tid("rev_1")),
})
.unwrap();
@@ -1420,7 +1424,7 @@ mod tests {
handle: None,
active: None,
status: None,
rev: Some("rev_2".to_owned()),
rev: Some(tid("rev_2")),
};
h.event_ops.bridge.insert_event(&crash_event).unwrap();
@@ -1456,7 +1460,7 @@ mod tests {
handle: None,
active: None,
status: None,
rev: Some("rev_3".to_owned()),
rev: Some(tid("rev_3")),
};
h.event_ops.bridge.insert_event(&crash_event_3).unwrap();
@@ -30,8 +30,8 @@ use tranquil_db_traits::{
};
use tranquil_oauth::{AuthorizedClientData, DeviceData, RequestData, TokenData};
use tranquil_types::{
AtUri, AuthorizationCode, CidLink, ClientId, DPoPProofId, DeviceId, Did, Handle, Nsid,
RefreshToken, RequestId, Rkey, TokenId,
AtUri, AuthorizationCode, CidLink, ClientId, DPoPProofId, DeviceId, Did, Handle, InviteCode,
Nsid, RefreshToken, RequestId, Rkey, Tid, TokenId,
};
use uuid::Uuid;
@@ -192,7 +192,7 @@ pub enum RepoRequest {
did: Did,
handle: Handle,
repo_root_cid: CidLink,
repo_rev: String,
repo_rev: Tid,
tx: Tx<()>,
},
UpdateRepoRoot {
@@ -2454,7 +2454,7 @@ fn convert_repo_info(r: super::repo_ops::RepoInfo) -> tranquil_db_traits::RepoIn
tranquil_db_traits::RepoInfo {
user_id: r.user_id,
repo_root_cid: r.repo_root_cid,
repo_rev: r.repo_rev,
repo_rev: r.repo_rev.map(Tid::from),
}
}
@@ -2481,7 +2481,7 @@ fn convert_repo_list_entry(
deactivated_at: r.deactivated_at,
takedown_ref: r.takedown_ref,
repo_root_cid: r.repo_root_cid,
repo_rev: r.repo_rev,
repo_rev: r.repo_rev.map(Tid::from),
})
}
@@ -6158,7 +6158,7 @@ mod tests {
did,
handle,
repo_root_cid: cid.clone(),
repo_rev: "rev1".to_string(),
repo_rev: Tid::from("rev1".to_string()),
tx,
}))
.unwrap();
@@ -6339,7 +6339,7 @@ mod tests {
did,
handle,
repo_root_cid: cid,
repo_rev: "rev1".to_string(),
repo_rev: Tid::from("rev1".to_string()),
tx,
}))
.unwrap();
@@ -28,7 +28,7 @@ use tranquil_db_traits::{
InviteCodeState, InviteCodeUse, NotificationHistoryRow, PlcTokenInfo, QueuedComms,
ReservedSigningKey, ReservedSigningKeyFull, ValidatedInviteCode,
};
use tranquil_types::{CidLink, Did, Handle};
use tranquil_types::{CidLink, Did, Handle, InviteCode};
pub struct InfraOps {
db: Database,
+4 -2
View File
@@ -465,8 +465,10 @@ mod tests {
encrypted_key_bytes: vec![7u8; 32],
encryption_version: 0,
reserved_key_id: None,
commit_cid: "bafyreib2rxk3ryblouj3fxza5jvx6psmwewwessc4m6g6e7pqhhkwqomfi".to_string(),
repo_rev: "rev0".to_string(),
commit_cid: tranquil_types::CidLink::from(
"bafyreib2rxk3ryblouj3fxza5jvx6psmwewwessc4m6g6e7pqhhkwqomfi".to_string(),
),
repo_rev: tranquil_types::Tid::from("rev0".to_string()),
genesis_block_cids: vec![],
invite_code: None,
birthdate_pref: None,
@@ -57,7 +57,7 @@ fn build_segments(segments_dir: &std::path::Path, n_events: u32) {
handle: None,
active: None,
status: None,
rev: Some(format!("rev{i}")),
rev: Some(tranquil_types::Tid::from(format!("rev{i}"))),
};
el.append_event(&did, RepoEventType::Commit, &event)
.unwrap();
+2 -2
View File
@@ -133,7 +133,7 @@ fn seed_events(store: &TestStore, count: u16) {
handle: None,
active: None,
status: None,
rev: Some(format!("rev{i}")),
rev: Some(tranquil_types::Tid::from(format!("rev{i}"))),
};
store
.eventlog
@@ -702,7 +702,7 @@ fn backup_during_concurrent_writes_produces_consistent_snapshot() {
handle: None,
active: None,
status: None,
rev: Some(format!("concurrent-{i}")),
rev: Some(tranquil_types::Tid::from(format!("concurrent-{i}"))),
};
let _ = el_clone.append_event(&did, tranquil_db_traits::RepoEventType::Commit, &event);
let _ = el_clone.sync();
@@ -222,12 +222,14 @@ fn payload_round_trip() {
ops: Some(
serde_json::json!([{"action": "create", "path": "app.bsky.feed.post/abc"}]),
),
blobs: Some(vec!["bafkreibtest".to_owned()]),
blobs: Some(vec![tranquil_types::CidLink::from(
"bafkreibtest".to_owned(),
)]),
blocks: None,
handle: None,
active: None,
status: None,
rev: Some("rev1".to_owned()),
rev: Some(tranquil_types::Tid::from("rev1".to_owned())),
},
),
(
@@ -66,7 +66,7 @@ fn make_commit_event(did: &Did, idx: u64) -> SequencedEvent {
handle: None,
active: None,
status: None,
rev: Some(format!("rev{idx}")),
rev: Some(tranquil_types::Tid::from(format!("rev{idx}"))),
}
}
@@ -495,7 +495,7 @@ fn sim_backup_during_concurrent_block_and_event_writes() {
handle: None,
active: None,
status: None,
rev: Some(format!("concurrent-{i}")),
rev: Some(tranquil_types::Tid::from(format!("concurrent-{i}"))),
};
let _ = stores
.eventlog
+1 -1
View File
@@ -44,7 +44,7 @@ fn append_seq(el: &EventLog<Arc<SimulatedIO>>, idx: u32) {
handle: None,
active: None,
status: None,
rev: Some(format!("rev{idx}")),
rev: Some(tranquil_types::Tid::from(format!("rev{idx}"))),
};
el.append_event(&did, RepoEventType::Commit, &event)
.unwrap();
+10 -10
View File
@@ -66,7 +66,7 @@ fn build_commit_event(
blobs: None,
blocks: None,
prev_data_cid: None,
rev: Some(rev.to_owned()),
rev: Some(tranquil_types::Tid::from(rev.to_owned())),
}
}
@@ -164,7 +164,7 @@ fn sim_apply_commit_crash_before_batch_commit_is_invisible() {
did: did.clone(),
expected_root_cid: Some(root_cid.clone()),
new_root_cid: new_cid.clone(),
new_rev: rev.to_owned(),
new_rev: tranquil_types::Tid::from(rev.to_owned()),
record_upserts: upserts,
record_deletes: vec![],
backlinks_to_add: vec![],
@@ -294,7 +294,7 @@ fn sim_apply_commit_atomicity_all_or_nothing() {
did: did.clone(),
expected_root_cid: Some(root_cid.clone()),
new_root_cid: new_cid.clone(),
new_rev: rev.to_owned(),
new_rev: tranquil_types::Tid::from(rev.to_owned()),
record_upserts: upserts,
record_deletes: vec![],
backlinks_to_add: backlinks,
@@ -387,7 +387,7 @@ fn sim_crash_recovery_cursor_tracks_last_durable_commit() {
did: did.clone(),
expected_root_cid: Some(prev_cid.clone()),
new_root_cid: new_cid.clone(),
new_rev: rev.to_owned(),
new_rev: tranquil_types::Tid::from(rev.to_owned()),
record_upserts: vec![RecordUpsert {
collection,
rkey,
@@ -533,7 +533,7 @@ fn sim_multi_commit_crash_cycle_consistency() {
did: did.clone(),
expected_root_cid: Some(current_cid.clone()),
new_root_cid: new_cid.clone(),
new_rev: rev.to_owned(),
new_rev: tranquil_types::Tid::from(rev.to_owned()),
record_upserts: upserts,
record_deletes: vec![],
backlinks_to_add: vec![],
@@ -657,7 +657,7 @@ fn sim_handler_pool_shutdown_with_inflight_commits() {
did: did.clone(),
expected_root_cid: Some(root_cid.clone()),
new_root_cid: new_cid.clone(),
new_rev: rev.to_owned(),
new_rev: tranquil_types::Tid::from(rev.to_owned()),
record_upserts: vec![RecordUpsert {
collection: collection_nsid(seed + i as u64),
rkey: test_rkey(idx),
@@ -781,7 +781,7 @@ fn sim_record_deletes_through_crash_recovery() {
did: did.clone(),
expected_root_cid: Some(root_cid.clone()),
new_root_cid: mid_cid.clone(),
new_rev: rev1.clone(),
new_rev: tranquil_types::Tid::from(rev1.clone()),
record_upserts: upserts,
record_deletes: vec![],
backlinks_to_add: vec![],
@@ -816,7 +816,7 @@ fn sim_record_deletes_through_crash_recovery() {
did: did.clone(),
expected_root_cid: Some(mid_cid.clone()),
new_root_cid: final_cid.clone(),
new_rev: rev2.clone(),
new_rev: tranquil_types::Tid::from(rev2.clone()),
record_upserts: vec![],
record_deletes: deletes,
backlinks_to_add: vec![],
@@ -941,7 +941,7 @@ fn sim_obsolete_block_cids_through_crash_recovery() {
did: did.clone(),
expected_root_cid: Some(root_cid.clone()),
new_root_cid: mid_cid.clone(),
new_rev: rev1.clone(),
new_rev: tranquil_types::Tid::from(rev1.clone()),
record_upserts: vec![RecordUpsert {
collection: collection_nsid(seed),
rkey: test_rkey(seed),
@@ -974,7 +974,7 @@ fn sim_obsolete_block_cids_through_crash_recovery() {
did: did.clone(),
expected_root_cid: Some(mid_cid.clone()),
new_root_cid: final_cid.clone(),
new_rev: rev2.clone(),
new_rev: tranquil_types::Tid::from(rev2.clone()),
record_upserts: vec![],
record_deletes: vec![],
backlinks_to_add: vec![],
@@ -459,7 +459,7 @@ fn append_n_events(el: &EventLog<RealIO>, n: u32) {
handle: None,
active: None,
status: None,
rev: Some(format!("rev{i}")),
rev: Some(tranquil_types::Tid::from(format!("rev{i}"))),
};
el.append_event(&did, RepoEventType::Commit, &event)
.unwrap();
+1 -1
View File
@@ -257,7 +257,7 @@ fn sim_soak_continuous_operations_with_crash_recovery() {
handle: None,
active: None,
status: None,
rev: Some(format!("soak-rev-{event_idx}")),
rev: Some(tranquil_types::Tid::from(format!("soak-rev-{event_idx}"))),
};
s.eventlog
.append_event(&did, RepoEventType::Commit, &event)
+6 -6
View File
@@ -11,7 +11,7 @@ use tracing::error;
use tranquil_pds::api::error::ApiError;
use tranquil_pds::state::AppState;
use tranquil_pds::sync::util::{RepoAccessLevel, assert_repo_availability};
use tranquil_types::{CidLink, Did};
use tranquil_types::{CidLink, Did, Tid};
#[derive(Deserialize)]
pub struct GetBlobParams {
@@ -69,8 +69,8 @@ pub struct ListBlobsParams {
#[derive(Serialize)]
pub struct ListBlobsOutput {
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
pub cids: Vec<String>,
pub cursor: Option<CidLink>,
pub cids: Vec<CidLink>,
}
pub async fn list_blobs(
@@ -91,11 +91,11 @@ pub async fn list_blobs(
let cursor_cid = params.cursor.as_deref().unwrap_or("");
let user_id = account.user_id;
let cids_result: Result<Vec<String>, _> = if let Some(since) = &params.since {
let cids_result: Result<Vec<CidLink>, _> = if let Some(since) = &params.since {
state
.repos
.blob
.list_blobs_since_rev(&did, since)
.list_blobs_since_rev(&did, &Tid::from(since.clone()))
.await
.map(|cids| {
let mut cid_strs: Vec<String> = cids.into_iter().map(|c| c.to_string()).collect();
@@ -118,7 +118,7 @@ pub async fn list_blobs(
Ok(cids) => {
let limit_usize = usize::try_from(limit).unwrap_or(0);
let has_more = cids.len() > limit_usize;
let cids: Vec<String> = cids.into_iter().take(limit_usize).collect();
let cids: Vec<CidLink> = cids.into_iter().take(limit_usize).collect();
let next_cursor = if has_more { cids.last().cloned() } else { None };
(
StatusCode::OK,
+5 -5
View File
@@ -16,13 +16,13 @@ use tranquil_pds::state::AppState;
use tranquil_pds::sync::util::{
RepoAccessLevel, assert_repo_availability, get_account_with_status,
};
use tranquil_types::Did;
use tranquil_types::{Did, Tid};
async fn get_rev_from_commit(state: &AppState, cid_str: &str) -> Option<String> {
async fn get_rev_from_commit(state: &AppState, cid_str: &str) -> Option<Tid> {
let cid = Cid::from_str(cid_str).ok()?;
let block = state.block_store.get(&cid).await.ok()??;
let commit = Commit::from_cbor(&block).ok()?;
Some(commit.rev().to_string())
Some(Tid::from(commit.rev().to_string()))
}
#[derive(Deserialize)]
@@ -33,7 +33,7 @@ pub struct GetLatestCommitParams {
#[derive(Serialize)]
pub struct GetLatestCommitOutput {
pub cid: String,
pub rev: String,
pub rev: Tid,
}
pub async fn get_latest_commit(
@@ -167,7 +167,7 @@ pub struct GetRepoStatusOutput {
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<AccountStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rev: Option<String>,
pub rev: Option<Tid>,
}
pub async fn get_repo_status(
+3 -3
View File
@@ -13,7 +13,7 @@ use tranquil_pds::scheduled::generate_repo_car_from_user_blocks;
use tranquil_pds::state::AppState;
use tranquil_pds::sync::car::{encode_car_block, encode_car_header};
use tranquil_pds::sync::util::{RepoAccessLevel, assert_repo_availability};
use tranquil_types::Did;
use tranquil_types::{Did, Tid};
struct GetBlocksParams {
did: Did,
@@ -139,7 +139,7 @@ pub async fn get_repo(
};
if let Some(since) = &query.since {
return get_repo_since(&state, &did, &head_cid, since).await;
return get_repo_since(&state, &did, &head_cid, &Tid::from(since.clone())).await;
}
let _permit = match state.repo_export_semaphore.try_acquire() {
@@ -179,7 +179,7 @@ pub async fn get_repo(
.into_response()
}
async fn get_repo_since(state: &AppState, did: &Did, head_cid: &Cid, since: &str) -> Response {
async fn get_repo_since(state: &AppState, did: &Did, head_cid: &Cid, since: &Tid) -> Response {
let user_id = match state.repos.user.get_id_by_did(did).await {
Ok(Some(id)) => id,
Ok(None) => {