@@ -11,6 +11,7 @@ use std::{
1111use anyhow:: Context ;
1212use bigdecimal:: { num_bigint:: ToBigInt , ToPrimitive } ;
1313use futures:: { stream, StreamExt } ;
14+ use indexer_allocation:: Allocation ;
1415use indexer_monitor:: { EscrowAccounts , SubgraphClient } ;
1516use indexer_query:: {
1617 closed_allocations:: { self , ClosedAllocations } ,
@@ -274,8 +275,9 @@ pub struct SenderAccountArgs {
274275 pub sender_id : Address ,
275276 /// Watcher that returns a list of escrow accounts for current indexer
276277 pub escrow_accounts : Receiver < EscrowAccounts > ,
277- /// Watcher that returns a set of open and recently closed allocation ids
278- pub indexer_allocations : Receiver < HashSet < AllocationId > > ,
278+ /// Raw watcher of open and recently closed allocations from Network Subgraph
279+ /// We normalize per-sender to the correct variant (Legacy/Horizon)
280+ pub indexer_allocations : Receiver < HashMap < Address , Allocation > > ,
279281 /// SubgraphClient of the escrow subgraph
280282 pub escrow_subgraph : & ' static SubgraphClient ,
281283 /// SubgraphClient of the network subgraph
@@ -828,16 +830,38 @@ impl Actor for SenderAccount {
828830 sender_type,
829831 } : Self :: Arguments ,
830832 ) -> Result < Self :: State , ActorProcessingErr > {
833+ // Normalize raw allocation addresses to the correct variant for this sender_type
831834 let myself_clone = myself. clone ( ) ;
832- watch_pipe ( indexer_allocations, move |allocation_ids| {
833- let allocation_ids = allocation_ids. clone ( ) ;
834- // Update the allocation_ids
835- myself_clone
836- . cast ( SenderAccountMessage :: UpdateAllocationIds ( allocation_ids) )
837- . unwrap_or_else ( |e| {
838- tracing:: error!( error=?e, "Error while updating allocation_ids" ) ;
839- } ) ;
840- async { }
835+ let sender_type_for_log = sender_type; // copy for move into closure
836+ watch_pipe ( indexer_allocations, move |alloc_map| {
837+ let raw_count = alloc_map. len ( ) ;
838+ // Extract addresses and normalize based on sender_type
839+ let normalized: HashSet < AllocationId > = alloc_map
840+ . keys ( )
841+ . cloned ( )
842+ . map ( |addr| match sender_type_for_log {
843+ SenderType :: Legacy => AllocationId :: Legacy ( AllocationIdCore :: from ( addr) ) ,
844+ SenderType :: Horizon => AllocationId :: Horizon ( CollectionId :: from ( addr) ) ,
845+ } )
846+ . collect ( ) ;
847+
848+ tracing:: info!(
849+ sender = %sender_id,
850+ ?sender_type_for_log,
851+ raw_count,
852+ normalized_count = normalized. len( ) ,
853+ "indexer_allocations update: normalizing allocations for sender_type" ,
854+ ) ;
855+
856+ // Forward normalized set to the actor to update allocations
857+ let myself = myself_clone. clone ( ) ;
858+ async move {
859+ myself
860+ . cast ( SenderAccountMessage :: UpdateAllocationIds ( normalized) )
861+ . unwrap_or_else ( |e| {
862+ tracing:: error!( error=?e, "Error while updating allocation_ids" ) ;
863+ } ) ;
864+ }
841865 } ) ;
842866
843867 let myself_clone = myself. clone ( ) ;
0 commit comments