@@ -21,12 +21,12 @@ use crate::{
21
21
} ;
22
22
23
23
const WAIT_TIME_BATCHES : u64 = 40 ;
24
- const NUM_RECEIPTS : u32 = 3 ;
24
+ const NUM_RECEIPTS : u32 = 30 ; // Increased to 30 receipts per batch
25
25
26
26
// Send receipts in batches with a delay in between
27
27
// to ensure some receipts get outside the timestamp buffer
28
- const BATCHES : u32 = 2 ;
29
- const MAX_TRIGGERS : usize = 100 ;
28
+ const BATCHES : u32 = 15 ; // Increased to 15 batches for total 450 receipts in Stage 1
29
+ const MAX_TRIGGERS : usize = 200 ; // Increased trigger attempts to 200
30
30
31
31
// Function to test the tap RAV generation
32
32
pub async fn test_tap_rav_v1 ( ) -> Result < ( ) > {
@@ -241,17 +241,23 @@ pub async fn test_tap_rav_v2() -> Result<()> {
241
241
"\n === V2 Initial metrics: RAVs created: {initial_ravs_created}, Unaggregated fees: {initial_unaggregated} ==="
242
242
) ;
243
243
244
+ // Calculate expected thresholds
245
+ let trigger_threshold = 2_000_000_000_000_000u128 ; // 0.002 GRT trigger value
246
+ let receipts_needed = trigger_threshold / ( MAX_RECEIPT_VALUE / 10 ) ; // Using trigger receipt value
247
+ println ! ( "📊 RAV trigger threshold: {trigger_threshold} wei (0.002 GRT)" , ) ;
248
+ let receipt_value = MAX_RECEIPT_VALUE / 10 ;
249
+ println ! (
250
+ "📊 Receipts needed for trigger: ~{receipts_needed} receipts at {receipt_value} wei each" ,
251
+ ) ;
252
+
244
253
println ! ( "\n === V2 STAGE 1: Sending large receipt batches with small pauses ===" ) ;
245
254
246
255
// Send multiple V2 receipts in two batches with a gap between them
247
256
let mut total_successful = 0 ;
248
257
249
258
for batch in 0 ..BATCHES {
250
- println ! (
251
- "Sending V2 batch {} of 2 with {} receipts each..." ,
252
- batch + 1 ,
253
- NUM_RECEIPTS
254
- ) ;
259
+ let batch = batch + 1 ;
260
+ println ! ( "Sending V2 batch {batch} of {BATCHES} with {NUM_RECEIPTS} receipts each..." , ) ;
255
261
256
262
for i in 0 ..NUM_RECEIPTS {
257
263
// Create V2 receipt
@@ -267,16 +273,17 @@ pub async fn test_tap_rav_v2() -> Result<()> {
267
273
268
274
let receipt_encoded = encode_v2_receipt ( & receipt) ?;
269
275
270
- let response = create_request (
271
- & http_client,
272
- & format ! ( "{INDEXER_URL}/subgraphs/id/{SUBGRAPH_ID}" ) ,
273
- & receipt_encoded,
274
- & json ! ( {
276
+ let response = http_client
277
+ . post ( format ! ( "{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}" ) )
278
+ . header ( "Content-Type" , "application/json" )
279
+ . header ( "Authorization" , format ! ( "Bearer {GATEWAY_API_KEY}" ) )
280
+ . header ( "Tap-Receipt" , receipt_encoded)
281
+ . json ( & json ! ( {
275
282
"query" : "{ _meta { block { number } } }"
276
- } ) ,
277
- )
278
- . send ( )
279
- . await ?;
283
+ } ) )
284
+ . timeout ( Duration :: from_secs ( 10 ) )
285
+ . send ( )
286
+ . await ?;
280
287
281
288
if response. status ( ) . is_success ( ) {
282
289
total_successful += 1 ;
@@ -298,15 +305,22 @@ pub async fn test_tap_rav_v2() -> Result<()> {
298
305
299
306
// Check metrics after batch
300
307
let batch_metrics = metrics_checker. get_current_metrics ( ) . await ?;
308
+ let current_unaggregated =
309
+ batch_metrics. unaggregated_fees_by_allocation ( & allocation_id. to_string ( ) ) ;
310
+ let trigger_threshold = 2_000_000_000_000_000u128 ;
311
+ let progress_pct =
312
+ ( current_unaggregated as f64 / trigger_threshold as f64 * 100.0 ) . min ( 100.0 ) ;
313
+
301
314
println ! (
302
- "After V2 batch {}: RAVs created: {}, Unaggregated fees: {}" ,
315
+ "After V2 batch {}: RAVs created: {}, Unaggregated fees: {} ({:.1}% of trigger threshold) " ,
303
316
batch + 1 ,
304
317
batch_metrics. ravs_created_by_allocation( & allocation_id. to_string( ) ) ,
305
- batch_metrics. unaggregated_fees_by_allocation( & allocation_id. to_string( ) )
318
+ current_unaggregated,
319
+ progress_pct
306
320
) ;
307
321
308
322
// Wait between batches - long enough for first batch to exit buffer
309
- if batch < 1 {
323
+ if batch < BATCHES - 1 {
310
324
println ! ( "Waiting for buffer period + 5s..." ) ;
311
325
tokio:: time:: sleep ( Duration :: from_secs ( WAIT_TIME_BATCHES ) ) . await ;
312
326
}
@@ -331,16 +345,17 @@ pub async fn test_tap_rav_v2() -> Result<()> {
331
345
332
346
let receipt_encoded = encode_v2_receipt ( & receipt) ?;
333
347
334
- let response = create_request (
335
- & http_client,
336
- & format ! ( "{INDEXER_URL}/subgraphs/id/{SUBGRAPH_ID}" ) ,
337
- & receipt_encoded,
338
- & json ! ( {
348
+ let response = http_client
349
+ . post ( format ! ( "{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}" ) )
350
+ . header ( "Content-Type" , "application/json" )
351
+ . header ( "Authorization" , format ! ( "Bearer {GATEWAY_API_KEY}" ) )
352
+ . header ( "Tap-Receipt" , receipt_encoded)
353
+ . json ( & json ! ( {
339
354
"query" : "{ _meta { block { number } } }"
340
- } ) ,
341
- )
342
- . send ( )
343
- . await ?;
355
+ } ) )
356
+ . timeout ( Duration :: from_secs ( 10 ) )
357
+ . send ( )
358
+ . await ?;
344
359
345
360
if response. status ( ) . is_success ( ) {
346
361
total_successful += 1 ;
@@ -361,11 +376,17 @@ pub async fn test_tap_rav_v2() -> Result<()> {
361
376
let current_unaggregated =
362
377
current_metrics. unaggregated_fees_by_allocation ( & allocation_id. to_string ( ) ) ;
363
378
379
+ // Calculate progress toward trigger threshold
380
+ let trigger_threshold = 2_000_000_000_000_000u128 ;
381
+ let progress_pct =
382
+ ( current_unaggregated as f64 / trigger_threshold as f64 * 100.0 ) . min ( 100.0 ) ;
383
+
364
384
println ! (
365
- "After V2 trigger {}: RAVs created: {}, Unaggregated fees: {}" ,
385
+ "After V2 trigger {}: RAVs created: {}, Unaggregated fees: {} ({:.1}% of trigger threshold) " ,
366
386
i + 1 ,
367
387
current_ravs_created,
368
- current_unaggregated
388
+ current_unaggregated,
389
+ progress_pct
369
390
) ;
370
391
371
392
// If we've succeeded, exit early
0 commit comments