@@ -230,11 +230,35 @@ impl Indexer for TestIndexer {
230
230
res
231
231
} ;
232
232
233
- let account_data = account
233
+ let mut account_data: CompressedAccount = account
234
234
. ok_or ( IndexerError :: AccountNotFound ) ?
235
235
. clone ( )
236
236
. try_into ( ) ?;
237
237
238
+ // CRITICAL FIX: For V2 trees, if the account is found in the output queue by its leaf index,
239
+ // use the event hash from the queue instead of the calculated hash
240
+ // This ensures that the returned account hash matches what's in the output queue
241
+ if account_data. tree_info . tree_type == TreeType :: StateV2 {
242
+ println ! ( "using output queue" ) ;
243
+ if let Some ( merkle_tree) = self
244
+ . state_merkle_trees
245
+ . iter ( )
246
+ . find ( |t| t. accounts . merkle_tree == account_data. tree_info . tree )
247
+ {
248
+ println ! ( "found merkle tree" ) ;
249
+ if let Some ( ( event_hash, _) ) = merkle_tree
250
+ . output_queue_elements
251
+ . iter ( )
252
+ . find ( |( _, leaf_idx) | * leaf_idx == account_data. leaf_index as u64 )
253
+ {
254
+ println ! ( "found hash in output queue: {:?}" , event_hash) ;
255
+ // Found the account in output queue by leaf index - use the event hash
256
+ // This allows the account to be found in output queue for prove_by_index
257
+ account_data. hash = * event_hash;
258
+ }
259
+ }
260
+ }
261
+
238
262
Ok ( Response {
239
263
context : Context {
240
264
slot : self . get_current_slot ( ) ,
@@ -445,6 +469,7 @@ impl Indexer for TestIndexer {
445
469
new_addresses_with_trees : Vec < AddressWithTree > ,
446
470
_config : Option < IndexerRpcConfig > ,
447
471
) -> Result < Response < ValidityProofWithContext > , IndexerError > {
472
+ // DEBUG: Only print essential info
448
473
#[ cfg( feature = "v2" ) ]
449
474
{
450
475
// V2 implementation with queue handling
@@ -457,9 +482,11 @@ impl Indexer for TestIndexer {
457
482
let mut proof_inputs = vec ! [ ] ;
458
483
459
484
let mut indices_to_remove = Vec :: new ( ) ;
460
- // for all accounts in batched trees, check whether values are in tree or queue
485
+ // For all accounts in batched trees, check whether values are in tree or queue.
486
+
461
487
let compressed_accounts = if !hashes. is_empty ( ) && !state_merkle_tree_pubkeys. is_empty ( )
462
488
{
489
+ // Processing compressed accounts
463
490
let zipped_accounts = hashes. iter ( ) . zip ( state_merkle_tree_pubkeys. iter ( ) ) ;
464
491
465
492
for ( i, ( compressed_account, state_merkle_tree_pubkey) ) in
@@ -469,7 +496,7 @@ impl Indexer for TestIndexer {
469
496
x. accounts . merkle_tree == * state_merkle_tree_pubkey
470
497
&& x. tree_type == TreeType :: StateV2
471
498
} ) ;
472
-
499
+ // Check if account is in output queue
473
500
if let Some ( accounts) = accounts {
474
501
let queue_element = accounts
475
502
. output_queue_elements
@@ -481,6 +508,8 @@ impl Indexer for TestIndexer {
481
508
{
482
509
use light_client:: indexer:: RootIndex ;
483
510
511
+ // Account found in output queue - use prove_by_index
512
+
484
513
indices_to_remove. push ( i) ;
485
514
proof_inputs. push ( AccountProofInputs {
486
515
hash : * compressed_account,
@@ -500,8 +529,14 @@ impl Indexer for TestIndexer {
500
529
tree_type : accounts. tree_type ,
501
530
} ,
502
531
} )
532
+ } else {
533
+ // Account found but not in valid queue range
503
534
}
535
+ } else {
536
+ // Account not found in output queue - will need merkle proof
504
537
}
538
+ } else {
539
+ // No StateV2 tree found
505
540
}
506
541
}
507
542
@@ -512,15 +547,22 @@ impl Indexer for TestIndexer {
512
547
. map ( |( _, x) | * x)
513
548
. collect :: < Vec < [ u8 ; 32 ] > > ( ) ;
514
549
550
+ // Final compressed_accounts that need merkle proofs
551
+
515
552
if compress_accounts. is_empty ( ) {
516
553
None
517
554
} else {
518
555
Some ( compress_accounts)
519
556
}
520
557
} else {
558
+ println ! (
559
+ "No hashes or state_merkle_tree_pubkeys provided, skipping compressed_accounts computation."
560
+ ) ;
521
561
None
522
562
} ;
523
563
564
+ // Processing remaining accounts that need merkle proofs
565
+
524
566
// Get the basic validity proof if needed
525
567
let rpc_result: Option < ValidityProofWithContext > = if ( compressed_accounts. is_some ( )
526
568
&& !compressed_accounts. as_ref ( ) . unwrap ( ) . is_empty ( ) )
@@ -1920,6 +1962,7 @@ impl TestIndexer {
1920
1962
tree_types. push ( bundle. tree_type ) ;
1921
1963
println ! ( "merkle_tree {:?}" , merkle_tree) ;
1922
1964
println ! ( "account {:?}" , account) ;
1965
+ println ! ( "bundle {:?}" , bundle. accounts) ;
1923
1966
let leaf_index = merkle_tree. get_leaf_index ( account) . unwrap ( ) ;
1924
1967
let proof = merkle_tree. get_proof_of_leaf ( leaf_index, true ) . unwrap ( ) ;
1925
1968
0 commit comments