@@ -14,6 +14,9 @@ use lazy_static::lazy_static;
1414use log:: { error, info} ;
1515use prometheus:: { register_counter, register_int_counter, Counter , IntCounter } ;
1616use tap_core:: signed_message:: Eip712SignedMessage ;
17+ #[ cfg( feature = "v2" ) ]
18+ use tap_graph:: v2:: { Receipt , ReceiptAggregateVoucher } ;
19+ #[ cfg( not( feature = "v2" ) ) ]
1720use tap_graph:: { Receipt , ReceiptAggregateVoucher , SignedReceipt } ;
1821use thegraph_core:: alloy:: {
1922 dyn_abi:: Eip712Domain , primitives:: Address , signers:: local:: PrivateKeySigner ,
@@ -159,13 +162,28 @@ fn aggregate_receipts_(
159162 }
160163
161164 let res = match api_version {
162- TapRpcApiVersion :: V0_0 => aggregator:: v1:: check_and_aggregate_receipts (
163- domain_separator,
164- & receipts,
165- previous_rav,
166- wallet,
167- accepted_addresses,
168- ) ,
165+ TapRpcApiVersion :: V0_0 => {
166+ #[ cfg( feature = "v2" ) ]
167+ {
168+ aggregator:: v2:: check_and_aggregate_receipts (
169+ domain_separator,
170+ & receipts,
171+ previous_rav,
172+ wallet,
173+ accepted_addresses,
174+ )
175+ }
176+ #[ cfg( not( feature = "v2" ) ) ]
177+ {
178+ aggregator:: v1:: check_and_aggregate_receipts (
179+ domain_separator,
180+ & receipts,
181+ previous_rav,
182+ wallet,
183+ accepted_addresses,
184+ )
185+ }
186+ }
169187 } ;
170188
171189 // Handle aggregation error
@@ -186,7 +204,8 @@ impl v1::tap_aggregator_server::TapAggregator for RpcImpl {
186204 request : Request < v1:: RavRequest > ,
187205 ) -> Result < Response < v1:: RavResponse > , Status > {
188206 let rav_request = request. into_inner ( ) ;
189- let receipts: Vec < SignedReceipt > = rav_request
207+
208+ let receipts: Vec < tap_graph:: SignedReceipt > = rav_request
190209 . receipts
191210 . into_iter ( )
192211 . map ( TryFrom :: try_from)
@@ -506,6 +525,9 @@ mod tests {
506525 use jsonrpsee:: { core:: client:: ClientT , http_client:: HttpClientBuilder , rpc_params} ;
507526 use rstest:: * ;
508527 use tap_core:: { signed_message:: Eip712SignedMessage , tap_eip712_domain} ;
528+ #[ cfg( feature = "v2" ) ]
529+ use tap_graph:: v2:: { Receipt , ReceiptAggregateVoucher } ;
530+ #[ cfg( not( feature = "v2" ) ) ]
509531 use tap_graph:: { Receipt , ReceiptAggregateVoucher } ;
510532 use thegraph_core:: alloy:: {
511533 dyn_abi:: Eip712Domain , primitives:: Address , signers:: local:: PrivateKeySigner ,
@@ -535,6 +557,21 @@ mod tests {
535557 ]
536558 }
537559
560+ #[ fixture]
561+ fn payer ( ) -> Address {
562+ Address :: from_str ( "0xabababababababababababababababababababab" ) . unwrap ( )
563+ }
564+
565+ #[ fixture]
566+ fn data_service ( ) -> Address {
567+ Address :: from_str ( "0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddead" ) . unwrap ( )
568+ }
569+
570+ #[ fixture]
571+ fn service_provider ( ) -> Address {
572+ Address :: from_str ( "0xbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef" ) . unwrap ( )
573+ }
574+
538575 #[ fixture]
539576 fn domain_separator ( ) -> Eip712Domain {
540577 tap_eip712_domain ( 1 , Address :: from ( [ 0x11u8 ; 20 ] ) )
@@ -602,6 +639,9 @@ mod tests {
602639 http_response_size_limit : u32 ,
603640 http_max_concurrent_connections : u32 ,
604641 allocation_ids : Vec < Address > ,
642+ payer : Address ,
643+ data_service : Address ,
644+ service_provider : Address ,
605645 #[ case] values : Vec < u128 > ,
606646 #[ values( "0.0" ) ] api_version : & str ,
607647 #[ values( 0 , 1 , 2 ) ] random_seed : u64 ,
@@ -643,6 +683,16 @@ mod tests {
643683 receipts. push (
644684 Eip712SignedMessage :: new (
645685 & domain_separator,
686+ #[ cfg( feature = "v2" ) ]
687+ Receipt :: new (
688+ allocation_ids[ 0 ] ,
689+ payer,
690+ data_service,
691+ service_provider,
692+ value,
693+ )
694+ . unwrap ( ) ,
695+ #[ cfg( not( feature = "v2" ) ) ]
646696 Receipt :: new ( allocation_ids[ 0 ] , value) . unwrap ( ) ,
647697 & all_wallets. choose ( & mut rng) . unwrap ( ) . wallet ,
648698 )
@@ -662,9 +712,25 @@ mod tests {
662712
663713 let remote_rav = res. data ;
664714
665- let local_rav =
666- ReceiptAggregateVoucher :: aggregate_receipts ( allocation_ids[ 0 ] , & receipts, None )
667- . unwrap ( ) ;
715+ let local_rav = {
716+ #[ cfg( feature = "v2" ) ]
717+ {
718+ ReceiptAggregateVoucher :: aggregate_receipts (
719+ allocation_ids[ 0 ] ,
720+ payer,
721+ data_service,
722+ service_provider,
723+ & receipts,
724+ None ,
725+ )
726+ . unwrap ( )
727+ }
728+ #[ cfg( not( feature = "v2" ) ) ]
729+ {
730+ ReceiptAggregateVoucher :: aggregate_receipts ( allocation_ids[ 0 ] , & receipts, None )
731+ . unwrap ( )
732+ }
733+ } ;
668734
669735 assert ! ( remote_rav. message. allocationId == local_rav. allocationId) ;
670736 assert ! ( remote_rav. message. timestampNs == local_rav. timestampNs) ;
@@ -685,6 +751,9 @@ mod tests {
685751 http_response_size_limit : u32 ,
686752 http_max_concurrent_connections : u32 ,
687753 allocation_ids : Vec < Address > ,
754+ payer : Address ,
755+ data_service : Address ,
756+ service_provider : Address ,
688757 #[ case] values : Vec < u128 > ,
689758 #[ values( "0.0" ) ] api_version : & str ,
690759 #[ values( 0 , 1 , 2 , 3 , 4 ) ] random_seed : u64 ,
@@ -726,6 +795,16 @@ mod tests {
726795 receipts. push (
727796 Eip712SignedMessage :: new (
728797 & domain_separator,
798+ #[ cfg( feature = "v2" ) ]
799+ Receipt :: new (
800+ allocation_ids[ 0 ] ,
801+ payer,
802+ data_service,
803+ service_provider,
804+ value,
805+ )
806+ . unwrap ( ) ,
807+ #[ cfg( not( feature = "v2" ) ) ]
729808 Receipt :: new ( allocation_ids[ 0 ] , value) . unwrap ( ) ,
730809 & all_wallets. choose ( & mut rng) . unwrap ( ) . wallet ,
731810 )
@@ -734,12 +813,29 @@ mod tests {
734813 }
735814
736815 // Create previous RAV from first half of receipts locally
737- let prev_rav = ReceiptAggregateVoucher :: aggregate_receipts (
738- allocation_ids[ 0 ] ,
739- & receipts[ 0 ..receipts. len ( ) / 2 ] ,
740- None ,
741- )
742- . unwrap ( ) ;
816+ let prev_rav = {
817+ #[ cfg( feature = "v2" ) ]
818+ {
819+ ReceiptAggregateVoucher :: aggregate_receipts (
820+ allocation_ids[ 0 ] ,
821+ payer,
822+ data_service,
823+ service_provider,
824+ & receipts[ 0 ..receipts. len ( ) / 2 ] ,
825+ None ,
826+ )
827+ . unwrap ( )
828+ }
829+ #[ cfg( not( feature = "v2" ) ) ]
830+ {
831+ ReceiptAggregateVoucher :: aggregate_receipts (
832+ allocation_ids[ 0 ] ,
833+ & receipts[ 0 ..receipts. len ( ) / 2 ] ,
834+ None ,
835+ )
836+ . unwrap ( )
837+ }
838+ } ;
743839 let signed_prev_rav = Eip712SignedMessage :: new (
744840 & domain_separator,
745841 prev_rav,
@@ -775,6 +871,9 @@ mod tests {
775871 http_response_size_limit : u32 ,
776872 http_max_concurrent_connections : u32 ,
777873 allocation_ids : Vec < Address > ,
874+ payer : Address ,
875+ data_service : Address ,
876+ service_provider : Address ,
778877 ) {
779878 // The keys that will be used to sign the new RAVs
780879 let keys_main = keys ( ) ;
@@ -801,6 +900,9 @@ mod tests {
801900 // Create receipts
802901 let receipts = vec ! [ Eip712SignedMessage :: new(
803902 & domain_separator,
903+ #[ cfg( feature = "v2" ) ]
904+ Receipt :: new( allocation_ids[ 0 ] , payer, data_service, service_provider, 42 ) . unwrap( ) ,
905+ #[ cfg( not( feature = "v2" ) ) ]
804906 Receipt :: new( allocation_ids[ 0 ] , 42 ) . unwrap( ) ,
805907 & keys_main. wallet,
806908 )
@@ -857,6 +959,9 @@ mod tests {
857959 http_response_size_limit : u32 ,
858960 http_max_concurrent_connections : u32 ,
859961 allocation_ids : Vec < Address > ,
962+ payer : Address ,
963+ data_service : Address ,
964+ service_provider : Address ,
860965 #[ values( "0.0" ) ] api_version : & str ,
861966 ) {
862967 // The keys that will be used to sign the new RAVs
@@ -869,6 +974,10 @@ mod tests {
869974 // Number of receipts that is just above the number that would fit within the
870975 // request size limit. This value is hard-coded here because it supports the
871976 // maximum number of receipts per aggregate value we wrote in the spec / docs.
977+ // Reduced for v2 receipts which are larger due to additional fields
978+ #[ cfg( feature = "v2" ) ]
979+ let number_of_receipts_to_exceed_limit = 200 ;
980+ #[ cfg( not( feature = "v2" ) ) ]
872981 let number_of_receipts_to_exceed_limit = 300 ;
873982
874983 // Start the JSON-RPC server.
@@ -896,6 +1005,16 @@ mod tests {
8961005 receipts. push (
8971006 Eip712SignedMessage :: new (
8981007 & domain_separator,
1008+ #[ cfg( feature = "v2" ) ]
1009+ Receipt :: new (
1010+ allocation_ids[ 0 ] ,
1011+ payer,
1012+ data_service,
1013+ service_provider,
1014+ u128:: MAX / 1000 ,
1015+ )
1016+ . unwrap ( ) ,
1017+ #[ cfg( not( feature = "v2" ) ) ]
8991018 Receipt :: new ( allocation_ids[ 0 ] , u128:: MAX / 1000 ) . unwrap ( ) ,
9001019 & keys_main. wallet ,
9011020 )
0 commit comments