Skip to content

Commit bbed999

Browse files
committed
telemetry: address timestamp index PR review comments
1 parent 2856c6b commit bbed999

File tree

4 files changed

+12
-66
lines changed

4 files changed

+12
-66
lines changed

smartcontract/programs/doublezero-telemetry/src/processors/telemetry/write_device_latency_samples.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@ pub fn process_write_device_latency_samples(
164164
);
165165
}
166166

167-
// If a timestamp index account is provided (4th account after
167+
// If a timestamp index account is provided (after
168168
// latency_samples, agent, system_program), append an entry.
169-
if accounts.len() > 3 {
170-
let timestamp_index_account = &accounts[3];
169+
// Skip past system_program in the iterator first.
170+
let _ = next_account_info(accounts_iter);
171+
if let Ok(timestamp_index_account) = next_account_info(accounts_iter) {
171172
append_timestamp_index_entry(
172173
program_id,
173174
timestamp_index_account,

smartcontract/programs/doublezero-telemetry/src/processors/telemetry/write_internet_latency_samples.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,11 @@ pub fn process_write_internet_latency_samples(
162162
);
163163
}
164164

165-
// If a timestamp index account is provided (4th account after
165+
// If a timestamp index account is provided (after
166166
// latency_samples, agent, system_program), append an entry.
167-
if accounts.len() > 3 {
168-
let timestamp_index_account = &accounts[3];
167+
// Skip past system_program in the iterator first.
168+
let _ = next_account_info(accounts_iter);
169+
if let Ok(timestamp_index_account) = next_account_info(accounts_iter) {
169170
append_timestamp_index_entry(
170171
program_id,
171172
timestamp_index_account,

smartcontract/programs/doublezero-telemetry/src/state/timestamp_index.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use std::{
1111

1212
/// Maximum number of timestamp index entries per account.
1313
/// At one entry per write batch (up to 245 samples each), this comfortably
14-
/// covers a 48-hour epoch. Once full, appends are silently skipped.
14+
/// covers a 48-hour epoch. The cap prevents unbounded account growth (each
15+
/// entry is 12 bytes, so 10K entries ≈ 120KB on top of the header). The
16+
/// resize in the write path grows the account *up to* this limit; once
17+
/// full, appends are silently skipped so the parent write still succeeds.
1518
pub const MAX_TIMESTAMP_INDEX_ENTRIES: usize = 10_000;
1619

1720
/// Header size in bytes:

smartcontract/programs/doublezero-telemetry/tests/timestamp_index_tests.rs

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -244,65 +244,6 @@ async fn test_write_device_latency_samples_with_timestamp_index() {
244244
assert_eq!(ts_index.entries[1].timestamp_microseconds, t2);
245245
}
246246

247-
#[tokio::test]
248-
async fn test_write_device_latency_samples_without_timestamp_index_still_works() {
249-
let mut ledger = LedgerHelper::new().await.unwrap();
250-
251-
let payer_pubkey = ledger
252-
.context
253-
.lock()
254-
.unwrap()
255-
.payer
256-
.insecure_clone()
257-
.pubkey();
258-
let contributor_pk = ledger
259-
.serviceability
260-
.create_contributor("CONTRIB".to_string(), payer_pubkey)
261-
.await
262-
.unwrap();
263-
264-
let (agent, origin_device_pk, target_device_pk, link_pk) = ledger
265-
.seed_with_two_linked_devices(contributor_pk)
266-
.await
267-
.unwrap();
268-
269-
ledger.wait_for_new_blockhash().await.unwrap();
270-
271-
let latency_samples_pda = ledger
272-
.telemetry
273-
.initialize_device_latency_samples(
274-
&agent,
275-
origin_device_pk,
276-
target_device_pk,
277-
link_pk,
278-
1u64,
279-
5_000_000,
280-
)
281-
.await
282-
.unwrap();
283-
284-
// Write without timestamp index — should succeed as before.
285-
ledger
286-
.telemetry
287-
.write_device_latency_samples(
288-
&agent,
289-
latency_samples_pda,
290-
vec![1000, 1100],
291-
1_700_000_000_000_000,
292-
)
293-
.await
294-
.unwrap();
295-
296-
let account = ledger
297-
.get_account(latency_samples_pda)
298-
.await
299-
.unwrap()
300-
.expect("Samples account does not exist");
301-
let samples_data = DeviceLatencySamples::try_from(&account.data[..]).unwrap();
302-
assert_eq!(samples_data.header.next_sample_index, 2);
303-
assert_eq!(samples_data.samples, vec![1000, 1100]);
304-
}
305-
306247
#[tokio::test]
307248
async fn test_initialize_timestamp_index_fail_samples_account_does_not_exist() {
308249
let mut ledger = LedgerHelper::new().await.unwrap();

0 commit comments

Comments
 (0)