@@ -720,7 +720,7 @@ impl<R: RpcConnection, I: Indexer<R>> EpochManager<R, I> {
720
720
& self ,
721
721
registration_info : & ForesterEpochInfo ,
722
722
tree_account : & TreeAccounts ,
723
- ) -> Result < bool > {
723
+ ) -> Result < ( ) > {
724
724
let mut rpc = self . rpc_pool . get_connection ( ) . await ?;
725
725
let current_slot = rpc. get_slot ( ) . await ?;
726
726
let forester_epoch_pda = rpc
@@ -754,7 +754,11 @@ impl<R: RpcConnection, I: Indexer<R>> EpochManager<R, I> {
754
754
"tree_schedule.slots[{}] = {:?}" ,
755
755
light_slot, tree_schedule. slots[ light_slot as usize ]
756
756
) ;
757
- Ok ( tree_schedule. is_eligible ( light_slot) )
757
+ if tree_schedule. is_eligible ( light_slot) {
758
+ Ok ( ( ) )
759
+ } else {
760
+ Err ( ForesterError :: NotEligible )
761
+ }
758
762
}
759
763
760
764
async fn process_transaction_batch_with_retry (
@@ -764,60 +768,68 @@ impl<R: RpcConnection, I: Indexer<R>> EpochManager<R, I> {
764
768
proof_chunk : & [ Proof ] ,
765
769
indexer_chunk : & [ WorkItem ] ,
766
770
) -> Result < Option < Signature > > {
767
- let first_work_item = indexer_chunk
771
+ let work_item = indexer_chunk
768
772
. first ( )
769
773
. ok_or_else ( || ForesterError :: Custom ( "Empty indexer chunk" . to_string ( ) ) ) ?;
770
774
debug ! (
771
775
"Processing work item {:?} with {} instructions" ,
772
- first_work_item . queue_item_data. hash,
776
+ work_item . queue_item_data. hash,
773
777
transaction_chunk. len( )
774
778
) ;
775
779
const BASE_RETRY_DELAY : Duration = Duration :: from_millis ( 100 ) ;
776
780
777
781
let mut retries = 0 ;
778
782
loop {
779
- if !self
780
- . check_eligibility ( epoch_info, & first_work_item. tree_account )
781
- . await ?
782
- {
783
- debug ! ( "Forester not eligible for this slot, skipping batch" ) ;
784
- return Ok ( None ) ;
785
- }
786
-
787
783
match self
788
- . process_transaction_batch (
789
- epoch_info,
790
- transaction_chunk,
791
- proof_chunk,
792
- indexer_chunk,
793
- )
784
+ . check_eligibility ( epoch_info, & work_item. tree_account )
794
785
. await
795
786
{
796
- Ok ( signature) => {
797
- debug ! (
798
- "Work item {:?} processed successfully. Signature: {:?}" ,
799
- first_work_item. queue_item_data. hash, signature
800
- ) ;
801
- self . increment_processed_items_count ( epoch_info. epoch . epoch )
802
- . await ;
803
- return Ok ( Some ( signature) ) ;
787
+ Ok ( _) => {
788
+ match self
789
+ . process_transaction_batch (
790
+ epoch_info,
791
+ transaction_chunk,
792
+ proof_chunk,
793
+ indexer_chunk,
794
+ )
795
+ . await
796
+ {
797
+ Ok ( signature) => {
798
+ debug ! (
799
+ "Work item {:?} processed successfully. Signature: {:?}" ,
800
+ work_item. queue_item_data. hash, signature
801
+ ) ;
802
+ self . increment_processed_items_count ( epoch_info. epoch . epoch )
803
+ . await ;
804
+ return Ok ( Some ( signature) ) ;
805
+ }
806
+ Err ( e) => {
807
+ if retries >= self . config . max_retries {
808
+ error ! (
809
+ "Max retries reached for work item {:?}. Error: {:?}" ,
810
+ work_item. queue_item_data. hash, e
811
+ ) ;
812
+ return Err ( e) ;
813
+ }
814
+ let delay = BASE_RETRY_DELAY
815
+ . saturating_mul ( 2u32 . saturating_pow ( retries as u32 ) ) ;
816
+ let jitter = rand:: thread_rng ( ) . gen_range ( 0 ..=50 ) ;
817
+ sleep ( delay + Duration :: from_millis ( jitter) ) . await ;
818
+ retries += 1 ;
819
+ warn ! (
820
+ "Retrying work item {:?}. Attempt {}/{}" ,
821
+ work_item. queue_item_data. hash, retries, self . config. max_retries
822
+ ) ;
823
+ }
824
+ }
825
+ }
826
+ Err ( ForesterError :: NotEligible ) => {
827
+ debug ! ( "Forester not eligible for this slot, skipping batch" ) ;
828
+ return Ok ( None ) ;
804
829
}
805
830
Err ( e) => {
806
- if retries >= self . config . max_retries {
807
- error ! (
808
- "Max retries reached for work item {:?}. Error: {:?}" ,
809
- first_work_item. queue_item_data. hash, e
810
- ) ;
811
- return Err ( e) ;
812
- }
813
- let delay = BASE_RETRY_DELAY * 2u32 . pow ( retries as u32 ) ;
814
- let jitter = rand:: thread_rng ( ) . gen_range ( 0 ..=50 ) ;
815
- sleep ( delay + Duration :: from_millis ( jitter) ) . await ;
816
- retries += 1 ;
817
- warn ! (
818
- "Retrying work item {:?}. Attempt {}/{}" ,
819
- first_work_item. queue_item_data. hash, retries, self . config. max_retries
820
- ) ;
831
+ error ! ( "Error checking eligibility: {:?}" , e) ;
832
+ return Err ( e) ;
821
833
}
822
834
}
823
835
}
0 commit comments