mirror of
https://github.com/block/buzz.git
synced 2026-12-01 13:42:45 +00:00
Revert "feat(relay): support community-scoped NIP-AR artifacts" (#9689)
Reverts #9650 (squash commit `eebf62b6`), except for migration `0097` and the channel artifact sync fences it added. Community scope adds a relay access gate based on community admission rather than channel membership, a new relay-admin command kind (`9034`) and an operator-run key transition. Its design and NIP-AR text need relay maintainer review before they ship. Two integration gaps also remain: - Media download authorization looks up references only in `events`, so an attachment referenced only by a community artifact is unreadable when media-read enforcement is on. - User erasure retires a community head in the database without signaling live syncs, so members who are already syncing keep the erased copy. The feature can return as a new PR once those are resolved. ## Kept from #9650 - **Migration `0097`, byte for byte.** Published images already include it, and databases that auto-migrated have recorded it. Dropping it would stop those relays from starting. It only adds columns and indexes that the channel code ignores. The declared schema matches that expanded shape and keeps the `(community_id, artifact_id)` primary key, so the operator key transition no longer exists. - **Channel artifact sync fences.** Snapshot and live sends check for a pending resync and for connection cancellation under the queue lock. A reader who loses access, or whose content is redacted, while a frame is in flight therefore receives no further payload. Handler-backed tests cover a resync recorded while a snapshot payload waits for queue room and one recorded after a live head read. ## Compatibility This revert supports databases that applied only migration `0097`, which is all that auto-migration runs. A database that ran #9650's operator contract script, or was bootstrapped from #9650's declared schema, has no `(community_id, artifact_id)` key, so channel artifact writes fail there. Before deploying to such a database, check that `artifact_heads_pkey` is on `(community_id, artifact_id)` and that `artifact_heads` has no rows with `scope = 'community'`; if either check fails, it needs a separate recovery step. --------- Signed-off-by: Will Pfleger <wpfleger@block.xyz> Co-authored-by: Paul <4a1bfa0013bc6d14a8d600d8bf6392efefbd2a26ac3c96c9b2a106b0d12297ca@buzz.block.builderlab.xyz>
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
//! Compact community artifact invalidations; never signed event payloads.
|
||||
use buzz_core::{CommunityId, TenantContext};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Why a community artifact identity needs a fresh authorized head read.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ArtifactChange {
|
||||
/// A revision committed, including an artifact deletion revision.
|
||||
Changed,
|
||||
/// The current head was redacted; an exact copy must resync.
|
||||
Redacted,
|
||||
}
|
||||
|
||||
/// Bounded metadata for one immutable type and artifact identity.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ArtifactSignal {
|
||||
/// Scoped artifact identity.
|
||||
pub d: Uuid,
|
||||
/// Immutable artifact type.
|
||||
#[serde(rename = "type")]
|
||||
pub artifact_type: String,
|
||||
/// Change or current-head redaction.
|
||||
pub cause: ArtifactChange,
|
||||
}
|
||||
impl ArtifactSignal {
|
||||
pub(crate) fn decode(payload: &str) -> Result<Self, crate::PubSubError> {
|
||||
let signal: Self = serde_json::from_str(payload)?;
|
||||
buzz_core::artifact::validate_type(&signal.artifact_type)
|
||||
.map_err(|_| crate::PubSubError::InvalidChannelKey("invalid artifact type".into()))?;
|
||||
Ok(signal)
|
||||
}
|
||||
}
|
||||
|
||||
/// A signal bound to the server-resolved Redis topic's tenant.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ScopedArtifactSignal {
|
||||
/// Tenant from the topic, never from the payload.
|
||||
pub community_id: CommunityId,
|
||||
/// Compact change metadata.
|
||||
pub signal: ArtifactSignal,
|
||||
}
|
||||
|
||||
/// Publish compact metadata only on the dedicated tenant artifact topic.
|
||||
pub async fn publish(
|
||||
pool: &crate::RedisConnection,
|
||||
tenant: &TenantContext,
|
||||
signal: &ArtifactSignal,
|
||||
) -> Result<i64, crate::PubSubError> {
|
||||
let key = crate::EventTopicKey::from_context(tenant, crate::EventTopic::CommunityArtifact)
|
||||
.redis_channel();
|
||||
Ok(redis::cmd("PUBLISH")
|
||||
.arg(key)
|
||||
.arg(serde_json::to_string(signal)?)
|
||||
.query_async(&mut pool.clone())
|
||||
.await?)
|
||||
}
|
||||
@@ -21,8 +21,6 @@
|
||||
//! The shared [`RedisConnection`] handles all other commands.
|
||||
//! Lagged receivers get `RecvError::Lagged`.
|
||||
|
||||
/// Compact tenant-scoped artifact change signals.
|
||||
pub mod artifact_signal;
|
||||
/// Cross-pod cache-key invalidation over Redis pub/sub.
|
||||
pub mod cache_invalidation;
|
||||
/// Cross-pod connection-control commands over Redis pub/sub.
|
||||
@@ -139,7 +137,6 @@ pub struct PubSubManager {
|
||||
/// Coalesced wake-up: reconcile desired topics with the live Redis link.
|
||||
subscription_changed: Arc<Notify>,
|
||||
broadcast_tx: broadcast::Sender<ChannelEvent>,
|
||||
artifact_tx: broadcast::Sender<artifact_signal::ScopedArtifactSignal>,
|
||||
cache_invalidation_tx: broadcast::Sender<ScopedCacheInvalidation>,
|
||||
conn_control_tx: broadcast::Sender<ScopedConnControl>,
|
||||
nip_fi_disconnect_tx: broadcast::Sender<NipFiDisconnect>,
|
||||
@@ -158,7 +155,6 @@ impl PubSubManager {
|
||||
pool: crate::RedisConnection,
|
||||
) -> Result<Self, PubSubError> {
|
||||
let (broadcast_tx, _) = broadcast::channel(4096);
|
||||
let (artifact_tx, _) = broadcast::channel(4096);
|
||||
let (cache_invalidation_tx, _) = broadcast::channel(4096);
|
||||
let (conn_control_tx, _) = broadcast::channel(4096);
|
||||
let (nip_fi_disconnect_tx, _) = broadcast::channel(4096);
|
||||
@@ -173,7 +169,6 @@ impl PubSubManager {
|
||||
subscription_rx: Mutex::new(Some(subscription_rx)),
|
||||
subscription_changed: Arc::new(Notify::new()),
|
||||
broadcast_tx,
|
||||
artifact_tx,
|
||||
cache_invalidation_tx,
|
||||
conn_control_tx,
|
||||
nip_fi_disconnect_tx,
|
||||
@@ -194,7 +189,6 @@ impl PubSubManager {
|
||||
subscriber::run_subscriber(
|
||||
self.redis_url.clone(),
|
||||
self.broadcast_tx.clone(),
|
||||
self.artifact_tx.clone(),
|
||||
self.desired_topics.clone(),
|
||||
subscription_rx,
|
||||
self.subscription_changed.clone(),
|
||||
@@ -246,22 +240,6 @@ impl PubSubManager {
|
||||
self.broadcast_tx.subscribe()
|
||||
}
|
||||
|
||||
/// Receive compact signals from the same subscriber and loss epoch as events.
|
||||
pub fn subscribe_artifacts(
|
||||
&self,
|
||||
) -> broadcast::Receiver<artifact_signal::ScopedArtifactSignal> {
|
||||
self.artifact_tx.subscribe()
|
||||
}
|
||||
|
||||
/// Publish a compact artifact signal, without using ordinary event fan-out.
|
||||
pub async fn publish_artifact(
|
||||
&self,
|
||||
tenant: &TenantContext,
|
||||
signal: &artifact_signal::ArtifactSignal,
|
||||
) -> Result<i64, PubSubError> {
|
||||
artifact_signal::publish(&self.pool, tenant, signal).await
|
||||
}
|
||||
|
||||
/// Retain local interest in a scoped Redis event topic.
|
||||
///
|
||||
/// The first retain for a topic asks the subscriber task to `SUBSCRIBE`.
|
||||
@@ -538,7 +516,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::test_util::make_test_pool;
|
||||
use buzz_core::{CommunityId, TenantContext};
|
||||
use nostr::{EventBuilder, JsonUtil, Keys, Kind};
|
||||
use nostr::{EventBuilder, Keys, Kind};
|
||||
use uuid::Uuid;
|
||||
|
||||
async fn make_manager() -> Arc<PubSubManager> {
|
||||
@@ -561,8 +539,8 @@ mod tests {
|
||||
let mut rx = manager.subscribe_local();
|
||||
|
||||
let manager_clone = manager.clone();
|
||||
let subscriber = tokio::spawn(async move { manager_clone.run_subscriber().await });
|
||||
manager.link_state().wait_for(|link| link.up).await.unwrap();
|
||||
tokio::spawn(async move { manager_clone.run_subscriber().await });
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(200)).await;
|
||||
|
||||
let ctx = ctx(0xaaaa, "a.example");
|
||||
let channel_id = Uuid::new_v4();
|
||||
@@ -576,10 +554,6 @@ mod tests {
|
||||
manager
|
||||
.retain_topic(&ctx, EventTopic::Channel(channel_id))
|
||||
.await;
|
||||
manager
|
||||
.confirm_topic(&ctx, EventTopic::Channel(channel_id))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
manager
|
||||
.publish_event(&ctx, EventTopic::Channel(channel_id), &event)
|
||||
@@ -594,53 +568,6 @@ mod tests {
|
||||
assert_eq!(received.community_id, ctx.community());
|
||||
assert_eq!(received.topic, EventTopic::Channel(channel_id));
|
||||
assert_eq!(received.event.id, event_id);
|
||||
let mut signals = manager.subscribe_artifacts();
|
||||
manager
|
||||
.retain_topic(&ctx, EventTopic::CommunityArtifact)
|
||||
.await;
|
||||
let epoch = manager
|
||||
.confirm_topic(&ctx, EventTopic::CommunityArtifact)
|
||||
.await
|
||||
.unwrap();
|
||||
let signal = artifact_signal::ArtifactSignal {
|
||||
d: Uuid::new_v4(),
|
||||
artifact_type: "example.settings".into(),
|
||||
cause: artifact_signal::ArtifactChange::Changed,
|
||||
};
|
||||
manager.publish_artifact(&ctx, &signal).await.unwrap();
|
||||
let received = tokio::time::timeout(Duration::from_secs(2), signals.recv())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(received.community_id, ctx.community());
|
||||
assert_eq!(received.signal, signal);
|
||||
assert!(
|
||||
rx.try_recv().is_err(),
|
||||
"typed signal cannot enter ordinary event fan-out"
|
||||
);
|
||||
// A signed event on the signal topic is a decode loss, never a fake
|
||||
// signal. Existing epoch observers must resync their exact copies.
|
||||
let key = EventTopicKey::from_context(&ctx, EventTopic::CommunityArtifact).redis_channel();
|
||||
let mut link = manager.link_state();
|
||||
redis::cmd("PUBLISH")
|
||||
.arg(key)
|
||||
.arg(event.as_json())
|
||||
.query_async::<i64>(&mut manager.pool.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
tokio::time::timeout(
|
||||
Duration::from_secs(2),
|
||||
link.wait_for(|link| link.epoch != epoch),
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert!(signals.try_recv().is_err());
|
||||
assert!(rx.try_recv().is_err());
|
||||
manager
|
||||
.release_topic(&ctx, EventTopic::CommunityArtifact)
|
||||
.await;
|
||||
subscriber.abort();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -49,7 +49,6 @@ fn mark_loss(link: &watch::Sender<LinkState>, up: bool) {
|
||||
pub(crate) async fn run_subscriber(
|
||||
redis_url: String,
|
||||
broadcast_tx: broadcast::Sender<ChannelEvent>,
|
||||
artifact_tx: broadcast::Sender<crate::artifact_signal::ScopedArtifactSignal>,
|
||||
desired_topics: DesiredTopics,
|
||||
mut subscription_rx: mpsc::Receiver<SubscriptionCommand>,
|
||||
subscription_changed: Arc<Notify>,
|
||||
@@ -61,7 +60,6 @@ pub(crate) async fn run_subscriber(
|
||||
let result = connect_and_subscribe(
|
||||
&redis_url,
|
||||
&broadcast_tx,
|
||||
&artifact_tx,
|
||||
desired_topics.clone(),
|
||||
&mut subscription_rx,
|
||||
&subscription_changed,
|
||||
@@ -97,7 +95,6 @@ pub(crate) async fn run_subscriber(
|
||||
async fn connect_and_subscribe(
|
||||
redis_url: &str,
|
||||
broadcast_tx: &broadcast::Sender<ChannelEvent>,
|
||||
artifact_tx: &broadcast::Sender<crate::artifact_signal::ScopedArtifactSignal>,
|
||||
desired_topics: DesiredTopics,
|
||||
subscription_rx: &mut mpsc::Receiver<SubscriptionCommand>,
|
||||
subscription_changed: &Notify,
|
||||
@@ -190,18 +187,6 @@ async fn connect_and_subscribe(
|
||||
}
|
||||
};
|
||||
|
||||
if topic_key.topic == crate::EventTopic::CommunityArtifact {
|
||||
match crate::artifact_signal::ArtifactSignal::decode(&payload) {
|
||||
Ok(signal) => { let _ = artifact_tx.send(crate::artifact_signal::ScopedArtifactSignal {
|
||||
community_id: topic_key.community_id, signal,
|
||||
}); }
|
||||
Err(error) => {
|
||||
tracing::warn!(%error, "Invalid artifact signal");
|
||||
mark_loss(link, true);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let event = match nostr::Event::from_json(&payload) {
|
||||
Ok(e) => e,
|
||||
Err(e) => {
|
||||
|
||||
@@ -19,8 +19,6 @@ pub enum EventTopic {
|
||||
Channel(Uuid),
|
||||
/// Community-global events that are not exact-channel routed.
|
||||
Global,
|
||||
/// Compact artifact signals, isolated from ordinary event fan-out.
|
||||
CommunityArtifact,
|
||||
}
|
||||
|
||||
/// A fully qualified event topic, including its server-resolved community.
|
||||
@@ -48,9 +46,6 @@ impl EventTopicKey {
|
||||
format!("{BUZZ_PREFIX}:{}:channel:{channel_id}", self.community_id)
|
||||
}
|
||||
EventTopic::Global => format!("{BUZZ_PREFIX}:{}:global", self.community_id),
|
||||
EventTopic::CommunityArtifact => {
|
||||
format!("{BUZZ_PREFIX}:{}:artifacts", self.community_id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +71,6 @@ impl EventTopicKey {
|
||||
};
|
||||
|
||||
let topic = match scope {
|
||||
"artifacts" if parts.next().is_none() => EventTopic::CommunityArtifact,
|
||||
"global" => {
|
||||
if parts.next().is_some() {
|
||||
return Err(PubSubError::InvalidChannelKey(channel.to_string()));
|
||||
|
||||
Reference in New Issue
Block a user