@@ -2,6 +2,7 @@ use crate::utils::database::{execute_with_better_error, ArcDbPool};
22use ahash:: AHashMap ;
33use anyhow:: Result ;
44use aptos_indexer_processor_sdk:: {
5+ aptos_protos,
56 traits:: {
67 pollable_async_step:: PollableAsyncRunType , NamedStep , PollableAsyncStep , Processable ,
78 } ,
@@ -11,10 +12,18 @@ use aptos_indexer_processor_sdk::{
1112use async_trait:: async_trait;
1213use diesel:: { upsert:: excluded, ExpressionMethods } ;
1314use processor:: { db:: common:: models:: processor_status:: ProcessorStatus , schema:: processor_status} ;
15+ use std:: marker:: PhantomData ;
1416use tracing:: info;
1517
1618const UPDATE_PROCESSOR_STATUS_SECS : u64 = 1 ;
1719
20+ pub struct ProcessedBatch {
21+ pub start_version : u64 ,
22+ pub end_version : u64 ,
23+ pub start_transaction_timestamp : Option < aptos_protos:: util:: timestamp:: Timestamp > ,
24+ pub end_transaction_timestamp : Option < aptos_protos:: util:: timestamp:: Timestamp > ,
25+ }
26+
1827pub struct LatestVersionProcessedTracker < T >
1928where
2029 Self : Sized + Send + ' static ,
2534 // Next version to process that we expect.
2635 next_version : u64 ,
2736 // Last successful batch of sequentially processed transactions. Includes metadata to write to storage.
28- last_success_batch : Option < TransactionContext < T > > ,
37+ last_success_batch : Option < ProcessedBatch > ,
2938 // Tracks all the versions that have been processed out of order.
30- seen_versions : AHashMap < u64 , TransactionContext < T > > ,
39+ seen_versions : AHashMap < u64 , ProcessedBatch > ,
40+ _marker : PhantomData < T > ,
3141}
3242
3343impl < T > LatestVersionProcessedTracker < T >
@@ -42,10 +52,11 @@ where
4252 next_version : starting_version,
4353 last_success_batch : None ,
4454 seen_versions : AHashMap :: new ( ) ,
55+ _marker : PhantomData ,
4556 }
4657 }
4758
48- fn update_last_success_batch ( & mut self , current_batch : TransactionContext < T > ) {
59+ fn update_last_success_batch ( & mut self , current_batch : ProcessedBatch ) {
4960 let mut new_prev_batch = current_batch;
5061 // While there are batches in seen_versions that are in order, update the new_prev_batch to the next batch.
5162 while let Some ( next_version) = self . seen_versions . remove ( & ( new_prev_batch. end_version + 1 ) )
@@ -107,41 +118,33 @@ where
107118 & mut self ,
108119 current_batch : TransactionContext < T > ,
109120 ) -> Result < Option < TransactionContext < T > > , ProcessorError > {
110- // info!(
111- // start_version = current_batch.start_version,
112- // end_version = current_batch.end_version,
113- // step_name = self.name(),
114- // "Processing versions"
115- // );
116- // If there's a gap in the next_version and current_version, save the current_version to seen_versions for
117- // later processing.
118- if self . next_version != current_batch. start_version {
119- info ! (
120- expected_next_version = self . next_version,
121- step = self . name( ) ,
122- batch_version = current_batch. start_version,
123- "Gap detected" ,
124- ) ;
125- self . seen_versions
126- . insert ( current_batch. start_version , TransactionContext {
127- data : vec ! [ ] , // No data is needed for tracking. This is to avoid clone.
128- start_version : current_batch. start_version ,
129- end_version : current_batch. end_version ,
130- start_transaction_timestamp : current_batch. start_transaction_timestamp . clone ( ) ,
131- end_transaction_timestamp : current_batch. end_transaction_timestamp . clone ( ) ,
132- total_size_in_bytes : current_batch. total_size_in_bytes ,
121+ for context in current_batch. context . iter ( ) {
122+ // If there's a gap in the next_version and current_version, save the current_version to seen_versions for
123+ // later processing.
124+ if self . next_version != context. start_version {
125+ tracing:: debug!(
126+ next_version = self . next_version,
127+ step = self . name( ) ,
128+ "Gap detected starting from version: {}" ,
129+ context. start_version
130+ ) ;
131+ self . seen_versions
132+ . insert ( context. start_version , ProcessedBatch {
133+ start_version : context. start_version ,
134+ end_version : context. end_version ,
135+ start_transaction_timestamp : context. start_transaction_timestamp . clone ( ) ,
136+ end_transaction_timestamp : context. end_transaction_timestamp . clone ( ) ,
137+ } ) ;
138+ } else {
139+ tracing:: debug!( "No gap detected" ) ;
140+ // If the current_batch is the next expected version, update the last success batch
141+ self . update_last_success_batch ( ProcessedBatch {
142+ start_version : context. start_version ,
143+ end_version : context. end_version ,
144+ start_transaction_timestamp : context. start_transaction_timestamp . clone ( ) ,
145+ end_transaction_timestamp : context. end_transaction_timestamp . clone ( ) ,
133146 } ) ;
134- } else {
135- // info!("No gap detected");
136- // If the current_batch is the next expected version, update the last success batch
137- self . update_last_success_batch ( TransactionContext {
138- data : vec ! [ ] , // No data is needed for tracking. This is to avoid clone.
139- start_version : current_batch. start_version ,
140- end_version : current_batch. end_version ,
141- start_transaction_timestamp : current_batch. start_transaction_timestamp . clone ( ) ,
142- end_transaction_timestamp : current_batch. end_transaction_timestamp . clone ( ) ,
143- total_size_in_bytes : current_batch. total_size_in_bytes ,
144- } ) ;
147+ }
145148 }
146149 // Pass through
147150 Ok ( Some ( current_batch) )
0 commit comments