Skip to content

Commit 6789277

Browse files
author
Elrond
committed
test(buzz-db): pin 0065 upgrade target and raw-writer TTL no-refresh
Address Legolas review P2s on 050e593: - Run the 0064 -> 0065 upgrade test to 65, not latest, so later migrations cannot change what it covers. - Assert that a raw INSERT INTO events no longer refreshes an expired ephemeral-channel deadline after 0065, sharing the fixture with the push-retirement test's positive check. - Docs: the unsupported-writer consequence names TTL expiry too. Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
1 parent 050e593 commit 6789277

2 files changed

Lines changed: 60 additions & 35 deletions

File tree

‎crates/buzz-db/src/runtime/follow_up_retirement_tests.rs‎

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Upgrade contracts for the event follow-up trigger retirements: push
22
//! (0063), then channel TTL (0065).
33
use super::postgres_tests::{connect_test_pool, reset_public_schema};
4-
use super::{run_migrations, run_migrations_through};
4+
use super::run_migrations_through;
55
use sqlx::PgPool;
66

77
async fn ttl_definitions(pool: &PgPool) -> Vec<(String, String)> {
@@ -21,6 +21,51 @@ async fn push_trigger_count(pool: &PgPool) -> i64 {
2121
.expect("count push triggers")
2222
}
2323

24+
/// Insert a channel with an expired TTL deadline, then a raw `INSERT INTO
25+
/// events` on it that bypasses the application follow-up. Returns whether the
26+
/// database itself pushed the deadline forward.
27+
async fn raw_insert_refreshes_expired_ttl(pool: &PgPool, content: &str) -> bool {
28+
let community = uuid::Uuid::new_v4();
29+
let channel = uuid::Uuid::new_v4();
30+
sqlx::query("INSERT INTO communities (id, host) VALUES ($1, $2)")
31+
.bind(community)
32+
.bind(format!("retirement-{community}.example"))
33+
.execute(pool)
34+
.await
35+
.unwrap();
36+
sqlx::query(
37+
"INSERT INTO channels (id, community_id, name, created_by, ttl_seconds, ttl_deadline) \
38+
VALUES ($1, $2, 'ttl', $3, 60, clock_timestamp() - interval '1 day')",
39+
)
40+
.bind(channel)
41+
.bind(community)
42+
.bind([11_u8; 32])
43+
.execute(pool)
44+
.await
45+
.unwrap();
46+
sqlx::query(
47+
"INSERT INTO events (community_id, id, pubkey, created_at, kind, tags, content, sig, channel_id) \
48+
VALUES ($1, $2, $3, now(), 9, '[]', $4, $5, $6)",
49+
)
50+
.bind(community)
51+
.bind([12_u8; 32])
52+
.bind([11_u8; 32])
53+
.bind(content)
54+
.bind([13_u8; 64])
55+
.bind(channel)
56+
.execute(pool)
57+
.await
58+
.unwrap();
59+
sqlx::query_scalar(
60+
"SELECT ttl_deadline > clock_timestamp() FROM channels WHERE id=$1 AND community_id=$2",
61+
)
62+
.bind(channel)
63+
.bind(community)
64+
.fetch_one(pool)
65+
.await
66+
.unwrap()
67+
}
68+
2469
#[tokio::test]
2570
#[ignore = "requires Postgres"]
2671
async fn migration_schema_push_retirement_preserves_ttl_and_published_checksums() {
@@ -80,38 +125,8 @@ async fn migration_schema_push_retirement_preserves_ttl_and_published_checksums(
80125

81126
// A raw writer has no application TTL follow-up. The preserved deferred
82127
// trigger must still refresh its channel when the event commits.
83-
let community = uuid::Uuid::new_v4();
84-
let channel = uuid::Uuid::new_v4();
85-
sqlx::query("INSERT INTO communities (id, host) VALUES ($1, $2)")
86-
.bind(community)
87-
.bind(format!("retirement-{community}.example"))
88-
.execute(&pool)
89-
.await
90-
.unwrap();
91-
sqlx::query(
92-
"INSERT INTO channels (id, community_id, name, created_by, ttl_seconds, ttl_deadline) \
93-
VALUES ($1, $2, 'ttl', $3, 60, clock_timestamp() - interval '1 day')",
94-
)
95-
.bind(channel)
96-
.bind(community)
97-
.bind([11_u8; 32])
98-
.execute(&pool)
99-
.await
100-
.unwrap();
101-
sqlx::query("INSERT INTO events (community_id, id, pubkey, created_at, kind, tags, content, sig, channel_id) \
102-
VALUES ($1, $2, $3, now(), 9, '[]', 'TTL survives push retirement', $4, $5)")
103-
.bind(community).bind([12_u8; 32]).bind([11_u8; 32]).bind([13_u8; 64]).bind(channel)
104-
.execute(&pool).await.unwrap();
105-
let refreshed: bool = sqlx::query_scalar(
106-
"SELECT ttl_deadline > clock_timestamp() FROM channels WHERE id=$1 AND community_id=$2",
107-
)
108-
.bind(channel)
109-
.bind(community)
110-
.fetch_one(&pool)
111-
.await
112-
.unwrap();
113128
assert!(
114-
refreshed,
129+
raw_insert_refreshes_expired_ttl(&pool, "TTL survives push retirement").await,
115130
"raw inserts still refresh TTL after push retirement"
116131
);
117132
pool.close().await;
@@ -146,7 +161,9 @@ async fn migration_schema_ttl_retirement_drops_every_partition_trigger_and_keeps
146161
.await
147162
.unwrap();
148163

149-
run_migrations(&pool).await.expect("retire TTL trigger");
164+
run_migrations_through(&pool, 65)
165+
.await
166+
.expect("retire TTL trigger");
150167
assert!(
151168
ttl_definitions(&pool).await.is_empty(),
152169
"retired on parent and every partition"
@@ -160,5 +177,12 @@ async fn migration_schema_ttl_retirement_drops_every_partition_trigger_and_keeps
160177
.await
161178
.unwrap();
162179
assert_eq!(checksums_after, checksums_before);
180+
181+
// With both triggers gone, a raw writer that skips the application
182+
// follow-up no longer extends an ephemeral channel's deadline.
183+
assert!(
184+
!raw_insert_refreshes_expired_ttl(&pool, "TTL no longer refreshed by the database").await,
185+
"raw inserts must not refresh TTL after 0065"
186+
);
163187
pool.close().await;
164188
}

‎docs/push-gateway-deployment.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ Migration 0065 then retires `events_refresh_channel_ttl` and
243243
writers no longer refresh ephemeral-channel deadlines. Verify application
244244
enqueueing and flag-only rollback on the exact deployed candidate. Legacy images and raw SQL
245245
writers without the application producer are unsupported after this point:
246-
their messages may commit without producing notifications. Do not restore the
247-
trigger or downgrade an image as an urgent rollback step. Reintroducing legacy
246+
their messages may commit without producing notifications or extending
247+
ephemeral-channel deadlines (so those channels can expire early). Do not restore
248+
either trigger or downgrade an image as an urgent rollback step. Reintroducing legacy
248249
writer support requires a separate reviewed forward migration and compatibility
249250
plan; never edit published migrations or their checksums.
250251

0 commit comments

Comments
 (0)